/* Justyle USA reporting dashboard.
   Tokens first, then components. Every colour is defined on :root so the dark
   block only has to redefine the token, never a rule. */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --ink: #131820;
  --ink-2: #414b5a;
  --ink-soft: #697487;
  --line: #e2e6ec;
  --line-soft: #eef1f5;
  --accent: #1f5eff;
  --accent-ink: #ffffff;
  --accent-soft: #edf2ff;
  --good: #0b8a4b;
  --good-soft: #e7f5ee;
  --warn: #b5760a;
  --warn-soft: #fdf4e3;
  --bad: #c62f27;
  --bad-soft: #fdeeed;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 10px 26px -18px rgba(16, 24, 40, .35);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar: 232px;
  --gap: 18px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0f14;
    --panel: #141920;
    --panel-2: #191f27;
    --ink: #e8ecf2;
    --ink-2: #b7c0cd;
    --ink-soft: #8b95a5;
    --line: #232b35;
    --line-soft: #1c232c;
    --accent: #5f8dff;
    --accent-ink: #0c0f14;
    --accent-soft: #182444;
    --good: #46c58a;
    --good-soft: #122b21;
    --warn: #e0a44a;
    --warn-soft: #2c2415;
    --bad: #f0796f;
    --bad-soft: #2e1a19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 14px 30px -20px rgba(0, 0, 0, .9);
  }
}

:root[data-theme="dark"] {
  --bg: #0c0f14;
  --panel: #141920;
  --panel-2: #191f27;
  --ink: #e8ecf2;
  --ink-2: #b7c0cd;
  --ink-soft: #8b95a5;
  --line: #232b35;
  --line-soft: #1c232c;
  --accent: #5f8dff;
  --accent-ink: #0c0f14;
  --accent-soft: #182444;
  --good: #46c58a;
  --good-soft: #122b21;
  --warn: #e0a44a;
  --warn-soft: #2c2415;
  --bad: #f0796f;
  --bad-soft: #2e1a19;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 14px 30px -20px rgba(0, 0, 0, .9);
}


* { box-sizing: border-box; }

/* A class that sets display beats the hidden attribute's UA style, which once
   left the login card and the dashboard drawn on top of each other. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.012em; }

.muted { color: var(--ink-soft); }

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
  color: var(--accent);
  text-transform: uppercase;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ login */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.login-card {
  width: 100%;
  max-width: 356px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}
.login-card h1 { font-size: 21px; margin-top: 4px; }
.login-card p { margin: 0 0 8px; font-size: 13px; }
.login-card label { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; }
.login-card input, .login-card button { font: inherit; }
.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--ink);
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  margin-top: 12px;
  padding: 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 620;
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.06); }
.login-card button[disabled] { opacity: .6; cursor: progress; }

/* ------------------------------------------------------------------ shell */

#app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 2px 8px 20px; }
.brand-logo {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.brand-text { display: grid; line-height: 1.25; }
.brand-name { font-weight: 620; font-size: 13.5px; }
.brand-sub { font-size: 11.5px; color: var(--ink-soft); }

#nav { display: grid; gap: 1px; }
#nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: none;
  border: 0;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink-2);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
#nav svg { width: 17px; height: 17px; fill: currentColor; opacity: .65; flex: none; }
#nav button:hover { background: var(--line-soft); color: var(--ink); }
#nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#nav button.active svg { opacity: 1; }

.sidebar-foot {
  margin-top: auto;
  padding: 14px 10px 0;
  border-top: 1px solid var(--line-soft);
  display: grid;
  gap: 5px;
  font-size: 12px;
}
.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--ink-soft); font: inherit;
  text-align: left; cursor: pointer; text-decoration: underline;
}
.link-btn:hover { color: var(--ink); }

.theme-toggle {
  display: inline-flex;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  width: max-content;
}
.theme-toggle button {
  font: inherit;
  font-size: 11px;
  padding: 2px 7px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
}
.theme-toggle button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { min-width: 0; }

/* ----------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 11px 22px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.range-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.date-pair { display: inline-flex; gap: 6px; align-items: center; }
.range-controls select, .range-controls input {
  font: inherit;
  font-size: 13px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink);
}
.range-controls select:hover, .range-controls input:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.dash-sep { color: var(--ink-soft); font-size: 12px; }

.topbar-right { display: flex; align-items: center; gap: 9px; }
.freshness { font-size: 12px; color: var(--ink-soft); }
.freshness .stale { color: var(--warn); }
.freshness .broken { color: var(--bad); }

.ghost-btn {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .12s ease, color .12s ease;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.ghost-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ghost-btn.primary:hover { filter: brightness(1.06); color: var(--accent-ink); }
.ghost-btn[disabled] { opacity: .55; cursor: progress; }


/* ------------------------------------------------- compact bar and drawer */

.mobile-bar { display: none; }
.drawer-backdrop { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink-2);
  cursor: pointer;
  flex: none;
}
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; }
.icon-btn:active { background: var(--line-soft); }
.icon-btn[disabled] { opacity: .5; }

.filter-summary { display: none; }

