/* ==========================================================================
   知时课表 · Teacher Timetable PWA — Core Design System (Vanilla CSS)
   Aesthetic: Warm Campus Editorial · Crisp, Calm, Glanceable
   ========================================================================== */

:root {
  /* Surfaces */
  --bg-canvas: hsl(40, 33%, 97%);
  --bg-surface: hsl(0, 0%, 100%);
  --bg-subtle: hsl(40, 22%, 94%);
  --bg-muted: hsl(40, 18%, 91%);
  --bg-elevated: hsla(0, 0%, 100%, 0.92);

  /* Typography Ink */
  --ink-primary: hsl(156, 18%, 13%);
  --ink-secondary: hsl(156, 10%, 34%);
  --ink-muted: hsl(156, 7%, 50%);
  --ink-faint: hsl(156, 6%, 66%);

  /* Brand & Functional Accents */
  --brand: hsl(157, 46%, 25%);
  --brand-hover: hsl(157, 48%, 20%);
  --brand-soft: hsl(154, 38%, 93%);
  --brand-ink: hsl(157, 52%, 20%);

  --amber: hsl(23, 67%, 46%);
  --amber-soft: hsl(26, 78%, 94%);
  --amber-ink: hsl(22, 72%, 30%);

  --danger: hsl(4, 62%, 48%);
  --danger-soft: hsl(4, 76%, 95%);

  /* Hairlines & Elevation */
  --border-hairline: hsla(156, 16%, 16%, 0.09);
  --border-strong: hsla(156, 16%, 16%, 0.17);
  --shadow-xs: 0 1px 2px hsla(156, 20%, 12%, 0.04);
  --shadow-sm: 0 2px 8px -2px hsla(156, 20%, 12%, 0.07), 0 1px 3px hsla(156, 20%, 12%, 0.04);
  --shadow-md: 0 10px 28px -6px hsla(156, 22%, 12%, 0.10), 0 2px 6px hsla(156, 20%, 12%, 0.05);
  --shadow-modal: 0 24px 60px -12px hsla(156, 25%, 10%, 0.24);

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  /* 8 Harmonious Teaching-Class Color Palettes (Light) */
  --cls-0-bg: #E6F4EE; --cls-0-ink: #154A33; --cls-0-bar: #2E7D5B;
  --cls-1-bg: #FDF0E6; --cls-1-ink: #6E320F; --cls-1-bar: #C86428;
  --cls-2-bg: #E8F0FA; --cls-2-ink: #173A63; --cls-2-bar: #2E629E;
  --cls-3-bg: #F7EBF2; --cls-3-ink: #5E1D41; --cls-3-bar: #A34178;
  --cls-4-bg: #EEF3E4; --cls-4-ink: #324711; --cls-4-bar: #5C7A29;
  --cls-5-bg: #F5EFE4; --cls-5-ink: #4F3914; --cls-5-bar: #8C6830;
  --cls-6-bg: #E5F3F5; --cls-6-ink: #11464F; --cls-6-bar: #237887;
  --cls-7-bg: #FCECEB; --cls-7-ink: #661D1A; --cls-7-bar: #B8433E;

  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg-canvas: hsl(210, 14%, 10%);
  --bg-surface: hsl(210, 13%, 14%);
  --bg-subtle: hsl(210, 12%, 18%);
  --bg-muted: hsl(210, 11%, 22%);
  --bg-elevated: hsla(210, 13%, 15%, 0.92);

  --ink-primary: hsl(150, 14%, 93%);
  --ink-secondary: hsl(150, 8%, 72%);
  --ink-muted: hsl(150, 6%, 54%);
  --ink-faint: hsl(150, 5%, 38%);

  --brand: hsl(155, 44%, 56%);
  --brand-hover: hsl(155, 48%, 63%);
  --brand-soft: hsla(155, 42%, 40%, 0.20);
  --brand-ink: hsl(155, 55%, 76%);

  --amber: hsl(27, 82%, 64%);
  --amber-soft: hsla(27, 70%, 42%, 0.22);
  --amber-ink: hsl(28, 86%, 78%);

  --danger: hsl(4, 72%, 64%);
  --danger-soft: hsla(4, 65%, 45%, 0.22);

  --border-hairline: hsla(150, 15%, 88%, 0.09);
  --border-strong: hsla(150, 15%, 88%, 0.18);
  --shadow-xs: 0 1px 2px hsla(0, 0%, 0%, 0.25);
  --shadow-sm: 0 2px 8px hsla(0, 0%, 0%, 0.32);
  --shadow-md: 0 12px 28px hsla(0, 0%, 0%, 0.45);
  --shadow-modal: 0 24px 64px hsla(0, 0%, 0%, 0.65);

  --cls-0-bg: #18362B; --cls-0-ink: #95E4BE; --cls-0-bar: #44A67B;
  --cls-1-bg: #3A2517; --cls-1-ink: #F7BE97; --cls-1-bar: #DF7B3F;
  --cls-2-bg: #192C40; --cls-2-ink: #9DC6F7; --cls-2-bar: #4B86C8;
  --cls-3-bg: #381D2E; --cls-3-ink: #F2AAD1; --cls-3-bar: #C45A95;
  --cls-4-bg: #27321A; --cls-4-ink: #C3E38C; --cls-4-bar: #7DA13D;
  --cls-5-bg: #352B1D; --cls-5-ink: #E8CB9A; --cls-5-bar: #B08644;
  --cls-6-bg: #163136; --cls-6-ink: #90DCE8; --cls-6-bar: #3799A8;
  --cls-7-bg: #3B1C1A; --cls-7-ink: #F7A8A4; --cls-7-bar: #D65B56;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* ==========================================================================
   Top Navigation Bar
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: var(--safe-top);
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-hairline);
}

