/* Shared by the three dashboard pages (dashboard-runs/-sales/-metrics.html).
   Tokens, login overlay and nav are the same as supplier-quotes.html, so the
   dashboards look like the rest of the engine. Colour is never the only
   signal: every status pill carries a word. Text uses the *-ink grades
   (>= 4.5:1); the plain fills are for dots and bars only. */
:root {
  --bg: #fafaf9; --bg-card: #ffffff; --bg-input: #f5f5f4;
  --text: #1a1a1a; --text-secondary: #666666; --text-tertiary: #6b6b6b;
  --border: #e5e5e5; --accent: #facc15; --accent-hover: #eab308; --accent-light: #fef9c3;
  --accent-ink: #854d0e; --on-accent: #1a1a1a;
  --red-ink: #b91c1c; --red-bg: #fee2e2; --red-fill: #dc2626;
  --amber-ink: #854d0e; --amber-bg: #fef3c7; --amber-fill: #d97706;
  --green-ink: #166534; --green-bg: #dcfce7; --green-fill: #16a34a;
  --grey-ink: #525252; --grey-bg: #f0f0ef; --grey-fill: #a3a3a3;
  --blue-ink: #1d4ed8;
  --shadow: 0 1px 3px rgba(120,80,20,0.08), 0 1px 2px rgba(120,80,20,0.04);
  --shadow-lg: 0 4px 12px rgba(120,80,20,0.1);
  --radius: 12px; --radius-sm: 8px; --radius-xs: 6px;
  --font: 'Geist', -apple-system, BlinkMacSystemFont, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1e1e; --bg-card: #2a2a2a; --bg-input: #333333;
    --text: #fafafa; --text-secondary: #a3a3a3; --text-tertiary: #9e9e9e;
    --border: #3a3a3a; --accent-light: rgba(250,204,21,0.15); --accent-ink: #facc15;
    --red-ink: #fca5a5; --red-bg: rgba(220,38,38,0.18);
    --amber-ink: #fcd34d; --amber-bg: rgba(217,119,6,0.18);
    --green-ink: #86efac; --green-bg: rgba(22,163,74,0.18);
    --grey-ink: #d4d4d4; --grey-bg: #3a3a3a; --blue-ink: #93c5fd;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.5);
  }
}
[data-theme="dark"] {
  --bg: #1e1e1e; --bg-card: #2a2a2a; --bg-input: #333333;
  --text: #fafafa; --text-secondary: #a3a3a3; --text-tertiary: #9e9e9e;
  --border: #3a3a3a; --accent-light: rgba(250,204,21,0.15); --accent-ink: #facc15;
  --red-ink: #fca5a5; --red-bg: rgba(220,38,38,0.18);
  --amber-ink: #fcd34d; --amber-bg: rgba(217,119,6,0.18);
  --green-ink: #86efac; --green-bg: rgba(22,163,74,0.18);
  --grey-ink: #d4d4d4; --grey-bg: #3a3a3a; --blue-ink: #93c5fd;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { overflow-x: clip; }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  min-height: 100vh; -webkit-font-smoothing: antialiased; line-height: 1.45;
}

/* ===== LOGIN OVERLAY (same mechanism as the other pages) ===== */
.login-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 1000;
  display: flex; align-items: center; justify-content: center; }
.login-overlay.hidden { display: none; }
.login-box { max-width: 380px; width: 100%; padding: 0 24px; text-align: center; }
.login-box .login-icon { width: 64px; height: 64px; background: var(--accent); border-radius: 16px;
  display: flex; align-items: center; justify-content: center; margin: 0 auto 24px;
  font-size: 28px; color: var(--on-accent); font-weight: 800; box-shadow: var(--shadow-lg); }
.login-box h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.02em; }
.login-box .login-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; }
.login-box input { width: 100%; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px;
  font-size: 15px; font-family: var(--font); text-align: center; margin-bottom: 14px; }
