:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #111827;
  --sub: #6b7280;
  --line: #e5e7eb;
  --accent: #3b82f6;
  --accent-bg: #eff6ff;
  --accent-border: rgba(59,130,246,0.2);
  --free: #16a34a;
  --free-bg: #f0fdf4;
  --free-border: rgba(22,163,74,0.2);
  --busy: #dc2626;
  --busy-bg: #fef2f2;
  --busy-border: rgba(220,38,38,0.2);
  --pending: #b45309;
  --pending-bg: #fffbeb;
  --pending-border: rgba(180,83,9,0.2);
  --sidebar: 272px;
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --ink: #f0f2f5;
    --sub: #8b95a3;
    --line: #2a2f3d;
    --accent: #60a5fa;
    --accent-bg: #1e2d45;
    --accent-border: rgba(96,165,250,0.25);
    --free: #4ade80;
    --free-bg: #0d2318;
    --free-border: rgba(74,222,128,0.25);
    --busy: #f87171;
    --busy-bg: #2a1010;
    --busy-border: rgba(248,113,113,0.25);
    --pending: #fbbf24;
    --pending-bg: #241c08;
    --pending-border: rgba(251,191,36,0.25);
  }
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; appearance: none; }

button { cursor: pointer; border: none; background: none; transition: opacity 0.1s, transform 0.1s; }
button:active { opacity: 0.7; transform: scale(0.97); }

/* ── Layout ── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 0 0 24px;
}

.workspace {
  padding: 20px 24px;
  min-height: 100vh;
}

/* ── Sidebar brand ── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.brand-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink);
}

/* ── Sidebar sections ── */
.sidebar-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sub);
}

/* ── Segmented control ── */
.seg-control {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  overflow: hidden;
}

.seg-control.wide {
  width: 100%;
}

.seg-control button {
  position: relative;
  z-index: 1;
  padding: 6px 0;
  border-radius: 6px;
  font-size: 13px;
  color: var(--sub);
  transition: color 0.15s;
  text-align: center;
}

.seg-control button.active {
  color: var(--ink);
  font-weight: 600;
}

.seg-thumb {
  position: absolute;
  inset: 3px;
  width: calc(50% - 3px);
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: transform 0.2s cubic-bezier(0.4,0,0.2,1);
  pointer-events: none;
}

/* ── Sidebar clock ── */
.sidebar-clock {
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.clock-time {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  line-height: 1.2;
}

.clock-sub {
  margin-top: 5px;
  font-size: 12px;
  color: var(--sub);
}

/* ── Field group (manual mode) ── */
.field-group {
  display: grid;
  gap: 8px;
}

.field-row {
  display: grid;
  gap: 4px;
}

.field-row label {
  font-size: 11px;
  font-weight: 600;
  color: var(--sub);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.field-row select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.field-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-border);
}

/* ── Global stats ── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-item {
  display: grid;
  gap: 2px;
  padding: 10px 8px;
  background: var(--bg);
  border-radius: 6px;
  text-align: center;
}

.stat-num {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.stat-lbl {
  font-size: 11px;
  color: var(--sub);
}

.stat-item.free .stat-num { color: var(--free); }

/* ── Filter toggle (mobile) ── */
.filter-toggle-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  text-align: left;
}

.filter-toggle-btn .chevron {
  font-size: 10px;
  color: var(--sub);
  flex-shrink: 0;
}

.filter-sections { display: grid; }

/* ── Zone / building lists ── */
.zone-list { display: grid; gap: 2px; }

.zone-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  text-align: left;
  transition: background 0.12s;
}

.zone-btn:hover { background: var(--bg); }

.zone-btn.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.zone-count {
  font-size: 12px;
  color: var(--sub);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 999px;
}

.zone-btn.active .zone-count {
  background: var(--accent-border);
  color: var(--accent);
}

.building-list {
  display: grid;
  gap: 1px;
  margin: 2px 0 2px 14px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
}

.building-btn {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 12px;
  color: var(--sub);
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.building-btn:hover { background: var(--bg); color: var(--ink); }

.building-btn.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

/* ── Chips ── */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--sub);
  background: var(--surface);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Search ── */
.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-border);
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-mode {
  font-weight: 700;
  font-size: 13px;
}

.toolbar-meta {
  font-size: 12px;
  color: var(--sub);
}

.toolbar-right {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg);
  color: var(--sub);
  border: 1px solid var(--line);
}

.count-badge.free { background: var(--free-bg); color: var(--free); border-color: var(--free-border); }
.count-badge.busy { background: var(--busy-bg); color: var(--busy); border-color: var(--busy-border); }

/* ── Room grid ── */
.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

