/* Design System v2 — tokens and the shared portal shell (Admin and Customer).
   Source: Figma "08.1 — DS v2 · Foundations" (variables "HMA v2 · Theme", mode Field ops)
   and Phase 1 shell frames (UI_REVIEW.md). Page content keeps its own styles until
   Phases 2–3. A Dark mode later redefines only the semantic variables below. */
:root {
  --hma-bg-canvas: #f4f5f1;
  --hma-bg-surface: #fff;
  --hma-bg-subtle: #eceee8;
  --hma-shell-bg: #1f2622;
  --hma-shell-bg-raised: #2b342f;
  --hma-shell-text: #f1f3ee;
  --hma-shell-text-muted: #aab3ac;
  --hma-shell-accent: #e5c961;
  --hma-shell-on-accent: #1f2622;
  --hma-text-primary: #17201b;
  --hma-text-secondary: #5c665f;
  --hma-text-on-primary: #fff;
  --hma-text-link: #0b6847;
  --hma-border-default: #dfe2da;
  --hma-border-control: #8a948c;
  --hma-focus: #1f5fae;
  --hma-action-primary: #0b6847;
  --hma-action-primary-hover: #08553a;
  --hma-action-danger: #b42318;
  --hma-status-success: #106b3f;
  --hma-status-success-bg: #e3f2e8;
  --hma-status-warning: #8a4b08;
  --hma-status-warning-bg: #fdf0dc;
  --hma-status-danger: #b42318;
  --hma-status-danger-bg: #fdecea;
  --hma-status-info: #1f5fae;
  --hma-status-info-bg: #e6eefa;
  --hma-status-neutral: #4f5852;
  --hma-status-neutral-bg: #eceee8;
  --hma-radius-sm: 4px;
  --hma-radius-md: 6px;
  --hma-radius-lg: 10px;
  --hma-control-sm: 32px;
  --hma-control-md: 36px;
  --hma-control-lg: 44px;
  --hma-shadow-popover: 0 8px 24px rgba(23,33,28,.16);
  /* Token cleanup (UI_REVIEW.md, Figma 872:770): shadows, overlay and chart bands. */
  --hma-shadow-card: 0 1px 2px rgba(23,33,28,.06);
  --hma-shadow-sheet: 0 -8px 24px rgba(23,33,28,.16);
  --hma-focus-ring: rgba(31,95,174,.2);
  --hma-scrim: rgba(23,33,28,.45);
  --hma-chart-monitored: #bce8cf;
  --hma-chart-paused: #f8dca0;
  --hma-chart-excluded: #d9dee2;
  --hma-font-mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}

body.hma-v2 { background: var(--hma-bg-canvas); color: var(--hma-text-primary); }
.hma-v2 .v2-shell { display: grid; grid-template-columns: 64px minmax(0,1fr); min-height: 100dvh; }
.hma-v2 .v2-shell.has-context { grid-template-columns: 288px minmax(0,1fr); }
.hma-v2 .v2-main { min-width: 0; background: var(--hma-bg-canvas); }

/* Sidebar: rail + optional context column. Below 992px Bootstrap turns it into the navigation sheet. */
.hma-v2 .v2-sidebar { --bs-offcanvas-width: 300px; --bs-offcanvas-bg: var(--hma-shell-bg); display: flex; background: var(--hma-shell-bg); color: var(--hma-shell-text); }
.hma-v2 .v2-rail { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 64px; flex: none; padding: 18px 10px 16px; background: var(--hma-shell-bg); }
.hma-v2 .v2-brand { margin: 0 0 28px; text-decoration: none; }
.hma-v2 .v2-mark, .hma-v2 .v2-topbar-mark { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 7px; background: var(--hma-action-primary); }
.hma-v2 .v2-mark img, .hma-v2 .v2-topbar-mark img { display: block; width: 18px; height: 18px; }
.hma-v2 .v2-rail-nav { display: flex; flex-direction: column; gap: 6px; }
.hma-v2 .v2-rail-link { display: flex; align-items: center; justify-content: center; gap: 12px; width: 44px; height: 40px; border-radius: 8px; color: var(--hma-shell-text); text-decoration: none; }
.hma-v2 .v2-rail-link img { display: block; width: 18px; height: 18px; flex: none; }
.hma-v2 .v2-rail-link:hover { background: var(--hma-shell-bg-raised); color: var(--hma-shell-text); }
.hma-v2 .v2-rail-link.active { background: var(--hma-shell-bg-raised); box-shadow: inset 3px 0 0 var(--hma-shell-accent); }
.hma-v2 .v2-rail-link:focus-visible, .hma-v2 .v2-context-link:focus-visible, .hma-v2 .v2-context-switch:focus-visible, .hma-v2 .v2-avatar:focus-visible, .hma-v2 .v2-menu-button:focus-visible, .hma-v2 .v2-breadcrumb a:focus-visible { outline: 2px solid var(--hma-shell-accent); outline-offset: 2px; }
.hma-v2 .v2-rail-label { display: none; }

