/* ==========================================================
   BIOFM-SFA — Soft Modern admin dashboard
   All colours, fonts, radii and shadows are CSS variables.
   ========================================================== */
:root {
  /* Brand */
  --primary: #1F5BE0;
  --primary-hover: #1748B8;
  --primary-tint: #EEF4FF;
  --primary-text: #1F5BE0;
  --on-primary: #FFFFFF;
  --brand-red: #E5383B;
  --brand-red-text: #C92D30; /* darker red for small text (AA) */
  --danger: #C81E4B;
  --danger-tint: #FDECF1;
  --danger-text: #C81E4B;
  --success: #12A150;
  --success-tint: #E6F6EC;
  --success-text: #0B7A3B;
  --warning: #D98A0B;
  --warning-tint: #FFF4DD;
  --warning-text: #8A5300;

  /* Neutrals */
  --bg: #F6F8FC;
  --surface: #FFFFFF;
  --surface-2: #F1F4FA;
  --border: #E3E8F0;
  --text: #0F172A;
  --muted: #5B6B82;

  /* Glass */
  --glass-bg: rgba(255, 255, 255, .72);
  --glass-border: rgba(227, 232, 240, .85);
  --blur: blur(16px);
  --scrim: rgba(15, 23, 42, .45);

  /* Type */
  --font-head: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Shadows (soft, layered) */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .03);
  --shadow-md: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .05), 0 12px 28px rgba(15, 23, 42, .04);
  --shadow-lg: 0 2px 4px rgba(15, 23, 42, .05), 0 12px 24px rgba(15, 23, 42, .08), 0 32px 64px rgba(15, 23, 42, .10);
  --ring: 0 0 0 3px rgba(31, 91, 224, .35);

  /* Layout */
  --sidebar-w: 260px;
  --rail-w: 76px;
  --topbar-h: 68px;
  --ease: 180ms ease;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;
}

[data-theme="dark"] {
  --primary-tint: #14264D;
  --primary-text: #8CB0FF;
  --brand-red-text: #FF7A7D;
  --danger: #E0426B;
  --danger-tint: rgba(224, 66, 107, .16);
  --danger-text: #FF8AA8;
  --success-tint: rgba(18, 161, 80, .16);
  --success-text: #4ADE80;
  --warning-tint: rgba(217, 138, 11, .18);
  --warning-text: #F5B94A;
  --bg: #0B1220;
  --surface: #111A2E;
  --surface-2: #17223A;
  --border: #223049;
  --text: #E8EEF9;
  --muted: #9AABC4;
  --glass-bg: rgba(17, 26, 46, .72);
  --glass-border: rgba(34, 48, 73, .9);
  --scrim: rgba(2, 6, 14, .65);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 2px 4px rgba(0, 0, 0, .4), 0 24px 56px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--ease), color var(--ease);
}
h1, h2, h3, h4 { font-family: var(--font-head); margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--primary-text); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
table { border-collapse: collapse; width: 100%; }
.num, .kpi-value, td.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -48px; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: var(--radius-sm); z-index: 5000; }
.skip-link:focus { top: 12px; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }
.icon { width: 20px; height: 20px; flex: none; }
.icon.sm { width: 16px; height: 16px; }

