:root {
  --ink: #1e293b;
  --ink-soft: #64748b;
  --paper: #f3f5f8;
  --paper-2: #eef1f6;
  --rule: #e2e8f0;
  --stamp: #0f172a;
  --blue: #16a34a;
  --blue-soft: #dcfce7;
  --moss: #16a34a;
  --gold: #16a34a;
  --forest: #15803d;
  --cream: #ffffff;
  --accent: #16a34a;
  --accent-soft: #dcfce7;
  --warn: #e11d48;
  --sand: #d4b896;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --sidebar: 248px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body::before {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.25s ease;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: #fff;
  color: #334155;
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 22px;
  z-index: 20;
  overflow: hidden;
  transition: transform 0.25s ease;
}

body.sidebar-collapsed .app {
  grid-template-columns: 0 1fr;
}

body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
}

.brand strong {
  display: block;
  letter-spacing: 0.04em;
  font-size: 16px;
  color: #0f172a;
}

.brand small {
  color: #94a3b8;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.nav button {
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.nav button:hover {
  background: #f1f5f9;
}

.nav button.active {
  background: #eff6ff;
  color: #2563eb;
  box-shadow: inset 3px 0 0 #2563eb;
}

.nav button[hidden],
[data-login][hidden],
[data-logout][hidden] {
  display: none !important;
}

.sidebar-foot {
  margin-top: auto;
  flex-shrink: 0;
  display: grid;
  gap: 8px;
}

.sidebar-foot .btn,
.sidebar-foot .ghost {
  width: 100%;
}

.sidebar-foot .ghost {
  color: #475569;
  border-color: var(--rule);
}

.account-name {
  margin: 0 0 4px;
  color: #94a3b8;
  font-size: 13px;
}

.auth-wrap {
  display: grid;
  gap: 18px;
  max-width: 480px;
}

.auth-card {
  padding: 22px;
  display: grid;
  gap: 12px;
}

.checks {
  display: grid;
  gap: 6px;
}

.checks span {
  font-weight: 700;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
}

.scope-box {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--rule);
  border-radius: 12px;
}

.scope-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.main {
  padding: 22px 28px 72px;
  position: relative;
  z-index: 1;
  background: var(--paper);
}

.topbar-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.topbar-account {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding-top: 6px;
}

.topbar-account span {
  color: var(--ink-soft);
  font-size: 14px;
  white-space: nowrap;
}

.topbar-account .btn,
.topbar-account .ghost {
  white-space: nowrap;
}

.lead {
  margin: 6px 0 0;
  color: var(--ink-soft);
}

.sync {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.cell.locked {
  cursor: default;
}

.cell.locked:hover {
  background: #f8fafc !important;
}

.app .school-grid thead th.col-readonly,
.app .school-grid .day-class-head th.col-readonly {
  background: #f1f5f9;
  color: var(--ink-soft);
}

.app .school-grid td.cell.locked {
  background: #f8fafc;
}

.menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  background: #fff;
  color: #334155;
  border: 1px solid var(--rule);
  border-radius: 10px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.sidebar .menu-btn {
  background: #f8fafc;
  color: #334155;
  width: 36px;
  height: 36px;
}

.topbar .menu-btn {
  margin-bottom: 10px;
}

.view {
  margin-top: 28px;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.card,
.panel {
  background: var(--cream);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  padding: 18px 20px;
}

.card span {
  color: var(--ink-soft);
  font-size: 13px;
}

.card strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
  font-family: Inter, "Segoe UI", sans-serif;
}

.toolbar,
.form-row,
.lesson-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}

.modal .lesson-form {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 14px;
}

.modal .lesson-form .field {
  min-width: 0;
  width: 100%;
}

.toolbar {
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
  flex: 1;
}

.field[hidden],
.checks[hidden],
.scope-box[hidden],
[hidden] {
  display: none !important;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .field-wide {
  grid-column: 1 / -1;
}

@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.field label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: #334155;
}

.subject-picks {
  display: grid;
  gap: 6px;
  max-height: 160px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: #fff;
  min-width: 220px;
}

