:root {
  --ink: #18201b;
  --muted: #657167;
  --paper: #f7f2e8;
  --panel: rgba(255, 252, 244, 0.88);
  --line: rgba(24, 32, 27, 0.14);
  --accent: #1f7a5a;
  --accent-dark: #13533d;
  --warm: #d88b42;
  --shadow: 0 24px 80px rgba(38, 43, 32, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(216, 139, 66, 0.24), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(31, 122, 90, 0.20), transparent 30rem),
    linear-gradient(135deg, #faf5ea 0%, #edf3e8 100%);
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1440px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

h1 {
  margin: 0;
  max-width: 820px;
  font-size: clamp(42px, 8vw, 82px);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.intro {
  max-width: 620px;
  margin-top: 18px;
  font-size: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
}

.brand {
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

button,
.download {
  border: 0;
  border-radius: 999px;
  padding: 16px 22px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

button:hover,
.download:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.download {
  background: var(--warm);
}

.hidden {
  display: none !important;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.login-topbar {
  position: fixed;
  top: 0;
  left: 50%;
  display: flex;
  height: 84px;
  align-items: center;
  justify-content: flex-end;
  padding: 18px 0 0;
  transform: translateX(-50%);
  pointer-events: none;
}

.login-brand {
  pointer-events: auto;
}

.login-card {
  position: relative;
  width: min(390px, 100%);
  border: 1px solid rgba(142, 93, 45, 0.20);
  border-radius: 28px;
  padding: 30px;
  background:
    radial-gradient(circle at top right, rgba(216, 139, 66, 0.16), transparent 38%),
    rgba(255, 252, 244, 0.86);
  box-shadow: 0 30px 80px rgba(38, 43, 32, 0.16);
}

.switch-account-button {
  position: absolute;
  top: 20px;
  right: 22px;
  padding: 6px 10px;
  border: 1px solid rgba(142, 93, 45, 0.18);
  border-radius: 999px;
  color: var(--accent-dark);
  background: rgba(255, 255, 255, 0.56);
  box-shadow: none;
  font-size: 12px;
  font-weight: 900;
}

.switch-account-button:hover {
  transform: translateY(-1px);
  background: rgba(216, 139, 66, 0.12);
}

.login-card h1 {
  margin: 0 0 18px;
  font-size: 30px;
}

.login-form {
  display: grid;
  align-content: center;
  gap: 10px;
}

.login-step-fields {
  display: grid;
  gap: 10px;
}

.login-form label {
  color: var(--accent-dark);
  font-weight: 900;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
  font-size: 15px;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 58px;
}

.password-field button {
  position: absolute;
  top: 50%;
  right: 8px;
  min-width: 42px;
  padding: 7px 10px;
  transform: translateY(-50%);
  border-radius: 12px;
  color: var(--accent-dark);
  background: rgba(216, 139, 66, 0.12);
  box-shadow: none;
}

.password-field button:hover {
  transform: translateY(-50%);
}

.login-message {
  min-height: 20px;
  color: #8f2f1f;
  font-size: 13px;
  font-weight: 800;
}

.privacy-hint {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.6;
}

.brand-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-menu-wrap {
  position: relative;
}

.user-menu-button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid rgba(142, 93, 45, 0.18);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 252, 244, 0.64);
  box-shadow: none;
}

.user-menu-button:hover {
  transform: translateY(-1px);
  background: rgba(216, 139, 66, 0.10);
}

.current-user {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.user-menu-caret {
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 900;
}

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 35;
  display: grid;
  gap: 4px;
  min-width: 136px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffaf0;
  box-shadow: 0 18px 44px rgba(24, 32, 27, 0.18);
}

.user-menu.hidden {
  display: none;
}

.user-menu button {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 12px;
  color: var(--ink);
  background: transparent;
  box-shadow: none;
  text-align: left;
}

.user-menu button:hover {
  transform: none;
  background: rgba(216, 139, 66, 0.12);
}

.ghost-button {
  border: 1px solid rgba(142, 93, 45, 0.24);
  color: var(--accent-dark);
  background: rgba(255, 252, 244, 0.74);
  box-shadow: none;
}

.main-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 252, 244, 0.72);
  box-shadow: 0 14px 38px rgba(38, 43, 32, 0.10);
}

.main-tab {
  background: transparent;
  color: var(--muted);
  padding: 13px 22px;
}

.main-tab:hover {
  color: #fff;
}

.main-tab.active {
  color: #fff;
  background: var(--ink);
}

.sub-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.sub-tab {
  color: var(--accent-dark);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.sub-tab.active {
  color: #fff;
  background: var(--accent);
}

.page-panel {
  display: none;
}

.page-panel.active {
  display: block;
}

.schedule-panel {
  display: none;
}

.schedule-panel.active {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 22px;
}

.sheet-card,
.log-card,
.result-card {
  min-height: 0;
  padding: 22px;
}

.full-card {
  min-height: calc(100vh - 158px);
}

.side-stack {
  display: grid;
  gap: 22px;
}

.side-stack .log-card,
.side-stack .result-card {
  min-height: 0;
}

.homeroom-card {
  min-height: 660px;
  padding: 24px;
}

.teacher-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: center;
  margin-top: 14px;
  border: 1px solid rgba(142, 93, 45, 0.18);
  border-radius: 18px;
  padding: 12px;
  background: rgba(255, 252, 244, 0.74);
}

.adjustment-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

.adjustment-toolbar label {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 900;
}

.adjustment-toolbar select {
  min-height: 40px;
  border: 1px solid rgba(142, 93, 45, 0.28);
  border-radius: 999px;
  padding: 8px 34px 8px 14px;
  color: var(--ink);
  background: rgba(255, 252, 244, 0.9);
  font-weight: 800;
}

.adjustment-hint {
  margin-top: 14px;
  border-radius: 14px;
  padding: 10px 12px;
  color: #386641;
  background: rgba(77, 140, 87, 0.12);
  border: 1px solid rgba(77, 140, 87, 0.28);
  font-size: 13px;
}

.adjustment-hint.failed {
  color: #8f2f1f;
  background: rgba(184, 68, 48, 0.10);
  border-color: rgba(184, 68, 48, 0.30);
}

.teacher-name {
  color: var(--muted);
  font-weight: 700;
}

.teacher-panel {
  display: none;
}

.teacher-panel.active {
  display: block;
}

#teacherStatsPanel {
  width: 100%;
}

.teacher-stats-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: center;
  margin-top: 14px;
  border: 1px solid rgba(142, 93, 45, 0.18);
  border-radius: 18px;
  padding: 12px;
  background: rgba(255, 252, 244, 0.74);
}

