/* ---------------------------------------------------------------------
   Issy dashboard.

   Colour is defined once, here, as roles. Nothing below this block
   mentions a hex value, so light/dark swap in one place and a chart is
   written against --series-1 rather than "the blue one".

   The categorical steps are the validated eight-slot order; the dark
   column is the same hues re-stepped for the dark surface, not a flip.
   --------------------------------------------------------------------- */

:root {
  color-scheme: light;

  --plane:          #f9f9f7;
  --surface-1:      #fcfcfb;
  --surface-2:      #f2f1ed;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --shadow:         0 1px 2px rgba(11, 11, 11, 0.05);

  --series-1: #2a78d6;  /* blue    - Hamilton, revenue, cash        */
  --series-2: #eb6834;  /* orange  - Glorietta, card                */
  --series-3: #1baf7a;  /* aqua    - other tender                   */
  --series-4: #eda100;  /* yellow  - expenses                       */

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

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface-1:      #1a1a19;
    --surface-2:      #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --shadow:         none;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --up-good:  #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface-1:      #1a1a19;
  --surface-2:      #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --shadow:         none;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --up-good:  #0ca30c;
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-secondary); }

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

/* --- top bar --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
}

.brand { display: flex; align-items: baseline; gap: 8px; margin-right: auto; }
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--series-1); display: inline-block;
}
.brand small { color: var(--text-muted); font-size: 12px; }

/* Filters sit in one row above the charts, as a group. */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.chip {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] {
  color: var(--text-primary);
  border-color: var(--text-muted);
  background: var(--surface-2);
  font-weight: 600;
}
.chip .swatch { width: 9px; height: 9px; border-radius: 2px; }

.range-input {
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: 8px;
  padding: 4px 8px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
  color: var(--text-secondary);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }

/* --- tabs ------------------------------------------------------------ */

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 53px;
  z-index: 19;
}
.tabs button {
  border: 0;
  background: none;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text-primary); }
.tabs button[aria-selected="true"] {
  color: var(--text-primary);
  border-bottom-color: var(--series-1);
  font-weight: 600;
}

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
section[hidden] { display: none; }

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

/* Every span from 2 to 12 is defined. A card using a class that does not
   exist here silently falls back to ONE column, and a chart inside a
   116px card computes a negative plot width and draws itself backwards -
   which is exactly what happened to col-7 and col-5 before they were
   added. If you use a new span, define it. */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(12, 1fr); }
.col-12 { grid-column: span 12; }
.col-10 { grid-column: span 10; }
.col-9  { grid-column: span 9; }
.col-8  { grid-column: span 8; }
.col-7  { grid-column: span 7; }
.col-6  { grid-column: span 6; }
.col-5  { grid-column: span 5; }
.col-4  { grid-column: span 4; }
.col-3  { grid-column: span 3; }
.col-2  { grid-column: span 2; }