.hma-v2 .v2-context { flex-direction: column; width: 224px; flex: none; padding: 20px 12px; background: var(--hma-shell-bg-raised); overflow-y: auto; }
.hma-v2 .v2-context-head { display: grid; gap: 4px; min-width: 0; padding: 0 4px 12px; }
.hma-v2 .v2-eyebrow { color: var(--hma-shell-text-muted); font-size: 11px; font-weight: 600; line-height: 14px; letter-spacing: .6px; text-transform: uppercase; }
.hma-v2 .v2-context-head strong { color: var(--hma-shell-text); font-size: 15px; font-weight: 600; line-height: 20px; }
.hma-v2 .v2-context-head code { display: block; overflow: hidden; color: var(--hma-shell-text-muted); font-family: var(--hma-font-mono); font-size: 13px; line-height: 18px; white-space: nowrap; text-overflow: ellipsis; }
.hma-v2 .v2-context-head small { color: var(--hma-shell-text-muted); font-size: 12px; line-height: 16px; }
.hma-v2 .v2-context-switch { display: flex; align-items: center; justify-content: center; height: var(--hma-control-md); margin-top: 10px; border: 1px solid var(--hma-border-control); border-radius: var(--hma-radius-md); color: var(--hma-shell-text); font-size: 13px; font-weight: 500; text-decoration: none; }
.hma-v2 .v2-context-switch:hover { background: var(--hma-shell-bg); color: var(--hma-shell-text); }
.hma-v2 .v2-context-nav { display: flex; flex-direction: column; gap: 2px; }
.hma-v2 .v2-context-link { display: flex; align-items: center; min-height: var(--hma-control-md); padding: 6px 12px; border-radius: var(--hma-radius-md); color: var(--hma-shell-text); font-size: 14px; line-height: 20px; text-decoration: none; }
.hma-v2 .v2-context-link:hover { background: var(--hma-shell-bg); color: var(--hma-shell-text); }
.hma-v2 .v2-context-link.active { background: var(--hma-shell-bg); box-shadow: inset 3px 0 0 var(--hma-shell-accent); color: var(--hma-shell-accent); font-weight: 600; }