.teacher-toolbar label,
.teacher-stats-filters label {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 900;
}

.single-select-filter,
.multi-select-filter {
  position: relative;
  min-width: 220px;
}

.filter-select-button {
  position: relative;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 34px 9px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.88);
  font-weight: 760;
  text-align: left;
  box-shadow: none;
}

.filter-select-button::after {
  content: "▾";
  position: absolute;
  right: 12px;
  color: var(--muted);
}

.filter-select-button:hover {
  transform: none;
  color: var(--ink);
  background: #fff;
}

.filter-select-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  width: min(320px, 84vw);
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: #fffdf7;
  box-shadow: 0 18px 40px rgba(38, 43, 32, 0.16);
}

.single-select-filter.open .filter-select-menu,
.multi-select-filter.open .multi-select-menu {
  display: block;
}

.multi-select-filter.open .filter-select-menu {
  display: block;
}

.multi-select-clear,
.single-select-option,
.multi-select-option {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
  background: transparent;
  font-size: 13px;
  font-weight: 760;
  text-align: left;
}

.multi-select-clear {
  color: var(--accent-dark);
}

.multi-select-clear:hover,
.single-select-option:hover,
.multi-select-option:hover {
  transform: none;
  background: rgba(216, 139, 66, 0.12);
}

.single-select-option.selected {
  color: var(--accent-dark);
  background: rgba(31, 122, 90, 0.12);
  font-weight: 900;
}

.multi-select-option input {
  accent-color: var(--accent);
}

