:root {
  --bg: #020617;
  --panel: #0f172a;
  --panel-2: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #cbd5e1;
  --accent: #60a5fa;
  --red: #f07178;
  --amber: #e0b35a;
  --green: #6bcf8e;
  --onb: #8b9dc3;
  --focus: #93c5fd;
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font); line-height: 1.4; font-size: 15px;
  max-width: 100%;
  overflow-x: hidden; /* page-level: no horizontal scroll */
}
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: #fff; color: #000; padding: 8px; z-index: 99; }

.app-header {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  background: var(--panel); position: sticky; top: 0; z-index: 10;
  max-width: 100%; min-width: 0;
}
.brand { min-width: 0; flex: 1 1 200px; }
.brand h1 { font-size: 1.02rem; margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.brand .sub { color: var(--muted); font-size: 0.8rem; overflow-wrap: anywhere; }
.badge {
  display: inline-flex; align-items: center;
  background: #7f1d1d; color: #fff1f2; border: 1px solid #fca5a5;
  padding: 4px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 650;
  white-space: nowrap;
}
.controls {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  min-width: 0; flex: 1 1 180px; max-width: 100%;
}
.controls select {
  max-width: min(100%, 280px); min-width: 0; flex: 1 1 140px;
}
select, input, button { font: inherit; }
select, input[type="search"] {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
button { background: var(--accent); color: #061018; border: 0; border-radius: 8px; padding: 7px 12px; font-weight: 650; cursor: pointer; }
button.linkish {
  background: none; border: 0; color: #93c5fd; padding: 0; font-weight: 600;
  text-align: left; cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
  overflow-wrap: anywhere;
}
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button:focus, select:focus, input:focus, a:focus { outline: 2px solid var(--focus); outline-offset: 2px; }

.layout {
  display: grid; grid-template-columns: 200px minmax(0, 1fr);
  min-height: calc(100vh - 64px); width: 100%; max-width: 100%;
}
nav {
  border-right: 1px solid var(--border); background: var(--panel); padding: 10px;
  min-width: 0; max-width: 100%;
  contain: paint;
}
nav button.navbtn {
  width: 100%; text-align: left; background: transparent; color: var(--text);
  border: 0; padding: 10px 12px; border-radius: 8px; margin-bottom: 3px;
  font-weight: 500; font-size: 0.9rem;
}
nav button.navbtn[aria-current="page"] {
  background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent);
}
main {
  padding: 18px; min-width: 0; max-width: 100%;
  overflow-x: hidden; /* contain; tables scroll in .table-wrap */
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
  gap: 12px; margin-bottom: 14px;
}
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; min-width: 0;
}
.card .label { color: #e2e8f0; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }
.card .value { font-size: 1.3rem; font-weight: 700; margin-top: 3px; overflow-wrap: anywhere; }
.card .hint { color: #94a3b8; font-size: 0.72rem; margin-top: 2px; }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
  min-width: 0; max-width: 100%;
}
.panel h2 { margin: 0 0 8px; font-size: 0.95rem; overflow-wrap: anywhere; }
.panel ul { margin: 0; padding-left: 18px; }
.panel ul li { margin-bottom: 4px; }

.table-wrap {
  max-width: 100%;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  contain: paint; /* prevent wide tables from expanding documentElement.scrollWidth */
}
.table-wrap > table {
  display: table;
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 0.86rem;
  table-layout: auto;
}
.table-wrap > table th:first-child,
.table-wrap > table td:first-child {
  position: sticky; left: 0; z-index: 1;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--border);
}
.col-rank { width: 44px; white-space: nowrap; }
.col-acct { min-width: 120px; }
.col-risk { width: 88px; }
.col-mrr { width: 96px; white-space: nowrap; }
.col-owner { width: 72px; }
.col-due { width: 100px; white-space: nowrap; }
.col-action { min-width: 140px; }
.col-why { width: 22%; color: var(--muted); font-size: 0.78rem; }
.action-cell { white-space: normal; line-height: 1.3; }
.acct-why { display: block; color: var(--muted); font-size: 0.72rem; margin-top: 2px; font-weight: 500; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 999px; padding: 2px 8px; font-size: 0.72rem; font-weight: 700;
  border: 1px solid transparent;
}
.pill-ico { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.pill-Red { color: #fecaca; background: rgba(127,29,29,0.45); border-color: #f87171; }
.pill-Amber { color: #fde68a; background: rgba(120,53,15,0.45); border-color: #fbbf24; }
.pill-Green { color: #bbf7d0; background: rgba(20,83,45,0.45); border-color: #4ade80; }
.pill-Onboarding { color: #e2e8f0; background: rgba(51,65,85,0.55); border-color: #94a3b8; }

.muted { color: var(--muted); }
.small { font-size: 0.78rem; }
.empty {
  padding: 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.grid-2 {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.85fr); gap: 12px;
}
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.bar { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin: 6px 0 10px; }
.bar > span { display: block; height: 100%; background: var(--red); }
.metric-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.chain { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.chain .card { border-top: 3px solid var(--accent); }
.chain .card.step-2 { border-top-color: var(--amber); }
.chain .card.step-3 { border-top-color: var(--green); }
.tag {
  display: inline-block; font-size: 0.68rem; padding: 2px 6px; border-radius: 6px;
  background: var(--panel-2); color: var(--muted); margin-right: 4px;
}
.tag-product { color: #93c5fd; border: 1px solid #334155; }
.tag-commercial { color: #fcd34d; border: 1px solid #78350f; }
code { font-size: 0.85em; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.footer {
  padding: 12px 18px 22px; color: #94a3b8; font-size: 0.78rem;
  border-top: 1px solid var(--border); margin-top: 8px; overflow-wrap: anywhere;
}

/* Laptop */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 180px minmax(0, 1fr); }
  .grid-2, .metric-split { grid-template-columns: minmax(0, 1fr); }
}

/* Tablet / phone: horizontal nav scrolls inside itself */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  nav {
    display: flex; flex-wrap: nowrap; gap: 4px;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    border-right: 0; border-bottom: 1px solid var(--border);
    max-width: 100%; width: 100%;
  }
  nav button.navbtn {
    width: auto; flex: 0 0 auto; white-space: nowrap; margin-bottom: 0;
  }
  .grid-2, .metric-split, .chain { grid-template-columns: minmax(0, 1fr); }
  main { padding: 12px; }
  .app-header { padding: 12px; }
}

@media (max-width: 480px) {
  .cards { grid-template-columns: repeat(auto-fit, minmax(min(100%, 148px), 1fr)); }
  .controls select { max-width: 100%; flex: 1 1 100%; }
  .badge { white-space: normal; }
}