/* Top bar */
.hma-v2 .v2-topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 24px 0 32px; background: var(--hma-shell-bg); color: var(--hma-shell-text); }
.hma-v2 .v2-breadcrumb { min-width: 0; }
.hma-v2 .v2-breadcrumb ol { display: flex; align-items: center; gap: 8px; min-width: 0; margin: 0; padding: 0; list-style: none; font-size: 13px; font-weight: 500; line-height: 18px; }
.hma-v2 .v2-breadcrumb li { display: flex; gap: 8px; min-width: 0; white-space: nowrap; }
.hma-v2 .v2-breadcrumb li + li::before { content: "/"; color: var(--hma-shell-text-muted); }
.hma-v2 .v2-breadcrumb a { color: var(--hma-shell-text-muted); text-decoration: none; }
.hma-v2 .v2-breadcrumb a:hover { color: var(--hma-shell-text); text-decoration: underline; }
.hma-v2 .v2-breadcrumb [aria-current] { overflow: hidden; color: var(--hma-shell-text); text-overflow: ellipsis; }
.hma-v2 .v2-topbar-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.hma-v2 .v2-environment { display: inline-flex; align-items: center; padding: 3px 10px; border: 1px solid var(--hma-shell-text-muted); border-radius: 999px; color: var(--hma-shell-text); font-size: 12px; font-weight: 500; line-height: 16px; }
.hma-v2 .v2-avatar { display: grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: var(--hma-shell-accent); color: var(--hma-shell-on-accent); font-size: 13px; font-weight: 600; }
.hma-v2 .v2-account-menu { min-width: 240px; padding: 8px 0; border: 1px solid var(--hma-border-default); border-radius: var(--hma-radius-lg); box-shadow: var(--hma-shadow-popover); }
.hma-v2 .v2-account-who { display: grid; gap: 2px; padding: 8px 16px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--hma-border-default); }
.hma-v2 .v2-account-who strong { color: var(--hma-text-primary); font-size: 14px; font-weight: 600; }
.hma-v2 .v2-account-who small { color: var(--hma-text-secondary); font-size: 12px; }
.hma-v2 .v2-account-menu .dropdown-item { padding: 10px 16px; color: var(--hma-text-primary); font-size: 14px; }
.hma-v2 .v2-account-menu .v2-signout { color: var(--hma-action-danger); }

/* Page header: shared partial and the existing per-page headers share one look. */
.hma-v2 .v2-page-header { margin-bottom: 20px; }
body.hma-v2 .v2-page-header h1, body.hma-v2 .hma-page-heading h1, body.hma-v2 .detail-header h1, body.hma-v2 .hma-heading h1, body.hma-v2 .customer-nodes-heading h1 { margin: 0; color: var(--hma-text-primary); font-size: 26px; font-weight: 700; line-height: 32px; letter-spacing: -.3px; }
body.hma-v2 .v2-page-header p, body.hma-v2 .hma-page-heading > div > p, body.hma-v2 .detail-header .hma-detail-title > p { margin: 4px 0 0; color: var(--hma-text-secondary); font-size: 14px; line-height: 20px; }
body.hma-v2 .hma-heading .hma-eyebrow, body.hma-v2 .customer-nodes-heading .hma-eyebrow { margin: 0 0 4px; color: var(--hma-text-secondary); font-size: 11px; font-weight: 600; line-height: 14px; letter-spacing: .6px; text-transform: uppercase; }

body.hma-v2 .v2-page-subtitle { margin: 4px 0 0; color: var(--hma-text-secondary); font-size: 14px; line-height: 20px; }
/* Section tabs inside a page (Node detail) use the v2 Tab: 44px, underline, scrolls inside itself. */
.hma-v2 .hma-node-tabs { display: flex; flex-wrap: nowrap; margin: 0 0 20px; padding: 0; overflow-x: auto; border: 0; border-bottom: 1px solid var(--hma-border-default); border-radius: 0; background: transparent; scrollbar-width: none; }
.hma-v2 .hma-node-tabs::-webkit-scrollbar { display: none; }
.hma-v2 .hma-node-tabs .nav-link { display: flex; flex: none; align-items: center; height: var(--hma-control-lg); padding: 0 12px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--hma-text-secondary); font-size: 14px; white-space: nowrap; }
.hma-v2 .hma-node-tabs .nav-link:hover { color: var(--hma-text-primary); }
.hma-v2 .hma-node-tabs .nav-link.active { border-bottom-color: var(--hma-action-primary); background: transparent; color: var(--hma-text-primary); font-weight: 600; }

