/* platecost — kitchen green, bar amber, unclassified grey. That colour pairing
   is the whole navigation system: a manager should be able to tell what kind of
   spend they are looking at without reading a word. */

:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1c1b19;
  --muted: #6b6862;
  --line: #e2e0db;
  --kitchen: #2f7d4f;
  --kitchen-bg: #eaf5ee;
  --bar: #b4791b;
  --bar-bg: #fbf2e2;
  --other: #8a867e;
  --other-bg: #f0efec;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --accent: #1c1b19;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: inherit; }

header.top {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
header.top .brand { font-weight: 650; letter-spacing: -.01em; }
header.top nav { display: flex; gap: 1rem; }
header.top nav a { text-decoration: none; color: var(--muted); font-size: .92rem; }
header.top nav a:hover, header.top nav a.on { color: var(--ink); }
header.top .spacer { margin-left: auto; }

main { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .6rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.pad { padding: 1rem 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.right { text-align: right; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* ------------------------------------------------------------- area colours */
.area-kitchen { --area: var(--kitchen); --area-bg: var(--kitchen-bg); }
.area-bar     { --area: var(--bar);     --area-bg: var(--bar-bg); }
.area-other   { --area: var(--other);   --area-bg: var(--other-bg); }
.area-mixed   { --area: var(--other);   --area-bg: var(--other-bg); }

.chip {
  display: inline-block; padding: .12rem .5rem; border-radius: 100px;
  font-size: .78rem; font-weight: 600; background: var(--area-bg); color: var(--area);
}
.stripe { border-left: 4px solid var(--area); }

/* ------------------------------------------------------------------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; }
.stat { padding: .9rem 1rem; }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase;
               letter-spacing: .04em; }
.stat .value { font-size: 1.7rem; font-weight: 650; letter-spacing: -.02em; margin-top: .15rem;
               font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
     color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafaf8; }
.table-wrap { overflow-x: auto; }

/* ------------------------------------------------------------------- forms */
input, select, button, textarea { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=date], input[type=email],
input[type=password], select, textarea {
  width: 100%; padding: .4rem .5rem; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: block; margin-bottom: .7rem; }
label.field span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }

.btn {
  display: inline-block; padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; text-decoration: none; font-size: .92rem;
}
.btn:hover { background: #f2f1ee; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }

/* --------------------------------------------------------------- messaging */
.note { padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .92rem; }
.note.ok    { background: var(--kitchen-bg); color: var(--kitchen); }
.note.warn  { background: var(--bar-bg);     color: var(--bar); }
.note.error { background: var(--danger-bg);  color: var(--danger); }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty p { margin: .4rem 0 1rem; }

/* ------------------------------------------------------------ review split */
.split { display: grid; grid-template-columns: minmax(320px, 4fr) 7fr; gap: 1rem; align-items: start; }
.doc-pane { position: sticky; top: 4.2rem; height: calc(100vh - 6rem); overflow: hidden; }
.doc-pane iframe, .doc-pane img { width: 100%; height: 100%; border: 0; object-fit: contain;
                                  background: #edece8; border-radius: var(--radius); }
.grid-pane table { font-size: .9rem; }
.grid-pane td { padding: .3rem .35rem; }
.grid-pane input, .grid-pane select { padding: .3rem .4rem; }
.grid-pane tr.flagged { background: var(--danger-bg); }

.area-toggle { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.area-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.area-toggle label {
  padding: .25rem .5rem; font-size: .8rem; cursor: pointer; background: var(--panel);
  color: var(--muted); border-right: 1px solid var(--line); user-select: none;
}
.area-toggle label:last-child { border-right: 0; }
.area-toggle input:checked + label { background: var(--area-bg); color: var(--area); font-weight: 600; }

.sticky-actions {
  position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line);
  padding: .75rem 1rem; display: flex; gap: .6rem; align-items: center;
  border-radius: 0 0 var(--radius) var(--radius);
}

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .doc-pane { position: static; height: 50vh; }
}

/* ------------------------------------------------------------ line types */
.type-select {
  width: auto; font-size: .72rem; padding: .1rem .2rem; margin-top: .2rem;
  border: 0; background: transparent; color: var(--muted); text-transform: uppercase;
  letter-spacing: .03em; cursor: pointer;
}
.type-select.non-product { color: var(--bar); font-weight: 700; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }

/* =========================================================================
   MOBILE
   An invoice gets photographed at the back door and reviewed standing up, so
   the phone layout is the real one, not a fallback. Three things matter:
   inputs that do not trigger iOS zoom, touch targets you can hit without
   looking, and a line grid that stops being a table.
   ========================================================================= */

@media (max-width: 780px) {

  /* 16px is the threshold below which iOS zooms the viewport on focus. Zooming
     mid-entry loses your place in a 20-line invoice, so nothing goes smaller. */
  input[type=text], input[type=number], input[type=date], input[type=email],
  input[type=password], select, textarea {
    font-size: 16px;
    padding: .55rem .6rem;
  }

  main { padding: .85rem .7rem 6rem; }
  h1 { font-size: 1.2rem; }

  header.top { gap: .7rem; padding: .6rem .75rem; flex-wrap: wrap; }
  header.top .brand { font-size: .95rem; }
  header.top nav { gap: .75rem; order: 3; width: 100%; }
  header.top nav a { font-size: .88rem; padding: .2rem 0; }
  header.top .small { font-size: .78rem; }

  .stats { grid-template-columns: 1fr 1fr; gap: .55rem; }
  .stat { padding: .7rem .75rem; }
  .stat .value { font-size: 1.3rem; }
  .stat .label { font-size: .7rem; }

  .hide-narrow { display: none; }

  /* --- the document, collapsed by default -------------------------------
     On a phone the photo is the thing you already saw. Give the grid the
     screen and let the document be pulled up when a line needs checking. */
  .split { grid-template-columns: 1fr; gap: .6rem; }
  .doc-pane { height: 34vh; position: relative; top: 0; }

  /* --- the line grid becomes a stack of cards --------------------------- */
  table.cards, table.cards thead, table.cards tbody,
  table.cards th, table.cards td, table.cards tr { display: block; }
  table.cards thead { position: absolute; left: -9999px; }  /* headers live in data-label */
  .table-wrap { overflow-x: visible; }

  table.cards tbody tr {
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: .6rem; margin: 0 .6rem .6rem;
    display: grid; grid-template-columns: 1fr 1fr; gap: .45rem .5rem;
    background: var(--panel);
  }
  table.cards tbody tr.flagged { border-color: var(--danger); background: var(--danger-bg); }
  table.cards tbody tr:hover { background: var(--panel); }

  /* description and cost centre span the full width; the numbers pair up */
  table.cards td[data-label="Item"],
  table.cards td[data-label="Cost centre"] { grid-column: 1 / -1; }
  table.cards td[data-label="SKU"] { display: none; }   /* rarely needed by hand */

  table.cards td { border: 0; padding: 0; }
  table.cards td::before {
    content: attr(data-label);
    display: block; font-size: .68rem; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted); margin-bottom: .12rem;
  }
  table.cards td[data-label="Item"]::before { display: none; }

  /* full-width segmented control, thumb-sized */
  .area-toggle { width: 100%; }
  .area-toggle label { flex: 1; text-align: center; padding: .55rem .3rem; font-size: .85rem; }

  /* --- actions pinned to the bottom ------------------------------------- */
  .sticky-actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    border-radius: 0; box-shadow: 0 -2px 12px rgba(0,0,0,.08);
    padding: .6rem .7rem; gap: .45rem;
  }
  .sticky-actions .btn { flex: 1; padding: .7rem .5rem; text-align: center; }
  .sticky-actions .btn.danger { flex: 0 0 auto; }

  /* --- list tables scroll rather than crush ----------------------------- */
  table { font-size: .88rem; }
  th, td { padding: .45rem .4rem; }

  /* upload form stacks */
  form .row { flex-direction: column; align-items: stretch; }
  form .row .btn { width: 100%; padding: .7rem; }
}

/* Very small phones: one column of numbers rather than two cramped ones. */
@media (max-width: 400px) {
  .stats { grid-template-columns: 1fr; }
  table.cards tbody tr { grid-template-columns: 1fr; }
}

/* Coarse pointers get bigger hit areas regardless of width. */
@media (pointer: coarse) {
  .btn { padding: .6rem 1rem; }
  .area-toggle label { padding: .5rem .6rem; }
}

/* ---------------------------------------------------------------- insights */
.up   { color: var(--danger); font-weight: 650; }   /* costs going up is the bad one */
.down { color: var(--kitchen); font-weight: 650; }
.block { display: block; font-weight: 400; }
/* Equal-width period buttons. `grid-auto-columns: 1fr` makes every column the
   width of the widest label, so "All" and "6 months" match without hard-coding
   a size — and it stays correct if a period is added or renamed. */
.periods {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: .3rem; flex-wrap: nowrap;
}
.periods .btn {
  padding: .35rem .6rem; font-size: .82rem; text-align: center;
  white-space: nowrap; line-height: 1.3;
}

/* ------------------------------------------------------------------------
   Nothing scrolls sideways. A horizontal scrollbar on a phone hides data the
   user does not know is there, which on a cost report is worse than useless.
   Every wide table becomes a card stack instead; the page itself never pans.
   ------------------------------------------------------------------------ */
html, body { max-width: 100%; overflow-x: hidden; }

@media (max-width: 780px) {
  .table-wrap { overflow-x: visible; }

  /* list tables: two columns of labelled values, the first spanning the width */
  table.cards tbody tr { grid-template-columns: 1fr 1fr; }
  table.cards td[data-label="Vendor"],
  table.cards td[data-label="Item"] { grid-column: 1 / -1; font-weight: 600; }
  table.cards td[data-label="Vendor"] a { text-decoration: none; }

  /* Still equal columns, now spanning the screen. flex: 1 would do nothing
     here — .periods is a grid, so the columns carry the sizing. */
  .periods { width: 100%; }
  .periods .btn { padding: .45rem .3rem; font-size: .78rem; }

  h2 { margin: 1.3rem 0 .5rem; }
}

/* ----------------------------------------------------------------- reports */
.filter-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem .7rem;
}
.filter-grid .field { margin: 0; }

/* A row of actions reads as one control, so they match. min-width rather than
   stretching: three buttons spanning the whole page would look like a mistake. */
.filters .row .btn { min-width: 132px; text-align: center; }

/* An inline share bar: the eye finds the big number before it reads any of them. */
.bar-track {
  display: block; height: 3px; background: var(--line); border-radius: 2px;
  margin-top: .25rem; overflow: hidden;
}
.bar-fill { display: block; height: 100%; background: var(--muted); }
tfoot th { border-top: 2px solid var(--line); border-bottom: 0; color: var(--ink);
           font-size: .9rem; text-transform: none; letter-spacing: 0; }

@media (max-width: 780px) {
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .filters .row .btn { flex: 1; text-align: center; }
  table.cards tfoot, table.cards tfoot tr, table.cards tfoot th { display: block; }
  table.cards tfoot tr {
    display: flex; justify-content: space-between; padding: .6rem;
    margin: 0 .6rem; border-top: 2px solid var(--line);
  }
  table.cards tfoot th:empty { display: none; }
}

/* ------------------------------------------------------------- signal cards
   A finding reads as a sentence, not a row. The colour bar on the left carries
   severity; the chip on the right carries kitchen/bar. */
.signals { display: grid; gap: .5rem; margin-bottom: .5rem; }
.signal {
  display: grid; grid-template-columns: 4px 1fr auto; gap: .8rem;
  align-items: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .7rem .9rem .7rem 0; overflow: hidden;
}
.signal-mark { align-self: stretch; background: var(--muted); }
.signal.sev-warn .signal-mark { background: var(--danger); }
.signal.sev-good .signal-mark { background: var(--kitchen); }
.signal.sev-info .signal-mark { background: var(--other); }
.signal-title { font-weight: 600; letter-spacing: -.01em; }
.signal .impact { color: var(--danger); font-weight: 600; margin-top: .1rem; }
.signal.sev-good .impact { color: var(--kitchen); }

@media (max-width: 780px) {
  .signal { grid-template-columns: 4px 1fr; padding: .65rem .75rem .65rem 0; }
  .signal .chip { grid-column: 2; justify-self: start; margin-top: .3rem; }
}
