:root {
  --gold: #e8b84b;
  --teal: #2aa89e;
  --pink: #dd7088;
  --green: #4d9e6e;
  --purple: #7059aa;

  --bg: #f0f2f6;
  --surface: #ffffff;
  --surface-muted: #f4f6fa;
  --ink: #1e2430;
  --muted: #4a5263;
  --line: #6e7583;
  --line-strong: #5c6472;
  --focus: #1f8a82;

  --btn-primary: var(--teal);
  --btn-primary-hover: #239089;
  --on-primary: #000000;
  --chip-active-bg: #1e2430;
  --chip-active-fg: #ffffff;
  --chip-t1-fg: #1e2430;
  --chip-bridge-bg: #9a3358;
  --chip-bridge-fg: #ffffff;
  --chip-t2-bg: #5b458c;
  --chip-t2-fg: #ffffff;

  --pill-t1-fg: #5c4300;
  --pill-t1-bg: #f6e7b8;
  --pill-t2-fg: #3b2d66;
  --pill-t2-bg: #e8e0f6;
  --pill-bridge-fg: #7a2440;
  --pill-bridge-bg: #f8d5de;
  --pill-sem-fg: #0d524e;
  --pill-sem-bg: #d3efec;
  --badge-free-fg: #1b5c32;
  --badge-free-bg: #d3eedc;
  --badge-blocked-fg: #7a2440;
  --badge-blocked-bg: #f8d5de;

  --shadow-sm: 0 1px 2px rgb(30 36 48 / 0.05);
  --shadow-md: 0 8px 24px rgb(30 36 48 / 0.07);
  --shadow-lg: 0 16px 40px rgb(30 36 48 / 0.09);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --t1: var(--gold);
  --bridge: var(--pink);
  --t2: var(--purple);
  --sem: var(--teal);
  --accent: var(--teal);
  --ok: var(--green);
  --danger: #a12a48;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101218;
    --surface: #1c212b;
    --surface-muted: #262c38;
    --ink: #f3f5fa;
    --muted: #c3c9d6;
    --line: #8e96a6;
    --line-strong: #a7b0c0;
    --focus: #7ee0d6;

    --chip-active-bg: #f3f5fa;
    --chip-active-fg: #101218;

    --pill-t1-fg: #ffe08a;
    --pill-t1-bg: #3d3420;
    --pill-t2-fg: #e4d7ff;
    --pill-t2-bg: #2f2844;
    --pill-bridge-fg: #ffc2d0;
    --pill-bridge-bg: #4a2430;
    --pill-sem-fg: #9eefe6;
    --pill-sem-bg: #163a38;
    --badge-free-fg: #b6ebc6;
    --badge-free-bg: #1c3a28;
    --badge-blocked-fg: #ffc2d0;
    --badge-blocked-bg: #4a2430;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.28);
    --shadow-md: 0 8px 24px rgb(0 0 0 / 0.38);
    --shadow-lg: 0 16px 40px rgb(0 0 0 / 0.45);
    --danger: #ff8da3;
  }
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

html,
body,
#root {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Roboto, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background:
    radial-gradient(900px 420px at 0% -10%, rgb(14 111 107 / 0.12), transparent 60%),
    radial-gradient(700px 360px at 100% 0%, rgb(91 69 140 / 0.12), transparent 55%),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 1000;
  padding: 10px 16px;
  background: var(--btn-primary);
  color: var(--on-primary);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

button {
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.1s ease;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

h1,
h2,
h3 {
  font-family: Roboto, sans-serif;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 32px 72px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.brand-logo img {
  display: block;
  height: 52px;
  width: auto;
}

.brand p {
  margin: 0;
  color: var(--muted);
  max-width: 48ch;
  font-size: 0.95rem;
}

.nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}

.nav button,
.nav a,
.chip,
.btn {
  border: 1px solid transparent;
  background: transparent;
  padding: 10px 16px;
  min-height: 44px;
  min-width: 44px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: none;
}

.nav button:hover,
.nav a:hover,
.chip:hover:not(.active),
.btn:hover:not(:disabled):not(.primary) {
  background: var(--surface-muted);
  color: var(--ink);
}

.nav button.active,
.nav a.active {
  background: var(--chip-t2-bg);
  color: var(--chip-t2-fg);
  box-shadow: var(--shadow-sm);
}

.chip.active {
  background: var(--chip-active-bg);
  color: var(--chip-active-fg);
}

.btn {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.btn.primary {
  background: var(--btn-primary);
  color: var(--on-primary);
  border-color: transparent;
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: var(--btn-primary-hover);
}

.btn.primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.reload-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--btn-primary);
}

