:root {
  color-scheme: light dark;
  --bg: #f5f6f3;
  --panel: #ffffff;
  --ink: #1d2420;
  --muted: #66706a;
  --line: #e2e5e0;
  --accent: #2f7d4f;
  --accent-ink: #ffffff;
  --accent-soft: #e5f1e9;
  --ok: #2f7d4f;
  --ok-soft: #e5f1e9;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --info: #1f5fa8;
  --info-soft: #e3edf9;
  --off: #8a918c;
  --off-soft: #eef0ed;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --panel: #1b201d; --ink: #e7ebe8; --muted: #9aa49e; --line: #2c332f;
    --accent: #4fae76; --accent-ink: #0d1510; --accent-soft: #1d3326;
    --ok: #5fc187; --ok-soft: #1d3326; --warn: #e2a63b; --warn-soft: #3a2d14;
    --bad: #ff8a80; --bad-soft: #3d1f1d; --info: #7fb0ec; --info-soft: #1b2a3d;
    --off: #8a918c; --off-soft: #262b28;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.boot { padding: 40px; color: var(--muted); }

/* layout */
.top {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--ink); white-space: nowrap; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a:hover { text-decoration: none; background: var(--off-soft); }
.me { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
main { max-width: 1200px; margin: 0 auto; padding: 20px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.stack > * + * { margin-top: 16px; }

/* chips / badges */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--off-soft); font-size: 13px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-off { background: var(--off-soft); color: var(--off); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.d-on { background: var(--ok); }
.d-off { background: var(--off); }

/* table */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--off-soft); }
td .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.cups { min-width: 90px; }
.bar { height: 6px; border-radius: 3px; background: var(--off-soft); margin-top: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar.low > i { background: var(--bad); }

/* key/value */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* forms */
form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label > input, label > select { margin-top: 4px; }
input, select, button { font: inherit; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], input[type=date], input[type=month], select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled, select:disabled { opacity: .6; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: -6px 0 12px; }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px; }
.errbox { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: 13px; }

input.search { max-width: 260px; }
.show-sm { display: none; }

/* action tiles on the machine page */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.tile .t { font-weight: 600; }
.tile .d { font-size: 13px; color: var(--muted); flex: 1; }
.progress { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--info-soft); color: var(--info); }
.progress.ok { background: var(--ok-soft); color: var(--ok); }
.progress.bad { background: var(--bad-soft); color: var(--bad); }