.subject-picks label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  margin: 0;
}

input,
select,
textarea {
  background: #f8fafc;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
}

.class-homeroom {
  min-width: 180px;
  max-width: 260px;
  width: 100%;
}

.btn,
.ghost,
.danger {
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 700;
}

.btn {
  background: var(--accent);
  color: #fff;
}

.btn:hover {
  background: var(--forest);
}

.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--rule);
}

.sidebar .ghost {
  background: #fff;
  color: #334155;
  border-color: var(--rule);
}

.sidebar .btn {
  background: var(--accent);
  color: #fff;
  border: 0;
}

.danger {
  background: #fff;
  color: var(--warn);
  border: 1px solid #fecdd3;
}

.icon-btn {
  background: transparent;
  border: 0;
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  color: #94a3b8;
}

.app table {
  width: 100%;
  border-collapse: collapse;
  background: var(--cream);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.app th,
.app td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}

.app th {
  background: #f8fafc;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: none;
  color: #334155;
  font-weight: 700;
}

.sheet {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
}

.kind-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.kind-tab {
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.kind-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.hour-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin: 0 0 12px;
  padding: 12px 16px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hour-total {
  font-size: 15px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.hour-total strong {
  color: var(--ink);
  font-size: 20px;
}

.hour-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.hour-chip {
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.hour-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.teacher-grid {
  min-width: 720px;
}

.schedule-wrap {
  overflow: auto;
  background: #fff;
  padding: 4px 8px 12px;
}

.schedule {
  min-width: 920px;
  width: 100%;
}

.school-grid {
  min-width: 1180px;
  border-collapse: collapse;
  background: #fff;
  box-shadow: none;
  border-radius: 0;
}

.app .school-grid th,
.app .school-grid td {
  border: 1px solid #edf1f5;
  text-align: center;
  vertical-align: middle;
  padding: 8px 6px;
  background: #fff;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.app .school-grid thead th,
.app .school-grid .day-class-head th {
  background: #f8fafc;
  color: #0f172a;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.app .school-grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
}

.app .school-grid .day-head,
.app .school-grid .day-cell {
  position: sticky;
  left: 0;
  z-index: 4;
  width: 36px;
  min-width: 36px;
  max-width: 36px;
  background: #f8fafc;
  padding: 8px 4px;
}

.app .school-grid .num-cell,
.app .school-grid thead th:nth-child(2) {
  position: sticky;
  left: 36px;
  z-index: 2;
  width: 44px;
  background: #f8fafc;
}

.app .school-grid .bell-cell,
.app .school-grid thead th:nth-child(3) {
  position: sticky;
  left: 80px;
  z-index: 2;
  min-width: 108px;
  white-space: nowrap;
  background: #f8fafc;
  font-variant-numeric: tabular-nums;
}

.app .school-grid thead th:nth-child(1),
.app .school-grid thead th:nth-child(2),
.app .school-grid thead th:nth-child(3) {
  z-index: 5;
}

.app .school-grid tfoot td,
.app .school-grid tfoot th {
  background: #f1f5f9;
  font-weight: 700;
  color: #0f172a;
}

.app .school-grid .homeroom-foot td,
.app .school-grid .homeroom-foot th {
  position: sticky;
  bottom: 0;
  z-index: 4;
  white-space: nowrap;
}

.day-cell span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.18em;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.app .school-grid .slot-text[draggable="true"] {
  cursor: grab;
}

.app .school-grid .slot-text.dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.app .school-grid td.cell.drag-over {
  background: var(--blue-soft) !important;
  outline: 2px dashed var(--blue);
  outline-offset: -2px;
}

.cell {
  min-width: 188px;
  cursor: pointer;
  position: relative;
  vertical-align: top;
  text-align: left;
}

.app .school-grid td.cell {
  text-align: left;
  background: #fafbfc;
  padding: 6px;
}

.slot-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 72px;
}

.cell:hover {
  background: #f4f7fb !important;
}

.empty-slot {
  color: #94a3b8;
  font-weight: 500;
}

.slot-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-weight: 500;
  background: #f3f5f8;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px 12px 10px;
  color: var(--ink);
}

.slot-text:hover {
  border-color: #d1d5db;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

.slot-time,
.slot-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #64748b;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

.slot-text b {
  font-size: 13.5px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.3;
}

.slot-ico {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.slot-missing {
  color: #e11d48;
}

.slot-text small {
  font-weight: 500;
  color: #64748b;
  font-size: 12px;
}

.slot-text.conflict,
td.cell:has(.conflict) {
  color: var(--ink);
}

.slot-text.conflict {
  background: #fef2f2;
  border-color: #fecaca;
}

.conflict {
  outline: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  font-size: 12px;
  font-weight: 700;
}

.teacher-subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.alert {
  background: #fef2f2;
  color: var(--ink);
  border: 1px solid #fecaca;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.kind-tag {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.02em;
  text-transform: none;
  font-weight: 700;
  color: #64748b;
  width: fit-content;
}

.slot-text.kind-extra {
  background: #eff6ff;
}

.slot-text.kind-home {
  background: #f8fafc;
}

.slot-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.slot-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--rule);
  border-radius: 10px;
  font-size: 13px;
}

.slot-item span:last-child {
  display: flex;
  gap: 6px;
}

.modal {
  width: min(560px, 100%);
  background: var(--cream);
  border-radius: 16px;
  padding: 22px 24px 24px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
}

.form-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 4px;
  color: #7c8aa0;
  font-size: 13px;
  line-height: 1.4;
}

.hint-ico {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  font-style: normal;
}

.lesson-time-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: #334155;
  font-size: 14px;
  font-weight: 600;
}