/* ---------- Shell ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1300;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transition: width var(--ease), transform var(--ease);
}
.sidebar-head { height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between; padding: 0 var(--s4) 0 var(--s5); border-bottom: 1px solid var(--border); }
#nav { flex: 1; overflow-y: auto; padding: var(--s4) var(--s3); }
.nav-group { margin-bottom: var(--s4); }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 var(--s3); margin-bottom: var(--s2); }
.nav-item {
  position: relative; display: flex; align-items: center; gap: var(--s3);
  padding: 9px var(--s3); border-radius: var(--radius-md); color: var(--muted);
  font-weight: 500; transition: background var(--ease), color var(--ease); white-space: nowrap;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--primary-tint); color: var(--primary-text); font-weight: 600; }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px;
  background: var(--brand-red); border-radius: 0 4px 4px 0;
}
.nav-item .count { margin-left: auto; font-size: 11px; background: var(--danger); color: #fff; border-radius: var(--radius-pill); padding: 1px 7px; font-weight: 600; }
.user-card { border-top: 1px solid var(--border); padding: var(--s3) var(--s4); display: flex; align-items: center; gap: var(--s3); }
.user-card .meta { min-width: 0; }
.user-card .name { font-weight: 600; font-size: 13px; }
.user-card .role { font-size: 12px; color: var(--muted); }

.shell { margin-left: var(--sidebar-w); min-height: 100vh; transition: margin var(--ease); }
body.sidebar-collapsed .sidebar { width: var(--rail-w); }
body.sidebar-collapsed .shell { margin-left: var(--rail-w); }
body.sidebar-collapsed .nav-label, body.sidebar-collapsed .nav-item .label, body.sidebar-collapsed .nav-item .count,
body.sidebar-collapsed .user-card .meta, body.sidebar-collapsed .logo-full { display: none; }
body.sidebar-collapsed .logo-mark { display: block; }
body.sidebar-collapsed .nav-item { justify-content: center; }
body.sidebar-collapsed .nav-item[aria-current="page"]::before { left: -12px; }
body.sidebar-collapsed .sidebar-head { padding: 0 var(--s2); flex-direction: column; justify-content: center; gap: 2px; }
body.sidebar-collapsed .user-card { justify-content: center; padding: var(--s3); }
body.sidebar-collapsed #collapseBtn .icon { transform: rotate(180deg); }

/* Logo */
.logo { display: flex; align-items: center; line-height: 0; }
.logo img { width: auto; }
.logo-full { height: 28px; }
.logo-mark { display: none; height: 30px; }
.pill { font-size: 10px; font-weight: 700; letter-spacing: .06em; background: var(--primary); color: #fff; border-radius: var(--radius-pill); padding: 1px 8px; }

/* Top bar (glass) */
.topbar {
  position: sticky; top: 0; z-index: 1200; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s4); padding: 0 var(--s8);
  background: var(--glass-bg); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--glass-border);
}
.topbar .titles { min-width: 0; }
.topbar h1 { font-size: 18px; line-height: 1.2; white-space: nowrap; }
.crumbs { font-size: 12px; color: var(--muted); }
.crumbs span + span::before { content: "/"; margin: 0 6px; opacity: .6; }
.topbar .spacer { flex: 1; }
.search { position: relative; width: 280px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.search input { padding-left: 38px; }
.menu-btn { display: none; }
.has-menu { position: relative; }
.badge-dot { position: absolute; top: 7px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand-red); border: 2px solid var(--surface); }

