/*
 * SOM Case Panel — shared application shell, Apple design system.
 * One interactive color (Action Blue), parchment canvas with white surfaces, near-black ink,
 * SF Pro (system font) with tight display tracking, pill-shaped actions, 18px cards,
 * hairlines instead of shadows, frosted (backdrop-blur) bars and overlays.
 * Status colors keep their meaning; a completed check is blue, never green (it is not an approval).
 * Loaded by every shell page. login.html keeps its own standalone stylesheet.
 */
:root {
  --font-text: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, 'Helvetica Neue', 'Segoe UI', Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, 'Helvetica Neue', 'Segoe UI', Arial, sans-serif;

  --canvas: #F5F5F7;
  --surface: #FFFFFF;
  --surface-pearl: #FAFAFC;
  --glass: rgba(245, 245, 247, 0.8);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --text: #1D1D1F;
  --text-secondary: #6E6E73;
  --text-faint: #86868B;
  --border: #E0E0E0;
  --border-soft: #F0F0F0;
  --accent: #0066CC;
  --accent-hover: #0077ED;
  --accent-focus: #0071E3;
  --accent-tint: rgba(0, 102, 204, 0.08);
  --accent-ring: rgba(0, 113, 227, 0.22);
  --on-accent: #FFFFFF;
  --scrim: rgba(0, 0, 0, 0.32);

  /* Status accents — meaning-bearing, never green for a completed check */
  --status-withheld-bg: #FDECEE;   --status-withheld-text: #C2000F;  --status-withheld-border: #F6C8CD;
  --status-redflag-bg: #FDF0EF;    --status-redflag-text: #B3261E;   --status-redflag-border: #F3D2CF;
  --status-review-bg: #FFF4E5;     --status-review-text: #A04A00;    --status-review-border: #F5D9A8;
  --status-insufficient-bg: #FDF7E4; --status-insufficient-text: #866200; --status-insufficient-border: #EFE0AC;
  --status-reviewed-bg: #EAF2FC;   --status-reviewed-text: #0058B0;  --status-reviewed-border: #CCE0F6;
  --status-unknown-bg: #F5F5F7;    --status-unknown-text: #6E6E73;   --status-unknown-border: #E0E0E0;

  --radius-sm: 8px;
  --radius-md: 11px;
  --radius-lg: 18px;
  --radius-pill: 9999px;
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow-md: none;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);

  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 52px;
}

/* ---- Dark mode: Apple's near-black tiles ---- */
html[data-theme="dark"] {
  --canvas: #000000;
  --surface: #1D1D1F;
  --surface-pearl: #272729;
  --glass: rgba(22, 22, 23, 0.8);
  --glass-strong: rgba(39, 39, 41, 0.86);
  --text: #F5F5F7;
  --text-secondary: #CCCCCC;
  --text-faint: #86868B;
  --border: #38383A;
  --border-soft: #2A2A2C;
  --accent: #2997FF;
  --accent-hover: #47A6FF;
  --accent-focus: #2997FF;
  --accent-tint: rgba(41, 151, 255, 0.16);
  --accent-ring: rgba(41, 151, 255, 0.32);
  --on-accent: #FFFFFF;
  --scrim: rgba(0, 0, 0, 0.55);

  --status-withheld-bg: #3A1C1E;     --status-withheld-text: #FF8A8F;     --status-withheld-border: #5A2A2E;
  --status-redflag-bg: #362220;      --status-redflag-text: #F5A39C;      --status-redflag-border: #4D3330;
  --status-review-bg: #3A2A12;       --status-review-text: #FFC266;       --status-review-border: #55401E;
  --status-insufficient-bg: #342C14; --status-insufficient-text: #F0D278; --status-insufficient-border: #4B4020;
  --status-reviewed-bg: rgba(41, 151, 255, 0.16); --status-reviewed-text: #7DBEFF; --status-reviewed-border: rgba(41, 151, 255, 0.32);
  --status-unknown-bg: #2A2A2C;      --status-unknown-text: #A1A1A6;      --status-unknown-border: #38383A;
}
html[data-theme="dark"] body { background: var(--canvas); }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 15px;
  line-height: 1.47;
  letter-spacing: -0.016em;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent-focus); outline-offset: 2px; }
button { font-family: inherit; letter-spacing: inherit; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ============================= App shell ============================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  flex: none;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  transition: width 0.2s var(--ease);
  overflow: hidden;
}
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }

.sidebar-top {
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px 16px 16px;
  min-width: var(--sidebar-w);
}
body.sidebar-collapsed .sidebar-top { min-width: 0; flex-direction: column; gap: 12px; padding-top: 16px; padding-bottom: 12px; }
.sidebar-top .mark { width: 34px; height: 34px; border-radius: 50%; flex: none; }
.sidebar-top .brand-block { min-width: 0; overflow: hidden; }
.sidebar-top .brand-name { font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: -0.02em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-top .brand-sub { font-size: 12px; font-weight: 400; color: var(--text-faint); letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
body.sidebar-collapsed .sidebar-top .brand-block { display: none; }

.sidebar-collapse-btn {
  flex: none;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.sidebar-collapse-btn:hover { background: var(--canvas); color: var(--text); }
.sidebar-collapse-btn svg { width: 15px; height: 15px; transition: transform 0.2s var(--ease); }
body.sidebar-collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }
/* Collapsed: too narrow for logo + corner button, so the button stacks below the logo. */
body.sidebar-collapsed .sidebar-collapse-btn { position: static; transform: none; }

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 12px 14px;
  min-width: var(--sidebar-w);
}
body.sidebar-collapsed .sidebar-nav { min-width: 0; }
.nav-section { margin-bottom: 20px; }
.nav-section-label {
  font-size: 12px; font-weight: 600; letter-spacing: -0.01em;
  color: var(--text-faint); padding: 0 12px 6px;
  white-space: nowrap;
}
body.sidebar-collapsed .nav-section-label { display: none; }

.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px; font-weight: 400;
  margin-bottom: 2px;
  white-space: nowrap;
  position: relative;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-link svg { width: 18px; height: 18px; flex: none; color: var(--accent); }
.nav-link:hover { background: var(--canvas); }
.nav-link.active { background: var(--accent); color: var(--on-accent); }
.nav-link.active svg { color: var(--on-accent); }
.nav-link .nav-label { overflow: hidden; text-overflow: ellipsis; }
body.sidebar-collapsed .nav-link .nav-label,
body.sidebar-collapsed .nav-link .nav-count { display: none; }
body.sidebar-collapsed .nav-link { justify-content: center; }
.nav-count {
  margin-left: auto;
  font-size: 12px; font-weight: 600;
  background: var(--status-unknown-bg); color: var(--text-secondary);
  border-radius: var(--radius-pill); padding: 1px 8px;
  flex: none; font-variant-numeric: tabular-nums;
}
.nav-link.active .nav-count { background: rgba(255, 255, 255, 0.24); color: var(--on-accent); }

.sidebar-bottom {
  flex: none;
  border-top: 1px solid var(--border-soft);
  padding: 12px;
  min-width: var(--sidebar-w);
}
body.sidebar-collapsed .sidebar-bottom { min-width: 0; }

.theme-toggle {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 8px 12px; border-radius: var(--radius-sm); border: none; background: none;
  color: var(--text); font-size: 14px; font-weight: 400; font-family: inherit;
  cursor: pointer; margin-bottom: 4px; white-space: nowrap;
}
.theme-toggle:hover { background: var(--canvas); }
.theme-toggle-icon { display: none; width: 16px; height: 16px; flex: none; color: var(--text-secondary); }
.theme-toggle-icon svg { width: 16px; height: 16px; }
.theme-icon-sun { display: flex; }
html[data-theme="dark"] .theme-icon-sun { display: none; }
html[data-theme="dark"] .theme-icon-moon { display: flex; }
.theme-toggle .nav-label { flex: 1 1 auto; text-align: left; }
/* iOS-style switch */
.theme-toggle-switch {
  flex: none; width: 38px; height: 22px; border-radius: var(--radius-pill); background: #E9E9EB;
  position: relative; transition: background 0.2s var(--ease);
}
html[data-theme="dark"] .theme-toggle-switch { background: var(--accent); }
.theme-toggle-knob {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #FFFFFF; transition: transform 0.2s var(--ease);
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.15);
}
html[data-theme="dark"] .theme-toggle-knob { transform: translateX(16px); }
body.sidebar-collapsed .theme-toggle .nav-label,
body.sidebar-collapsed .theme-toggle-switch { display: none; }
body.sidebar-collapsed .theme-toggle { justify-content: center; }

.sidebar-support-link {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; font-weight: 400;
  margin-bottom: 4px; white-space: nowrap;
}
.sidebar-support-link:hover { background: var(--canvas); }
.sidebar-support-link svg { width: 16px; height: 16px; flex: none; color: var(--text-secondary); }
body.sidebar-collapsed .sidebar-support-link .nav-label { display: none; }
body.sidebar-collapsed .sidebar-support-link { justify-content: center; }