.login-box input::placeholder { color: var(--text-tertiary); }
.login-box button { width: 100%; min-height: 44px; background: var(--accent); color: var(--on-accent);
  border: none; border-radius: var(--radius-sm); padding: 12px 24px; font-size: 15px;
  font-weight: 600; font-family: var(--font); cursor: pointer; }
.login-box button:hover { background: var(--accent-hover); }
.login-error { display: none; color: var(--red-ink); font-size: 13px; margin-top: 12px; }
.ms-signin { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  min-height: 44px; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--text-tertiary); border-radius: var(--radius-sm); padding: 11px 24px;
  font-size: 15px; font-weight: 600; text-decoration: none; }
.ms-signin:hover { border-color: var(--accent-ink); }
.ms-signin svg { width: 18px; height: 18px; flex-shrink: 0; }
.login-or { display: flex; align-items: center; gap: 12px; color: var(--text-secondary);
  font-size: 13px; margin: 18px 0; }
.login-or::before, .login-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ===== NAVIGATION ===== */
.top-nav { background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; height: 52px;
  box-shadow: var(--shadow); position: sticky; top: 0; z-index: 10; }
.top-nav .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.top-nav .brand-icon { width: 32px; height: 32px; background: var(--accent); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px;
  color: var(--on-accent); flex-shrink: 0; }
.top-nav .brand-name { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -0.02em;
  white-space: nowrap; }
.top-nav .brand-name span { font-weight: 400; color: var(--text-secondary); }
.top-nav .nav-center { display: flex; align-items: center; height: 100%; }
.top-nav .nav-center a { color: var(--text-secondary); text-decoration: none; font-size: 14px;
  font-weight: 500; padding: 0 14px; height: 100%; display: flex; align-items: center;
  border-bottom: 2px solid transparent; white-space: nowrap; }
.top-nav .nav-center a:hover { color: var(--text); }
.top-nav .nav-center a.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.top-nav .nav-right { display: flex; align-items: center; gap: 8px; }
.icon-btn, .logout-btn { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  height: 36px; min-width: 36px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 6px; color: var(--text-secondary); font-size: 13px;
  font-weight: 600; font-family: inherit; padding: 0 10px; }
.icon-btn:hover, .logout-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.icon-btn svg, .logout-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
#logout-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.hamburger { display: none; }
.mobile-nav { display: none; position: fixed; top: 52px; left: 0; right: 0; background: var(--bg-card);
  border-bottom: 1px solid var(--border); padding: 8px 16px; z-index: 50; box-shadow: var(--shadow-lg);
  flex-direction: column; gap: 2px; }
.mobile-nav.open { display: flex; }
.mobile-nav a { display: block; padding: 12px; color: var(--text-secondary); text-decoration: none;
  font-size: 15px; font-weight: 500; border-radius: var(--radius-xs); }
.mobile-nav a.active { color: var(--accent-ink); background: var(--accent-light); }

/* ===== PAGE ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.page-head p { color: var(--text-secondary); font-size: 14px; max-width: 70ch; margin-top: 4px; }
.freshness { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center;
  gap: 10px; flex-wrap: wrap; }
.btn { min-height: 40px; padding: 8px 16px; border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
  font-family: var(--font); cursor: pointer; }
.btn:hover { border-color: var(--accent-ink); }
.banner { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; margin-bottom: 16px; }
.banner.error { background: var(--red-bg); color: var(--red-ink); }
.banner.note { background: var(--grey-bg); color: var(--grey-ink); }
.banner[hidden] { display: none; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;
  margin-bottom: 20px; }
.tile { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .tile-label { font-size: 13px; color: var(--text-secondary); }
.tile .tile-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile.warn .tile-value { color: var(--red-ink); }

.section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); min-width: 0; }
.section h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 4px; }
.section .hint { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"], .toolbar select { min-height: 40px; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 14px;
  font-family: var(--font); min-width: 0; }
.toolbar input[type="search"] { flex: 1 1 220px; }
.toolbar label { font-size: 14px; color: var(--text-secondary); display: flex; gap: 8px;
  align-items: center; min-height: 40px; cursor: pointer; }
.toolbar input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent-ink);
  flex-shrink: 0; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top;
  overflow-wrap: anywhere; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: none; }
.sub { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
a.link { color: var(--blue-ink); }
.empty { color: var(--text-secondary); font-size: 14px; padding: 16px 0; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.green { background: var(--green-bg); color: var(--green-ink); }
.pill.amber { background: var(--amber-bg); color: var(--amber-ink); }
.pill.red { background: var(--red-bg); color: var(--red-ink); }
.pill.grey { background: var(--grey-bg); color: var(--grey-ink); }

.bar { height: 8px; background: var(--grey-bg); border-radius: 999px; overflow: hidden; margin-top: 6px;
  max-width: 220px; }
.bar > span { display: block; height: 100%; background: var(--green-fill); border-radius: 999px; }

/* Metrics */
.dept { margin-bottom: 8px; }
.dept h3 { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin: 6px 0 10px; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px;
  margin-bottom: 12px; }