.time-box {
  display: inline-flex;
  align-items: center;
  min-width: 92px;
  background: #f8fafc;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 8px 10px;
  color: #0f172a;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.time-mins {
  color: #94a3b8;
  font-weight: 500;
}

.req {
  color: #e11d48;
  font-weight: 700;
}

.modal .lesson-form select,
.modal .lesson-form input:not([type="hidden"]) {
  background: #f8fafc;
}

.lesson-form {
  margin-top: 12px;
}

.modal .actions .btn {
  min-width: 120px;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  width: 100%;
  margin-top: 8px;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  white-space: nowrap;
}

.row-actions .ghost,
.row-actions .danger {
  padding: 6px 10px;
  font-size: 13px;
}

.empty {
  padding: 40px;
  text-align: center;
  color: var(--ink-soft);
}

.color-swatch {
  width: 100%;
  height: 38px;
  border: 0;
  padding: 0;
  background: transparent;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    width: min(280px, 86vw);
  }

  .sidebar.open {
    transform: none;
  }

  body.sidebar-collapsed .app {
    grid-template-columns: 1fr;
  }

  body.sidebar-collapsed .sidebar {
    transform: translateX(-105%);
  }

  body.sidebar-collapsed .sidebar.open {
    transform: none;
  }

  .grid-cards {
    grid-template-columns: 1fr 1fr;
  }

  .main {
    padding: 20px 16px 80px;
  }

  .topbar-main {
    flex-direction: column;
  }
}

@media print {
  body::before,
  .sidebar,
  .toolbar,
  .menu-btn,
  .topbar .lead,
  .topbar-account {
    display: none !important;
  }

  .app {
    display: block;
  }

  .main {
    padding: 0;
  }

  .sheet,
  .schedule-wrap,
  table {
    box-shadow: none;
    border-radius: 0;
  }

  .school-grid {
    min-width: 0;
  }

  .teacher-grid {
    min-width: 0;
  }

  .app .school-grid .day-head,
  .app .school-grid .day-cell,
  .app .school-grid .num-cell,
  .app .school-grid .bell-cell,
  .app .school-grid thead th {
    position: static;
  }

  .slot-text {
    box-shadow: none !important;
    padding: 4px 6px;
    gap: 2px;
  }

  .slot-ico {
    display: none;
  }
}