.account-menu-wrap { position: relative; }
.account-trigger {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px; border-radius: var(--radius-md);
  border: none; background: none; cursor: pointer; text-align: left;
}
.account-trigger:hover { background: var(--canvas); }
.account-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--text); color: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; letter-spacing: 0;
}
.account-meta { min-width: 0; display: flex; flex-direction: column; gap: 0; }
.account-name { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-role { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
body.sidebar-collapsed .account-meta { display: none; }
body.sidebar-collapsed .account-trigger { justify-content: center; }

.account-dropdown {
  display: none;
  position: absolute; bottom: calc(100% + 6px); left: 8px; right: 8px;
  background: var(--glass-strong); border: 1px solid var(--border); border-radius: var(--radius-md);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  padding: 6px; z-index: 40;
}
.account-dropdown.open { display: block; }
body.sidebar-collapsed .account-dropdown { left: 4px; right: auto; min-width: 190px; }
.account-dropdown button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border-radius: var(--radius-sm); border: none; background: none;
  cursor: pointer; font-size: 14px; font-weight: 400; color: var(--text); text-align: left;
}
.account-dropdown button:hover { background: var(--accent); color: var(--on-accent); }
.account-dropdown button:hover svg { color: var(--on-accent); }
.account-dropdown svg { width: 15px; height: 15px; color: var(--text-secondary); }

/* Mobile off-canvas */
.sidebar-scrim { display: none; }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); width: 272px; transition: transform 0.25s var(--ease); }
  body.mobile-nav-open .sidebar { transform: translateX(0); }
  body.sidebar-collapsed .sidebar { width: 272px; }
  body.sidebar-collapsed .sidebar-top .brand-block,
  body.sidebar-collapsed .nav-link .nav-label,
  body.sidebar-collapsed .nav-link .nav-count,
  body.sidebar-collapsed .theme-toggle .nav-label,
  body.sidebar-collapsed .theme-toggle-switch,
  body.sidebar-collapsed .account-meta { display: revert; }
  body.sidebar-collapsed .theme-toggle { justify-content: flex-start; }
  .sidebar-collapse-btn { display: none; }
  .sidebar-scrim {
    display: none; position: fixed; inset: 0; background: var(--scrim); z-index: 55;
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  }
  body.mobile-nav-open .sidebar-scrim { display: block; }
  .mobile-nav-btn { display: inline-flex !important; }
}