/* login */
.login { max-width: 360px; margin: 10vh auto; }
.login h1 { margin-bottom: 16px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 700px) {
  .top { flex-wrap: wrap; padding: 10px 16px; }
  .nav { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  form .row { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .hide-sm { display: none; }
  .show-sm { display: block; }
}

/* sales summary */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.split { grid-column: 1 / -1; height: 10px; border-radius: 5px; background: var(--warn); overflow: hidden; }
.split > i { display: block; height: 100%; background: var(--accent); }
.splitlegend { grid-column: 1 / -1; display: flex; gap: 16px; color: var(--muted); margin-top: -4px; }
.splitlegend .dot { margin-right: 4px; }

/* temperature chart (series colours: reference palette slots 1 and 2) */
:root { --s1: #2a78d6; --s2: #eb6834; }
@media (prefers-color-scheme: dark) { :root { --s1: #3987e5; --s2: #d95926; } }
.chartwrap { position: relative; }
.tchart { display: block; height: auto; overflow: hidden; }
.tchart .grid { stroke: var(--line); stroke-width: 1; }
.tchart .axis { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.tchart .tick { fill: var(--muted); font-size: 11px; }
.tchart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.tchart .ln.s1 { stroke: var(--s1); }
.tchart .ln.s2 { stroke: var(--s2); }
.tchart .limit { stroke: var(--bad); stroke-width: 1.5; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.tchart .limitlbl { fill: var(--bad); font-size: 11px; font-weight: 600; }
.tchart .cross { stroke: var(--muted); stroke-width: 1; }
.tchart .dotm { stroke: var(--panel); stroke-width: 2; }
.tchart .dotm.s1 { fill: var(--s1); }
.tchart .dotm.s2 { fill: var(--s2); }
.ttip { position: absolute; top: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.6; box-shadow: 0 4px 12px rgba(0,0,0,.12); pointer-events: none; min-width: 150px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.sw.s1 { background: var(--s1); }
.sw.s2 { background: var(--s2); }
.sw.lim { background: repeating-linear-gradient(90deg, var(--bad) 0 5px, transparent 5px 9px); }
.thist { font-weight: 600; }

/* ---- Monitor page: equal-size compact cards ---- */
.mgrid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); align-items: stretch; }
.mon { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.mhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.mname { min-width: 0; }
.mname .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mright { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.mstock { border-top: 1px solid var(--line); padding-top: 8px; min-height: 92px; }  /* room for 2 stock rows, so all cards match */
.mlabel { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.mrow { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; font-variant-numeric: tabular-nums; font-size: 14px; }
.mstats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.mstats:empty { display: none; }
.mlast { font-size: 13px; border-top: 1px solid var(--line); padding-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mlast .mlabel { display: inline; margin-right: 6px; }
.mstats .mwide { grid-column: 1 / -1; }
.mval { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mbtn { width: 100%; margin-top: auto; padding-top: 10px; padding-bottom: 10px; }
/* ---- confirmation box ---- */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { max-width: 440px; width: 100%; }
.modal-body p { margin: 8px 0; line-height: 1.5; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 600px) { .kpis { grid-template-columns: 1fr 1fr; } .kpi .v { font-size: 22px; } }
.drinkbtns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.drinkbtns .btn { padding-left: 4px; padding-right: 4px; }

/* Monitor as a table: one line per machine */
.montbl td { vertical-align: middle; }
.montbl .num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.msoldcell { min-width: 170px; }
.msold + .msold { margin-top: 6px; }

/* Staff page: machine tick boxes */
.mpick { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 4px 0 8px; }
.mpick .check { margin-bottom: 0; }

/* Monitor: "Needs attention" box on top */
.attn { border: 2px solid var(--bad); margin-bottom: 16px; padding: 12px 14px; }
.attn h2 { margin: 0 0 6px; color: var(--bad); font-size: 16px; }
.attn td { vertical-align: middle; }

/* Monitor: notifications bar */
.notifbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; background: var(--info-soft);
  color: var(--ink); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }

/* Ads page */
.adcell { display: flex; align-items: center; gap: 12px; }
.adthumb { width: 96px; height: 128px; object-fit: cover; border-radius: 6px; background: var(--off-soft); display: flex; align-items: center; justify-content: center; text-align: center; }

/* ---------------------------------------------------------------- phone layout (12 Oct)
   Smaller text and spacing, and every table turns into a list of cards: one card per row,
   each value with its column name above it (labels are added by app.js from the table header). */
@media (max-width: 700px) {
  :root { font-size: 14px; }
  body { font-size: 14px; }
  h1 { font-size: 19px; }
  h2 { font-size: 15px; }
  .top { gap: 8px; padding: 8px 12px; }
  .brand { font-size: 15px; }
  .me .btn.small { padding: 4px 8px; font-size: 12px; }
  .nav { gap: 2px; margin: 0 -4px; }
  .nav a { padding: 6px 9px; font-size: 14px; }
  main { padding: 12px; }
  .head { gap: 8px; margin-bottom: 10px; }
  .card { padding: 12px; }
  /* iPhone zooms into any box with text under 16px when you tap it, and stays zoomed in */
  input, select, textarea { font-size: 16px !important; }
  .btn { padding: 7px 12px; }
  .btn.small { padding: 5px 9px; font-size: 13px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .k { font-size: 10.5px; letter-spacing: .2px; }
  .kpi .v { font-size: 19px; }
  .kpi .s { font-size: 11px; }
  .search { width: 100% !important; }

  .tablewrap { overflow-x: visible; }
  .tablewrap table, .tablewrap tbody, .tablewrap tr, .tablewrap td { display: block; width: auto; }
  .tablewrap thead { display: none; }
  .tablewrap tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .tablewrap tr:last-child { border-bottom: 0; }
  .tablewrap td { border: 0; padding: 3px 0; text-align: left !important; }
  .tablewrap td.num { text-align: left !important; }
  .tablewrap td[data-label]:not([data-label=""])::before {
    content: attr(data-label); display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .3px;
    color: var(--muted); font-weight: 600; margin-bottom: 1px;
  }
  /* first column (usually the machine or the time) = the card's title */
  .tablewrap td:first-child { font-size: 15px; font-weight: 600; padding-top: 0; }
  .tablewrap td:first-child::before { display: none !important; }
  .tablewrap td:first-child .sub { font-weight: 400; }
  .tablewrap td:empty { display: none; }
  .tablewrap td .actions { justify-content: flex-start !important; margin-top: 4px; }
  .tablewrap td[colspan] { font-weight: 400; }
}
@media (max-width: 700px) {
  .tablewrap tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
  .tablewrap td.wide { grid-column: 1 / -1; }
}
