:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #66726c;
  --line: #d9e1dc;
  --paper: #f7f8f5;
  --surface: #ffffff;
  --green: #167a63;
  --green-dark: #0f5d4b;
  --green-soft: #e6f2ed;
  --red: #c64a36;
  --amber: #d99a2b;
  --shadow: 0 10px 28px rgba(23, 33, 29, 0.08);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: "Noto Sans SC", sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a, select, input[type="checkbox"] { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; }
[hidden] { display: none !important; }

.loading-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.spinner {
  width: 24px;
  height: 24px;
  margin: 0 auto 14px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.maintenance-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #fff;
  color: #1f2925;
}
.maintenance-page p {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
}

.public-shell { min-height: 100vh; }
.public-header {
  padding: 18px clamp(18px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--green); color: white; font-weight: 700; border-radius: 6px;
}
.brand-copy strong { display: block; font-size: 16px; }
.brand-copy span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.text-link { border: 0; background: none; color: var(--green-dark); font-weight: 600; }

.query-stage {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(36px, 8vw, 92px) 0 48px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  gap: clamp(32px, 7vw, 88px);
  align-items: start;
}
.query-intro { padding-top: 18px; }
.eyebrow {
  color: var(--green); font-family: "IBM Plex Mono", monospace;
  font-size: 12px; font-weight: 600; text-transform: uppercase;
}
.query-intro h1 { margin: 0 0 16px; font-size: clamp(34px, 5vw, 58px); line-height: 1.14; }
.query-intro .query-description { color: var(--muted); font-size: 17px; line-height: 1.8; max-width: 590px; margin: 1em 0; }
.query-description a { color: #1769aa; text-decoration: underline; text-underline-offset: 2px; }
.query-description a:hover { color: #0f4f83; }
.query-meta { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 32px; color: var(--muted); font-size: 13px; }
.query-meta span { display: inline-flex; align-items: center; gap: 7px; }

.query-panel, .login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 28px;
}
.panel-title { margin: 0 0 22px; font-size: 20px; }
.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field label { font-size: 13px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; border: 1px solid #cbd5cf;
  border-radius: 5px; background: white; padding: 10px 12px; color: var(--ink);
}
.field textarea { min-height: 104px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(22,122,99,.18); border-color: var(--green);
}
.field-help { color: var(--muted); font-size: 12px; }
.btn {
  min-height: 42px; border: 1px solid transparent; border-radius: 5px;
  padding: 0 16px; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; font-weight: 600; text-decoration: none;
}
.btn-primary { background: var(--green); color: white; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: white; color: var(--ink); border-color: var(--line); }
.btn-danger { background: #fff3f0; color: var(--red); border-color: #efd0c8; }
.btn-block { width: 100%; }
.icon-btn {
  width: 38px; height: 38px; border: 1px solid var(--line);
  border-radius: 5px; background: white; display: grid; place-items: center;
}
.notice-band {
  border-top: 1px solid var(--line);
  min-height: 88px;
  padding: 24px max(20px, calc((100% - 1068px) / 2));
  color: var(--muted); font-size: 16px; line-height: 1.75;
  display: flex;
  align-items: center;
}
.notice-band > span { width: 100%; }
.schedule-page.has-fixed-notice {
  padding-bottom: calc(var(--schedule-notice-height, 88px) + 18px);
}
.schedule-notice {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 14;
  min-height: 88px;
  max-height: 30vh;
  overflow-y: auto;
  box-shadow: 0 -4px 18px rgba(23,33,29,.08);
}

.schedule-page { width: 100%; min-width: 0; overflow-x: clip; }
.schedule-toolbar {
  position: sticky; top: 0; z-index: 8; background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line); padding: 8px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.schedule-title { min-width: 0; flex: 1; }
.schedule-title strong {
  display: block;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.schedule-title span { color: var(--muted); font-size: 11px; }
.schedule-toolbar .icon-btn { width: 34px; height: 34px; }
.schedule-toolbar .btn { min-height: 34px; padding: 0 11px; font-size: 13px; }
.schedule-wrap {
  width: 100%;
  max-width: 100vw;
  padding: 24px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}
.schedule-canvas {
  position: relative;
  width: max(100%, 820px);
  min-width: 820px;
}
.schedule-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 46px repeat(7, minmax(104px, 1fr));
  grid-template-rows: 52px repeat(12, 70px);
  border: 1px solid var(--line); background: white; position: relative;
}
.grid-head, .period-cell {
  display: grid; place-items: center; font-weight: 600; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.grid-head { background: #fbfcfa; z-index: 3; }
.grid-head:first-child, .period-cell {
  position: sticky;
  left: 0;
}
.grid-head:first-child { z-index: 5; }
.period-cell {
  color: var(--muted);
  background: white;
  font-family: "IBM Plex Mono", monospace;
  z-index: 3;
}
.grid-slot { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.course-block {
  z-index: 2; min-width: 0; margin: 4px; padding: 8px 6px; border-radius: 5px;
  color: white; font-weight: 600; font-size: 13px; line-height: 1.45;
  display: flex; align-items: center; justify-content: center; text-align: center;
  overflow: hidden; overflow-wrap: anywhere;
  box-shadow: 0 4px 12px rgba(23,33,29,.12); border: 1px solid rgba(255,255,255,.45);
}
.watermark-layer {
  position: absolute; inset: 52px 0 0 46px; pointer-events: none; z-index: 4;
  overflow: hidden; color: var(--green); font-weight: 700; white-space: pre;
  text-align: center;
}
.modal-mask {
  position: fixed; inset: 0; z-index: 30; background: rgba(14,24,20,.54);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(520px, 100%); max-height: 88vh; overflow: auto;
  background: white; border-radius: 8px; box-shadow: 0 24px 70px rgba(0,0,0,.22); padding: 24px;
}
.modal img { max-width: 100%; max-height: 240px; object-fit: contain; display: block; margin: 0 auto 16px; }
.modal h2 { margin: 0 0 12px; }
.modal p { color: var(--muted); line-height: 1.7; white-space: pre-wrap; }
.popup-content { display: block; color: inherit; text-decoration: none; }
.popup-content[href]:hover h2 { color: var(--green-dark); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.floating-widget {
  position: fixed; bottom: 22px; z-index: 20; width: min(300px, calc(100vw - 32px));
  background: white; border: 1px solid var(--line); box-shadow: var(--shadow);
  border-radius: 7px; padding: 14px; display: grid; grid-template-columns: 58px 1fr auto; gap: 12px;
}
.floating-widget.right { right: 18px; }
.floating-widget.left { left: 18px; }
.schedule-page.has-fixed-notice .floating-widget {
  bottom: calc(var(--schedule-notice-height, 88px) + 14px);
}
.floating-widget img { width: 58px; height: 58px; object-fit: cover; border-radius: 4px; }
.floating-widget strong { display: block; font-size: 14px; }
.floating-widget span { color: var(--muted); font-size: 12px; line-height: 1.5; }
.floating-content {
  grid-column: 1 / 3;
  min-width: 0;
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}
.floating-content[href]:hover strong { color: var(--green-dark); }

.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(280px, .8fr) minmax(420px, 1.2fr); }
.auth-aside {
  background: var(--ink); color: white; padding: clamp(32px, 6vw, 72px);
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth-aside h1 { margin: 24px 0 14px; font-size: clamp(32px, 4vw, 50px); }
.auth-aside p { color: #b9c6bf; line-height: 1.8; }
.auth-main { display: grid; place-items: center; padding: 28px; }
.login-panel { width: min(430px, 100%); }
.error-banner { background: #fff1ee; color: #9f3424; border: 1px solid #efc7bf; border-radius: 5px; padding: 10px 12px; margin-bottom: 16px; font-size: 13px; }

.school-select-page { min-height: 100vh; padding: clamp(28px, 6vw, 72px); }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 34px; }
.page-header h1 { margin: 5px 0 0; font-size: 30px; }
.school-list { width: min(860px, 100%); display: grid; gap: 10px; }
.school-row {
  background: white; border: 1px solid var(--line); border-radius: 6px;
  padding: 18px; display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 14px;
}
.school-row .brand-mark { width: 44px; height: 44px; }
.school-row p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0,1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--ink); color: white;
  padding: 20px 14px; display: flex; flex-direction: column;
}
.sidebar .brand { padding: 4px 8px 20px; }
.sidebar .brand-copy span { color: #aebbb4; }
.nav-list { display: grid; gap: 4px; margin-top: 14px; }
.nav-item {
  border: 0; color: #cbd5cf; background: transparent; min-height: 42px;
  border-radius: 5px; padding: 0 12px; display: flex; align-items: center; gap: 10px; text-align: left;
}
.nav-item:hover, .nav-item.active { color: white; background: rgba(255,255,255,.1); }
.sidebar-bottom { margin-top: auto; border-top: 1px solid rgba(255,255,255,.14); padding-top: 14px; }
.admin-main { min-width: 0; }
.admin-topbar {
  min-height: 66px; background: white; border-bottom: 1px solid var(--line);
  padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.current-school { display: flex; align-items: center; gap: 10px; }
.current-school span { color: var(--muted); font-size: 12px; display: block; }
.admin-content { padding: 24px; }
.content-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 20px; }
.content-heading h1 { margin: 0; font-size: 26px; }
.content-heading p { margin: 5px 0 0; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: white; border: 1px solid var(--line); border-radius: 6px; padding: 18px;
}
.stat span { color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin-top: 10px; font: 600 28px "IBM Plex Mono", monospace; }
.workspace-panel {
  margin-top: 18px; background: white; border: 1px solid var(--line);
  border-radius: 6px; padding: 20px;
}
.toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.toolbar-group { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.status {
  display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px;
  border-radius: 999px; font-size: 12px; font-weight: 600;
}
.status.published, .status.active { color: var(--green-dark); background: var(--green-soft); }
.status.draft { color: #8a5a00; background: #fff2d7; }
.status.archived, .status.frozen { color: var(--muted); background: #edf0ee; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 600; background: #fafbf9; }
.empty { color: var(--muted); padding: 40px 18px; text-align: center; border: 1px dashed var(--line); border-radius: 5px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch-row input { width: 18px; height: 18px; accent-color: var(--green); }
.config-section { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 20px; }
.config-section h3 { margin: 0 0 14px; }
.file-drop {
  border: 1px dashed #aebbb4; border-radius: 6px; padding: 34px; text-align: center;
  background: #fafbf9;
}
.file-drop input { max-width: 100%; }
.import-preview { margin-top: 18px; }
.code-note { font: 500 12px/1.7 "IBM Plex Mono", monospace; color: var(--muted); background: #f0f3f1; padding: 12px; border-radius: 4px; overflow-wrap: anywhere; }
.toast {
  position: fixed; right: 18px; top: 18px; z-index: 100; max-width: 380px;
  background: var(--ink); color: white; border-radius: 5px; padding: 12px 16px; box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .query-stage { grid-template-columns: 1fr; padding-top: 34px; }
  .query-intro h1 { font-size: 38px; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-aside { min-height: 250px; }
  .admin-shell { grid-template-columns: 72px minmax(0,1fr); }
  .sidebar .brand-copy, .nav-item span, .sidebar-bottom span { display: none; }
  .sidebar .brand { justify-content: center; padding-inline: 0; }
  .nav-item { justify-content: center; padding: 0; }
  .admin-content, .admin-topbar { padding-inline: 14px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(120px,1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .page-header { align-items: flex-start; }
  .schedule-toolbar {
    padding: 6px 8px;
    gap: 7px;
    align-items: center;
    flex-wrap: nowrap;
  }
  .schedule-toolbar .icon-btn { flex: 0 0 32px; width: 32px; height: 32px; }
  .schedule-title { flex: 1 1 auto; }
  .schedule-title strong { font-size: 13px; line-height: 1.3; }
  .schedule-title span { display: block; margin-top: 1px; font-size: 10px; }
  .schedule-toolbar .btn { flex: 0 0 auto; min-height: 32px; padding: 0 8px; font-size: 12px; }
  .schedule-wrap {
    padding: 12px 0 16px;
    overflow-x: hidden;
    overscroll-behavior-inline: auto;
  }
  .schedule-canvas { width: 100%; min-width: 0; }
  .schedule-grid {
    grid-template-columns: 34px repeat(7, minmax(0, 1fr));
    grid-template-rows: 42px repeat(12, 62px);
  }
  .watermark-layer { inset: 42px 0 0 34px; }
  .course-block {
    margin: 2px;
    padding: 4px 2px;
    font-size: 11px;
    line-height: 1.3;
    word-break: break-all;
  }
  .grid-head, .period-cell { font-size: 12px; }
  .notice-band { min-height: 104px; padding: 24px 18px; }
  .schedule-notice { min-height: 96px; padding: 16px 14px; }
  .floating-widget { bottom: 14px; }
}

@media (max-width: 480px) {
  .schedule-grid {
    grid-template-columns: 26px repeat(7, minmax(0, 1fr));
    grid-template-rows: 38px repeat(12, 58px);
  }
  .watermark-layer { inset: 38px 0 0 26px; }
  .grid-head, .period-cell { font-size: 11px; }
  .course-block {
    margin: 1px;
    padding: 3px 1px;
    border-radius: 3px;
    font-size: 10px;
    line-height: 1.25;
    box-shadow: 0 2px 6px rgba(23,33,29,.1);
  }
}