.reload-btn {
  font-size: 0.95rem;
  padding: 11px 20px;
}

.reload-bar span {
  color: var(--muted);
  font-size: 0.875rem;
}

.chip.t1.active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--chip-t1-fg);
}

.chip.bridge.active {
  background: var(--chip-bridge-bg);
  border-color: var(--chip-bridge-bg);
  color: var(--chip-bridge-fg);
}

.chip.t2.active {
  background: var(--chip-t2-bg);
  border-color: var(--chip-t2-bg);
  color: var(--chip-t2-fg);
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-size: 0.92em;
}

.status {
  margin: 56px 0;
  text-align: center;
  padding: 32px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-height: 100%;
  box-shadow: var(--shadow-md);
}

.panel h2 {
  font-size: 1.35rem;
  margin-bottom: 6px;
  color: var(--ink);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 20px 0;
}

.kpi {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.kpi:nth-child(1) { border-top: 3px solid var(--teal); }
.kpi:nth-child(2) { border-top: 3px solid var(--purple); }
.kpi:nth-child(3) { border-top: 3px solid var(--gold); }
.kpi:nth-child(4) { border-top: 3px solid var(--pink); }

.kpi .value {
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
}

.kpi .label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 4px;
}

.period-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  width: fit-content;
  max-width: 100%;
}

.bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 92px 1fr 64px;
  gap: 10px;
  align-items: center;
  font-size: 0.8125rem;
}

.bar-track {
  height: 8px;
  background: var(--line);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--teal);
  border-radius: var(--radius-pill);
}

.heat {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--surface-muted);
}

.heat-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.legend-stop {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.legend-stop i {
  display: inline-block;
  width: 18px;
  height: 10px;
  border-radius: 3px;
  border: 1px solid var(--line);
}

.heat-wide {
  max-height: 560px;
}

.heat th.sticky {
  position: sticky;
  left: 0;
  background: var(--surface-muted);
  text-align: left;
  min-width: 160px;
  z-index: 1;
  font-weight: 500;
}

.heat thead th {
  white-space: nowrap;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.75rem;
}

.heat table {
  border-collapse: separate;
  border-spacing: 3px;
  width: 100%;
  font-size: 0.75rem;
}

.heat th,
.heat td {
  text-align: center;
  padding: 8px 6px;
  border: none;
  border-radius: 6px;
}

.heat tbody th {
  background: var(--surface);
  color: var(--muted);
  font-weight: 500;
}

.heat td.cell {
  min-width: 52px;
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-weight: 500;
  font-size: 0.7rem;
}

.section {
  margin-top: 28px;
}

.section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--ink);
}

.bars-scroll {
  overflow: auto;
  max-height: 420px;
  padding-right: 4px;
}

.table-wrap {
  overflow: auto;
  max-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.table-wrap.full {
  max-height: none;
  overflow: hidden;
}

table.data thead th:first-child {
  border-top-left-radius: calc(var(--radius-md) - 1px);
}

table.data thead th:last-child {
  border-top-right-radius: calc(var(--radius-md) - 1px);
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8125rem;
}

table.data th,
table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

table.data tbody tr:hover {
  background: var(--surface-muted);
}

table.data th {
  position: sticky;
  top: 0;
  background: var(--surface-muted);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
  border: none;
}

.pill.trail1 {
  color: var(--pill-t1-fg);
  background: var(--pill-t1-bg);
}

.pill.trail2 {
  color: var(--pill-t2-fg);
  background: var(--pill-t2-bg);
}

.pill.bridge {
  color: var(--pill-bridge-fg);
  background: var(--pill-bridge-bg);
}

.pill.semester {
  color: var(--pill-sem-fg);
  background: var(--pill-sem-bg);
}

.conflict {
  font-size: 0.8125rem;
  padding: 12px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--pill-bridge-bg);
  color: var(--pill-bridge-fg);
  border-left: 3px solid var(--chip-bridge-bg);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8125rem;
}

