/* ==========================================================================
   HBD UI — shared look for every HBD dashboard
   One file, no build step, no external fonts or CDNs (works offline).
   Copy this file unchanged into each project's dashboard folder.
   Version 1.0
   ========================================================================== */

:root {
  /* Brand */
  --brand: #f7941d;
  --brand-strong: #d97a06;
  --brand-soft: #fff4e5;

  /* Neutrals */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e6ec;
  --text: #1c2430;
  --text-muted: #5d6877;
  --text-faint: #8b95a3;

  /* Meaning (fixed across every dashboard) */
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --wait: #b45309;
  --wait-soft: #fdf1dc;
  --bad: #b91c1c;
  --bad-soft: #fde9e9;
  --info: #1d4ed8;
  --info-soft: #e8efff;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --brand: #ffa940;
  --brand-strong: #ffb85c;
  --brand-soft: #3a2a12;
  --bg: #12161c;
  --surface: #1a2029;
  --surface-2: #222a35;
  --border: #2d3745;
  --text: #e8ecf1;
  --text-muted: #a3adbb;
  --text-faint: #7b8696;
  --ok: #4ade80;
  --ok-soft: #14301f;
  --wait: #fbbf24;
  --wait-soft: #38290d;
  --bad: #f87171;
  --bad-soft: #3a1818;
  --info: #7aa2ff;
  --info-soft: #172544;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--info); }
button, input, select { font: inherit; color: inherit; }

/* ---- Top bar ------------------------------------------------------------ */
.hbd-topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--brand);
}
.hbd-logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--brand); color: #fff; font-weight: 700;
  display: grid; place-items: center; letter-spacing: -0.5px;
}
.hbd-title { font-size: 16px; font-weight: 650; }
.hbd-sub { font-size: 12px; color: var(--text-muted); }
.hbd-spacer { flex: 1; }
.hbd-updated { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.hbd-live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); margin-right: 6px;
}
.hbd-live-dot.stale { background: var(--wait); }
.hbd-live-dot.down { background: var(--bad); }

/* ---- Page frame --------------------------------------------------------- */
.hbd-page { max-width: 1400px; margin: 0 auto; padding: 20px 24px 48px; }
.hbd-section-title {
  font-size: 13px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-muted); margin: 26px 0 10px;
}

/* ---- Tabs --------------------------------------------------------------- */
.hbd-tabs {
  display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  border-bottom: 1px solid var(--border); margin-bottom: 18px;
}
.hbd-tab {
  appearance: none; background: none; border: 0; cursor: pointer;
  padding: 10px 14px; font-weight: 600; color: var(--text-muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.hbd-tab:hover { color: var(--text); }
.hbd-tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }
.hbd-tab .hbd-count {
  margin-left: 6px; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted); font-size: 12px;
}