.topbar-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 11px;
  flex: 1 1 auto;
  min-width: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

.brand-titles {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.brand-titles h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.brand-name {
  flex-shrink: 0;
}

.brand-subtitle {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--bg-subtle);
  color: var(--ink-secondary);
  border: 1px solid var(--border-hairline);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sync-pill:hover {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.show-mobile-inline {
  display: none;
}

.btn-icon-toggle {
  min-width: 36px;
  padding: 7px 10px;
}

/* ==========================================================================
   Buttons & Segmented Controls
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-xs);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
  transform: none;
  pointer-events: none;
}

.btn-primary {
  background: var(--brand);
  color: #FFFFFF;
  border-color: transparent;
}

[data-theme="dark"] .btn-primary {
  color: #0E1D16;
}

.btn-primary:hover {
  background: var(--brand-hover);
  border-color: transparent;
}

.btn-amber {
  background: var(--amber-soft);
  color: var(--amber-ink);
  border-color: transparent;
}

.btn-amber:hover {
  filter: brightness(0.97);
}

.btn-ghost {
  background: transparent;
  box-shadow: none;
  border-color: transparent;
  color: var(--ink-secondary);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
  color: var(--ink-primary);
  border-color: transparent;
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: var(--radius-xs);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.icon-svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* ==========================================================================
   Main Workspace Layout (Desktop 2-Column Glanceable, Mobile Adaptive)
   ========================================================================== */
.workspace {
  max-width: 1480px;
  margin: 0 auto;
  padding: 16px 20px calc(24px + var(--safe-bottom));
  display: grid;
  grid-template-columns: 316px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

/* ==========================================================================
   Left Focus Rail (Now / Next ⇄ Tomorrow Auto-Switch + Class Spotlight)
   ========================================================================== */
.focus-rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 70px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

/* Time Simulator Bar (for testing Today vs After-School Tomorrow mode) */
.sim-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 11px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-hairline);
  font-size: 12px;
}

.sim-bar-label {
  color: var(--ink-secondary);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

.sim-pills {
  display: flex;
  gap: 4px;
}

.sim-pill {
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 600;
  transition: all 0.14s ease;
}

.sim-pill.active {
  background: var(--bg-surface);
  color: var(--brand-ink);
  box-shadow: var(--shadow-xs);
}

/* Hero Focus Card */
.focus-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.focus-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.focus-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.focus-heading {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}

.status-tag.today {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.status-tag.tomorrow {
  background: var(--amber-soft);
  color: var(--amber-ink);
}

/* Spotlight Active/Next Lesson Box */
.hero-next-box {
  padding: 13px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-hairline);
}

.hero-next-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 5px;
}

.hero-next-class {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 3px;
}

.hero-next-sub {
  font-size: 13px;
  opacity: 0.88;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hero-memo {
  margin-top: 8px;
  padding: 5px 9px;
  border-radius: var(--radius-xs);
  background: hsla(0, 0%, 100%, 0.62);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

[data-theme="dark"] .hero-memo {
  background: hsla(0, 0%, 0%, 0.28);
}

.progress-track {
  margin-top: 10px;
  height: 5px;
  border-radius: 99px;
  background: hsla(0, 0%, 0%, 0.09);
  overflow: hidden;
}

[data-theme="dark"] .progress-track {
  background: hsla(0, 0%, 100%, 0.12);
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* Timeline list inside Focus Card & Mobile Today Tab */
.day-timeline {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.timeline-item:hover {
  border-color: var(--border-strong);
}

.timeline-item.done {
  opacity: 0.52;
}

.timeline-item.active {
  background: var(--bg-surface);
  border-color: var(--brand);
  box-shadow: var(--shadow-xs);
}

.tl-time {
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.tl-period {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-muted);
}

.tl-body {
  min-width: 0;
}

.tl-class-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 13.5px;
}

.tl-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tl-sub {
  font-size: 12px;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-memo {
  font-size: 11.5px;
  color: var(--amber-ink);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-day-state {
  text-align: center;
  padding: 20px 12px;
  color: var(--ink-secondary);
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
}

.empty-day-state strong {
  display: block;
  font-size: 14px;
  color: var(--ink-primary);
  margin-bottom: 4px;
}

/* Mobile Day Strip (shown in Today view on mobile) */
.mobile-day-strip {
  display: none;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-bottom: 12px;
}

.day-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 7px 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  font-size: 12px;
  gap: 2px;
}

.day-chip .d-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
}

.day-chip.selected {
  background: var(--brand);
  color: #FFFFFF;
  border-color: transparent;
}

[data-theme="dark"] .day-chip.selected {
  color: #0E1D16;
}

.day-chip.selected .d-num {
  color: inherit;
  opacity: 0.85;
}

/* Class Filter Chips Card */
.class-chips-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-secondary);
  margin: 0 0 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.class-chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.class-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: transform 0.12s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.class-filter-chip.dimmed {
  opacity: 0.38;
}

.class-filter-chip.selected {
  box-shadow: 0 0 0 2px var(--ink-primary);
}

/* ==========================================================================
   Main Timetable Stage (Glanceable Full-Week Grid)
   ========================================================================== */
.grid-stage {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.grid-toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.week-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.week-label {
  font-size: 14.5px;
  font-weight: 700;
  min-width: 132px;
  text-align: center;
}

.week-select {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-primary);
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
  padding: 4px 10px;
  min-width: 138px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.week-select:hover,
.week-select:focus {
  border-color: var(--brand);
  outline: none;
}

.grid-toggles {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.toggle-chip {
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--ink-secondary);
  border: 1px solid transparent;
}

.toggle-chip.on {
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-color: hsla(157, 46%, 25%, 0.18);
}

/* Timetable Matrix Table */
.timetable-scroll {
  width: 100%;
  overflow-x: auto;
}

.timetable-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.timetable-table th,
.timetable-table td {
  border-bottom: 1px solid var(--border-hairline);
  border-right: 1px solid var(--border-hairline);
}

.timetable-table th:last-child,
.timetable-table td:last-child {
  border-right: none;
}

.timetable-table thead th {
  background: var(--bg-subtle);
  padding: 9px 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-secondary);
  text-align: center;
}

.timetable-table thead th.col-period {
  width: 88px;
}

.timetable-table thead th.is-today {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.th-date {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  opacity: 0.78;
  margin-top: 1px;
}

/* Section Divider Rows (Lunch / Evening) */
.section-divider-row td {
  background: var(--bg-canvas);
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  text-align: center;
}

/* Period Left Header Cell */
.period-cell {
  padding: 6px 6px;
  text-align: center;
  background: var(--bg-canvas);
  vertical-align: middle;
}

.period-num {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--ink-primary);
}

.period-time {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  line-height: 1.25;
  margin-top: 2px;
}

/* Lesson Slot Cell */
.slot-td {
  height: 64px;
  padding: 4px;
  vertical-align: stretch;
  position: relative;
  transition: background 0.12s ease;
}

.slot-td.is-today-col {
  background: hsla(154, 38%, 50%, 0.03);
}

.slot-td.drag-over {
  background: var(--brand-soft) !important;
  outline: 2px dashed var(--brand);
  outline-offset: -3px;
}

.empty-slot-btn {
  width: 100%;
  height: 100%;
  min-height: 54px;
  border: 1px dashed transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.slot-td:hover .empty-slot-btn {
  opacity: 1;
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

/* Lesson Card inside Grid */
.lesson-card {
  width: 100%;
  height: 100%;
  min-height: 54px;
  padding: 6px 8px 6px 10px;
  border-radius: var(--radius-sm);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.14s ease, opacity 0.15s ease;
  border: 1px solid hsla(0, 0%, 0%, 0.04);
}

.lesson-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  bottom: 5px;
  width: 3.5px;
  border-radius: 0 3px 3px 0;
  background: var(--card-bar, var(--brand));
}

.lesson-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.lesson-card.spotlight-dim {
  opacity: 0.22;
}

.lesson-card.is-canceled {
  opacity: 0.48;
  background: var(--bg-subtle) !important;
  color: var(--ink-muted) !important;
  border: 1px dashed var(--border-strong);
}

.lesson-card.is-canceled .lc-class {
  text-decoration: line-through;
}

.lc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.lc-class {
  font-weight: 800;
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lc-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: hsla(0, 0%, 100%, 0.72);
  flex-shrink: 0;
}

[data-theme="dark"] .lc-badge {
  background: hsla(0, 0%, 0%, 0.38);
}

.lc-meta {
  font-size: 11.5px;
  opacity: 0.86;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lc-memo {
  font-size: 10.5px;
  font-weight: 600;
  margin-top: 2px;
  padding: 1px 5px;
  border-radius: 4px;
  background: hsla(0, 0%, 100%, 0.58);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

[data-theme="dark"] .lc-memo {
  background: hsla(0, 0%, 0%, 0.30);
}

/* Palette Helper Classes */
.pal-0 { background: var(--cls-0-bg); color: var(--cls-0-ink); --card-bar: var(--cls-0-bar); }
.pal-1 { background: var(--cls-1-bg); color: var(--cls-1-ink); --card-bar: var(--cls-1-bar); }
.pal-2 { background: var(--cls-2-bg); color: var(--cls-2-ink); --card-bar: var(--cls-2-bar); }
.pal-3 { background: var(--cls-3-bg); color: var(--cls-3-ink); --card-bar: var(--cls-3-bar); }
.pal-4 { background: var(--cls-4-bg); color: var(--cls-4-ink); --card-bar: var(--cls-4-bar); }
.pal-5 { background: var(--cls-5-bg); color: var(--cls-5-ink); --card-bar: var(--cls-5-bar); }
.pal-6 { background: var(--cls-6-bg); color: var(--cls-6-ink); --card-bar: var(--cls-6-bar); }
.pal-7 { background: var(--cls-7-bg); color: var(--cls-7-ink); --card-bar: var(--cls-7-bar); }

/* ==========================================================================
   Modals & Drawers
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: hsla(160, 18%, 8%, 0.46);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-panel {
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  padding: 20px 22px;
  transform: translateY(8px);
  transition: transform 0.18s ease;
}

.modal-backdrop.open .modal-panel {
  transform: translateY(0);
}

.modal-panel.modal-wide {
  max-width: 960px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.modal-head p {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--ink-muted);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-secondary);
}

.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-canvas);
  color: var(--ink-primary);
  font-size: 13.5px;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.quick-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 3px;
}

.quick-tag {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  color: var(--ink-secondary);
}

.quick-tag:hover {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.mode-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}

.mode-tab {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-secondary);
}

.mode-tab.active {
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-xs);
}

.modal-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ==========================================================================
   Photo OCR Upload & Split-Screen Proofreader
   ========================================================================== */
.ocr-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 26px 18px;
  text-align: center;
  background: var(--bg-canvas);
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: pointer;
}

.ocr-dropzone:hover, .ocr-dropzone.dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.ocr-split {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  margin-top: 14px;
  align-items: start;
}

.ocr-photo-box {
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 8px;
  max-height: 440px;
  overflow: auto;
}

.ocr-photo-box img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-xs);
  display: block;
}

.proof-grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  table-layout: fixed;
}

.proof-grid-table th, .proof-grid-table td {
  border: 1px solid var(--border-hairline);
  padding: 4px;
  text-align: center;
}

.proof-cell {
  min-height: 42px;
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.proof-cell.parsed {
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 700;
}

.proof-cell.empty {
  color: var(--ink-faint);
}

/* ==========================================================================
   iOS Widget Live Simulator inside Reminder & Widget Modal
   ========================================================================== */
.ios-sim-shell {
  background: linear-gradient(145deg, #D9E6DF 0%, #EFE9DC 100%);
  padding: 18px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

[data-theme="dark"] .ios-sim-shell {
  background: linear-gradient(145deg, #1E2924 0%, #262320 100%);
}

.ios-widget-card {
  width: 100%;
  max-width: 348px;
  border-radius: 22px;
  padding: 14px 16px;
  background: #FAF8F4;
  color: #1C2421;
  box-shadow: 0 14px 32px rgba(18, 28, 23, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.ios-widget-card.dark-widget {
  background: #181B20;
  color: #F2F4F3;
  border-color: rgba(255, 255, 255, 0.08);
}

.ios-w-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.ios-w-title {
  font-weight: 800;
  font-size: 13.5px;
}

.ios-w-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.ios-w-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ios-w-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 9px;
  border-radius: 10px;
}

.ios-w-bar {
  width: 3.5px;
  height: 28px;
  border-radius: 2px;
  flex-shrink: 0;
}

.sync-code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
}

.sync-digits {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--brand);
}

.ios-cards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

/* ==========================================================================
   Dynamic Period Generator & Editor (#modal-settings + Timetable Footer)
   ========================================================================== */
.period-gen-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  font-size: 12.5px;
}

.period-gen-title {
  font-weight: 700;
  color: var(--ink-primary);
}

.period-gen-chk,
.period-gen-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink-secondary);
  font-weight: 600;
}

.period-gen-num {
  width: 50px;
  padding: 4px 6px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
}

.period-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-secondary);
}

