/* Failing Food — clean, minimal, high-contrast.
   Near-black on white, generous whitespace, one accent, tabular data feel. */
:root {
  /* Jira / Xero design tokens */
  --ink: #172B4D;        /* primary text */
  --ink-2: #5E6C84;      /* muted text (AA) */
  --ink-3: #97A0AF;      /* decoration only */
  --canvas: #F4F5F7;     /* page background */
  --bg: #FFFFFF;         /* card / surface */
  --bg-2: #F4F5F7;       /* subtle fill (headers, hover) */
  --line: #DFE1E6;
  --line-2: #C1C7D0;
  --accent: #0052CC;     /* Jira blue — brand + primary */
  --accent-hover: #0747A6;
  --accent-tint: #DEEBFF;
  --accent-ink: #FFFFFF;
  --risk: #0747A6;       /* category Risk (blue) — badge text (AA on --risk-bg) */
  --risk-bg: #DEEBFF;
  --risk-bar: #0052CC;   /* Risk bar / dot fill */
  --surveil: #0052CC;    /* category Surveillance (light blue) — badge text (AA) */
  --surveil-bg: #E6F2FF;
  --surveil-bar: #4C9AFF; /* Surveillance bar / dot / donut fill */
  --other: #42526E;      /* category Other (grey) — badge text */
  --other-bg: #EBECF0;
  --other-bar: #A5ADBA;  /* Other bar / dot fill */
  --track: #EBECF0;      /* empty bar track */
  --up: #DE350B;         /* trend up = more failures (warning) */
  --down: #006644;       /* trend down = fewer failures */
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--canvas);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* Fill the viewport; only the table / monthly area scrolls (no double scrollbar). */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  position: relative; z-index: 20; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 20px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 7px; flex: 0 0 auto; display: block;
}
.brand-text h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.brand-text p { margin: 0; font-size: 11.5px; color: var(--ink-2); letter-spacing: .01em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.updated { font-size: 12px; color: var(--ink-2); white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 13px;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  padding: 8px 14px; border-radius: 7px; cursor: pointer;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--bg-2); }
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.btn-ghost .spinner { border-color: rgba(0,0,0,.25); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

main {
  max-width: 1280px; width: 100%; margin: 0 auto; padding: 18px 20px 12px;
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
}
.summary, .filters, .resultbar { flex: 0 0 auto; }

/* ---------- Summary strip ---------- */
.summary {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px;
}
.stat {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 16px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); min-width: 110px;
}
.stat-num { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-lab { font-size: 11px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; }
.stat.prov { justify-content: center; flex: 1 1 320px; }
.prov-text { font-size: 12px; line-height: 1.4; color: var(--ink-2); }
.prov-cov { font-size: 12px; line-height: 1.4; color: var(--ink-2); margin-top: 3px; }

/* ---------- Filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 14px; background: var(--bg);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field-sm { width: 96px; }
.field-grow { flex: 1 1 220px; min-width: 180px; }
.field label { font-size: 11px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select {
  font: inherit; font-size: 13px; color: var(--ink);
  height: 38px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 7px;
  background: #fff; min-width: 150px; box-sizing: border-box; line-height: normal; margin: 0;
}
/* Normalise selects (Safari otherwise renders them a different size/height). */
.field select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4.5l4 4 4-4' fill='none' stroke='%235E6C84' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center;
}
.field-sm select { min-width: 0; width: 100%; }
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.segmented { display: inline-flex; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; }
.seg {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--ink);
  background: #fff; border: 0; border-right: 1px solid var(--line-2);
  padding: 8px 14px; cursor: pointer;
}
.seg:last-child { border-right: 0; }
.seg:hover { background: var(--bg-2); }
.seg.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Result bar ---------- */
.resultbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin: 4px 2px 10px; }
.count { font-size: 13px; font-weight: 700; }
.count b { font-variant-numeric: tabular-nums; }
.errnote { font-size: 12px; color: var(--accent); font-weight: 600; }

/* ---------- Table ---------- */
.table-wrap {
  border: 1px solid var(--line); border-radius: 10px;
  overflow-x: hidden; overflow-y: auto; flex: 1 1 auto; min-height: 0;
}
.monthly-wrap {
  border: 1px solid var(--line); border-radius: 10px;
  overflow: auto; flex: 1 1 auto; min-height: 0;
  padding: 14px; background: var(--bg);
}
/* Fixed layout = columns keep their set widths and long text wraps, so the
   table always fits the panel width (no horizontal scrollbar). */
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
thead th {
  position: sticky; top: 0; z-index: 5;
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-2); background: var(--bg-2);
  padding: 10px 12px; border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
