/* RentBooks stylesheet.
   Colour tokens follow a validated palette: categorical slots 1-3 are used for
   chart series, status colours only ever mean good/bad. Dark mode is a selected
   set of steps for the dark surface, not an inversion. */

:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --surface-sunk:    #f2f1ed;
  --ink:             #0b0b0b;
  --ink-2:           #52514e;
  --muted:           #898781;
  --grid:            #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --border-strong:   rgba(11, 11, 11, 0.18);

  --series-1:        #2a78d6;
  --series-2:        #eb6834;
  --series-3:        #1baf7a;

  --good:            #0ca30c;
  --warning:         #fab219;
  --serious:         #ec835a;
  --critical:        #d03b3b;
  --delta-up:        #006300;
  --delta-down:      #d03b3b;

  --accent:          #2a78d6;
  --accent-ink:      #ffffff;
  --focus:           #2a78d6;

  --radius:          10px;
  --radius-sm:       6px;
  --shadow:          0 1px 2px rgba(11, 11, 11, 0.05);
  --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:       #1a1a19;
    --surface-sunk:  #141413;
    --ink:           #ffffff;
    --ink-2:         #c3c2b7;
    --muted:         #898781;
    --grid:          #2c2c2a;
    --baseline:      #383835;
    --border:        rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.20);
    --series-1:      #3987e5;
    --series-2:      #d95926;
    --series-3:      #199e70;
    --delta-up:      #0ca30c;
    --delta-down:    #e66767;
    --accent:        #3987e5;
    --shadow:        0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:          #0d0d0d;
  --surface:       #1a1a19;
  --surface-sunk:  #141413;
  --ink:           #ffffff;
  --ink-2:         #c3c2b7;
  --muted:         #898781;
  --grid:          #2c2c2a;
  --baseline:      #383835;
  --border:        rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);
  --series-1:      #3987e5;
  --series-2:      #d95926;
  --series-3:      #199e70;
  --delta-up:      #0ca30c;
  --delta-down:    #e66767;
  --accent:        #3987e5;
  --shadow:        0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

/* .field sets display:grid, which would otherwise win over the UA's
   [hidden] rule and leave the custom date range on screen. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------------------------------------------------------------- layout */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 56px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent);
  display: grid; place-items: center;
  color: var(--accent-ink); font-size: 12px; font-weight: 700;
}
nav.main { display: flex; gap: 2px; margin-inline-start: auto; flex-wrap: wrap; }
nav.main a {
  color: var(--ink-2);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  white-space: nowrap;
}
nav.main a:hover { background: var(--surface-sunk); text-decoration: none; color: var(--ink); }
nav.main a[aria-current="page"] { background: var(--surface-sunk); color: var(--ink); font-weight: 600; }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 72px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; letter-spacing: -0.01em; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.subtitle { color: var(--ink-2); font-size: 14px; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }
.card-note { color: var(--muted); font-size: 12.5px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 15px;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 600; margin-bottom: 6px;
}
.stat-value { font-size: 25px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.stat-value.sm { font-size: 20px; }
.stat-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 5px; }
.delta { font-size: 12.5px; font-weight: 600; margin-top: 5px; display: flex; gap: 5px; align-items: center; }
.delta.up { color: var(--delta-up); }
.delta.down { color: var(--delta-down); }
.delta.flat { color: var(--muted); }
.delta-base { color: var(--muted); font-weight: 400; }

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

.chart-wrap { position: relative; }
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--font); fill: var(--muted); }
.chart .axis-label { font-size: 11px; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .mark-label { font-size: 11px; fill: var(--ink-2); font-weight: 600; }
.chart .hover-band { fill: transparent; }
.chart .hover-band:hover { fill: var(--ink); fill-opacity: 0.04; }
.chart .crosshair { stroke: var(--baseline); stroke-width: 1; }

.legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--ink-2); margin-bottom: 10px;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-swatch.line { height: 3px; border-radius: 2px; width: 14px; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
  padding: 8px 10px;
  font-size: 12.5px;
  min-width: 130px;
  opacity: 0;
  transition: opacity 90ms ease;
  z-index: 10;
  color: var(--ink);
}
.tooltip.on { opacity: 1; }
.tooltip-title { font-weight: 650; margin-bottom: 5px; }
.tooltip-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.tooltip-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.tooltip-key { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }

details.table-view { margin-top: 12px; }
details.table-view summary {
  cursor: pointer; font-size: 12.5px; color: var(--ink-2);
  padding: 4px 0; user-select: none;
}
details.table-view summary:hover { color: var(--ink); }

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

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.045em;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td {
  padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-sunk); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td {
  font-weight: 650; border-top: 1px solid var(--border-strong); border-bottom: none;
}
.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }

