/* Owner dashboard for a wholesale bakery.
   One family (the system UI face), one accent (oven-door enamel blue), cool neutral
   surfaces. The memorable piece is the ledger band of main numbers at the top of each page;
   everything else stays quiet. Spacing scale: 4 8 12 16 24 32 48. */

:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --ink: #1b2430;
  --ink-2: #4f5b67;
  --ink-3: #6f7a86;
  --rule: #dfe4e9;
  --track: #edf0f3;
  --accent: #1d4f6e;
  --accent-deep: #143a52;
  --accent-soft: #e2edf4;
  --good: #2e7d4f;
  --warn: #9a6200;
  --bad: #b3261e;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 6px;
  font-family: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Ubuntu, Cantarell, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1 { font-size: 1.75rem; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 var(--s1); }
h2 { font-size: 1rem; line-height: 1.3; font-weight: 650; margin: 0 0 var(--s3); }
.lede { color: var(--ink-2); margin: 0 0 var(--s5); max-width: 65ch; }
.muted { color: var(--ink-3); }
.small { font-size: 0.85rem; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 88px 1fr; min-height: 100vh; }

.rail {
  background: var(--accent-deep);
  display: flex; flex-direction: column; align-items: stretch;
  padding: var(--s3) 0; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; justify-content: center; padding: var(--s2) 0 var(--s4); }
.brand svg { width: 34px; height: 34px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rail-link {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--s2) var(--s1);
  color: #c4d3de; text-decoration: none; font-size: 0.72rem;
  border-left: 3px solid transparent;
}
.rail-link svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail-link:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.rail-link.active { color: #fff; background: rgba(255, 255, 255, 0.12); border-left-color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: var(--s5);
  padding: var(--s3) var(--s6);
  border-bottom: 1px solid var(--rule); background: var(--panel);
  font-size: 0.85rem; color: var(--ink-2);
}
.business { font-weight: 650; color: var(--ink); margin-right: auto; }
.live { display: inline-flex; align-items: center; gap: var(--s2); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.live.on .live-dot { background: var(--good); box-shadow: 0 0 0 3px rgba(46, 125, 79, 0.18); }
.live.off .live-dot { background: var(--warn); }
.updated { transition: color 0.4s; }
.updated.pulse { color: var(--accent); }

.content { padding: var(--s6); max-width: 1500px; width: 100%; }

/* ---------- ledger band (main numbers) ---------- */
.ledger {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  background: var(--panel);
  border: 1px solid var(--rule); border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  margin-bottom: var(--s5);
}
.figure { padding: var(--s4) var(--s5); border-left: 1px solid var(--rule); }
.figure:first-child { border-left: 0; }
.figure-value { font-size: 1.9rem; line-height: 1.15; font-weight: 600; letter-spacing: -0.02em; }
.figure-label { color: var(--ink); font-weight: 550; margin-top: var(--s1); }
.figure-sub { color: var(--ink-3); font-size: 0.85rem; }

/* ---------- layout ---------- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: var(--s5); align-items: start; }
.grid-2.inner { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--s5); margin-bottom: var(--s5); }
.stack { display: grid; gap: var(--s5); min-width: 0; }

.panel, .chart {
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: var(--s4) var(--s5); margin: 0; min-width: 0;
}
.panel + .panel { margin-top: var(--s5); }
.stack > .panel + .panel { margin-top: 0; }

/* ---------- bar chart ---------- */
.chart figcaption { display: flex; align-items: baseline; gap: var(--s2); margin-bottom: var(--s3); }
.chart-title { font-weight: 650; }
.chart-note { color: var(--ink-3); font-size: 0.85rem; }
.chart-empty { color: var(--ink-3); padding: var(--s4) 0; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.bar-row {
  display: grid; grid-template-columns: var(--label-w, 11rem) 1fr auto; align-items: center; gap: var(--s3);
  padding: 5px var(--s1); border-radius: 4px;
}
.bar-row:hover, .bar-row:focus-visible { background: var(--accent-soft); }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar-track { height: 12px; background: var(--track); border-radius: 0 4px 4px 0; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.bar-value { min-width: 5.5rem; text-align: right; font-weight: 550; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th { text-align: left; font-weight: 600; color: var(--ink-2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--rule); white-space: nowrap; }
.table td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--track); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #f7f9fb; }
.num { text-align: right; white-space: nowrap; }
.table .strong { font-weight: 600; }
.list-head { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s3); }
.list-head h2 { margin: 0; margin-right: auto; }
.search {
  font: inherit; padding: 6px var(--s3); border: 1px solid var(--rule); border-radius: 4px;
  min-width: 240px; background: var(--panel); color: var(--ink);
}
.search:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- status (word + shape, never colour alone) ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.status-good .status-dot { background: var(--good); }
.status-warn .status-dot { background: transparent; border: 2px solid var(--warn); }
.status-bad .status-dot { background: var(--bad); border-radius: 1px; }
.status-bad { color: var(--bad); }

.stock { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); align-items: center; min-width: 160px; }
.stock .bar-track { height: 8px; }
.stock.low .bar-fill { background: var(--bad); }

.page-error { background: #fcefee; color: var(--bad); border: 1px solid #efc9c6; padding: var(--s3) var(--s4); border-radius: var(--radius); }

/* ---------- live feed & toasts ---------- */
.feed { position: sticky; top: var(--s5); }
.feed-list { list-style: none; margin: 0; padding: 0; }
.feed-item { display: grid; grid-template-columns: 4.5rem 1fr; gap: var(--s3); padding: var(--s2) 0; border-top: 1px solid var(--track); font-size: 0.9rem; }
.feed-item:first-child { border-top: 0; }
.feed-item time { color: var(--ink-3); }

.toasts { position: fixed; right: var(--s5); bottom: var(--s5); display: grid; gap: var(--s2); width: min(360px, calc(100vw - 32px)); z-index: 20; }
.toast {
  background: var(--panel); border: 1px solid var(--rule); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: var(--s3) var(--s4);
  box-shadow: 0 6px 20px rgba(20, 40, 60, 0.12);
  font-size: 0.9rem;
  animation: toast-in 0.25s ease-out;
}
.toast.kind-removed, .toast.kind-unlinked { border-left-color: var(--ink-3); }
.toast-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.toast-close { border: 0; background: none; font-size: 1.2rem; line-height: 1; color: var(--ink-3); cursor: pointer; padding: 0 var(--s1); }
.toast-body { color: var(--ink-2); }
.toast-changed { color: var(--ink-3); font-size: 0.85rem; margin-top: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } .updated { transition: none; } }

/* ---------- Blazor reconnect / error ---------- */
#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: var(--s3) var(--s5); background: #fff4d6; border-top: 1px solid #e7cf8a; z-index: 30; }

/* ---------- smaller screens ---------- */
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
  .feed { position: static; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: sticky; top: 0; height: auto; flex-direction: row; overflow-x: auto; padding: 0 var(--s2); z-index: 10; }
  .brand { padding: var(--s2); }
  .rail-link { border-left: 0; border-bottom: 3px solid transparent; min-width: 68px; }
  .rail-link.active { border-bottom-color: #fff; }
  .content { padding: var(--s4); }
  .topbar { padding: var(--s2) var(--s4); flex-wrap: wrap; gap: var(--s3); }
  .bar-row { grid-template-columns: 7rem 1fr auto; }
  .figure { border-left: 0; border-top: 1px solid var(--rule); }
}
