/* ============================================================
   styles.css — the look of the costing site.
   Colours are set once as tokens at the top (light + dark mode).
   The one stand-out element is the "cup bar": a bar that fills
   with espresso colour up to the drink's cost %, with a notch at
   your target. Everything else stays quiet.
   ============================================================ */
:root {
  --bg: #EEF2F1;
  --surface: #FFFFFF;
  --surface-2: #F6F8F7;
  --ink: #1B2A2C;
  --muted: #5B6A6C;
  --line: #D5DDDB;
  --accent: #1E5A5E;
  --accent-ink: #FFFFFF;
  --espresso: #6A4330;
  --crema: #E8DCCB;
  --good: #24704E;
  --good-bg: #E2F1E9;
  --warn: #8F5A0B;
  --warn-bg: #FBEFD9;
  --bad: #A8231B;
  --bad-bg: #FBE4E1;
  --focus: #2F7F86;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131B1C; --surface: #1B2526; --surface-2: #212D2E; --ink: #E5ECEA; --muted: #9AA9A7;
    --line: #304042; --accent: #6FB8BC; --accent-ink: #0F2224; --espresso: #C99A7C; --crema: #3A3029;
    --good: #7FCFA6; --good-bg: #1D3529; --warn: #E9B866; --warn-bg: #3A2E18; --bad: #F2948B; --bad-bg: #3E2220;
    --focus: #8FD3D7; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131B1C; --surface: #1B2526; --surface-2: #212D2E; --ink: #E5ECEA; --muted: #9AA9A7;
  --line: #304042; --accent: #6FB8BC; --accent-ink: #0F2224; --espresso: #C99A7C; --crema: #3A3029;
  --good: #7FCFA6; --good-bg: #1D3529; --warn: #E9B866; --warn-bg: #3A2E18; --bad: #F2948B; --bad-bg: #3E2220;
  --focus: #8FD3D7; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.5 "IBM Plex Sans", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: "Bricolage Grotesque", system-ui, sans-serif; font-weight: 700; line-height: 1.15; margin: 0; }
h1 { font-size: 30px; letter-spacing: -0.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
a { color: var(--accent); }
.boot { padding: 40px; color: var(--muted); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- frame: sidebar on wide screens, top tabs on phones ---------- */
.frame { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 22px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-family: "Bricolage Grotesque", sans-serif; font-weight: 700; font-size: 19px; padding: 0 10px 18px; display: flex; gap: 8px; align-items: center; }
.brand svg { flex: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { text-decoration: none; color: var(--ink); padding: 8px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.nav .gap { height: 12px; }
.side .who { margin-top: 24px; padding: 0 10px; font-size: 13px; color: var(--muted); word-break: break-all; }
main { padding: 28px 32px 80px; max-width: 1180px; width: 100%; }
.pagehead { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.lede { color: var(--muted); max-width: 70ch; margin: 6px 0 22px; }

@media (max-width: 900px) {
  .frame { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; padding: 10px 0 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 16px 8px; font-size: 17px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; padding: 0 12px 10px; } /* wraps onto more lines instead of scrolling sideways */
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav .gap, .side .who { display: none; }
  main { padding: 20px 16px 80px; }
  h1 { font-size: 25px; }
}

/* ---------- panels, tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.panel > h2 { margin-bottom: 4px; }
.panel > .sub { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.tablewrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: bottom; }
td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.section td { background: var(--surface-2); font-family: "Bricolage Grotesque", sans-serif; font-weight: 700; font-size: 14px; padding-top: 10px; }
tr.total td { font-weight: 600; border-top: 2px solid var(--line); }
tr.paid td { color: var(--muted); }
tr.paid td input[type=text] { text-decoration: line-through; }
.rowlink { font-weight: 600; text-decoration: none; }
.rowlink:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- inputs ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=month], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; min-width: 0; width: 100%;
}
input[type=number] { text-align: right; }
td input[type=number] { width: 92px; }
td input.w-s { width: 80px; }
td input.w-l { min-width: 170px; }
td .money input { width: 112px; }
td input[type=text] { min-width: 110px; }
td select { min-width: 140px; }
input:hover, select:hover { border-color: var(--muted); }
.money { position: relative; display: inline-block; }
.money::before { content: "$"; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.money input { padding-left: 18px; }
.pct { position: relative; display: inline-block; }
.pct::after { content: "%"; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.pct input { padding-right: 22px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 18px; }
.field label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.field .money, .field .pct { display: block; }

button, .btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink); display: inline-block;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 2px 4px; color: var(--muted); }
button.link:hover { color: var(--bad); }
button.use { padding: 2px 8px; font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }

/* ---------- status chips ---------- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.none { background: var(--surface-2); color: var(--muted); }

/* ---------- the cup bar: cost % filled in espresso, target notch ---------- */
.cup { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.cup .bar { position: relative; flex: 1; height: 12px; border-radius: 6px; background: var(--crema); overflow: visible; }
.cup .fill { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: var(--espresso); }
.cup .fill.over { background: var(--bad); }
.cup .notch { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); border-radius: 1px; }
.cup .val { width: 46px; text-align: right; font-weight: 600; font-size: 13.5px; }

/* ---------- overview ---------- */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.figure { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.figure .k { color: var(--muted); font-size: 13.5px; }
.figure .v { font-family: "Bricolage Grotesque", sans-serif; font-size: 26px; font-weight: 700; margin-top: 2px; }
.figure .v.neg { color: var(--bad); }
.figure .f { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.alerts li:last-child { border-bottom: 0; }
.alerts .what { flex: 1; min-width: 200px; }
.empty { color: var(--muted); padding: 8px 0; }

/* ---------- recipe page ---------- */
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; font-weight: 500; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.summary div { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.summary .k { font-size: 13px; color: var(--muted); }
.summary .v { font-weight: 600; font-size: 17px; }
.namefield { font-family: "Bricolage Grotesque", sans-serif; font-size: 26px; font-weight: 700; border: 1px solid transparent !important; padding: 2px 6px !important; margin-left: -6px; background: transparent !important; }
.namefield:hover, .namefield:focus { border-color: var(--line) !important; background: var(--surface) !important; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; display: grid; gap: 14px; }
.login h1 { font-size: 26px; }
.login p { margin: 0; color: var(--muted); }
.err { color: var(--bad); font-size: 14px; min-height: 1.2em; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); color: #fff; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* ---------- login extras: show/hide password, remember me, mode links ---------- */
.pw { position: relative; }
.pw input { padding-right: 64px; }
.pwtoggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); padding: 3px 9px; font-size: 13px; border-radius: 6px; background: var(--surface-2); }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.login button.link { color: var(--accent); font-weight: 500; padding: 0; }
.login button.link:hover { color: var(--accent); text-decoration: underline; }
.switch { font-size: 14px; text-align: center; }
.okmsg { color: var(--good); background: var(--good-bg); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.err:empty { display: none; }
.brand small { display: block; font-family: "IBM Plex Sans", sans-serif; font-weight: 400; font-size: 13px; color: var(--muted); }

/* ---------- tables too wide for the screen become stacked cards (fitTables in app.js) ----------
   Each row becomes a small card; each value gets its column name above it.
   Nothing scrolls sideways; you just scroll down. */
table.stacked, table.stacked tbody { display: block; width: 100%; }
table.stacked thead { display: none; }
table.stacked tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
table.stacked td { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 0; border: 0; text-align: left; white-space: normal; min-width: 0; }
table.stacked td.num { text-align: left; }
table.stacked td[data-label]:not([data-label=""])::before { content: attr(data-label); font-size: 12px; font-weight: 500; color: var(--muted); }
table.stacked td:first-child { grid-column: 1 / -1; font-weight: 600; }
table.stacked td:empty { display: none; }
table.stacked tr.section { display: block; padding: 0; border: 0; }
table.stacked tr.section td { padding: 10px 8px; }
table.stacked tr.total { background: var(--surface-2); border: 0; border-radius: 8px; padding: 12px; margin-top: 8px; }
table.stacked td input, table.stacked td select, table.stacked td .money, table.stacked td .pct { width: 100%; min-width: 0; max-width: 100%; }
table.stacked td .money input, table.stacked td .pct input, table.stacked td input.w-s, table.stacked td input.w-l { width: 100%; min-width: 0; }
table.stacked .cup { min-width: 0; width: 100%; }
td input[type=number] { max-width: 100%; }
table.stacked td:first-child:has(> a)::before { display: none; } /* a drink's name needs no "Drink" label above it */