.field > span,
.field > label {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
}

.field input:not([type="checkbox"]),
.field select,
.field textarea {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  color-scheme: inherit;
  min-height: 44px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:not([type="checkbox"]):focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
  border-color: var(--focus);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

.check-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 20px;
  min-height: 44px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ink);
  font-weight: 500;
  font-size: 0.8125rem;
  min-height: 44px;
}

.check input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  min-width: 1.25rem;
  min-height: 1.25rem;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--btn-primary);
  flex-shrink: 0;
}

.mode {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  background: var(--surface-muted);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  width: fit-content;
  flex-wrap: wrap;
}

.hit {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border: 1px solid var(--line);
  padding: 16px 18px;
  margin-bottom: 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease;
}

.hit:hover {
  box-shadow: var(--shadow-md);
}

.hit header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.hit h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.hit .room-name {
  margin: 2px 0 0;
}

.hit-body {
  flex: 1;
  min-width: 0;
}

.room-gallery-wrap {
  display: inline-flex;
}

.room-photo-cell {
  width: 72px;
}

.room-thumb-btn {
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  overflow: hidden;
  cursor: pointer;
  color: inherit;
  flex-shrink: 0;
}

.room-thumb-btn.table {
  width: 64px;
  height: 48px;
  min-width: 44px;
  min-height: 44px;
}

.room-thumb-btn.card {
  width: 120px;
  height: 90px;
  min-width: 44px;
  min-height: 44px;
}

.room-thumb-btn img,
.room-gallery-strip-btn img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.room-thumb-btn:hover,
.room-gallery-strip-btn:hover {
  border-color: var(--focus);
}

.room-thumb-btn.is-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  color: var(--muted);
}

.room-thumb-btn.is-placeholder:hover {
  border-color: var(--line-strong);
}

.room-gallery {
  width: min(52rem, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: var(--surface);
  color: var(--ink);
  color-scheme: inherit;
}

.room-gallery::backdrop {
  background: rgb(16 18 24 / 0.72);
}

.room-gallery-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.room-gallery-head h3 {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin: 0;
  font-size: 1rem;
}

.room-gallery-stage {
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.room-gallery-stage img {
  display: block;
  width: 100%;
  max-height: min(70vh, 720px);
  object-fit: contain;
  background: var(--surface-muted);
}

.room-gallery-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.room-gallery-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.room-gallery-strip-btn {
  width: 72px;
  height: 54px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-muted);
  cursor: pointer;
}

.room-gallery-strip-btn[aria-current="true"] {
  border-color: var(--focus);
}

.badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}

.badge.free {
  color: var(--badge-free-fg);
  background: var(--badge-free-bg);
}

.badge.restricted {
  color: var(--pill-t1-fg);
  background: var(--pill-t1-bg);
}

.badge.blocked {
  color: var(--badge-blocked-fg);
  background: var(--badge-blocked-bg);
}

.exceptions {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.room-edit input[type="number"],
.room-edit input[type="text"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 8px 10px;
  min-height: 44px;
  color: var(--ink);
  color-scheme: inherit;
  border-radius: var(--radius-sm);
}

.room-edit input:focus-visible {
  border-color: var(--focus);
}

.tiny {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.callout {
  border-left: 4px solid var(--btn-primary);
  padding: 12px 16px;
  margin: 16px 0;
  color: var(--ink);
  font-size: 0.875rem;
  background: var(--pill-sem-bg);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

@media (max-width: 1100px) {
  .split,
  .kpis,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .shell {
    padding: 20px 16px 56px;
  }

  .topbar {
    flex-direction: column;
  }

  .brand-logo img {
    height: 44px;
  }

  .nav {
    width: 100%;
    justify-content: stretch;
  }

  .nav button {
    flex: 1;
    text-align: center;
  }

  .hit {
    flex-direction: column;
  }

  .room-thumb-btn.card {
    width: 100%;
    max-width: 240px;
    height: 135px;
  }
}

[x-cloak] { display: none !important; }
a.chip { text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  button:active:not(:disabled) {
    transform: none;
  }
}

@media (forced-colors: active) {
  .bar-fill,
  .legend-stop i,
  .heat td.cell {
    outline: 1px solid CanvasText;
  }
}