.metric { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; min-width: 0;
  background: var(--bg-card); }
.metric .metric-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.metric .metric-name { font-weight: 600; font-size: 15px; }
.metric .metric-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums;
  margin-top: 6px; }
.metric .metric-target { font-size: 13px; color: var(--text-secondary); }
.spark { display: block; width: 100%; height: 40px; margin-top: 8px; color: var(--blue-ink); }
.spark-caption { font-size: 12px; color: var(--text-secondary); }
details.drill { margin-top: 10px; font-size: 14px; }
details.drill > summary { cursor: pointer; color: var(--blue-ink); font-weight: 600; min-height: 32px;
  display: flex; align-items: center; }
.tree, .tree ul { list-style: none; padding-left: 14px; border-left: 1px solid var(--border); }
.tree { margin-top: 6px; }
.tree li { margin: 4px 0; }
/* One drill row: a long label wraps under itself, the amount stays whole on the right. */
.tree .row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; column-gap: 6px;
  align-items: start; min-height: 28px; }
.tree .name, .tree .val { padding-top: 4px; line-height: 20px; }
.tree .tog, .tree .tog-gap { width: 28px; height: 28px; align-self: start; }
.tree .tog { display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0;
  border-radius: 6px; background: transparent; color: var(--text-secondary); cursor: pointer; }
.tree .tog::before { content: "\25B8"; font-size: 15px; line-height: 1; }
.tree .tog[aria-expanded="true"]::before { content: "\25BE"; }
.tree .tog:hover { color: var(--blue-ink); }
.tree .tog:focus-visible { outline: 2px solid var(--blue-ink); outline-offset: 1px; }
.tree .lvl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-secondary); margin-right: 2px; }
.tree .name { overflow-wrap: break-word; }
.tree .lbl .code { white-space: nowrap; }
.tree .val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; text-align: right; }

/* ===== PHONE ===== */
@media (max-width: 900px) {
  .top-nav .nav-center { display: none; }
  .hamburger { display: flex; }
}
@media (max-width: 768px) {
  .top-nav { padding: 0 12px; }
  .top-nav .brand-name span { display: none; }
  #logout-label { display: none; }
  .logout-btn { width: 36px; padding: 0; }
  .container { padding: 18px 14px 40px; }
  .page-head h1 { font-size: 21px; }
  .section { padding: 16px 14px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .tile-value { font-size: 22px; }
  /* Tables become one card per row, each cell labelled. */
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 12px;
    margin-bottom: 10px; }
  /* Label above its value: a cell holds several pieces (link, sub-line, pill),
     so a two-column grid would scatter them. */
  table.data td { border-bottom: none; padding: 6px 0; text-align: left; }
  table.data td.num { text-align: left; }
  table.data td::before { content: attr(data-label); display: block; font-size: 12px;
    font-weight: 600; color: var(--text-secondary); margin-bottom: 2px; }
  .pill { white-space: normal; }
  .metric-grid { grid-template-columns: minmax(0, 1fr); }
}