main#view { padding: var(--s8); max-width: 1600px; margin: 0 auto; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); flex-wrap: wrap; }
.page-head h2 { font-size: 22px; }
.page-head p { color: var(--muted); margin-top: 2px; }
.page-head .actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ---------- Cards & grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); transition: background var(--ease), border-color var(--ease); }
.card-pad { padding: var(--s6); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s5) var(--s6) 0; }
.card-head h3 { font-size: 15px; }
.card-body { padding: var(--s5) var(--s6) var(--s6); }
.grid { display: grid; gap: var(--s5); }
.g-4 { grid-template-columns: repeat(4, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.g-main { grid-template-columns: 2fr 1fr; }
.stack { display: flex; flex-direction: column; gap: var(--s5); }
.row { display: flex; align-items: center; gap: var(--s3); }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

/* KPI */
.kpi { padding: var(--s5) var(--s6); }
.kpi-label { color: var(--muted); font-weight: 500; font-size: 13px; }
.kpi-value { font-family: var(--font-head); font-weight: 800; font-size: 30px; margin: 6px 0 2px; letter-spacing: -.02em; }
.kpi-foot { display: flex; align-items: end; justify-content: space-between; gap: var(--s3); }
.trend { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 12.5px; }
.trend .icon { width: 14px; height: 14px; }
.trend.good { color: var(--success-text); } .trend.bad { color: var(--danger-text); }
.spark { width: 96px; height: 34px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 38px; padding: 0 var(--s4); border-radius: var(--radius-md); border: 1px solid transparent;
  font-weight: 600; font-size: 13.5px; white-space: nowrap; position: relative;
  transition: background var(--ease), border-color var(--ease), color var(--ease), box-shadow var(--ease), transform var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 1px 2px rgba(31, 91, 224, .35); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.92); }
.btn.sm { height: 32px; padding: 0 var(--s3); font-size: 12.5px; }
.btn.icon-btn { width: 38px; padding: 0; background: transparent; color: var(--muted); }
.btn.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.btn.icon-btn.sm { width: 32px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn.secondary.is-loading::after, .btn.ghost.is-loading::after { border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=tel], input[type=password], input[type=email], input[type=number], input[type=search], input[type=time], input[type=date], select, textarea {
  width: 100%; height: 40px; padding: 0 var(--s3); border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); font: inherit; transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}
textarea { height: auto; padding: var(--s3); resize: vertical; min-height: 96px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .85; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235B6B82' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
.input-group { position: relative; display: flex; gap: var(--s2); }
.input-group .eye { position: absolute; right: 4px; top: 4px; }
.input-group input { padding-right: 40px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
input[type=range] { width: 100%; accent-color: var(--primary); height: 24px; padding: 0; border: 0; box-shadow: none; }
.range-row { display: flex; align-items: center; gap: var(--s3); }
.range-row output { min-width: 48px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.checkbox { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; background: #B6C0D0; border-radius: var(--radius-pill); transition: background var(--ease); }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; box-shadow: var(--shadow-sm); transition: transform var(--ease); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s3) 0; border-bottom: 1px solid var(--border); grid-column: 1 / -1; }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .t { font-weight: 600; } .toggle-row .d { color: var(--muted); font-size: 12.5px; }

/* Drop zone */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius-lg); padding: var(--s8); text-align: center; color: var(--muted); background: var(--surface-2); transition: all var(--ease); cursor: pointer; }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-tint); color: var(--primary-text); }
.dropzone .icon { width: 32px; height: 32px; margin-bottom: var(--s2); }
.dropzone strong { color: var(--text); display: block; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }
.b-success { background: var(--success-tint); color: var(--success-text); }
.b-danger { background: var(--danger-tint); color: var(--danger-text); }
.b-warning { background: var(--warning-tint); color: var(--warning-text); }
.b-primary { background: var(--primary-tint); color: var(--primary-text); }
.b-muted { background: var(--surface-2); color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: var(--radius-pill); background: var(--primary-tint); color: var(--primary-text); font-size: 12px; font-weight: 500; border: 1px solid transparent; }
button.chip:hover { border-color: var(--primary); }
.chip.var { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; max-height: 620px; border-radius: var(--radius-lg); }
.table-wrap.flush { max-height: none; }
th, td { text-align: left; padding: 12px var(--s4); white-space: nowrap; }
th { position: sticky; top: 0; z-index: 2; background: var(--surface); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--border); }
td { border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
tbody tr { transition: background var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 180px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.toolbar .search { width: 260px; }
.toolbar select { width: auto; min-width: 140px; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s5); border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pager .pages { display: flex; gap: 4px; }
.pager .pg { min-width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }
.pager .pg[aria-current="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager .pg:disabled { opacity: .5; cursor: not-allowed; }
.person { display: flex; align-items: center; gap: var(--s3); }
.person .sub { font-size: 12px; color: var(--muted); }

/* Avatar */
.avatar { --h: 220; position: relative; width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; overflow: hidden; flex: none; background: hsl(var(--h) 70% 92%); color: hsl(var(--h) 60% 28%); font-weight: 700; font-size: 13px; }
[data-theme="dark"] .avatar { background: hsl(var(--h) 40% 22%); color: hsl(var(--h) 80% 85%); }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.avatar.xl { width: 72px; height: 72px; font-size: 22px; }

/* Row menu */
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 6px; display: none; text-align: left; white-space: nowrap; }
.menu.open { display: block; }
.menu .mi { display: flex; align-items: center; gap: var(--s2); width: 100%; padding: 8px var(--s3); border: 0; background: none; border-radius: var(--radius-sm); text-align: left; }
.menu .mi:hover { background: var(--surface-2); }
.menu .mi.danger { color: var(--danger-text); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.menu .menu-head { padding: 8px var(--s3); font-weight: 600; }
.notif { display: flex; gap: var(--s3); padding: 10px var(--s3); border-radius: var(--radius-sm); }
.notif:hover { background: var(--surface-2); }
.notif .t { font-size: 13px; } .notif .d { font-size: 12px; color: var(--muted); }
td .has-menu .menu { top: 100%; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--border); margin-bottom: var(--s6); overflow-x: auto; }
.tab { border: 0; background: none; padding: 10px var(--s4); font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; transition: color var(--ease), border-color var(--ease); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary-text); border-bottom-color: var(--primary); }

/* ---------- Forms (section cards) ---------- */
.form-stack { display: flex; flex-direction: column; gap: var(--s5); }
.form-section { display: grid; grid-template-columns: 1fr 2fr; gap: var(--s8); padding: var(--s6); }
.fs-head h3 { font-size: 15px; }
.fs-head p { color: var(--muted); font-size: 13px; margin-top: 4px; max-width: 34ch; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4) var(--s4); align-content: start; }
.form-grid .full { grid-column: 1 / -1; }
.form-section.stacked { grid-template-columns: 1fr; gap: var(--s4); }
.form-section.flat { border: 0; box-shadow: none; padding: 0; background: transparent; }
.form-section.flat .fs-head p { display: none; }
.form-section.flat .fs-head h3 { font-size: 14px; }
.form-bar { position: sticky; bottom: 0; z-index: 20; display: flex; justify-content: flex-end; gap: var(--s3); padding: var(--s4) var(--s6); margin-top: var(--s5); background: var(--glass-bg); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border: 1px solid var(--glass-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; min-height: 40px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.tag-input:focus-within { border-color: var(--primary); box-shadow: var(--ring); }
.tag-input input { border: 0; box-shadow: none !important; flex: 1; min-width: 120px; height: 28px; padding: 0 6px; background: transparent; }
.tag-input .chip button { background: none; border: 0; padding: 0; line-height: 1; color: inherit; }
.map-picker { height: 220px; border-radius: var(--radius-md); border: 1px solid var(--border); overflow: hidden; isolation: isolate; }
.swatches { display: flex; gap: var(--s2); flex-wrap: wrap; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; display: grid; place-items: center; color: #fff; font-weight: 700; padding: 0; }
.swatch[aria-checked="true"] { border-color: var(--surface); box-shadow: 0 0 0 2px var(--primary); }

/* ---------- Overlays ---------- */
#overlay-root { position: relative; z-index: 2000; }
.scrim, .overlay-scrim { position: fixed; inset: 0; background: var(--scrim); opacity: 0; transition: opacity var(--ease); }
.scrim { display: none; z-index: 1250; }
.overlay-scrim { z-index: 2000; display: flex; align-items: center; justify-content: center; padding: var(--s4); }
.overlay-scrim.show { opacity: 1; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; background: var(--glass-bg); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border: 1px solid var(--glass-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); transform: translateY(8px) scale(.98); transition: transform var(--ease); }
.modal.solid, .slideover.solid { background: var(--surface); }
.overlay-scrim.show .modal { transform: none; }
.o-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); padding: var(--s5) var(--s6) var(--s3); }
.o-head h3 { font-size: 17px; } .o-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.o-body { padding: var(--s3) var(--s6) var(--s5); overflow-y: auto; }
.o-foot { display: flex; justify-content: flex-end; gap: var(--s3); padding: var(--s4) var(--s6); border-top: 1px solid var(--border); }
.overlay-scrim.right { justify-content: flex-end; align-items: stretch; padding: 0; }
.slideover { width: min(520px, 100%); height: 100%; display: flex; flex-direction: column; background: var(--glass-bg); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border-left: 1px solid var(--glass-border); box-shadow: var(--shadow-lg); transform: translateX(24px); transition: transform 200ms ease; }
.overlay-scrim.show .slideover { transform: none; }
.slideover .o-body { flex: 1; }
#toasts { position: fixed; right: var(--s6); bottom: var(--s6); z-index: 3000; display: flex; flex-direction: column; gap: var(--s2); }
.toast { display: flex; align-items: center; gap: var(--s3); min-width: 260px; max-width: 380px; padding: 12px var(--s4); border-radius: var(--radius-md); background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); animation: toast-in 200ms ease; }
.toast .icon { color: #4ADE80; }
.toast.error .icon { color: #FF8AA8; }
.toast.out { opacity: 0; transform: translateY(8px); transition: all 200ms ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Skeleton / empty ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.2s ease infinite; border-radius: var(--radius-md); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.empty { text-align: center; padding: var(--s10) var(--s6); color: var(--muted); }
.empty > .icon { width: 40px; height: 40px; margin-bottom: var(--s3); opacity: .6; }
.empty h4 { color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ---------- Section specifics ---------- */
.chart-box { position: relative; height: 300px; }
.leader { display: flex; flex-direction: column; gap: var(--s4); }
.leader-row { display: flex; align-items: center; gap: var(--s3); }
.leader-row .rank { width: 20px; font-weight: 700; color: var(--muted); text-align: center; }
.bar { height: 6px; background: var(--surface-2); border-radius: var(--radius-pill); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.bar > i.warn { background: var(--warning); } .bar > i.bad { background: var(--danger); } .bar > i.ok { background: var(--success); }
.feed { display: flex; flex-direction: column; max-height: 340px; overflow-y: auto; }
.feed-item { display: flex; gap: var(--s3); padding: 10px 0; border-bottom: 1px solid var(--border); animation: toast-in 240ms ease; }
.feed-item:last-child { border-bottom: 0; }
.feed-dot { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.feed-item .t { font-size: 13px; } .feed-item .d { font-size: 12px; color: var(--muted); }
.flag-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); width: 100%; text-align: left; transition: background var(--ease); }
.flag-row:hover { background: var(--surface-2); }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 10px var(--s4); }
.dl dt { color: var(--muted); font-size: 13px; } .dl dd { margin: 0; font-weight: 500; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.compare > div { padding: var(--s3) var(--s4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.compare .k { font-size: 12px; color: var(--muted); } .compare .v { font-family: var(--font-head); font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.mini-map { height: 220px; border-radius: var(--radius-md); border: 1px solid var(--border); overflow: hidden; isolation: isolate; }
.map-wrap { position: relative; isolation: isolate; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow-md); }
.big-map { height: calc(100vh - 220px); min-height: 520px; }
.map-card { position: absolute; top: 16px; right: 16px; z-index: 1000; width: 260px; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); background: var(--glass-bg); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border: 1px solid var(--glass-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.map-banner { position: absolute; left: 50%; transform: translateX(-50%); top: 16px; z-index: 1000; display: none; align-items: center; gap: var(--s3); padding: 8px 12px 8px 16px; border-radius: var(--radius-pill); background: var(--glass-bg); backdrop-filter: var(--blur); border: 1px solid var(--glass-border); box-shadow: var(--shadow-lg); }
.map-banner.show { display: flex; }
.legend { display: flex; gap: var(--s4); font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.seg { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.rep-card { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.rep-card .stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.rep-card .stats > div { background: var(--surface-2); border-radius: var(--radius-md); padding: 10px 12px; }
.rep-card .stats .v { font-family: var(--font-head); font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.rep-card .stats .k { font-size: 12px; color: var(--muted); }
.terr-layout { display: grid; grid-template-columns: 1fr 340px; gap: var(--s5); }
.terr-item { display: flex; align-items: center; gap: var(--s3); padding: var(--s3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); width: 100%; text-align: left; transition: all var(--ease); }
.terr-item:hover { background: var(--surface-2); border-color: var(--primary); }
.terr-item .sw { width: 14px; height: 40px; border-radius: 4px; flex: none; }
.sched { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s3); }
.kv { display: flex; align-items: center; gap: var(--s2); color: var(--muted); font-size: 13px; }
.kv strong { color: var(--text); font-weight: 600; }
.export-card { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s3); align-items: flex-start; }
.ico-tile { width: 44px; height: 44px; border-radius: var(--radius-md); display: grid; place-items: center; background: var(--primary-tint); color: var(--primary-text); }
.ai-layout { display: grid; grid-template-columns: 280px 1fr; gap: var(--s5); }
.prompt-item { display: block; width: 100%; text-align: left; padding: 12px var(--s4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); transition: all var(--ease); }
.prompt-item:hover { background: var(--surface-2); }
.prompt-item[aria-current="true"] { border-color: var(--primary); background: var(--primary-tint); }
.prompt-item .t { font-weight: 600; } .prompt-item .d { color: var(--muted); font-size: 12.5px; }
.is-disabled { opacity: .5; pointer-events: none; filter: grayscale(.4); }
.chat { display: flex; flex-direction: column; height: 620px; }
.chat-log { flex: 1; overflow-y: auto; padding: var(--s6); display: flex; flex-direction: column; gap: var(--s4); }
.msg { max-width: 78%; padding: 10px 14px; border-radius: var(--radius-lg); line-height: 1.55; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.ai.wide { max-width: 90%; }
.chat-foot { border-top: 1px solid var(--border); padding: var(--s4) var(--s5); display: flex; flex-direction: column; gap: var(--s3); }
.chat-foot form { display: flex; gap: var(--s2); }
.draft { margin-top: var(--s3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.draft .dh { padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 13px; }
.draft .db { padding: 14px; white-space: pre-line; outline: none; }
.draft .db[contenteditable="true"] { box-shadow: inset 0 0 0 2px var(--primary); }
.draft .df { padding: 10px 14px; display: flex; gap: var(--s2); border-top: 1px solid var(--border); flex-wrap: wrap; }
.typing i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); margin: 0 2px; animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.persona-preview { padding: var(--s6); display: flex; gap: var(--s4); align-items: flex-start; background: linear-gradient(135deg, var(--primary-tint), var(--surface)); }
.bubble { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); border-top-left-radius: 4px; padding: var(--s4); box-shadow: var(--shadow-sm); }
.usage { display: flex; flex-direction: column; gap: var(--s3); }
.usage .big { font-family: var(--font-head); font-weight: 800; font-size: 28px; font-variant-numeric: tabular-nums; }
.result-box { border: 1px dashed var(--border); border-radius: var(--radius-md); padding: var(--s4); background: var(--surface-2); white-space: pre-line; }
.status-inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.matrix td, .matrix th { text-align: center; } .matrix td:first-child, .matrix th:first-child { text-align: left; }
.matrix .grp td { background: var(--surface-2); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.preview-table { font-size: 13px; }

/* Dark-mode map tiles */
[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88); }
[data-theme="dark"] .leaflet-container { background: #1b2433; }

/* ---------- Responsive ---------- */
@media (max-width: 1360px) {
  .g-4 { grid-template-columns: repeat(2, 1fr); }
  .search { width: 220px; }
}
@media (max-width: 1100px) {
  .g-main, .terr-layout, .ai-layout { grid-template-columns: 1fr; }
  .g-3 { grid-template-columns: repeat(2, 1fr); }
  .form-section { grid-template-columns: 1fr; gap: var(--s4); }
  .fs-head p { max-width: none; }
}
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; box-shadow: var(--shadow-lg); }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .scrim { display: block; opacity: 1; }
  .shell, body.sidebar-collapsed .shell { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  #collapseBtn { display: none; }
  body.sidebar-collapsed .nav-label, body.sidebar-collapsed .nav-item .label, body.sidebar-collapsed .user-card .meta, body.sidebar-collapsed .logo-full { display: revert; }
  body.sidebar-collapsed .logo-mark { display: none; }
  body.sidebar-collapsed .nav-item { justify-content: flex-start; }
  .topbar { padding: 0 var(--s4); }
  main#view { padding: var(--s5) var(--s4); }
}
@media (max-width: 760px) {
  .g-4, .g-3, .g-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .search.top { display: none; }
  .range-select { display: none; }
  .crumbs { display: none; }
  .toolbar .search { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ==========================================================
   Login (split screen) — same tokens as the dashboard
   ========================================================== */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-brand {
  position: relative; overflow: hidden; color: #fff; padding: var(--s10);
  display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(120% 90% at 0% 0%, #3D74F2 0%, var(--primary) 45%, #1748B8 100%);
}
.auth-brand::before, .auth-brand::after {
  content: ""; position: absolute; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .14);
}
.auth-brand::before { width: 520px; height: 520px; right: -180px; bottom: -160px; }
.auth-brand::after { width: 340px; height: 340px; right: -60px; bottom: -40px; background: rgba(255, 255, 255, .04); }
.auth-brand .cross { position: absolute; color: rgba(255, 255, 255, .10); font: 800 120px/1 var(--font-head); }
.auth-brand .logo { align-self: flex-start; position: relative; z-index: 1; background: #fff; padding: 12px 18px; border-radius: 16px; box-shadow: 0 10px 30px rgba(10, 30, 90, .25); }
.auth-brand .logo-full { height: 52px; }
.auth-brand h2 { font-size: 34px; line-height: 1.2; max-width: 16ch; position: relative; z-index: 1; }
.auth-brand p.lead { color: rgba(255, 255, 255, .8); max-width: 42ch; margin-top: var(--s3); position: relative; z-index: 1; }
.auth-points { display: flex; flex-direction: column; gap: var(--s3); margin-top: var(--s8); position: relative; z-index: 1; }
.auth-points div { display: flex; align-items: center; gap: var(--s3); color: rgba(255, 255, 255, .92); }
.auth-points .ico { width: 34px; height: 34px; border-radius: var(--radius-md); background: rgba(255, 255, 255, .14); display: grid; place-items: center; }
.auth-brand footer { position: relative; z-index: 1; font-size: 12.5px; color: rgba(255, 255, 255, .7); }
.auth-main { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: var(--s8) var(--s4); background: var(--bg); }
.auth-card { width: min(420px, 100%); padding: var(--s8); }
.auth-card h1 { font-size: 24px; }
.auth-card .sub { color: var(--muted); margin: 6px 0 var(--s6); }
.auth-card form { display: flex; flex-direction: column; gap: var(--s4); }
.auth-card .btn.primary { height: 44px; width: 100%; margin-top: var(--s2); }
.auth-mobile-logo { display: none; margin-bottom: var(--s6); }
.auth-mobile-logo .logo-full { height: 52px; }
.field-error { font-size: 12.5px; color: var(--danger-text); font-weight: 500; }
.alert { display: flex; gap: var(--s2); align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500; }
.alert.danger { background: var(--danger-tint); color: var(--danger-text); }
.alert.success { background: var(--success-tint); color: var(--success-text); }
.alert.warning { background: var(--warning-tint); color: var(--warning-text); }
.bell-count { position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 16px; text-align: center; }
.has-menu > .btn { position: relative; }
.auth-links { margin-top: var(--s6); display: flex; gap: var(--s4); justify-content: center; font-size: 12.5px; }
.auth-links a { color: var(--muted); }
.auth-links a:hover { color: var(--primary-text); }
.auth-theme { position: absolute; top: var(--s4); right: var(--s4); }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-mobile-logo { display: flex; }
}

/* Coming-soon placeholder pages */
.soon { padding: var(--s10) var(--s6); text-align: center; }
.soon .ico-tile { width: 56px; height: 56px; margin: 0 auto var(--s4); }
.soon .ico-tile .icon { width: 26px; height: 26px; }
.soon h3 { font-size: 18px; margin-bottom: 6px; }
.soon p { color: var(--muted); max-width: 48ch; margin: 0 auto; }

/* Search boxes: the generic input padding rule above outranks `.search input`, hiding the icon behind the text */
.search input[type=search] { padding-left: 38px; }

/* Toggleable chips (multi-select, e.g. products of interest) */
.chip-toggles { display: flex; flex-wrap: wrap; gap: var(--s2); }
.area-filter { width: 100%; margin-bottom: var(--s3); }
.area-chips { max-height: 240px; overflow-y: auto; padding: 2px; }
.chip-toggle { position: relative; display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-weight: 500; font-size: 13px; cursor: pointer; transition: all var(--ease); }
.chip-toggle:hover { border-color: var(--primary); color: var(--text); }
.chip-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip-toggle:has(input:checked) { background: var(--primary-tint); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.chip-toggle:has(input:focus-visible) { box-shadow: var(--ring); }

/* Territories: list item holds a focus button plus a row menu (no nested buttons) */
.terr-item { padding: 0 var(--s2) 0 0; }
.terr-item .terr-main { display: flex; align-items: center; gap: var(--s3); flex: 1; min-width: 0; padding: var(--s3); background: none; border: 0; text-align: left; color: inherit; font: inherit; cursor: pointer; border-radius: var(--radius-md); }
.swatch.sm { width: 32px; height: 32px; }
.map-banner .badge { white-space: nowrap; }

/* Import: the file input covers the whole dropzone so click and drag-and-drop both work natively */
.dropzone { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dropzone input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone:has(input:focus-visible) { box-shadow: var(--ring); }
.preview-table { border: 1px solid var(--border); border-radius: var(--radius-md); }
.preview-table th { vertical-align: top; }
.preview-table th .muted { display: block; font-weight: 500; margin-bottom: 6px; text-transform: none; letter-spacing: 0; }
.map-select { height: 34px; min-width: 150px; font-size: 13px; }
.map-select.skip { color: var(--muted); border-style: dashed; }
.import-errors { margin: 8px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.toolbar input[type=date] { width: auto; min-width: 150px; }
.map-banner { width: max-content; max-width: calc(100% - 32px); white-space: nowrap; }
.map-banner > span:first-child { overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; font-weight: 500; }

/* Place search (map picker + territories map) */
.place-search { position: relative; margin-bottom: var(--s2); }
.place-search > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; pointer-events: none; z-index: 1; }
.place-search input[type=search] { width: 100%; padding-left: 38px; }
.place-search.on-map { position: absolute; top: 12px; right: 12px; width: min(340px, calc(100% - 80px)); z-index: 1000; margin: 0; }
.place-search.on-map input[type=search] { box-shadow: var(--shadow-lg); background: var(--surface); }
.place-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 1100; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); max-height: 300px; overflow-y: auto; padding: 4px; }
.pr-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: var(--radius-sm, 6px); color: var(--text); cursor: pointer; font: inherit; }
.pr-item strong { font-weight: 600; font-size: 13.5px; }
.pr-item span { font-size: 12px; color: var(--muted); }
.pr-item:hover, .pr-item.active { background: var(--primary-tint); }
.pr-empty { padding: 10px 12px; font-size: 13px; color: var(--muted); }

/* Visit Plans */
.t-danger { color: var(--danger-text); font-weight: 700; }
.kpi-of { font-size: 18px; font-weight: 600; }
.week-nav { display: flex; align-items: center; gap: var(--s2); }
.week-label { min-width: 150px; text-align: center; font-variant-numeric: tabular-nums; }
.plan-legend { display: flex; flex-wrap: wrap; gap: var(--s4); margin-bottom: var(--s4); font-size: 12.5px; color: var(--muted); }
.plan-legend span { display: inline-flex; align-items: center; gap: 6px; }
.plan-days { display: flex; flex-direction: column; gap: var(--s3); }
.plan-day { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--s3) var(--s4); background: var(--surface); }
.plan-day.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.pd-head { display: flex; align-items: baseline; gap: var(--s2); margin-bottom: 6px; }
.pd-count { margin-left: auto; font-size: 12.5px; }
.pd-item { display: flex; align-items: center; gap: var(--s2); padding: 5px 0; border-top: 1px dashed var(--border); min-width: 0; }
.pd-item:first-of-type { border-top: 0; }
.pd-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.pd-area { font-size: 12.5px; white-space: nowrap; }
.pd-item.missed .pd-name { color: var(--danger-text); }
.pd-empty { font-size: 13px; padding: 4px 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; background: var(--muted); }
.dot.done, .dot.late { background: var(--success); } .dot.missed { background: var(--danger); } .dot.upcoming { background: var(--primary); } .dot.unplanned { background: var(--warning); }
.pd-week { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: var(--s3) 0 -2px; }
.pd-week:first-child { margin-top: 0; }
