:root {
  --ink: #182126;
  --muted: #506977;
  --line: #d8e0e3;
  --panel: #ffffff;
  --bg: #eef3f1;
  --accent: #176b5d;
  --accent-strong: #0f4f45;
  --warn: #b35c00;
  --danger: #b63c45;
  --info: #245a9b;
  --soft-green: #dcebe5;
  --soft-blue: #e0e8f5;
  --soft-yellow: #f5ecd7;
  --shadow: 0 12px 30px rgba(28, 43, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  color: var(--ink);
  background: var(--bg);
  font-family: "Yu Gothic", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: #132823;
  color: white;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: #102520;
  background: #9ed8c6;
  font-weight: 800;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  color: #dce8e4;
  background: transparent;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  color: white;
  background: rgba(255, 255, 255, 0.12);
}

.main {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  margin: 0 0 4px;
}

h1 {
  font-size: 32px;
  font-weight: 800;
  margin: 0;
}

.primary-action {
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  min-height: 40px;
  color: white;
  background: var(--accent);
  font-weight: 700;
}

.secondary-action {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  min-height: 40px;
  color: var(--ink);
  background: white;
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view[hidden] {
  display: none !important;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.panel-heading h2 {
  font-size: 18px;
  margin: 0;
}

.lesson-card {
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.cancelled {
  opacity: 0.5;
  color: gray;
}

.card-title {
  font-weight: 800;
}

.card-meta {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  background: var(--soft-green);
}

.timetable {
  display: grid;
  grid-template-columns: 96px repeat(5, minmax(150px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: auto;
}

.tt-cell {
  min-height: 104px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px;
}

.tt-cell.header,
.tt-cell.period {
  background: #f7faf9;
  font-weight: 800;
  color: var(--muted);
  display: grid;
  place-items: center;


}

.dialog-form {
  display: grid;
  gap: 12px;
  padding: 22px;
}

.dialog-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.dialog-form input,
.dialog-form select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

#lessonName,
#editLessonName {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
  line-height: 1.5;
}

.button-row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.period-row {
  display: grid;
  grid-template-columns: 60px 1fr 1fr;
  align-items: center;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.empty-message {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 40px 0;
}

/* Mobile optimized layout */
@media (max-width: 760px) {

  html,
  body {
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
    background: #edf6ff;
  }

  .app-shell {
    display: block;
    min-width: 0;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: block;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    background: #ffffff;
    color: #738492;
    border-top: 1px solid #dce7ef;
    box-shadow: 0 -8px 24px rgba(22, 41, 54, 0.08);
  }

  .brand {
    display: none;

  }

  .nav-list {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2px;
    overflow: visible;
  }

  .nav-item {
    width: auto;
    min-width: 0;
    border-radius: 8px;
    padding: 8px 2px;
    color: #7b8c99;
    background: transparent;
    text-align: center;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
  }

  .nav-item.active,
  .nav-item:hover {
    color: #2f80dc;
    background: transparent;
  }

  .main {
    width: 100%;
    min-width: 0;
    padding: 18px 6px 86px;
    background: #edf6ff;
  }

  .topbar {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 0 14px;
    min-height: 54px;
    text-align: center;
  }

  .eyebrow {
    margin: 0 0 4px;
    color: #657b8a;
    font-size: 15px;
    font-weight: 800;
    text-transform: none;
  }

  h1 {
    font-size: 28px;
    line-height: 1.15;
    color: #142431;
  }

  .dashboard,
  .change-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .panel {
    padding: 16px;
    border-radius: 12px;
  }

  .toolbar,
  .button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .primary-action,
  .secondary-action {
    min-height: 42px;
    padding: 0 14px;
    white-space: nowrap;
  }

  textarea {
    width: 100%;
    min-height: 160px;
  }

  #lessonName,
  #editLessonName {
    min-height: 64px;
  }

  #timetable .toolbar {
    display: none;
  }

  #timetable {
    margin-inline: -4px;
  }

  .timetable {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 30px repeat(5, minmax(0, 1fr));
    gap: 8px 2px;
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }

  .tt-cell {
    min-width: 0;
    min-height: 104px;
    border: 0;
    padding: 0;
    overflow: hidden;
    background: transparent;
  }

  .tt-cell.header {
    min-height: 50px;
    display: grid;
    place-items: center;
    color: #647887;
    background: #ffffff;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 900;
    line-height: 1.2;
    text-align: center;
  }

  .tt-cell.header small {
    display: block;
    margin-top: 3px;
    color: #7f909c;
    font-size: 10px;
    font-weight: 800;
  }

  .tt-cell.period {
    min-height: 104px;
    display: grid;
    place-items: center;
    color: #647887;
    background: transparent;
    font-size: 22px;
    font-weight: 900;
    line-height: 1.15;
    text-align: center;
  }

  .tt-cell.period small {
    display: block;
    margin-top: 8px;
    color: #6c7f8d;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.35;
    white-space: normal;
  }

  .tt-cell:not(.header):not(.period) {
    min-height: 104px;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: none;
  }

  .tt-stack {
    height: 100%;
    display: grid;
    gap: 4px;
    padding: 2px;
  }

  .lesson-card {
    position: relative;
    display: grid;
    place-items: center;
    min-width: 0;
    height: 100%;
    min-height: 92px;
    padding: 10px 4px 30px;
    border: 0;
    border-radius: 12px;
    background: #bdd8f6;
    overflow: hidden;
  }

  .lesson-card>div {
    width: 100%;
    height: 100%;
    display: grid !important;
    place-items: center;
  }

  .lesson-info {
    display: grid;
    place-items: center;
    gap: 0;
    min-width: 0;
    width: 100%;
    height: 100%;
    padding-bottom: 4px;
  }

  .lesson-card div {
    min-width: 0;
  }

  .lesson-name {
    display: block;
    min-width: 0;
    width: 100%;
    overflow: hidden;
    color: #24333d;
    font-size: 15px;
    font-weight: 950;
    line-height: 1.18;
    text-align: center;
    white-space: pre;
    overflow-wrap: normal;
    word-break: keep-all;
    text-shadow: 0.2px 0 currentColor;
  }

  .lesson-name-text {
    display: block;
    width: 100%;
    text-align: center;
    white-space: pre;
  }

  .lesson-name.fit-name-one-line {
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    -webkit-line-clamp: unset;
  }

  .lesson-name.fit-name-one-line .lesson-name-text {
    display: block;
    min-width: max-content;
    max-width: none;
    width: auto;
    text-align: center;
    white-space: nowrap;
    transform: scaleX(var(--name-scale, 1));
    transform-origin: center;
  }

  .lesson-room {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0;
    height: 22px;
    max-width: 100%;
    overflow: hidden;
    border-radius: 0 0 12px 12px;
    padding: 2px 5px;
    color: #647887;
    background: #ffffff;
    font-size: 13px;
    font-weight: 900;
    line-height: 1.3;
    text-align: center;
    text-overflow: clip;
    white-space: nowrap;
  }

  .lesson-room.fit-room-one-line {
    overflow: hidden;
    text-overflow: clip;
  }

  .lesson-room-text {
    display: block;
    min-width: max-content;
    max-width: none;
    overflow: visible;
    white-space: nowrap;
    transform: scaleX(var(--room-scale, 1));
    transform-origin: center;
  }

  .lesson-room.room-code-one-line {
    letter-spacing: 0;
    white-space: nowrap;
    word-break: keep-all;
  }

  .lesson-card button {
    display: none;
  }

  .card-title {
    font-size: 12px;
  }

  .card-meta {
    font-size: 11px;
  }

  .period-row {
    grid-template-columns: 54px 1fr 1fr;
    gap: 8px;
  }

  dialog {
    width: calc(100vw - 28px);
    max-width: 460px;
  }

  dialog form,
  .dialog-form {
    padding: 18px;
  }
}
