/* ---------------------------------------------------------------------------
   TravelHub operator dashboard.
   Tokens first, then layout, then components. Light is the base palette; dark
   is a selected set of steps, not an automatic inversion.
   --------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --surface-2:       #f3f3f0;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);

  --series-1:        #2a78d6;
  --series-1-wash:   rgba(42, 120, 214, 0.10);
  --series-1-track:  #cde2fb;

  --good:            #0ca30c;
  --warning:         #fab219;
  --serious:         #ec835a;
  --critical:        #d03b3b;
  --success-text:    #006300;

  --radius:          12px;
  --radius-sm:       8px;
  --shadow:          0 1px 2px rgba(11, 11, 11, 0.04),
                     0 8px 24px -16px rgba(11, 11, 11, 0.18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --surface-2:      #232321;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-1-wash:  rgba(57, 135, 229, 0.16);
    --series-1-track: #184f95;
    --success-text:   #0ca30c;
    --shadow:         0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface-1:      #1a1a19;
  --surface-2:      #232321;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-1-wash:  rgba(57, 135, 229, 0.16);
  --series-1-track: #184f95;
  --success-text:   #0ca30c;
  --shadow:         0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); }
a:hover { text-decoration: none; }

/* --- shell ---------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--series-1); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  flex: 0 0 auto;
}
.brand__name { font-weight: 650; letter-spacing: -0.01em; }
.brand__sub { font-size: 11px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav a[aria-current="page"] {
  background: var(--series-1-wash); color: var(--series-1); font-weight: 600;
}
.nav__icon { width: 18px; text-align: center; opacity: 0.85; }
.nav__group {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin: 12px 0 4px 10px;
}

.sidebar__foot { margin-top: auto; font-size: 12px; color: var(--text-muted); }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }

.page-head {
  display: flex; flex-wrap: wrap; gap: 14px;
  align-items: flex-end; justify-content: space-between;
  margin-bottom: 22px;
}
.page-head h1 {
  margin: 0; font-size: 22px; letter-spacing: -0.02em; font-weight: 650;
}
.page-head p { margin: 4px 0 0; color: var(--text-secondary); }

/* --- status chip --------------------------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip--good     { color: var(--success-text); }
.chip--warning  { color: #8a6100; }
.chip--critical { color: var(--critical); }
.chip--info     { color: var(--series-1); }
/* On the dark surface the brighter warning step clears 3:1; on light we keep
   the darker amber ink. Either way the chip carries an icon and a word. */
:root[data-theme="dark"] .chip--warning { color: var(--warning); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip--warning { color: var(--warning); }
}

/* --- cards & grid -------------------------------------------------------- */

.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); }
.grid--halves { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card__title { font-size: 14px; font-weight: 650; margin: 0; }
.card__sub { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }

/* --- stat tiles ---------------------------------------------------------- */

.stat__label {
  font-size: 12px; color: var(--text-secondary); margin: 0 0 6px;
}
.stat__value {
  font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin: 0;
  /* proportional figures on purpose - tabular looks loose at display sizes */
}
.stat__row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.stat__delta { font-size: 12px; font-weight: 600; margin: 6px 0 0; }
.stat__delta--up { color: var(--success-text); }
.stat__delta--down { color: var(--critical); }
.stat__delta--flat { color: var(--text-muted); }
.stat__delta span { color: var(--text-muted); font-weight: 500; }

.hero { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 18px; }
.hero__value {
  font-size: 48px; line-height: 1.05; font-weight: 680;
  letter-spacing: -0.03em; margin: 0;
}
.hero__meta { color: var(--text-secondary); }

/* --- charts -------------------------------------------------------------- */

.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; max-width: 100%; height: auto; }
.chart__grid line { stroke: var(--gridline); stroke-width: 1; }
.chart__baseline { stroke: var(--baseline); stroke-width: 1; }
.chart__tick, .chart__axis-label {
  fill: var(--text-muted); font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.chart__bar { fill: var(--series-1); }
.chart__bar-hit { fill: transparent; }
.chart__value { fill: var(--text-primary); font-size: 10.5px; font-weight: 600; }
.chart__label { fill: var(--text-primary); font-size: 12px; }
.chart__sub { fill: var(--text-muted); font-size: 10.5px; }
.chart__spark { fill: none; stroke: var(--series-1); stroke-width: 2;
  stroke-linejoin: round; stroke-linecap: round; }
.chart__empty {
  color: var(--text-muted); font-size: 13px; padding: 28px 4px; text-align: center;
}
.chart__row:hover .chart__bar,
.chart__col:hover .chart__bar { fill-opacity: 0.82; }

.viz-tip {
  position: fixed; z-index: 40; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 7px 10px; font-size: 12px;
  font-weight: 500; white-space: nowrap; opacity: 0;
  transform: translate(-50%, -130%); transition: opacity 90ms linear;
}
.viz-tip[data-show="true"] { opacity: 1; }

/* --- meters -------------------------------------------------------------- */

.meter { display: grid; gap: 6px; }
.meter__track {
  height: 8px; border-radius: 999px; background: var(--series-1-track);
  overflow: hidden;
}
.meter__fill { height: 100%; border-radius: 999px; background: var(--series-1); }
.meter--good .meter__fill     { background: var(--good); }
.meter--warning .meter__fill  { background: var(--warning); }
.meter--critical .meter__fill { background: var(--critical); }
.meter__meta {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--text-secondary);
}