/* ── Room card ── */
.room-card {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  animation: fade-up 0.3s ease forwards;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.room-card:hover {
  border-color: var(--line);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.room-card.visited {
  opacity: 0.55;
}

.room-card.visited:hover {
  opacity: 0.8;
}

.room-card.free  { border-left: 3px solid var(--free); }
.room-card.busy  { border-left: 3px solid var(--busy); }
.room-card.pending { border-left: 3px solid var(--pending); }

.card-header {
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.free    { background: var(--free); }
.dot.busy    { background: var(--busy); }
.dot.pending { background: var(--pending); }

.card-name {
  font-weight: 700;
  font-size: 15px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}
.status-tag.free    { background: var(--free-bg);    color: var(--free); }
.status-tag.busy    { background: var(--busy-bg);    color: var(--busy); }
.status-tag.pending { background: var(--pending-bg); color: var(--pending); }

.card-loc {
  font-size: 11px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-course {
  font-size: 12px;
  line-height: 1.4;
}

.course-name {
  display: block;
  font-weight: 600;
}

.course-meta {
  display: block;
  color: var(--sub);
}

.card-course.empty {
  color: var(--sub);
  font-style: italic;
}

.next-tag {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--sub);
}
.next-tag.free    { color: var(--free);    background: var(--free-bg);    border-color: var(--free-border); }
.next-tag.busy    { color: var(--busy);    background: var(--busy-bg);    border-color: var(--busy-border); }
.next-tag.pending { color: var(--pending); background: var(--pending-bg); border-color: var(--pending-border); }

/* ── Empty state ── */
/* ── Animations ── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.spinner {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
}

.spinner span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.spinner span:nth-child(2) { animation-delay: 0.2s; }
.spinner span:nth-child(3) { animation-delay: 0.4s; }

.fade-in > * {
  opacity: 0;
  animation: fade-up 0.3s ease forwards;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--sub);
}

.state-screen {
  padding: 64px 24px;
  text-align: center;
}

.state-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.state-body  { color: var(--sub); }

/* ── Modal ── */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.3);
}

.modal {
  position: relative;
  z-index: 1;
  width: min(880px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  background: var(--surface);
  border-radius: 12px;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-room-name {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.modal-room-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--sub);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sub);
  font-size: 14px;
  flex-shrink: 0;
  transition: background 0.12s;
}

.modal-close:hover { background: var(--bg); color: var(--ink); }

.modal-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  align-items: start;
}

.modal-status-block {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  align-self: start;
}

.modal-status-block.free    { background: var(--free-bg);    color: var(--free); }
.modal-status-block.busy    { background: var(--busy-bg);    color: var(--busy); }
.modal-status-block.pending { background: var(--pending-bg); color: var(--pending); }

.modal-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.modal-info-item {
  display: grid;
  gap: 3px;
}

.info-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.info-val {
  font-size: 12px;
  color: var(--ink);
  line-height: 1.4;
}

.modal-tabs {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-body {
  overflow: auto;
  padding: 16px 20px;
}

/* ── Occupancy list ── */
.occupancy-list { display: grid; gap: 8px; }

.occ-card {
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.occ-course {
  font-weight: 700;
  font-size: 14px;
}

.occ-meta {
  font-size: 12px;
  color: var(--sub);
}

.occ-empty {
  display: grid;
  gap: 4px;
  padding: 24px;
  text-align: center;
  color: var(--sub);
}

.occ-empty-sub { font-size: 12px; }

/* ── Schedule table (modal + page) ── */
.schedule-wrap,
.sp-scroll {
  overflow: auto;
}

.schedule-table {
  border-collapse: separate;
  border-spacing: 6px;
  min-width: 700px;
  width: 100%;
}

.schedule-table th {
  font-size: 12px;
  font-weight: 700;
  color: var(--sub);
  padding: 6px 8px;
  text-align: center;
}

.row-head {
  text-align: left !important;
  min-width: 100px;
  vertical-align: top;
}

.slot-code {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.slot-time {
  display: block;
  font-size: 11px;
  color: var(--sub);
  font-weight: 400;
}

.s-cell {
  min-width: 110px;
  min-height: 80px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  vertical-align: top;
  background: var(--bg);
}

.s-cell.sel {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.s-entry {
  padding: 6px 8px;
  border-radius: 5px;
  margin-bottom: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.s-entry.active {
  border-color: var(--accent-border);
  background: var(--accent-bg);
}

.s-entry strong {
  display: block;
  font-size: 12px;
  margin-bottom: 2px;
}

.s-entry span {
  display: block;
  font-size: 11px;
  color: var(--sub);
  line-height: 1.3;
}

.s-empty {
  color: var(--line);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 60px;
}

/* ── Schedule full-screen page (mobile) ── */
.schedule-page {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
  background: var(--surface);
  overflow: hidden;
}

.sp-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.sp-back {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  flex-shrink: 0;
}

.sp-back:hover { background: var(--accent-bg); }

.sp-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sp-room {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-meta {
  font-size: 11px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-context {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--sub);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.sp-scroll {
  overflow: auto;
  padding: 12px 8px;
}

/* ── Date picker ── */
.date-picker {
  display: grid;
  gap: 4px;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.cal-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.cal-nav-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 16px;
  color: var(--sub);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}

.cal-nav-btn:hover {
  background: var(--bg);
  color: var(--ink);
}

.cal-grid {
  width: 100%;
  border-collapse: collapse;
}

.cal-grid thead th {
  font-size: 11px;
  font-weight: 600;
  color: var(--sub);
  text-align: center;
  padding: 4px 0;
}

.cal-grid td {
  padding: 2px;
  text-align: center;
}

.cal-day {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}

.cal-day:hover:not(.disabled):not(.selected) {
  background: var(--bg);
}

.cal-day.other {
  color: var(--line);
}

.cal-day.disabled {
  color: var(--line);
  cursor: not-allowed;
}

.cal-day.today {
  color: var(--accent);
  font-weight: 700;
}

.cal-day.selected {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }
}

@media (max-width: 680px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .workspace { padding: 14px; }

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

  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal {
    width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    position: fixed;
    inset: 0;
    border: none;
    grid-template-rows: auto auto auto 1fr;
  }

  .modal-root {
    align-items: stretch;
  }

  .modal-summary {
    grid-template-columns: 1fr;
  }

  .modal-info-grid {
    grid-template-columns: 1fr;
  }
}