.teacher-stats-summary {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.teacher-stats-wrap {
  width: 100%;
  height: calc(100vh - 360px);
  min-height: 520px;
  max-height: none;
}

.teacher-stats-wrap table {
  min-width: 1540px;
}

.teacher-card .teacher-stats-wrap th {
  position: sticky;
  top: 0;
  z-index: 2;
  width: auto;
  min-width: 112px;
  height: 46px;
  color: var(--accent-dark);
  background: #f2eadb;
}

.teacher-sort-button {
  width: 100%;
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.teacher-sort-button:hover {
  color: var(--ink);
}

.teacher-card .teacher-stats-wrap td {
  width: auto;
  min-width: 112px;
  height: 46px;
}

.teacher-card .teacher-stats-wrap th:first-child,
.teacher-card .teacher-stats-wrap td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fff8ec;
  font-weight: 900;
}

.teacher-card .teacher-stats-wrap th:first-child {
  z-index: 4;
  background: #f2eadb;
}

.teacher-card .teacher-stats-conflict-row td {
  background: #fff1ec;
}

.teacher-card .teacher-stats-conflict-row td:first-child {
  background: #ffe7dc;
}

.teacher-conflict-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-top: 14px;
  border: 1px solid rgba(184, 68, 48, 0.30);
  border-radius: 14px;
  padding: 10px 12px;
  color: #8f2f1f;
  background: rgba(184, 68, 48, 0.10);
  font-size: 13px;
}

.teacher-conflict-summary strong {
  font-size: 14px;
}

.track-stale-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-top: 14px;
  border: 1px solid rgba(216, 139, 66, 0.34);
  border-radius: 14px;
  padding: 10px 12px;
  color: #8a4b12;
  background: rgba(216, 139, 66, 0.13);
  font-size: 13px;
}

.track-stale-summary strong {
  font-size: 14px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0 14px;
}

.tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.56);
  font-size: 13px;
  font-weight: 700;
}

.tab.active {
  color: #fff;
  background: var(--ink);
}

.tab:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.nested-tabs {
  margin-top: 8px;
}

.grid-wrap {
  overflow: auto;
  max-height: 300px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fffdf7;
}

.editable-grid-wrap {
  max-height: 430px;
}

.full-grid-wrap {
  max-height: calc(100vh - 306px);
  min-height: 520px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

td,
th {
  min-width: 110px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  white-space: nowrap;
}

.sheet-header-cell,
.sheet-header-row th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--muted);
  background: #f2eadb;
  font-weight: 800;
}

.row-index {
  position: sticky;
  top: auto;
  left: 0;
  width: 64px;
  min-width: 64px;
  max-width: 64px;
  z-index: 3;
  text-align: center;
  color: var(--muted);
  background: #f2eadb;
  font-weight: 800;
}

.corner-cell {
  position: sticky;
  top: 0 !important;
  left: 0 !important;
  z-index: 8;
}

.default-corner-cell {
  top: 0 !important;
  left: 0 !important;
  z-index: 8 !important;
}

.sheet-header-row .corner-cell {
  position: sticky !important;
  top: 0 !important;
  left: 0 !important;
}

.subject-header-row-1 .corner-cell {
  z-index: 9;
}

.merged-subject-hours {
  padding: 0;
  min-width: 220px;
}

.merged-subject-hours > span {
  display: block;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}

.subject-hour-types {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.subject-hour-types small {
  display: block;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.subject-hour-types small:first-child {
  border-right: 1px solid var(--line);
}

td {
  outline: none;
  background: rgba(255, 255, 255, 0.74);
}

td:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
}

td.header-cell {
  color: var(--accent-dark);
  background: rgba(31, 122, 90, 0.08);
  font-weight: 800;
}

#statusText {
  margin-bottom: 14px;
  color: var(--accent-dark);
  font-weight: 700;
}

.solve-summary {
  min-height: 132px;
  margin: 0;
  padding: 18px;
  border-radius: 20px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  line-height: 1.55;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(24, 32, 27, 0.38);
  backdrop-filter: blur(8px);
}

.modal.hidden {
  display: none;
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 26px;
  background: #fffaf0;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin-right: 42px;
}

.modal-card .solve-summary {
  margin: 18px 0;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: rgba(24, 32, 27, 0.08);
}

.password-form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.password-form label {
  color: var(--accent-dark);
  font-weight: 900;
}