.topbar-body {
  display: flex;
  flex: 1;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------- view */

#view { padding: 20px 22px 40px; display: grid; gap: var(--gap); }

.page-head { display: grid; gap: 3px; }
.page-head h1 { font-size: 19px; }
.page-head p { margin: 0; font-size: 13px; color: var(--ink-soft); max-width: 78ch; }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); }

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 3px;
  align-content: start;
}
.kpi .label { font-size: 12px; color: var(--ink-soft); display: flex; align-items: center; gap: 5px; }
.kpi .value { font-size: 25px; font-weight: 640; letter-spacing: -.02em; line-height: 1.2; }
.kpi .delta { font-size: 11.5px; display: flex; gap: 4px 10px; flex-wrap: wrap; margin-top: 2px; }
.kpi.alert { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.up { color: var(--good); }
.down { color: var(--bad); }
.flat { color: var(--ink-soft); }

.hint-dot {
  width: 13px; height: 13px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 9px;
  cursor: help;
  flex: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 15px 18px 17px;
  min-width: 0;
}
.panel > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.panel h2 { font-size: 14.5px; }
.panel .hint { font-size: 12px; color: var(--ink-soft); }

.grid-2 { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.grid-2.uneven { grid-template-columns: minmax(360px, 1.6fr) minmax(280px, 1fr); }

.chart { width: 100%; height: 300px; }
.chart.tall { height: 430px; }
.chart.short { height: 224px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
thead th {
  color: var(--ink-soft);
  font-weight: 560;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom-color: var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
}
/* Numbers must never wrap: "748,47 $" broken across two lines reads as two
   different figures. Squeeze the table into a scroller instead. */
td.num, th.num { text-align: right; white-space: nowrap; }
table.wide { min-width: 760px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
.table-scroll { overflow-x: auto; max-height: 460px; overflow-y: auto; }
td a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 620;
  white-space: nowrap;
}
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.err { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.idle { background: var(--line-soft); color: var(--ink-soft); }

.empty {
  padding: 28px 20px;
  text-align: center;
  color: var(--ink-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.empty strong { color: var(--ink); display: block; margin-bottom: 3px; font-size: 13.5px; }

.alert {
  border-left: 3px solid var(--warn);
  background: var(--warn-soft);
  color: var(--ink);
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.alert.bad { border-left-color: var(--bad); background: var(--bad-soft); }
.alert.info { border-left-color: var(--accent); background: var(--accent-soft); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  font: inherit; font-size: 12px;
  padding: 5px 11px;
  background: var(--panel);
  border: 0;
  color: var(--ink-soft);
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--accent); color: var(--accent-ink); }

/* Skeletons keep the page from jumping while a tab loads. */
.skeleton { display: grid; gap: var(--gap); }
.sk-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); }
.sk-box {
  background: linear-gradient(90deg, var(--line-soft) 25%, var(--line) 37%, var(--line-soft) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--radius);
}
.sk-box.kpi-h { height: 88px; }
.sk-box.chart-h { height: 300px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .sk-box { animation: none; } }

.print-header { display: none; }

/* ------------------------------------------------------------------ print */

@media print {
  :root { --bg: #fff; --panel: #fff; --shadow: none; }
  .sidebar, .topbar, .no-print, .seg { display: none !important; }
  #app { display: block; }
  .sidebar { display: none; }
  main { width: 100%; }
  #view { padding: 0; gap: 12px; }
  .print-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0 0 10px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 12px;
    font-size: 12px;
  }
  .panel, .kpi { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .table-scroll { overflow: visible; max-height: none; }
  .chart { height: 250px; }
  .chart.tall { height: 330px; }
  a { text-decoration: none; color: inherit; }
  @page { size: A4 landscape; margin: 12mm; }
}

/* ----------------------------------------------------------------- narrow */

/* Under 900px the sidebar stops being a rail and becomes a drawer. The old
   behaviour, a horizontal strip, showed two and a half of eight sections and
   pushed the account controls somewhere nobody would ever scroll to. */
@media (max-width: 900px) {
  #app { display: block; }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }
  .mobile-title {
    flex: 1;
    font-weight: 620;
    font-size: 15px;
    letter-spacing: -.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    width: min(80vw, 290px);
    height: 100dvh;
    padding: 16px 12px;
    border-right: 1px solid var(--line);
    overflow-y: auto;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .18);
  }
  #app.drawer-open .sidebar { transform: none; }
  @media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(6, 10, 16, .45);
  }

  #nav button { padding: 11px 12px; font-size: 14.5px; }
  #nav svg { width: 18px; height: 18px; }
  .sidebar-foot { gap: 10px; padding-top: 16px; }

  /* The filter row folds away behind one line that says what is being shown. */
  .topbar { padding: 8px 12px; gap: 8px; flex-direction: column; align-items: stretch; }
  .filter-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    font: inherit;
    font-size: 13.5px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel);
    color: var(--ink);
    cursor: pointer;
  }
  .filter-summary svg { width: 18px; height: 18px; fill: var(--ink-soft); transition: transform .18s ease; }
  .filter-summary[aria-expanded="true"] svg { transform: rotate(180deg); }

  .topbar-body { display: none; }
  .topbar-body.open { display: grid; gap: 10px; padding: 4px 0 6px; }
  .range-controls { display: grid; gap: 8px; }
  .range-controls select, .range-controls input { width: 100%; padding: 9px 10px; font-size: 14px; }
  .date-pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
  /* Two buttons side by side with the freshness note on its own line above.
     Left in the same row it wrapped to two lines and threw the row off. */
  .topbar-right { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: center; }
  .topbar-right .freshness { grid-column: 1 / -1; text-align: center; padding-bottom: 2px; }
  .topbar-right .ghost-btn { padding: 9px 10px; white-space: nowrap; }
  #refresh { display: none; }

  #view { padding: 14px 12px 32px; gap: 14px; }
  .page-head h1 { font-size: 17px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 11px 12px; }
  .kpi .value { font-size: 20px; }
  .kpi .delta { font-size: 11px; }
  .panel { padding: 13px 13px 15px; }
  .grid-2, .grid-2.uneven { grid-template-columns: 1fr; }
  .chart { height: 250px; }
  .chart.tall { height: 320px; }
  .chart.short { height: 210px; }
  .table-scroll { max-height: 380px; }
}

@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr; }
}