.period-table-wrap {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  background: var(--bg-canvas);
}

.period-editor-table {
  min-width: 580px;
  table-layout: auto;
}

.period-editor-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-subtle);
  padding: 7px 6px;
  font-size: 12px;
}

.period-editor-table td {
  padding: 5px 6px;
  vertical-align: middle;
}

.period-row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}

.p-act-btn {
  padding: 3px 7px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  transition: background 0.12s ease, color 0.12s ease;
}

.p-act-btn:hover {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.p-act-btn.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.period-add-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.timetable-add-period-row td {
  padding: 8px 12px;
  background: var(--bg-canvas);
  text-align: center;
}

.timetable-add-period-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ==========================================================================
   Mobile Bottom Tab Bar & Responsive Adaptation
   ========================================================================== */
.mobile-tabbar {
  display: none;
}

/* Toast Notification */
.toast-stack {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--ink-primary);
  color: var(--bg-surface);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.2s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 980px) {
  .topbar-inner {
    padding: 8px 14px;
    gap: 10px;
  }

  .brand-group {
    gap: 10px;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  .brand-titles h1 {
    font-size: 15.5px;
    gap: 6px;
  }

  .brand-subtitle {
    font-size: 11.5px;
  }

  .sync-pill {
    padding: 1px 7px;
    font-size: 10.5px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .hide-mobile,
  .hide-mobile-inline {
    display: none !important;
  }

  .show-mobile-inline {
    display: inline;
  }

  #btn-open-settings {
    height: 34px;
    padding: 0 10px;
    font-size: 12.5px;
    border-radius: 9px;
  }

  .btn-icon-toggle {
    width: 34px;
    height: 34px;
    min-width: 34px;
    padding: 0;
    border-radius: 9px;
    background: var(--bg-subtle);
    border: 1px solid var(--border-hairline);
  }

  /* Prevent iOS Safari viewport auto-zoom when tapping form controls */
  .input, .select, .textarea {
    font-size: 16px;
  }

  .ios-cards-grid {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px 12px calc(78px + var(--safe-bottom));
  }

  .focus-rail {
    position: static;
  }

  .mobile-day-strip {
    display: grid;
  }

  body[data-mobile-tab="today"] .grid-stage {
    display: none;
  }

  body[data-mobile-tab="week"] .focus-rail {
    display: none;
  }

  .timetable-table thead th.col-period {
    width: 56px;
  }

  .period-time {
    font-size: 9.5px;
  }

  .lc-class {
    font-size: 11.5px;
  }

  .lc-meta {
    font-size: 10px;
  }

  .empty-slot-btn {
    opacity: 0.55;
  }

  .ocr-split {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .mobile-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 6px 8px calc(6px + var(--safe-bottom));
    background: var(--bg-elevated);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-hairline);
  }

  .mob-tab {
    border: none;
    background: transparent;
    padding: 5px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-muted);
    border-radius: var(--radius-sm);
  }

  .mob-tab.active {
    color: var(--brand);
  }

  .toast-stack {
    left: 16px;
    right: 16px;
    bottom: calc(76px + var(--safe-bottom));
    align-items: center;
  }
}

@media (max-width: 640px) {
  .sim-bar {
    padding: 7px 10px;
  }

  .sim-bar-label {
    white-space: nowrap;
    font-size: 11.5px;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-panel,
  .modal-panel.modal-wide {
    max-width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding: 18px 16px calc(20px + var(--safe-bottom));
  }
}

@media (max-width: 359px) {
  .sync-pill {
    display: none;
  }
}

@media print {
  .topbar, .focus-rail, .grid-toolbar, .mobile-tabbar, .modal-backdrop, .timetable-add-period-row {
    display: none !important;
  }
  .workspace {
    display: block;
    padding: 0;
  }
  .grid-stage {
    border: none;
    box-shadow: none;
  }
  body {
    background: #FFFFFF;
  }
}