.main-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* Frosted sub-nav bar */
.topbar {
  height: var(--topbar-h);
  flex: none;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mobile-nav-btn {
  display: none; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: transparent; color: var(--text);
  cursor: pointer; flex: none;
}
.mobile-nav-btn:hover { background: var(--surface); }
.mobile-nav-btn svg { width: 18px; height: 18px; }
.breadcrumb { font-size: 14px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; }
.breadcrumb a { color: var(--accent); }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .crumb-current { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breadcrumb svg { width: 12px; height: 12px; color: var(--text-faint); flex: none; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex: none; }
.last-updated { font-size: 12px; color: var(--text-faint); white-space: nowrap; }

.content { flex: 1 1 auto; padding: 36px 32px 80px; max-width: 1360px; width: 100%; margin: 0 auto; }
@media (max-width: 700px) { .content { padding: 20px 16px 56px; } }

/* ============================= Buttons ============================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; flex: none;
  height: 36px; padding: 0 18px;
  border-radius: var(--radius-pill); font-size: 15px; font-weight: 400; letter-spacing: -0.016em;
  cursor: pointer; font-family: inherit; white-space: nowrap; border: 1px solid transparent;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.95); }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn-sm { height: 32px; padding: 0 15px; font-size: 14px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-outline { background: var(--surface-pearl); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface); border-color: var(--text-faint); }
.btn-ghost { background: none; color: var(--accent); border-color: transparent; }
.btn-ghost:hover { background: var(--accent-tint); }
.btn-danger-ghost { background: none; color: var(--status-withheld-text); border-color: transparent; }
.btn-danger-ghost:hover { background: var(--status-withheld-bg); }
.btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; border: none; background: transparent; color: var(--text-secondary); cursor: pointer;
}
.icon-btn:hover { background: var(--canvas); color: var(--text); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn svg { width: 16px; height: 16px; }

/* ============================= Page head ============================= */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 32px; }
.page-head h1 { margin: 0; font-family: var(--font-display); font-size: 40px; font-weight: 600; line-height: 1.1; color: var(--text); letter-spacing: -0.012em; }
.page-head p { margin: 8px 0 0; font-size: 17px; line-height: 1.47; color: var(--text-secondary); letter-spacing: -0.022em; }
.page-head-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.page-head-actions-col { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
@media (max-width: 700px) { .page-head h1 { font-size: 32px; } .page-head p { font-size: 15px; } }

/* ============================= Stat tiles ============================= */
.stats-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  margin-bottom: 32px;
}
.stat-tile {
  padding: 22px 24px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), transform 0.1s var(--ease);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  text-align: left; font-family: inherit; display: block; width: 100%;
}
.stat-tile:hover { border-color: var(--text-faint); }
.stat-tile:active { transform: scale(0.98); }
.stat-tile.active { border: 2px solid var(--accent-focus); padding: 21px 23px; }
.stat-tile-label { font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: -0.016em; }
.stat-tile-subtitle { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.stat-tile-value-row { display: flex; align-items: baseline; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.stat-tile-value { font-family: var(--font-display); font-size: 40px; font-weight: 600; color: var(--text); line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-badge { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: var(--radius-pill); white-space: nowrap; }
.stat-badge.blue { background: var(--accent-tint); color: var(--accent); }
.stat-badge.amber { background: var(--status-review-bg); color: var(--status-review-text); }
.stat-badge.gray { background: var(--status-unknown-bg); color: var(--status-unknown-text); }
.stat-badge.slate { background: var(--status-reviewed-bg); color: var(--status-reviewed-text); }
.stat-trend {
  display: flex; align-items: center; gap: 9px; margin-top: 14px;
  padding-top: 12px; border-top: 1px solid var(--border-soft);
}
.stat-trend-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-pill);
}
.stat-trend-pill svg { width: 11px; height: 11px; }
.stat-trend-pill.up.good, .stat-trend-pill.down.bad { background: var(--status-reviewed-bg); color: var(--status-reviewed-text); }
.stat-trend-pill.up.bad, .stat-trend-pill.down.good { background: var(--status-withheld-bg); color: var(--status-withheld-text); }
.stat-trend-note { font-size: 12px; color: var(--text-faint); }
@media (max-width: 860px) { .stats-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stats-row { grid-template-columns: 1fr; } }

/* ============================= Toolbar / search / filters ============================= */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.search-field {
  display: flex; align-items: stretch; flex: 1 1 300px; min-width: 240px; height: 38px;
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface); overflow: hidden;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.search-field:focus-within { border-color: var(--accent-focus); box-shadow: 0 0 0 3px var(--accent-ring); }
.search-scope {
  border: none; border-right: 1px solid var(--border); background: var(--surface-pearl); color: var(--text);
  font-size: 14px; font-weight: 400; padding: 0 10px 0 14px; font-family: inherit; cursor: pointer;
}
.search-input-wrap { position: relative; flex: 1 1 auto; display: flex; align-items: center; }
.search-input-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-faint); pointer-events: none; }
.search-input-wrap input {
  width: 100%; border: none; outline: none; background: none;
  padding: 0 36px 0 36px; height: 100%; font-size: 15px; font-family: inherit; letter-spacing: -0.016em; color: var(--text);
}
.search-input-wrap input::placeholder { color: var(--text-faint); }
.search-input-wrap input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: 10px; width: 20px; height: 20px; border: none; background: var(--text-faint);
  color: var(--surface); cursor: pointer; display: none; align-items: center; justify-content: center; border-radius: 50%;
  font-size: 10px; line-height: 1;
}
.search-clear:hover { background: var(--text-secondary); }
.search-clear.visible { display: flex; }

.filter-select {
  height: 38px; padding: 0 30px 0 14px; border: 1px solid var(--border); border-radius: var(--radius-pill);
  background: var(--surface) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%2386868B" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>') no-repeat right 11px center;
  background-size: 12px; font-size: 14px; font-weight: 400; letter-spacing: -0.016em; color: var(--text); font-family: inherit; cursor: pointer; appearance: none; flex: none;
}
.filter-select:hover { border-color: var(--text-faint); }
.filter-select:focus { outline: none; border-color: var(--accent-focus); box-shadow: 0 0 0 3px var(--accent-ring); }