table.data.waterfall td { padding: 10px; }
table.data.waterfall tr.subtotal td {
  font-weight: 650;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunk);
}
table.data.waterfall tr.total td {
  font-weight: 700;
  font-size: 16px;
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
}
table.data.waterfall td.num { width: 1%; white-space: nowrap; }

.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar-track { flex: 1; height: 6px; background: var(--surface-sunk); border-radius: 3px; min-width: 40px; }
.bar-fill { height: 6px; border-radius: 3px; background: var(--series-1); display: block; }

/* ----------------------------------------------------------------- forms */

form.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="file"], input[type="search"], select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
}
textarea { resize: vertical; min-height: 70px; font-family: var(--font); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-sunk); color: var(--muted); }

.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-sunk); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(0.93); background: var(--accent); }
.btn-danger { color: var(--critical); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--surface-sunk); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.subform {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunk);
  padding: 14px;
}
#repeat-summary { color: var(--ink-2); font-weight: 600; }

/* ------------------------------------------------------------ filter bar */

.filters {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.filters .field { gap: 4px; }
.filters .field label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.045em; color: var(--muted); }
.filters select, .filters input { min-width: 130px; width: auto; }
.filters .spacer { margin-inline-start: auto; }

/* ----------------------------------------------------------------- misc */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; border: 1px solid var(--border-strong);
  color: var(--ink-2); white-space: nowrap;
}
.badge.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.badge.warn { color: var(--serious); border-color: color-mix(in srgb, var(--serious) 45%, transparent); }
.badge.bad { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.badge.muted { color: var(--muted); }

.notice {
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  display: flex; gap: 9px; align-items: flex-start;
}
.notice.ok { border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.notice.err { border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.notice-icon { flex: none; font-weight: 700; }
.notice.ok .notice-icon { color: var(--good); }
.notice.err .notice-icon { color: var(--critical); }

.empty {
  text-align: center; padding: 44px 20px; color: var(--ink-2);
}
.empty h2 { margin-bottom: 6px; }
.empty p { margin: 0 auto 18px; max-width: 380px; color: var(--muted); }

.auth-page {
  max-width: 400px; margin: 8vh auto; padding: 0 20px;
}
.auth-page .card { padding: 26px; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head .brand-mark { width: 34px; height: 34px; font-size: 16px; margin: 0 auto 12px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.pos { color: var(--delta-up); }
.neg { color: var(--delta-down); }
.divider { height: 1px; background: var(--border); margin: 18px 0; border: 0; }

/* -------------------------------------------------------- rate calendar */

.cal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 18px; }
.cal-month h3 { margin-bottom: 8px; }
.cal-table { width: 100%; border-collapse: separate; border-spacing: 2px; }
.cal-table th {
  font-size: 10.5px; color: var(--muted); font-weight: 600; padding-bottom: 3px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.cal-day {
  border-radius: var(--radius-sm);
  background: var(--surface-sunk);
  padding: 4px 3px 5px;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.25;
  border: 1px solid transparent;
}
.cal-day .d { color: var(--ink-2); font-weight: 600; }
.cal-day .p { color: var(--ink); font-variant-numeric: tabular-nums; }
.cal-day.weekend { border-color: var(--border); }
.cal-day.booked { background: color-mix(in srgb, var(--series-1) 18%, var(--surface)); }
.cal-day.booked .p { color: var(--ink); font-weight: 650; }
.cal-day.past { opacity: 0.42; }
.cal-day.empty-cell { background: transparent; }

@media (max-width: 640px) {
  .topbar-inner { gap: 10px; }
  nav.main { margin-inline-start: 0; width: 100%; overflow-x: auto; padding-bottom: 6px; }
  main { padding: 16px 14px 60px; }
  .stat-value { font-size: 22px; }
  .table-scroll { margin: 0 -18px; }
}

@media print {
  .topbar, .filters, .btn-row, form { display: none !important; }
  body { background: #fff; }
  .card { break-inside: avoid; box-shadow: none; }
}

/* ------------------------------------------------- category bar list */

.cat-bars { display: grid; gap: 9px; }
.cat-row {
  display: grid;
  grid-template-columns: minmax(96px, 1.1fr) 2fr auto 40px;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}
.cat-name { color: var(--ink-2); }
.cat-value { font-weight: 600; }
.cat-share { font-size: 12px; text-align: right; }
@media (max-width: 520px) {
  .cat-row { grid-template-columns: minmax(80px, 1fr) 1.4fr auto; }
  .cat-share { display: none; }
}
