:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-deep: #173a72;
  --blue-soft: #eef4ff;
  --ink: #10233f;
  --slate: #40536d;
  --muted: #6a7c92;
  --bg: #f3f6fa;
  --card: #ffffff;
  --line: #dfe6ef;
  --line-soft: #edf1f6;
  --red: #c93636;
  --red-soft: #fff0ef;
  --red-ink: #9e2424;
  --green: #158047;
  --green-soft: #eaf7ef;
  --green-ink: #12663b;
  --amber: #ad6508;
  --amber-soft: #fff6e6;
  --amber-ink: #8c5209;
  --gray-soft: #f0f3f7;
  --gray-ink: #53647a;
  --nav: #10233f;
  --nav-2: #172d4b;
  --shadow: 0 1px 2px rgba(16, 35, 63, .05), 0 1px 4px rgba(16, 35, 63, .05);
  --shadow-md: 0 10px 28px rgba(16, 35, 63, .09);
  --radius: 14px;
  --radius-sm: 9px;
  --fs-page-title: 32px;
  --fs-page-subtitle: 15px;
  --fs-section-title: 21px;
  --fs-section-desc: 14px;
  --fs-card-title: 16px;
  --fs-body: 14px;
  --fs-helper: 13px;
  --fs-micro: 11.5px;
  --fs-kpi-lg: 38px;
  --fs-kpi-md: 29px;
  --fs-kpi-sm: 22px;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 650;
  --fw-bold: 740;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --sidebar-width: 248px;
  --mobile-bar-height: 60px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-dark); }
a:hover { color: #153d91; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
svg { display: block; }

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 10px;
  left: 12px;
  padding: 9px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-150%);
  transition: transform .15s ease;
}
.skip-link:focus { transform: translateY(0); }