.chips-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; min-height: 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-tint); color: var(--accent);
  font-size: 13px; font-weight: 400; padding: 5px 6px 5px 13px; border-radius: var(--radius-pill);
}
.chip button { border: none; background: none; color: inherit; cursor: pointer; display: flex; padding: 3px; border-radius: 50%; }
.chip button:hover { background: var(--accent-tint); }
.chip button svg { width: 11px; height: 11px; }
.chips-clear { font-size: 13px; font-weight: 400; color: var(--accent); background: none; border: none; cursor: pointer; padding: 5px 4px; }
.chips-clear:hover { text-decoration: underline; }
.results-count { font-size: 13px; color: var(--text-faint); margin-left: auto; white-space: nowrap; }

/* ============================= Table ============================= */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.case-table { width: 100%; border-collapse: collapse; min-width: 860px; }
.case-table thead th {
  position: sticky; top: 0; background: var(--surface); z-index: 5;
  text-align: left; font-size: 12px; font-weight: 600; color: var(--text-secondary);
  letter-spacing: -0.01em;
  padding: 13px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.case-table thead th.num { text-align: right; }
.case-table tbody td { padding: 15px 16px; border-bottom: 1px solid var(--border-soft); font-size: 14px; color: var(--text); vertical-align: top; }
.case-table tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
.case-table tbody tr { height: 60px; cursor: pointer; transition: background 0.12s var(--ease); }
.case-table tbody tr:hover { background: var(--canvas); }
.case-table tbody tr:last-child td { border-bottom: none; }
.cell-case-id { font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.cell-borrower { display: block; font-size: 13px; color: var(--text-secondary); margin-top: 2px; font-weight: 400; }
.cell-open-link { color: var(--text-faint); display: inline-flex; }
.cell-open-link svg { width: 16px; height: 16px; }
.cell-open-link:hover { color: var(--accent); }
.rating-cell-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.rating-cell-unrated { color: var(--text-faint); font-weight: 400; }

.table-empty { padding: 72px 24px; text-align: center; }
.table-empty .empty-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--canvas); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; color: var(--text-faint); }
.table-empty .empty-icon svg { width: 22px; height: 22px; }
.table-empty .empty-title { font-family: var(--font-display); font-size: 21px; font-weight: 600; color: var(--text); margin-bottom: 6px; letter-spacing: 0.011em; }
.table-empty .empty-body { font-size: 15px; color: var(--text-secondary); max-width: 360px; margin: 0 auto 16px; line-height: 1.47; }

.pagination-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-top: 1px solid var(--border-soft);
}
.pagination-count { font-size: 13px; color: var(--text-secondary); }
.pagination-controls { display: flex; align-items: center; gap: 6px; }
.page-btn {
  min-width: 32px; height: 32px; padding: 0 10px; border-radius: var(--radius-pill); border: 1px solid transparent;
  background: transparent; color: var(--text); font-size: 14px; font-weight: 400; cursor: pointer; font-variant-numeric: tabular-nums;
}
.page-btn:hover { background: var(--canvas); }
.page-btn:active:not(:disabled) { transform: scale(0.95); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.page-btn:disabled { opacity: 0.35; cursor: default; }
.page-size-select { height: 32px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 400; padding: 0 10px; font-family: inherit; }

/* ============================= Status badges ============================= */
.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: var(--radius-pill);
  border: 1px solid transparent; white-space: normal; line-height: 1.3; letter-spacing: -0.01em;
}
.status-badge .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; flex: none; }
.status-withheld { background: var(--status-withheld-bg); color: var(--status-withheld-text); border-color: var(--status-withheld-border); }
.status-redflag { background: var(--status-redflag-bg); color: var(--status-redflag-text); border-color: var(--status-redflag-border); }
.status-review { background: var(--status-review-bg); color: var(--status-review-text); border-color: var(--status-review-border); }
.status-insufficient { background: var(--status-insufficient-bg); color: var(--status-insufficient-text); border-color: var(--status-insufficient-border); }
.status-reviewed { background: var(--status-reviewed-bg); color: var(--status-reviewed-text); border-color: var(--status-reviewed-border); }
.case-table .status-badge { white-space: nowrap; }
.status-unknown { background: var(--status-unknown-bg); color: var(--status-unknown-text); border-color: var(--status-unknown-border); }

/* ============================= Cards / sections ============================= */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.section-title { font-family: var(--font-display); font-size: 21px; font-weight: 600; color: var(--text); margin: 0 0 14px; letter-spacing: 0.011em; line-height: 1.19; }