@media (max-width: 1000px) {
  .col-10, .col-9, .col-8, .col-7, .col-6, .col-5, .col-4 { grid-column: span 12; }
  .col-3, .col-2 { grid-column: span 6; }
}
@media (max-width: 560px) {
  .col-3 { grid-column: span 12; }
  main { padding: 12px; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.card-note { color: var(--text-muted); font-size: 12px; margin: 0 0 10px; }

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

.stat .label { color: var(--text-secondary); font-size: 12px; text-transform: none; }
.stat .value {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-top: 2px;
  line-height: 1.15;
}
.stat .sub { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.delta { font-size: 12px; font-weight: 600; display: inline-flex; gap: 4px; align-items: center; }
.delta.up   { color: var(--up-good); }
.delta.down { color: var(--critical); }
.delta.flat { color: var(--text-muted); }

/* --- legend ---------------------------------------------------------- */

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 2px 0 8px; }
.legend span {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-secondary); font-size: 12px;
}
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend i.dash {
  height: 0; border-top: 2px dashed currentColor; border-radius: 0; width: 14px;
}

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

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line  { stroke: var(--axis); stroke-width: 1; }
.chart .tick {
  fill: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chart .mark-label { fill: var(--text-secondary); font-size: 11px; }
.chart .value-label {
  fill: var(--text-primary); font-size: 11px; font-weight: 600;
}
.chart .crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
  min-width: 140px;
  z-index: 5;
  opacity: 0;
  transition: opacity 90ms linear;
}
.tooltip.on { opacity: 1; }
.tooltip .t-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .t-row {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
}
.tooltip .t-row .k { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip .t-row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.tooltip i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

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

.table-wrap { overflow-x: auto; margin-top: 4px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  position: sticky;
  top: 0;
  background: var(--surface-1);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
td.wrap { white-space: normal; max-width: 320px; }

details.table-view { margin-top: 10px; }
details.table-view summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  list-style: none;
}
details.table-view summary::-webkit-details-marker { display: none; }
details.table-view summary::before { content: "▸ "; }
details.table-view[open] summary::before { content: "▾ "; }
details.table-view .table-wrap { max-height: 320px; overflow-y: auto; }

/* --- badges ---------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--text-primary);
  background: var(--surface-2);
}
/* Status never rides on colour alone: each badge carries a glyph and a
   word as well. */
.badge.good     { color: var(--good); }
.badge.warning  { color: #8a6100; }
.badge.critical { color: var(--critical); }
.badge.muted    { color: var(--text-muted); }
:root[data-theme="dark"] .badge.warning,
:root:where(:not([data-theme="light"])) .badge.warning { color: var(--warning); }

.pill {
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
}
/* The backup warning in the header (backupView in app.js). Hidden while
   backups are fine; when it shows it is the one pill that is not grey,
   and a button that opens the Health tab. Glyph and words as well as
   colour, like the badges. */
button.pill { font: inherit; font-size: 11px; background: none; cursor: pointer; }
.pill[hidden] { display: none; }
.pill.warning  { color: #8a6100; border-color: currentColor; font-weight: 600; }
.pill.critical { color: var(--critical); border-color: currentColor; font-weight: 600; }
:root[data-theme="dark"] .pill.warning,
:root:where(:not([data-theme="light"])) .pill.warning { color: var(--warning); }

.empty { color: var(--text-muted); padding: 22px 0; text-align: center; }
.error {
  color: var(--critical);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
}

/* --- login ----------------------------------------------------------- */

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: min(360px, 100%);
  box-shadow: var(--shadow);
}
.login-card h1 { margin-bottom: 4px; }
.login-card p { color: var(--text-muted); font-size: 13px; margin: 0 0 18px; }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 10px;
}
.login-card button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 0;
  background: var(--series-1);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.login-card .msg { color: var(--critical); font-size: 13px; min-height: 20px; }

.skeleton {
  background: var(--surface-2);
  border-radius: 6px;
  height: 12px;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Forced colours: the marks keep their shape, the browser owns colour. */
@media (forced-colors: active) {
  .card, .tooltip { border: 1px solid CanvasText; }
}

/* Used by the standalone note cards. Was an inline style attribute,
   which the page's Content-Security-Policy blocks. */
.card-note.flush { margin: 0; }

/* --- phones ----------------------------------------------------------
   The grid already collapses to one column below 1000px, but the pieces
   INSIDE a card were still laid out for a wide one. On a 375px screen a
   card head put "What the drinks used" beside five filter chips, which
   squeezed the heading into three words on three lines. */
@media (max-width: 560px) {
  /* Heading on its own line, controls underneath, each full width. */
  .card-head {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .card-head h2 { font-size: 15px; }
  /* The filter row inside a head should start at the left edge like
     everything else, not sit right-aligned under the heading. */
  .card-head .filters { justify-content: flex-start; }

  /* Chips are the main control on the Inventory tab and there are a lot
     of them. A little tighter fits two or three to a row rather than
     one, which is the difference between a tap and a scroll. */
  .chip { padding: 5px 10px; font-size: 12.5px; }

  /* Tables scroll sideways inside their card rather than squashing a
     column to nothing. Momentum scrolling so it feels like the rest of
     the phone, and a touch less padding so fewer columns are cut off in
     the first place. */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  th, td { padding: 7px 8px; }

  .card { padding: 12px 12px 14px; }
  .stat .value { font-size: 22px; }
}

/* --- dropdowns -------------------------------------------------------
   A native <select>, not a custom menu. On a phone it opens the OS
   picker, which is a better control than anything built here would be,
   and it comes with keyboard support and screen-reader semantics for
   free. The panel carries an <optgroup> label naming what is being
   chosen, and the arrow follows light/dark because :root already sets
   color-scheme.

   These replace the pick-one chip rows. Chips remain for the multi-
   select filters (branches, cost centres), where the whole point is
   seeing several on at once. */
.select {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
  max-width: 100%;
}
.select:hover { background: var(--surface-2); }
.select:focus-visible { outline: 2px solid var(--text-muted); outline-offset: 1px; }
/* Chrome on Windows takes these for the popup rows; elsewhere the OS
   decides and this is ignored, which is fine. */
.select option { background: var(--surface-1); color: var(--text-primary); }
.select optgroup { color: var(--text-muted); font-style: normal; }

@media (max-width: 560px) {
  /* Room to read the chosen value rather than an ellipsis. */
  .select { font-size: 13px; padding: 6px 10px; flex: 1 1 auto; min-width: 8rem; }
}