tbody td {
  padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top;
  overflow-wrap: anywhere; word-break: break-word;
}
tbody tr:hover { background: var(--bg-2); }
tbody tr:last-child td { border-bottom: 0; }
/* Column widths (sum to 100%); table-layout:fixed enforces them. */
.c-date { width: 7.5%; }
.c-prod { width: 13%; }
.c-ctry { width: 10%; }
.c-prdc { width: 15%; }
.c-rsn  { width: 21.5%; }
.c-res  { width: 10%; }
.c-crit { width: 9%; }
.c-cat  { width: 10%; }
.c-src  { width: 4%; }
td.c-date { font-family: var(--mono); font-size: 12px; white-space: nowrap; color: var(--ink-2); }
td.c-crit { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
td.c-prod { font-weight: 600; }
td.c-res { font-variant-numeric: tabular-nums; color: var(--ink-2); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.b-risk { color: var(--risk); background: var(--risk-bg); }
.b-surveil { color: var(--surveil); background: var(--surveil-bg); }
.b-other { color: var(--other); background: var(--other-bg); }
.ho { display: block; font-size: 10.5px; color: var(--ink-2); margin-top: 2px; font-family: var(--mono); }

.src { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--ink-2); }

.empty { padding: 40px 16px; text-align: center; color: var(--ink-2); font-size: 14px; }
.loadmore-wrap { display: flex; justify-content: center; padding: 14px; }

.foot { flex: 0 0 auto; width: 100%; max-width: 1280px; margin: 0 auto; padding: 8px 20px 12px; color: var(--ink-2); font-size: 11.5px; }

/* ---------- Monthly dashboard ---------- */
.viewtoggle { margin-left: auto; }
.monthly-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px;
}
.mcard {
  text-align: left; font: inherit; cursor: pointer;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 9px;
}
.mcard:hover { background: var(--bg-2); border-color: var(--line-2); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.mc-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.mc-month { font-weight: 700; font-size: 13.5px; }
.mc-total { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.mc-bar { display: flex; height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.mc-bar i { display: block; height: 100%; }
.mc-bar .b-r { background: var(--risk-bar); }
.mc-bar .b-s { background: var(--surveil-bar); }
.mc-bar .b-o { background: var(--other-bar); }
.mc-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mc-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.dot.d-r { background: var(--risk-bar); }
.dot.d-s { background: var(--surveil-bar); }
.dot.d-o { background: var(--other-bar); }
.mc-meta { font-size: 11.5px; color: var(--ink-2); }

/* ---------- Insights dashboard ---------- */
.insights-wrap {
  border: 1px solid var(--line); border-radius: 10px;
  overflow: auto; flex: 1 1 auto; min-height: 0; padding: 14px; background: var(--bg);
}
.ins-periodbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.ins-plabel { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.ins-prange { font-size: 12px; color: var(--ink-2); }

.ins-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--bg); }
.kpi-num { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-lab { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin-top: 2px; }
.kpi-sub { font-size: 11.5px; color: var(--ink-2); margin-top: 4px; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--up); font-weight: 700; }
.delta-down { color: var(--down); font-weight: 700; }

.ins-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.ins-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(258px, 1fr)); gap: 14px; }
.ins-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--bg); }
.ins-card h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin: 0 0 12px; }
.ins-none { font-size: 12.5px; color: var(--ink-2); }

.blist { display: flex; flex-direction: column; gap: 9px; }
.brow-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; align-items: baseline; }
.brow-lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow-ct { font-variant-numeric: tabular-nums; font-weight: 700; }
.brow-bar { height: 6px; border-radius: 999px; background: var(--track); margin-top: 3px; overflow: hidden; }
.brow-bar i { display: block; height: 100%; background: #4C9AFF; border-radius: 999px; }
.brow.clickable { cursor: pointer; }
.brow.clickable:hover .brow-lab { text-decoration: underline; }
.brow.clickable:hover .brow-bar i { background: var(--accent); }

.rvs-bar { display: flex; height: 24px; border-radius: 6px; overflow: hidden; background: var(--track); }
.rvs-bar i { display: block; height: 100%; }
.rvs-bar .b-r { background: var(--risk-bar); }
.rvs-bar .b-s { background: var(--surveil-bar); }
.rvs-bar .b-o { background: var(--other-bar); }
.rvs-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut { width: 128px; height: 128px; flex: 0 0 auto; }
.donut-num { font-size: 21px; font-weight: 800; fill: var(--ink); font-family: var(--sans); }
.donut-cap { font-size: 8.5px; fill: var(--ink-2); text-transform: uppercase; letter-spacing: .08em; font-family: var(--sans); }
.rvs-legend { display: flex; flex-direction: column; gap: 6px; flex: 1 1 150px; font-size: 12.5px; }
.rvs-legend > div { display: flex; align-items: center; gap: 8px; }
.rvs-legend b { margin-left: auto; font-variant-numeric: tabular-nums; }
.rvs-legend .pc { color: var(--ink-2); width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.rvs-legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.trend { display: flex; align-items: flex-end; gap: 2px; height: 130px; }
.tcol { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column-reverse; }
.tcol i { display: block; width: 100%; }
.tcol .b-r { background: var(--risk-bar); }
.tcol .b-s { background: var(--surveil-bar); }
.tcol .b-o { background: var(--other-bar); }
.trend-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); margin-top: 6px; }
.field select:disabled { opacity: .45; cursor: not-allowed; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 40;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .brand-text p { display: none; }
  /* On phones, let the whole page scroll normally (single scrollbar there is fine). */
  body { overflow: auto; height: auto; display: block; }
  main { display: block; }
  .table-wrap { max-height: 72vh; flex: none; }
  .monthly-wrap { overflow: visible; flex: none; }
  .insights-wrap { overflow: visible; flex: none; }
  .ins-grid2 { grid-template-columns: 1fr; }
  /* Hide lower-priority columns on small screens */
  .c-prdc, .c-crit, .c-res { display: none; }
  td.c-prdc, td.c-crit, td.c-res { display: none; }
  .field input, .field select { min-width: 0; width: 100%; }
  .field { flex: 1 1 140px; }
}