/* ---- Summary counters --------------------------------------------------- */
.hbd-stats {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.hbd-stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  border-left: 4px solid var(--border);
}
.hbd-stat .label { font-size: 12px; color: var(--text-muted); }
.hbd-stat .value { font-size: 28px; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.hbd-stat .note { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.hbd-stat.ok { border-left-color: var(--ok); }
.hbd-stat.wait { border-left-color: var(--wait); }
.hbd-stat.bad { border-left-color: var(--bad); }
.hbd-stat.info { border-left-color: var(--info); }
.hbd-stat.brand { border-left-color: var(--brand); }

/* ---- Cards -------------------------------------------------------------- */
.hbd-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.hbd-card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.hbd-card-head h2 { font-size: 15px; font-weight: 650; }
.hbd-card-body { padding: 16px; }
.hbd-grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

/* ---- Filters & buttons -------------------------------------------------- */
.hbd-filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.hbd-input, .hbd-select {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 130px;
}
.hbd-input:focus, .hbd-select:focus, .hbd-btn:focus-visible, .hbd-tab:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.hbd-btn {
  appearance: none; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  padding: 7px 12px; font-weight: 600;
}
.hbd-btn { text-decoration: none; display: inline-block; text-align: center; }
.hbd-btn:hover { background: var(--surface-2); }
.hbd-btn.primary { background: var(--brand); border-color: var(--brand); color: #1c1200; }
.hbd-btn.primary:hover { background: var(--brand-strong); }

/* ---- Tables ------------------------------------------------------------- */
.hbd-table-wrap { overflow: auto; max-height: 560px; }
.hbd-table { width: 100%; border-collapse: collapse; }
.hbd-table th, .hbd-table td {
  padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.hbd-table th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  font-size: 12px; font-weight: 650; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
  cursor: pointer; user-select: none;
}
.hbd-table th[data-sort="asc"]::after { content: " ▲"; font-size: 10px; }
.hbd-table th[data-sort="desc"]::after { content: " ▼"; font-size: 10px; }
.hbd-table tbody tr:hover { background: var(--brand-soft); }
.hbd-table td.num, .hbd-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.hbd-table .reason { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.hbd-table tfoot td { font-weight: 700; background: var(--surface-2); position: sticky; bottom: 0; border-top: 2px solid var(--border); }
.hbd-table.plain th { text-transform: none; letter-spacing: 0; font-size: 13px; }
.hbd-empty { padding: 36px 16px; text-align: center; color: var(--text-muted); }

/* ---- Badges (meaning is fixed: green done, amber waiting, red act now) --- */
.hbd-badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted);
}
.hbd-badge.ok { background: var(--ok-soft); color: var(--ok); }
.hbd-badge.wait { background: var(--wait-soft); color: var(--wait); }
.hbd-badge.bad { background: var(--bad-soft); color: var(--bad); }
.hbd-badge.info { background: var(--info-soft); color: var(--info); }

/* ---- Bar list (simple horizontal chart, no library) --------------------- */
.hbd-bars { display: grid; gap: 8px; }
.hbd-bar-row { display: grid; grid-template-columns: 170px 1fr 48px; gap: 10px; align-items: center; }
.hbd-bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbd-bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); }

/* ---- Drawer (full mail / row detail) ------------------------------------ */
.hbd-drawer-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 40; }
.hbd-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%);
  background: var(--surface); z-index: 41; box-shadow: -4px 0 24px rgba(0, 0, 0, 0.2);
  display: flex; flex-direction: column;
}
.hbd-drawer-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.hbd-drawer-body { padding: 18px; overflow: auto; white-space: pre-wrap; }
.hbd-kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin-bottom: 14px; }
.hbd-kv dt { color: var(--text-muted); }
.hbd-kv dd { margin: 0; word-break: break-word; }

/* ---- Login --------------------------------------------------------------- */
.hbd-login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.hbd-login .hbd-card { width: min(380px, 100%); padding: 26px; display: grid; gap: 14px; }
.hbd-login .hbd-input { width: 100%; }
.hbd-error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---- Small helpers (classes, not inline styles: the site's security header forbids inline styles) */
.hbd-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; }
.hbd-sw { display: inline-block; vertical-align: -1px; margin-right: 5px; }
.hbd-donut-wrap { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.hbd-donut-item { margin: 4px 0; }
.hbd-muted { color: var(--text-muted); }
.hbd-clickable { cursor: pointer; }
.hbd-grow { flex: 1; font-size: 15px; }
.hbd-mb { margin-bottom: 14px; }
.hbd-input.narrow { min-width: 0; }
.hbd-note { margin-bottom: 10px; font-size: 12px; color: var(--text-muted); }
.hbd-pb0 { padding-bottom: 0; }
.hbd-bar-svg { display: block; }
.hbd-bar-svg .track { fill: var(--surface-2); }
.hbd-bar-svg .fill { fill: var(--brand); }
.hbd-user { font-size: 13px; font-weight: 600; white-space: nowrap; }
.hbd-login p { margin: 0; color: var(--text-muted); }

/* ---- Small screens -------------------------------------------------------- */
@media (max-width: 720px) {
  .hbd-topbar { padding: 10px 14px; flex-wrap: wrap; }
  .hbd-page { padding: 14px 14px 40px; }
  .hbd-grid-2 { grid-template-columns: 1fr; }
  .hbd-bar-row { grid-template-columns: 110px 1fr 40px; }
  .hbd-stat .value { font-size: 24px; }
}