/* Mobile and tablet: navigation sheet, 56px top bar, context bar with section tabs. */
@media (max-width: 991.98px) {
  .hma-v2 .v2-shell, .hma-v2 .v2-shell.has-context { display: block; }
  .hma-v2 .v2-sidebar { flex-direction: column; }
  .hma-v2 .v2-rail { width: 100%; height: 100%; align-items: stretch; gap: 4px; padding: 8px 12px 16px; }
  .hma-v2 .v2-sheet-head { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; }
  .hma-v2 .v2-sheet-head strong { flex: 1; color: var(--hma-shell-text); font-size: 15px; font-weight: 600; }
  .hma-v2 .v2-sheet-close { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; color: var(--hma-shell-text); font-size: 18px; }
  .hma-v2 .v2-rail-nav { gap: 4px; }
  .hma-v2 .v2-rail-link { justify-content: flex-start; width: 100%; height: 44px; padding: 0 12px; border-radius: var(--hma-radius-md); }
  .hma-v2 .v2-rail-label { display: inline; color: var(--hma-shell-text); font-size: 14px; }
  .hma-v2 .v2-rail-link.active .v2-rail-label { color: var(--hma-shell-accent); font-weight: 600; }
  .hma-v2 .v2-sheet-account { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--hma-shell-bg-raised); }
  .hma-v2 .v2-sheet-who { display: grid; flex: 1; min-width: 0; }
  .hma-v2 .v2-sheet-who strong { overflow: hidden; color: var(--hma-shell-text); font-size: 13px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
  .hma-v2 .v2-sheet-who small { overflow: hidden; color: var(--hma-shell-text-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .hma-v2 .v2-sheet-signout { height: var(--hma-control-lg); padding: 0 12px; border: 1px solid var(--hma-border-control); border-radius: var(--hma-radius-md); background: transparent; color: var(--hma-shell-text); font-size: 13px; font-weight: 500; }
  .hma-v2 .v2-topbar { gap: 8px; height: 56px; padding: 0 12px 0 8px; }
  .hma-v2 .v2-menu-button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; }
  .hma-v2 .v2-menu-button span { display: block; width: 18px; height: 2px; border-radius: 1px; background: var(--hma-shell-text); }
  .hma-v2 .v2-topbar-title { flex: 1; min-width: 0; overflow: hidden; color: var(--hma-shell-text); font-size: 15px; font-weight: 600; line-height: 20px; text-overflow: ellipsis; white-space: nowrap; }
  .hma-v2 .v2-environment { display: none; }
  .hma-v2 .v2-context-bar { display: grid; gap: 8px; padding: 12px 16px 0; background: var(--hma-bg-surface); border-bottom: 1px solid var(--hma-border-default); }
  .hma-v2 .v2-context-back { color: var(--hma-text-link); font-size: 13px; font-weight: 500; text-decoration: none; }
  .hma-v2 .v2-context-switch-mobile { display: flex; align-items: center; justify-content: center; min-height: var(--hma-control-lg); padding: 0 12px; border: 1px solid var(--hma-border-control); border-radius: var(--hma-radius-md); color: var(--hma-text-primary); font-size: 15px; font-weight: 600; text-align: center; text-decoration: none; }
  .hma-v2 .v2-tabs { display: flex; margin: 0 -16px; padding: 0 16px; overflow-x: auto; scrollbar-width: none; }
  .hma-v2 .v2-tabs::-webkit-scrollbar { display: none; }
  .hma-v2 .v2-tab { display: flex; flex: none; align-items: center; height: var(--hma-control-lg); padding: 0 12px; border-bottom: 2px solid transparent; color: var(--hma-text-secondary); font-size: 14px; white-space: nowrap; text-decoration: none; }
  .hma-v2 .v2-tab.active { border-bottom-color: var(--hma-action-primary); color: var(--hma-text-primary); font-weight: 600; }
  body.hma-v2 .v2-page-header h1, body.hma-v2 .hma-page-heading h1, body.hma-v2 .detail-header h1, body.hma-v2 .hma-heading h1, body.hma-v2 .customer-nodes-heading h1 { font-size: 22px; line-height: 28px; letter-spacing: -.2px; }
}

@media print {
  .hma-v2 .v2-shell, .hma-v2 .v2-shell.has-context { display: block; }
  .hma-v2 .v2-sidebar, .hma-v2 .v2-topbar, .hma-v2 .v2-context-bar { display: none; }
}