/* --- tables -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); font-weight: 600;
  padding: 0 12px 8px 0; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 11px 12px 11px 0; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.t-sub { color: var(--text-muted); font-size: 12px; }
.t-strong { font-weight: 600; }

details.table-view { margin-top: 12px; }
details.table-view summary {
  cursor: pointer; font-size: 12px; color: var(--text-secondary);
  font-weight: 600;
}
details.table-view[open] summary { margin-bottom: 10px; }

/* --- forms & buttons ----------------------------------------------------- */

.field { display: grid; gap: 5px; margin-bottom: 14px; }
.field__label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.field__input {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
}
.field__input:focus {
  outline: 2px solid var(--series-1); outline-offset: 1px; border-color: var(--series-1);
}
.field__help { font-size: 11.5px; color: var(--text-muted); }
.field__error { font-size: 12px; color: var(--critical); font-weight: 500; }
.field--inline { display: flex; align-items: flex-start; gap: 8px; }
.field__check { margin-top: 3px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; text-decoration: none;
  background: var(--series-1); color: #fff;
}
.btn:hover { filter: brightness(1.06); }
.btn--ghost {
  background: var(--surface-1); color: var(--text-primary);
  border-color: var(--baseline);
}
.btn--ghost:hover { background: var(--surface-2); filter: none; }
.btn--danger { background: var(--critical); }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  margin-bottom: 18px;
}
.filters .field { margin: 0; min-width: 160px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg {
  display: inline-flex; border: 1px solid var(--border); border-radius: 999px;
  overflow: hidden; background: var(--surface-1);
}
.seg a {
  padding: 5px 12px; font-size: 12.5px; font-weight: 600;
  color: var(--text-secondary); text-decoration: none;
}
.seg a[aria-current="true"] { background: var(--series-1); color: #fff; }

/* --- messages ------------------------------------------------------------ */

.messages { display: grid; gap: 8px; margin-bottom: 18px; }
.msg {
  padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-1);
  display: flex; gap: 9px; align-items: flex-start;
}
.msg--success { border-left: 3px solid var(--good); }
.msg--error { border-left: 3px solid var(--critical); }
.msg--warning { border-left: 3px solid var(--warning); }
.msg--info { border-left: 3px solid var(--series-1); }

/* --- auth pages ---------------------------------------------------------- */

.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 40px 20px;
}
.auth__card {
  width: 100%; max-width: 520px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 30px; box-shadow: var(--shadow);
}
.auth__card--wide { max-width: 760px; }
.auth h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
.auth__lede { color: var(--text-secondary); margin: 0 0 22px; }
.auth__cols { display: grid; gap: 0 20px; grid-template-columns: 1fr 1fr; }
.auth__section {
  grid-column: 1 / -1; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); font-weight: 700;
  margin: 10px 0 8px; padding-top: 12px; border-top: 1px solid var(--border);
}
.auth__section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.auth__full { grid-column: 1 / -1; }
.auth__foot { margin-top: 18px; font-size: 13px; color: var(--text-secondary); }

.empty {
  text-align: center; padding: 44px 20px; color: var(--text-secondary);
}
.empty h3 { margin: 0 0 6px; color: var(--text-primary); }

.pager {
  display: flex; gap: 10px; align-items: center; justify-content: center;
  margin-top: 18px; font-size: 13px; color: var(--text-secondary);
}

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.kv dt { color: var(--text-muted); font-size: 12.5px; }
.kv dd { margin: 0; }

.print-only { display: none; }

@media (max-width: 880px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    flex-direction: row; align-items: center; gap: 14px; overflow-x: auto;
  }
  .nav { flex-direction: row; }
  .nav__group, .sidebar__foot, .brand__sub { display: none; }
  .main { padding: 18px 16px 48px; }
  .auth__cols { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .toolbar, .btn, .filters { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .print-only { display: block; }
  body { background: #fff; }
}