.password-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
  font-size: 15px;
}

.password-message {
  min-height: 20px;
  color: #8f2f1f;
  font-size: 13px;
  font-weight: 800;
}

.password-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.context-menu {
  position: fixed;
  z-index: 30;
  display: grid;
  gap: 4px;
  min-width: 176px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffaf0;
  box-shadow: 0 18px 44px rgba(24, 32, 27, 0.18);
}

.context-menu.hidden {
  display: none;
}

.context-menu button {
  width: 100%;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.context-menu button:hover {
  color: #fff;
  background: var(--accent);
}

.context-menu button:disabled {
  color: var(--muted);
  background: transparent;
}

.solve-summary strong {
  display: inline-block;
  margin-bottom: 10px;
  font-size: 22px;
}

.solve-summary p {
  margin: 6px 0 0;
}

.solve-summary.success {
  border: 1px solid rgba(31, 122, 90, 0.28);
  background: rgba(31, 122, 90, 0.10);
}

.solve-summary.failed {
  border: 1px solid rgba(184, 68, 48, 0.30);
  background: rgba(184, 68, 48, 0.10);
}

.solve-summary.running {
  border: 1px solid rgba(216, 139, 66, 0.30);
  background: rgba(216, 139, 66, 0.12);
}

.result-grid-wrap {
  max-height: 330px;
}

.homeroom-grid-wrap {
  max-height: 620px;
}

.compact-tabs {
  margin-top: 14px;
}

.result-card td,
.result-card th {
  min-width: 96px;
  font-size: 13px;
}

.result-card th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--accent-dark);
  background: #f2eadb;
}

.result-card .result-first-column {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fff8ec;
  font-weight: 800;
}

.result-card th.result-first-column {
  z-index: 4;
  background: #f2eadb;
}

.result-card tr:first-child th {
  text-align: center;
}

.result-card tr td:not(:first-child) {
  text-align: center;
}

.result-card .result-day-start {
  border-left: 4px solid rgba(115, 74, 38, 0.58);
}

.result-card th.result-day-header {
  color: #5f3619;
  background: linear-gradient(180deg, #ead4af 0%, #f4e7cf 100%);
  font-weight: 900;
}

.homeroom-card td,
.homeroom-card th {
  min-width: 150px;
  height: 54px;
  text-align: center;
}

.homeroom-card td {
  white-space: pre-line;
  line-height: 1.45;
}

.homeroom-card td.course-color-cell {
  color: var(--ink);
  background: var(--course-bg);
  font-weight: 760;
}

.homeroom-card td.schedule-draggable-cell {
  cursor: grab;
}

.homeroom-card td.schedule-draggable-cell:active {
  cursor: grabbing;
}

.homeroom-card td.schedule-locked-cell {
  cursor: not-allowed;
}

.homeroom-card td.swap-allowed-cell {
  background: #d9f7d6;
  box-shadow: inset 0 0 0 3px rgba(47, 125, 69, 0.42);
}

.homeroom-card td.swap-blocked-cell {
  background: #ffe0dc;
  box-shadow: inset 0 0 0 3px rgba(184, 68, 48, 0.38);
}

.teacher-card td {
  white-space: pre-line;
  line-height: 1.45;
}

td.teacher-conflict-cell,
.teacher-card td.teacher-conflict-slot {
  color: #8f2f1f;
  background: #ffe2d8;
  box-shadow: inset 0 0 0 2px rgba(184, 68, 48, 0.34);
}

.homeroom-card tr th:first-child {
  min-width: 90px;
}

.empty-result {
  min-width: 280px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
}

@media (max-width: 920px) {
  .topbar,
  .action-card,
  .workspace {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .shell {
    width: min(100% - 20px, 720px);
    padding: 24px 0;
  }

  .main-tabs {
    width: 100%;
  }

  .login-page {
    place-items: center;
  }

  .login-topbar {
    height: 82px;
    padding: 24px 0 0;
  }

  .login-card {
    width: min(390px, 100%);
  }

  .teacher-stats-wrap {
    height: calc(100vh - 430px);
    min-height: 420px;
  }

  .brand {
    align-self: flex-end;
  }
}