/* ============================= Alerts ============================= */
.alert-banner {
  display: flex; align-items: flex-start; gap: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 20px; margin-bottom: 24px;
}
.alert-banner svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.alert-banner .alert-title { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.alert-banner .alert-body { font-size: 14px; line-height: 1.47; }
.alert-banner.danger { background: var(--status-withheld-bg); border-color: var(--status-withheld-border); color: var(--status-withheld-text); }
.alert-banner.warning { background: var(--status-review-bg); border-color: var(--status-review-border); color: var(--status-review-text); }
.alert-banner.info { background: var(--accent-tint); border-color: var(--accent-ring); color: var(--accent); }

.toast-stack { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 100; max-width: 360px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--glass-strong); border: 1px solid var(--border); border-radius: var(--radius-lg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  padding: 14px 16px;
}
.toast svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast.success svg { color: var(--accent); }
.toast.error svg { color: var(--status-withheld-text); }
.toast .toast-title { font-size: 14px; font-weight: 600; color: var(--text); }
.toast .toast-body { font-size: 13px; color: var(--text-secondary); margin-top: 1px; }
.toast-dismiss { margin-left: auto; border: none; background: none; color: var(--text-faint); cursor: pointer; }

/* ============================= Forms ============================= */
.field-label { display: block; font-size: 13px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); margin-bottom: 6px; }
.text-input, textarea.text-input, select.text-input {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 10px 14px; font-size: 15px; font-family: inherit; letter-spacing: -0.016em; color: var(--text); background: var(--surface);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.text-input:focus { outline: none; border-color: var(--accent-focus); box-shadow: 0 0 0 3px var(--accent-ring); }
textarea.text-input { resize: vertical; min-height: 88px; }
.checkbox-row { display: flex; align-items: flex-start; gap: 9px; font-size: 14px; color: var(--text); }
.checkbox-row input[type="checkbox"] { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }

/* ============================= Skeletons ============================= */
.skel {
  background: linear-gradient(90deg, var(--border-soft) 25%, var(--border) 37%, var(--border-soft) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ============================= Utility ============================= */
.text-muted { color: var(--text-secondary); }
.text-faint { color: var(--text-faint); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sr-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ============================= Cases toolbar grid =============================
   Row 1: search (spans the filter columns) · More filters · Columns.
   Row 2: the four filters, each the same width, aligned under the search field. */
.toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.toolbar .search-field { grid-column: 1 / 5; grid-row: 1; min-width: 0; flex: none; }
.toolbar .filter-trigger-wrap { grid-column: 5; grid-row: 1; }
.toolbar .col-menu-wrap { grid-column: 6; grid-row: 1; margin-left: 0; }
.toolbar .filter-select { grid-row: 2; width: 100%; min-width: 0; text-overflow: ellipsis; }
.toolbar .filter-trigger-wrap .btn, .toolbar .col-menu-wrap .btn { height: 38px; }
.chips-row { margin-bottom: 14px; }
.chips-row .results-count { margin-left: auto; }

.page-btn { display: inline-flex; align-items: center; justify-content: center; }
.page-btn svg { width: 14px; height: 14px; flex: none; }
.pagination-controls { gap: 10px; }
.page-btns { align-items: center; }
.page-size-select { padding: 0 28px 0 12px; appearance: none; cursor: pointer;
  background: var(--surface) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%2386868B" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>') no-repeat right 10px center;
  background-size: 11px; }
.page-size-select:focus { outline: none; border-color: var(--accent-focus); box-shadow: 0 0 0 3px var(--accent-ring); }

@media (max-width: 1000px) {
  .toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar .search-field { grid-column: 1 / -1; grid-row: 1; }
  .toolbar .filter-select { grid-row: auto; }
  .toolbar .filter-trigger-wrap { grid-column: 1; grid-row: 4; justify-self: start; }
  .toolbar .col-menu-wrap { grid-column: 2; grid-row: 4; justify-self: end; }
}
@media (max-width: 480px) {
  .toolbar { grid-template-columns: minmax(0, 1fr); }
  .toolbar .filter-trigger-wrap, .toolbar .col-menu-wrap { grid-column: 1; grid-row: auto; justify-self: stretch; }
  .toolbar .filter-trigger-wrap .btn, .toolbar .col-menu-wrap .btn { width: 100%; }
  .search-scope { max-width: 110px; }
  .pagination-bar { justify-content: center; }
  .pagination-count { width: 100%; text-align: center; }
}