/* Application shell */
.portal-shell { min-height: 100vh; }
.portal-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 90;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  overflow-y: auto;
  color: #d8e3f0;
  background:
    radial-gradient(circle at 15% -10%, rgba(59, 130, 246, .28), transparent 32%),
    linear-gradient(180deg, var(--nav-2), var(--nav));
  border-right: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 10px 0 30px rgba(16, 35, 63, .08);
}
.sidebar-brand {
  display: flex;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-brand > a,
.mobile-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: #fff;
  text-decoration: none;
}
.sidebar-brand strong { display: block; font-size: 16px; line-height: 1.15; letter-spacing: .02em; }
.sidebar-brand small { display: block; margin-top: 2px; color: #aebdd0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  flex: none;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(145deg, #4c8dff, #2563eb);
  box-shadow: 0 7px 16px rgba(37, 99, 235, .3), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.brand-mark span { width: 12px; height: 12px; border: 3px solid #fff; border-radius: 4px; }
.icon-button.sidebar-close { display: none; }
.primary-nav { flex: 1; padding: 16px 12px 22px; }
.nav-group + .nav-group { margin-top: 16px; }
.nav-group-label {
  padding: 0 10px 6px;
  color: #7f94ad;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.portal-nav-link {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  margin: 2px 0;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #b9c8da;
  font-size: 13.5px;
  font-weight: 580;
  text-decoration: none;
  transition: color .12s, background .12s, border-color .12s, transform .12s;
}
.portal-nav-link:hover { color: #fff; background: rgba(255, 255, 255, .065); }
.portal-nav-link.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(57, 124, 245, .30), rgba(57, 124, 245, .14));
  border-color: rgba(100, 155, 255, .26);
  box-shadow: inset 3px 0 0 #5d9aff;
}
.nav-glyph {
  display: grid;
  width: 25px;
  height: 25px;
  flex: none;
  place-items: center;
  border-radius: 7px;
  color: #8fa4bd;
  background: rgba(255, 255, 255, .055);
  font-size: 9.5px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.portal-nav-link.active .nav-glyph { color: #fff; background: rgba(75, 139, 255, .28); }
.sidebar-account {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 15px 14px 18px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  background: rgba(0, 0, 0, .08);
}
.account-avatar {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 11px;
  color: #fff;
  background: rgba(255, 255, 255, .09);
  font-weight: 750;
}
.account-copy { min-width: 0; }
.account-copy strong,
.account-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { color: #fff; font-size: 12.5px; }
.account-copy small { color: #93a6bc; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; }
.account-logout { color: #b9c8da; font-size: 11.5px; font-weight: 650; text-decoration: none; }
.account-logout:hover { color: #fff; }
.portal-frame { min-width: 0; min-height: 100vh; margin-left: var(--sidebar-width); }
.mobile-bar { display: none; }
.sidebar-backdrop { display: none; }
.portal-main {
  min-width: 0;
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 34px 38px 72px;
  outline: none;
}
.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  color: inherit;
  background: transparent;
  cursor: pointer;
}
.icon-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-button:hover { background: rgba(255, 255, 255, .08); }

/* Typography and layout */
h1, h2, h3, p { overflow-wrap: break-word; }
h1 { margin: 0 0 var(--space-2); font-size: var(--fs-page-title); font-weight: var(--fw-bold); line-height: 1.12; letter-spacing: -.025em; }
h2 { margin: 0 0 var(--space-3); font-size: var(--fs-section-title); font-weight: var(--fw-semibold); line-height: 1.25; letter-spacing: -.012em; }
h3 { margin: 0 0 var(--space-3); font-size: var(--fs-card-title); font-weight: var(--fw-semibold); line-height: 1.32; }
.muted { color: var(--muted); }
.page-head, .page-header { margin: 0 0 26px; }
.page-head h1, .page-title { margin: 0 0 7px; font-size: var(--fs-page-title); font-weight: var(--fw-bold); line-height: 1.12; letter-spacing: -.025em; }
.page-head .sub, .page-subtitle { max-width: 76ch; margin: 0; color: var(--slate); font-size: var(--fs-page-subtitle); line-height: 1.55; }
.page-eyebrow { margin-bottom: 6px; color: var(--blue-dark); font-size: 11px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.page-back { display: inline-block; margin-bottom: 12px; color: var(--muted); font-size: 13px; font-weight: 650; text-decoration: none; }
.page-back:hover { color: var(--blue-dark); }
.section { margin: 0 0 var(--space-8); }
.section-header { margin: 0 0 var(--space-4); }
.section-title { margin: 0 0 var(--space-1); color: var(--ink); font-size: var(--fs-section-title); font-weight: var(--fw-semibold); line-height: 1.22; }
.section-description { max-width: 80ch; margin: 0; color: var(--slate); font-size: var(--fs-section-desc); line-height: 1.5; }
.section-meta { color: var(--muted); font-size: var(--fs-helper); white-space: nowrap; }
.split-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.card-title { margin: 0 0 var(--space-3); color: var(--ink); font-size: var(--fs-card-title); font-weight: var(--fw-semibold); }
.helper-text { color: var(--muted); font-size: var(--fs-helper); line-height: 1.5; }
.num, .tnum { font-variant-numeric: tabular-nums; }

/* Surfaces, cards, metrics */
.card {
  margin-bottom: var(--space-5);
  padding: var(--space-6);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi {
  position: relative;
  overflow: hidden;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.kpi::before { position: absolute; inset: 0 auto 0 0; width: 3px; background: #cbd5e1; content: ""; }
.kpi .n, .kpi-value { color: var(--ink); font-size: var(--fs-kpi-md); font-weight: var(--fw-bold); line-height: 1.08; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.kpi .l, .kpi-label { margin-top: 5px; color: var(--muted); font-size: var(--fs-helper); font-weight: var(--fw-medium); }
.kpi-description { margin-top: 4px; color: var(--muted); font-size: var(--fs-micro); line-height: 1.4; }
.kpi.red::before { background: var(--red); } .kpi.red .n { color: var(--red); }
.kpi.green::before { background: var(--green); } .kpi.green .n { color: var(--green); }
.kpi.amber::before { background: var(--amber); } .kpi.amber .n { color: var(--amber); }
.kpi.blue::before { background: var(--blue); } .kpi.blue .n { color: var(--blue-dark); }
.two-col { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

/* Tables */
.table-wrapper { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table-wrapper table { border: 0; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
th {
  color: var(--muted);
  background: #f8fafc;
  border-bottom-color: var(--line);
  font-size: 10.5px;
  font-weight: 750;
  letter-spacing: .065em;
  text-transform: uppercase;
  white-space: nowrap;
}
thead th, table > tr:first-child th { position: sticky; top: 0; z-index: 2; }
tbody tr:hover td, table tr:hover td { background: #f8fafd; }
tr:last-child td { border-bottom: 0; }
.row-overdue td { background: #fff8f7; }
.row-overdue:hover td { background: #fff2f0; }

/* Buttons and status */
.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 15px;
  border: 1px solid var(--blue);
  border-radius: var(--radius-sm);
  color: #fff;
  background: var(--blue);
  font-size: 13px;
  font-weight: 680;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .08s;
}
.btn:hover { color: #fff; background: var(--blue-dark); border-color: var(--blue-dark); }
.btn:active { transform: translateY(1px); }
.btn.gray { color: var(--slate); background: #fff; border-color: var(--line); }
.btn.gray:hover { color: var(--ink); background: #f5f7fa; border-color: #cbd5e1; }
.btn.danger { color: var(--red-ink); background: var(--red-soft); border-color: #f0c9c5; }
.btn:disabled, .btn[disabled], .btn.is-disabled { color: #94a3b8; background: #edf1f5; border-color: var(--line); box-shadow: none; cursor: not-allowed; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1.45;
}
.pill.churn, .pill.overdue { color: var(--red-ink); background: var(--red-soft); border-color: #f3d0cc; }
.pill.early, .pill.due-today, .pill.atrisk { color: var(--amber-ink); background: var(--amber-soft); border-color: #f0dfbd; }
.pill.done, .pill.save { color: var(--green-ink); background: var(--green-soft); border-color: #c7e7d3; }
.pill.on-time, .pill.followup { color: var(--blue-dark); background: var(--blue-soft); border-color: #d1e0ff; }
.pill.neutral { color: var(--gray-ink); background: var(--gray-soft); border-color: #dfe5ec; }

/* Forms */
select, input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="month"], textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: #fff;
  font-size: 13.5px;
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; }
select:hover, input:hover, textarea:hover { border-color: #aebccd; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
label { color: var(--slate); font-weight: 650; }

/* Tick-box outcome groups (retention record: "what happened on this visit") */
.check-group { padding: 0; border: 0; margin: 0; }
.check-group > legend { padding: 0; margin-bottom: 10px; color: var(--slate); font-size: 13px; font-weight: 650; }
.check-group-block { margin-bottom: 14px; padding-left: 12px; border-left: 3px solid var(--line); }
.check-group-block:last-child { margin-bottom: 0; }
.check-group-label { margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.check-row { display: flex; gap: 9px; align-items: flex-start; padding: 4px 0; color: var(--ink); font-weight: 500; cursor: pointer; }
.check-row input[type="checkbox"] { width: 16px; height: 16px; margin-top: 2px; flex: none; accent-color: var(--blue); cursor: pointer; }
.check-row input[type="checkbox"]:disabled { cursor: not-allowed; }
.check-row.is-blocked { color: #9aa7b6; cursor: not-allowed; }
.check-group-block .helper-text { margin-top: 4px; }
kbd { display: inline-block; padding: 1px 7px; border: 1px solid #cbd5e1; border-bottom-width: 2px; border-radius: 5px; color: #33475b; background: #eef2f7; font: 650 12px ui-monospace, Menlo, monospace; }

/* Flash, tabs, empty states */
.flash {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13.5px;
}
.flash.ok { color: var(--green-ink); background: var(--green-soft); border-color: #c7e7d3; }
.flash.error { color: var(--red-ink); background: var(--red-soft); border-color: #f3d0cc; }
.flash-mark { display: grid; width: 20px; height: 20px; flex: none; place-items: center; border-radius: 50%; color: #fff; background: var(--green); font-size: 11px; }
.flash.error .flash-mark { background: var(--red); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tabs a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-size: 13px; font-weight: 650; text-decoration: none; }
.tabs a:hover { color: var(--ink); background: #eef1f6; }
.tabs a.active { color: var(--blue-dark); background: var(--blue-soft); }
.empty-state, .empty { padding: 40px 22px; text-align: center; }
.empty-state { border: 1px dashed #cbd6e3; border-radius: var(--radius); background: #fbfcfe; }
.empty-state-mark, .empty .ico { display: grid; width: 42px; height: 42px; margin: 0 auto 13px; place-items: center; border-radius: 13px; color: var(--green-ink); background: var(--green-soft); font-weight: 800; }
.empty-state h2, .empty h3 { margin-bottom: 6px; }
.empty-state p, .empty p { max-width: 58ch; margin: 0 auto 16px; color: var(--muted); }
.empty-state.compact { padding: 24px 18px; }
.empty-state.compact p { margin-bottom: 0; }

/* Signed-out experience */
.auth-main {
  display: grid;
  min-height: 100vh;
  padding: 28px;
  place-items: center;
  background:
    radial-gradient(circle at 12% 12%, rgba(76, 141, 255, .17), transparent 30%),
    radial-gradient(circle at 90% 86%, rgba(21, 128, 71, .10), transparent 28%),
    #eef3f9;
}
.auth-card { width: min(100%, 440px); padding: 34px; border: 1px solid rgba(203, 213, 225, .82); border-radius: 18px; background: rgba(255, 255, 255, .96); box-shadow: 0 22px 60px rgba(16, 35, 63, .13); }
.auth-brand { display: inline-flex; align-items: center; gap: 12px; margin-bottom: 27px; }
.auth-brand strong { display: block; font-size: 15px; }
.auth-brand span:last-child small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.auth-card h1 { font-size: 27px; }
.auth-card .auth-subtitle { margin: 0 0 24px; color: var(--slate); }
.auth-card .form-field + .form-field { margin-top: 14px; }
.auth-card .form-field label { display: block; margin-bottom: 6px; font-size: 12.5px; }
.auth-card .btn { width: 100%; margin-top: 18px; }
.auth-note { margin: 14px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

/* Shared workflow refinements */
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.page-head-row { display: flex; gap: 24px; align-items: flex-start; justify-content: space-between; margin-bottom: 26px; }
.page-head-row .page-header, .page-head-row .page-head { margin-bottom: 0; }
.progress-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.progress-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--slate); background: #fff; font-size: 12px; }
.progress-chip strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.callout { padding: 14px 16px; border: 1px solid #d6e2f7; border-radius: 11px; color: #29496e; background: #f3f7ff; font-size: 13.5px; }
.callout.warning { color: var(--amber-ink); background: var(--amber-soft); border-color: #efdfbf; }
.entity-header { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; justify-content: space-between; }
.entity-meta { display: flex; flex-wrap: wrap; gap: 7px 16px; color: var(--slate); font-size: 13px; }
.form-section { padding-top: 22px; border-top: 1px solid var(--line); }
.form-section:first-child { padding-top: 0; border-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-field label { display: block; margin-bottom: 6px; font-size: 12.5px; }
.field-full { grid-column: 1 / -1; }
/* A grid child still obeys [hidden]; stated explicitly so a future display rule
   on .form-field cannot un-hide the "Other" address box. */
.form-field[hidden] { display: none; }
.detail-list { display: grid; gap: 10px; margin: 0; }
.detail-list div { display: flex; gap: 20px; align-items: baseline; justify-content: space-between; padding-bottom: 9px; border-bottom: 1px solid var(--line-soft); }
.detail-list div:last-child { padding-bottom: 0; border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 12px; font-weight: 650; }
.detail-list dd { margin: 0; text-align: right; font-size: 13px; font-weight: 650; }
.entity-title { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.chip { display: inline-flex; align-items: center; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--gray-ink); background: var(--gray-soft); font-size: 11px; font-weight: 700; letter-spacing: .01em; }
.chip.active { color: var(--green-ink); background: var(--green-soft); border-color: #c7e7d3; }
.chip.hist { color: var(--gray-ink); background: var(--gray-soft); }

/* Focused review */
.review-progress { display: flex; gap: 10px; margin: -8px 0 14px; color: var(--muted); font-size: 12px; }
.review-progress span { padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; background: #fff; }
.review-card { max-width: 860px; }
.review-form { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.required-note { margin-left: 5px; color: var(--red); font-size: 11px; }
.shortcut-bar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-top: 22px; padding: 13px 0 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; }
.shortcut-bar strong { color: var(--slate); }

/* Dashboard priority compression */
.wq-row.is-clear { min-height: 58px; padding-top: 11px; padding-bottom: 11px; border-left-width: 3px; }
.wq-row.is-clear .wq-num { min-width: 38px; font-size: 22px; }
.wq-row.is-clear .what, .wq-row.is-clear .do { display: none; }

/* Upload and data source */
.dataset-card { padding: 22px 24px; }
.dataset-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px 24px; margin: 22px 0 0; }
.dataset-grid div { min-width: 0; }
.dataset-grid dt { margin-bottom: 3px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.dataset-grid dd { overflow: hidden; margin: 0; color: var(--ink); font-size: 13.5px; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.upload-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr); gap: 20px; align-items: start; }
.upload-dropzone { display: grid; min-height: 210px; place-items: center; align-content: center; gap: 5px; padding: 26px; border: 2px dashed #bdcad9; border-radius: 13px; color: var(--slate); background: #f9fbfd; text-align: center; cursor: pointer; transition: border-color .12s, background .12s, opacity .12s; }
.upload-dropzone:hover, .upload-dropzone.is-dragging { border-color: var(--blue); background: var(--blue-soft); }
.upload-dropzone.is-disabled { opacity: .55; pointer-events: none; }
.upload-dropzone strong { color: var(--ink); font-size: 16px; }
.upload-dropzone > span:not(.upload-icon) { font-size: 12.5px; }
.upload-icon { display: grid; width: 44px; height: 44px; margin-bottom: 6px; place-items: center; border-radius: 13px; color: var(--blue-dark); background: var(--blue-soft); font-size: 26px; font-weight: 500; }
.upload-filename { min-height: 20px; margin-top: 5px; color: var(--blue-dark); font-weight: 680; }
#upform > .btn { margin-top: 14px; }
.upload-status { display: flex; gap: 11px; align-items: flex-start; margin-top: 14px; padding: 13px; border: 1px solid #cfe0ff; border-radius: 10px; color: var(--blue-dark); background: var(--blue-soft); }
.upload-status[hidden] { display: none; }
.upload-status small { display: block; margin-top: 2px; color: var(--slate); }
.spinner { display: inline-block; width: 17px; height: 17px; flex: none; margin-top: 2px; border: 2px solid #b9d2f2; border-top-color: var(--blue); border-radius: 50%; animation: portal-spin .7s linear infinite; }
@keyframes portal-spin { to { transform: rotate(360deg); } }
.import-list { margin-top: 18px; border-top: 1px solid var(--line); }
.import-item { display: grid; grid-template-columns: .75fr 1.5fr .55fr .55fr; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line-soft); }
.import-item > div { min-width: 0; }
.import-item strong, .import-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-item strong { font-size: 12.5px; }
.import-item span { margin-top: 2px; color: var(--muted); font-size: 10.5px; }

/* Upload SOP panel — persistent weekly instructions above the dropzone. */
  display: inline-block;
  max-width: 100%;
  padding: 2px 7px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: #1f3557;
  background: #f4f7fb;
  font: 650 12.5px/1.55 ui-monospace, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

/* Churn Insights directory */
.analysis-directory { margin: 0 0 18px; border: 1px solid var(--line); border-radius: 11px; background: #fff; box-shadow: var(--shadow); }
.analysis-directory > summary { padding: 12px 15px; color: var(--slate); font-size: 13px; font-weight: 700; cursor: pointer; }
.analysis-directory[open] > summary { border-bottom: 1px solid var(--line); }
.analysis-directory .hub { margin: 0; padding: 14px; }

/* Sales shell shared treatments override page-local legacy rules. */
.sales-disclaimer { display: flex; gap: 13px; align-items: flex-start; margin: 0 0 14px; padding: 15px 17px; border: 1px solid #efd59a; border-left: 5px solid #d48a18; border-radius: 12px; color: #6f4b0d; background: #fff9e9; }
.sales-disclaimer-mark { display: grid; width: 25px; height: 25px; flex: none; place-items: center; border-radius: 50%; color: #fff; background: #d48a18; font-weight: 800; }
.sales-disclaimer p { margin: 2px 0 0; font-size: 13px; }
.sales-local-nav { display: flex; gap: 15px; align-items: center; justify-content: space-between; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.sales-local-links { display: flex; gap: 4px; }
.sales-local-links a { padding: 10px 12px; border-bottom: 2px solid transparent; color: var(--muted); font-size: 13.5px; font-weight: 650; text-decoration: none; }
.sales-local-links a.active { color: var(--blue-dark); border-color: var(--blue); }
.sales-coverage { color: var(--muted); font-size: 12px; }
.cust-name { text-decoration: none; }

/* Keep legacy sticky offsets compatible with the side navigation. */
.ar-table thead th { top: 0 !important; }
.jumpnav { top: 10px !important; }

/* --- Tooltips -----------------------------------------------------------
   A hover tooltip that also works on a touch screen and on a keyboard, which
   is the whole reason `title=` was not good enough: it never appears on a
   phone, and Ginger and Irving read this portal on one. Three ways in:
   hover the host, focus the thing being explained, or tap the small "?".
   The bubble is faded with `opacity` and NOT `display:none`/`visibility`, so
   it stays in the accessibility tree and `aria-describedby` still announces
   it, and so `portal.js` can measure it before it is shown in order to clamp
   it inside the viewport. `pointer-events:none` keeps the invisible bubble
   from eating clicks meant for whatever is underneath it. */
.tip-host { position: relative; display: inline-flex; align-items: center; gap: 5px; vertical-align: middle; }
.tip-trigger {
  position: relative;
  display: inline-grid;
  width: 17px;
  height: 17px;
  flex: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  cursor: help;
  font: inherit;
  font-size: 11px;
  font-weight: var(--fw-bold);
  line-height: 1;
  letter-spacing: normal;
  place-items: center;
  text-transform: none;
}
/* A 17px circle is a 17px target. This grows the TAPPABLE area to ~33px for a
   thumb without growing the drawn dot, which is the whole point of the
   component: a tooltip nobody can hit on a phone is not a tooltip. */
.tip-trigger::after { content: ''; position: absolute; inset: -8px; border-radius: 50%; }
.tip-trigger:hover,
.tip-trigger:focus-visible { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-dark); }
.tip-bubble {
  position: absolute;
  z-index: 95;
  top: calc(100% + 8px);
  left: 0;
  width: max-content;
  max-width: min(268px, calc(100vw - 32px));
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  box-shadow: var(--shadow-md);
  color: #e9effa;
  font-size: var(--fs-helper);
  font-weight: var(--fw-medium);
  letter-spacing: normal;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  text-transform: none;
  transition: opacity .12s ease;
  white-space: normal;
}
/* Flip above when there is no room below. Never sits ON TOP of its host. */
.tip-host.tip-above > .tip-bubble { top: auto; bottom: calc(100% + 8px); }
.tip-host:hover > .tip-bubble,
.tip-host:focus-within > .tip-bubble,
.tip-host.tip-open > .tip-bubble { opacity: 1; }
/* Escape wins over hover and focus until the pointer or focus leaves. */
.tip-host.tip-dismissed > .tip-bubble { opacity: 0; }

/* Sidebar: dark ground, and the bubble must stay INSIDE the rail because
   `.portal-sidebar` scrolls and would otherwise clip it. */
.primary-nav .tip-host { display: flex; width: 100%; gap: 0; }
.primary-nav .tip-host > .portal-nav-link { flex: 1 1 auto; min-width: 0; padding-right: 32px; }
.primary-nav .tip-trigger {
  position: absolute;
  top: 50%;
  right: 9px;
  border-color: rgba(255, 255, 255, .22);
  background: rgba(255, 255, 255, .09);
  color: #c6d4e4;
  transform: translateY(-50%);
}
.primary-nav .tip-trigger:hover,
.primary-nav .tip-trigger:focus-visible { border-color: rgba(255, 255, 255, .45); background: rgba(255, 255, 255, .2); color: #fff; }
.primary-nav .tip-bubble {
  left: 0;
  width: auto;
  max-width: 100%;
  border: 1px solid rgba(255, 255, 255, .14);
  background: #0a1830;
}

@media (max-width: 760px) {
  .tip-bubble { max-width: calc(100vw - 28px); }
  .tip-trigger { width: 20px; height: 20px; font-size: 12px; }
  /* `.page-actions .btn { flex: 1 1 auto }` stretches buttons across a phone.
     Wrapping one in a host made the HOST the flex item, so the button stopped
     stretching and the row went ragged. Hand the rule down. */
  .page-actions > .tip-host { flex: 1 1 auto; }
  .page-actions > .tip-host > .btn { flex: 1 1 auto; }
}

:focus-visible { outline: 3px solid rgba(37, 99, 235, .42); outline-offset: 2px; }
.btn:focus-visible, .portal-nav-link:focus-visible, .icon-button:focus-visible { outline: 3px solid rgba(93, 154, 255, .55); outline-offset: 2px; box-shadow: none; }

@media (max-width: 1120px) {
  .portal-main { padding-right: 26px; padding-left: 26px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dataset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .upload-layout { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  :root { --nav-h: var(--mobile-bar-height); }
  html, body { max-width: 100%; overflow-x: clip; }
  .portal-shell { width: 100vw; max-width: 100vw; overflow-x: hidden; }
  .portal-sidebar { width: min(86vw, 286px); transform: translateX(-105%); transition: transform .2s ease; }
  .nav-open .portal-sidebar { transform: translateX(0); }
  .icon-button.sidebar-close { display: inline-grid; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 80; display: block; border: 0; background: rgba(8, 20, 37, .52); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .nav-open { overflow: hidden; }
  .portal-frame { width: 100vw; max-width: 100vw; margin-left: 0; overflow-x: hidden; }
  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 70;
    display: grid;
    height: var(--mobile-bar-height);
    grid-template-columns: 42px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 0 16px;
    color: #fff;
    background: rgba(16, 35, 63, .97);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    box-shadow: 0 3px 12px rgba(16, 35, 63, .18);
    backdrop-filter: blur(10px);
  }
  .mobile-brand { justify-self: start; gap: 9px; font-size: 14px; }
  .mobile-brand .brand-mark { width: 28px; height: 28px; border-radius: 8px; }
  .mobile-role { padding: 4px 8px; border-radius: 999px; color: #c6d4e4; background: rgba(255, 255, 255, .08); font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
  .portal-main { width: 100vw; max-width: 100vw; padding: 24px 20px 56px; }
  .portal-main > * { min-width: 0; max-width: 100%; }
  .jumpnav { top: calc(var(--mobile-bar-height) + 6px) !important; }
}

@media (max-width: 760px) {
  :root { --fs-page-title: 28px; --fs-section-title: 20px; }
  .portal-main { padding-right: 15px; padding-left: 15px; }
  .card { padding: 19px; }
  .page-head-row, .split-heading { align-items: flex-start; flex-direction: column; gap: 12px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .two-col, .three-col, .form-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
  .table-wrapper { max-width: 100%; }
  .import-item { grid-template-columns: 1fr 1.5fr; }
  .sales-local-nav { align-items: flex-start; flex-direction: column; gap: 4px; }
  .sales-local-links { width: 100%; overflow-x: auto; }
  .sales-coverage { padding: 0 12px 8px; }
}

@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 9px; }
  .kpi { padding: 14px; }
  .kpi .n { font-size: 25px; }
  .auth-main { padding: 16px; }
  .auth-card { padding: 25px 21px; }
  .mobile-bar { padding: 0 12px; }
  .dataset-grid { grid-template-columns: 1fr; gap: 13px; }
  .import-item { grid-template-columns: 1fr; }
  .review-card { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
