/* ==========================================================================
   SubTrack design system
   Neutral zinc palette, near-black primary (near-white in dark mode), one blue accent
   used only for links, focus rings and selection. 1px borders over shadows.
   Status colours carry meaning: red = expired, orange = 0–7 days, yellow = 8–30 days / pending, green = active.
   ========================================================================== */

:root {
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;

  --bg: #fafafa;              /* canvas: app background, sidebar, top bar */
  --surface: #ffffff;         /* cards, inputs, menus, modals */
  --surface-2: #f4f4f5;       /* hover, table header, subtle fills */
  --surface-3: #e4e4e7;       /* pressed / active nav item / avatar */
  --hover: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;   /* inputs, secondary buttons */
  --text: #18181b;
  --text-2: #52525b;
  --muted: #71717a;
  --faint: #a1a1aa;

  --primary: #18181b;
  --primary-hover: #3f3f46;
  --primary-fg: #fafafa;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, .08);
  --accent-text: #2563eb;
  --on-accent: #ffffff;
  --ring: rgba(37, 99, 235, .15);

  --green: #15803d; --green-soft: rgba(21, 128, 61, .1); --green-text: #15803d;
  --amber: #a16207; --amber-soft: rgba(161, 98, 7, .1); --amber-text: #a16207;
  --orange: #c2410c; --orange-soft: rgba(194, 65, 12, .1); --orange-text: #c2410c;
  --red: #dc2626; --red-soft: rgba(220, 38, 38, .1); --red-text: #dc2626;
  /* Pending reads as "needs attention" (caution), not as a decorative blue */
  --blue: var(--amber); --blue-soft: var(--amber-soft); --blue-text: var(--amber-text);
  --gray-soft: #f4f4f5; --gray-text: #71717a;
  --chart-base: rgba(113, 113, 122, .6);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, .05), 0 4px 6px -4px rgba(0, 0, 0, .05);
  --overlay: rgba(0, 0, 0, .4);

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --sidebar: 224px;
  --topbar: 56px;
  color-scheme: light;
}

/* Dark tokens: the .dark class is set by an inline script in <head> (system / light / dark preference) */
html.dark {
  --bg: #0a0a0c;
  --surface: #141417;
  --surface-2: #1d1d21;
  --surface-3: #28282d;
  --hover: #1d1d21;
  --border: #26262b;
  --border-strong: #3a3a41;
  --text: #f4f4f5;
  --text-2: #c3c3cb;
  --muted: #9696a0;
  --faint: #696973;

  --primary: #f4f4f5;
  --primary-hover: #d4d4d8;
  --primary-fg: #141417;

  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-soft: rgba(96, 165, 250, .12);
  --accent-text: #60a5fa;
  --on-accent: #0a0a0c;
  --ring: rgba(96, 165, 250, .2);

  --green: #4ade80; --green-soft: rgba(74, 222, 128, .1); --green-text: #4ade80;
  --amber: #facc15; --amber-soft: rgba(250, 204, 21, .1); --amber-text: #facc15;
  --orange: #fb923c; --orange-soft: rgba(251, 146, 60, .1); --orange-text: #fb923c;
  --red: #f87171; --red-soft: rgba(248, 113, 113, .1); --red-text: #f87171;
  --gray-soft: #1d1d21; --gray-text: #9696a0;
  --chart-base: rgba(150, 150, 160, .6);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, .4), 0 4px 6px -4px rgba(0, 0, 0, .4);
  --overlay: rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11', 'ss01';
  text-rendering: optimizeLegibility;
}
html { background: var(--bg); -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.011em; line-height: 1.25; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.lucide { width: 16px; height: 16px; stroke-width: 1.5; flex-shrink: 0; }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; }
::selection { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.bold { font-weight: 600; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.text-green { color: var(--green-text); }
.text-red { color: var(--red-text); }
.text-amber { color: var(--amber-text); }

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

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar);
  display: flex; flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 0 12px 12px;
  transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.brand { display: flex; align-items: center; gap: 10px; height: var(--topbar); padding: 0 4px; margin-bottom: 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: var(--radius-sm); display: grid; place-items: center; flex-shrink: 0;
  background: var(--primary); color: var(--primary-fg);
}
.brand-mark svg { width: 16px; height: 16px; stroke-width: 2; }
.brand-name { font-weight: 600; font-size: 14px; letter-spacing: -.011em; }
.brand-sub { font-size: 12px; color: var(--muted); max-width: 150px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 24px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  height: 32px; padding: 0 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; font-weight: 500; text-decoration: none;
  transition: background .12s, color .12s;
}
.nav a svg { color: currentColor; opacity: .8; width: 16px; height: 16px; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: color-mix(in srgb, var(--surface-3) 70%, transparent); color: var(--text); }
.nav .count {
  margin-left: auto; font-size: 11px; font-weight: 500; padding: 0 6px; border-radius: 4px; font-variant-numeric: tabular-nums;
  background: var(--red-soft); color: var(--red-text);
}
.foot-icons { display: flex; justify-content: space-around; gap: 4px; }
.foot-icons .btn.active { background: var(--surface-3); color: var(--text); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); background: var(--c); cursor: pointer; box-shadow: 0 0 0 1px var(--border); }
.swatch.on { box-shadow: 0 0 0 2px var(--text); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.theme-switch { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.theme-switch button {
  border: 0; background: transparent; padding: 6px; border-radius: 5px; cursor: pointer; color: var(--muted);
  display: grid; place-items: center;
}
.theme-switch button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar);
  display: flex; align-items: center; gap: 12px;
  padding: 0 32px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 15px; font-weight: 600; }
/* Phones only: the logo sits in the top bar (the sidebar is hidden there) */
.topbar-brand { display: none; align-items: center; gap: 8px; color: var(--text); text-decoration: none !important; }
.search-trigger {
  display: flex; align-items: center; gap: 8px;
  width: 100%; max-width: 448px; height: 32px; padding: 0 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--faint); cursor: pointer;
  transition: border-color .15s;
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger kbd { margin-left: auto; }
kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px;
  font-family: var(--font); font-size: 11px; font-weight: 500;
  padding: 0 4px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted);
}
.btn.menu-btn { display: none; }
.view { padding: 8px 32px 48px; max-width: 1280px; width: 100%; margin: 0 auto; }
.view-enter { animation: fadeUp .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes fadeUp { from { opacity: 0; } to { opacity: 1; } }

/* Every page: title + one-line subtitle on the left, all actions grouped on the right, centred on the block */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 24px 0; }
.page-title { min-width: 0; }
.page-title p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.page-actions .segmented { flex-wrap: nowrap; }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-top: 24px; font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none !important; }
.back-link:hover { color: var(--text); }
.back-link svg { width: 14px; height: 14px; }
.profile-card { padding: 20px; margin: 12px 0 24px; }
.profile-name { font-size: 22px; font-weight: 600; letter-spacing: -.011em; }

/* Underline tabs with counts */
.tabbar { display: flex; margin-bottom: 16px; box-shadow: inset 0 -1px 0 var(--border); }
.utabs { display: flex; gap: 20px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; min-width: 0; }
.utabs::-webkit-scrollbar { display: none; }
.utabs button {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 4px 0 10px; border: 0; border-bottom: 2px solid transparent; background: none;
  font-size: 13.5px; font-weight: 500; color: var(--muted); cursor: pointer; transition: color .15s;
}
.utabs button:hover { color: var(--text); }
.utabs button.on { border-bottom-color: var(--text); color: var(--text); }
.utabs button svg { width: 14px; height: 14px; }
.utabs .n { padding: 0 6px; border-radius: 4px; background: var(--surface-2); font-size: 11px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.utabs button.on .n { background: var(--surface-3); color: var(--text); }
.page-head h2 { font-size: 22px; font-weight: 600; line-height: 1.2; letter-spacing: -.011em; }
.page-head p { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

.bottom-nav { display: none; }
.scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 12px; gap: 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font-weight: 500; font-size: 13.5px; white-space: nowrap;
  cursor: pointer; text-decoration: none !important;
  box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, color .15s;
  user-select: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 1px var(--bg), 0 0 0 3px color-mix(in srgb, var(--accent) 50%, transparent); }
.btn:disabled, .btn.loading { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn.primary:hover { background: color-mix(in srgb, var(--primary) 85%, transparent); border-color: transparent; }
.btn.danger { color: var(--red-text); background: transparent; border-color: transparent; box-shadow: none; }
.btn.danger:hover { background: var(--red-soft); border-color: transparent; }
.btn.danger-solid { background: var(--red); border-color: var(--red); color: #fff; }
html.dark .btn.danger-solid { color: var(--bg); }
.btn.danger-solid:hover { background: color-mix(in srgb, var(--red) 90%, transparent); }
.btn.success { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: var(--radius-sm); gap: 6px; }
.btn.sm svg { width: 14px; height: 14px; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 32px; }
.btn.wa { color: var(--green-text); }
.btn.loading::after {
  content: ''; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.card-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); min-height: 52px; }
.card-head h3 { font-size: 14px; font-weight: 600; }
.card-head .sub { color: var(--muted); font-size: 13px; }
.card-body { padding: 20px; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--border); }

/* KPI tiles */
/* Key numbers: tiles in one bordered grid with 1px gaps */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-bottom: 24px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.kpis > .kpi { border: 0; border-radius: 0; }
.kpi { padding: 20px; position: relative; min-width: 0; }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.kpi-icon { display: inline-flex; color: var(--muted); }
.kpi-icon svg { width: 16px; height: 16px; }
.kpi-value { font-size: 26px; font-weight: 600; line-height: 1; letter-spacing: -.025em; margin-top: 10px; font-variant-numeric: tabular-nums; }
.kpi-meta { font-size: 12px; color: var(--muted); margin-top: 8px; }
.kpi.link { cursor: pointer; transition: background .15s; }
.kpi.link:hover { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.kpi.tone-red .kpi-icon { color: var(--red-text); }
.kpi.tone-amber .kpi-icon { color: var(--amber-text); }
.kpi.tone-green .kpi-icon { color: var(--green-text); }
.kpi.tone-blue .kpi-icon { color: var(--blue-text); }

/* Status strip */
.status-strip { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin: 4px 0 16px; }
.status-strip span { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 20%, transparent);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge svg { width: 12px; height: 12px; }
.badge.active { background: var(--green-soft); color: var(--green-text); }
.badge.due { background: var(--amber-soft); color: var(--amber-text); }
.badge.critical { background: var(--orange-soft); color: var(--orange-text); }
.badge.expired { background: var(--red-soft); color: var(--red-text); }
.badge.pending { background: var(--blue-soft); color: var(--blue-text); }
.badge.suspended, .badge.cancelled { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }
.badge.paid { background: var(--green-soft); color: var(--green-text); }
.badge.unpaid { background: var(--amber-soft); color: var(--amber-text); }
.badge.sent { background: var(--green-soft); color: var(--green-text); }
.badge.failed { background: var(--red-soft); color: var(--red-text); }
.badge.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border); color: var(--text-2); }

.type-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.type-icon {
  /* Neutral bordered square: icons never sit on coloured blobs */
  width: 32px; height: 32px; border-radius: var(--radius-sm); display: grid; place-items: center; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.type-icon svg { width: 16px; height: 16px; }
.type-icon.sm { width: 24px; height: 24px; }
.type-icon.sm svg { width: 14px; height: 14px; }
.type-icon.lg { width: 40px; height: 40px; border-radius: var(--radius); }
.type-icon.lg svg { width: 20px; height: 20px; }

.days { font-size: 12px; font-weight: 500; }
.days.expired { color: var(--red-text); }
.days.critical { color: var(--orange-text); }
.days.due { color: var(--amber-text); }
.days.active { color: var(--muted); font-weight: 500; }

.progress { height: 4px; border-radius: 99px; background: var(--surface-2); overflow: hidden; width: 100%; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: var(--green); }
.progress.due > span { background: var(--amber); }
.progress.critical > span { background: var(--orange); }
.progress.expired > span { background: var(--red); width: 100% !important; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 600; font-size: 11.5px;
  background: var(--surface-3); color: var(--text-2);
}
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 13px; font-weight: 500; color: var(--text); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err { font-size: 13px; color: var(--red-text); display: none; }
.field.invalid .err { display: block; }
.field.invalid .input, .field.invalid .select, .field.invalid .textarea, .field.invalid .combo-input { border-color: color-mix(in srgb, var(--red) 70%, transparent); }
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px; font-size: 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.55; }
.select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 20 20' fill='none' stroke='%23898990' stroke-width='1.5'%3E%3Cpath d='m6 8 4 4 4-4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.input-group { position: relative; display: flex; align-items: center; }
.input-group > svg, .input-group > .prefix { position: absolute; left: 11px; color: var(--muted); pointer-events: none; }
.input-group > .prefix { font-weight: 500; font-size: 13.5px; }
.input-group .input { padding-left: 34px; }
.input-group .suffix { position: absolute; right: 6px; }
.input.sm, .select.sm { height: 32px; font-size: 13px; border-radius: var(--radius-sm); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-grid .full { grid-column: 1 / -1; }
.form-section { font-size: 14px; font-weight: 600; color: var(--text); margin: 8px 0 -4px; grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
.form-section::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 36px; height: 20px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background .15s; flex-shrink: 0; }
.switch .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); transition: transform .15s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px color-mix(in srgb, var(--accent) 50%, transparent); }
.switch-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.switch-row .t { font-weight: 500; font-size: 13.5px; }
.switch-row .d { font-size: 13px; color: var(--muted); }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; height: 28px; padding: 0 12px; border-radius: 5px;
  font-weight: 500; font-size: 13px; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.segmented button:hover { color: var(--text); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented.block { display: flex; width: 100%; flex-wrap: nowrap; }
.segmented.block button { flex: 1; justify-content: center; }
.segmented .n { font-size: 11px; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.segmented button.on .n { color: var(--text); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; font-weight: 500; color: var(--text-2); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.on { background: var(--surface-3); border-color: var(--border-strong); color: var(--text); }
.chip svg { width: 14px; height: 14px; }

/* Searchable combobox */
.combo { position: relative; }
.combo-input { cursor: text; }
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 70;
  max-height: 260px; overflow: auto; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: none;
}
.combo.open .combo-list { display: block; }
.combo-opt { padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.combo-opt.hl, .combo-opt:hover { background: var(--hover); }
.combo-opt .sub { color: var(--muted); font-size: 12px; }
.combo-empty { padding: 10px; color: var(--muted); font-size: 13px; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .search { flex: 1 1 240px; min-width: 0; }
/* Everything on a toolbar line lines up with the 40px search box */
.toolbar .select.sm, .toolbar .btn.sm { height: 40px; }
.toolbar .chip { height: 40px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .select { width: auto; min-width: 140px; }

.bulkbar {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); z-index: 45;
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: all .2s cubic-bezier(.2, .8, .2, 1);
  margin-left: calc(var(--sidebar) / 2);
}
.bulkbar.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.bulkbar .count { font-weight: 500; margin-right: 6px; font-size: 13.5px; font-variant-numeric: tabular-nums; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
  text-align: left; font-size: 12px; font-weight: 500;
  color: var(--muted); height: 36px; padding: 0 12px; background: color-mix(in srgb, var(--surface-2) 60%, var(--surface));
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th:first-child { border-top-left-radius: var(--radius-lg); }
.table th:last-child { border-top-right-radius: var(--radius-lg); }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 14px; }
.table th:first-child, .table td:first-child { padding-left: 16px; }
.table th:last-child, .table td:last-child { padding-right: 16px; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 50%, var(--surface)); }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.selected { background: var(--accent-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { width: 1%; white-space: nowrap; text-align: right; }
.table .check { width: 36px; padding-right: 0; }
.table .row-actions { display: inline-flex; gap: 2px; opacity: .55; transition: opacity .12s; }
/* The main column takes the spare width and truncates, so the actions column never scrolls out of view */
.table td.grow { width: 45%; max-width: 0; }
.table td.grow .cell-title, .table td.grow .cell-sub { max-width: none; }
.show-md { display: none; }
@media (max-width: 1200px) { .table .hide-md, .row-actions .hide-md { display: none; } .show-md { display: inline; } }
.table tr:hover .row-actions { opacity: 1; }
.cell-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-title { font-weight: 500; color: var(--text); max-width: 320px; }
.cell-sub { font-size: 13px; color: var(--muted); max-width: 320px; }
.checkbox { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; margin: 0; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager .pages { display: flex; gap: 4px; }

/* Mobile list cards */
.mlist { display: none; }
.mcard { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.mcard:last-child { border-bottom: 0; }
.mcard:active { background: var(--hover); }
.mcard.selected { background: var(--accent-soft); }
.mcheck { display: flex; align-items: center; align-self: stretch; padding: 0 8px; margin: -14px 0 -14px -8px; cursor: pointer; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); transition: background .1s; }
.list-item:first-child { border-top: 0; }
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }

/* ---------- Empty / skeleton ---------- */
.empty { text-align: center; padding: 56px 24px; color: var(--muted); font-size: 13px; }
.empty-icon { width: 40px; height: 40px; border-radius: var(--radius); margin: 0 auto 16px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.empty-icon svg { width: 20px; height: 20px; }
.empty h3 { color: var(--text); font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.empty .btn { margin-top: 20px; }
.skel { border-radius: var(--radius-sm); background: var(--surface-2); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- Drawer / modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 80; background: var(--overlay);
  opacity: 0; transition: opacity .2s;
}
.overlay.show { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 81;
  width: min(560px, 100vw); display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow-lg);
  border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}
.drawer.wide { width: min(680px, 100vw); }
.drawer.show { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 12px; height: var(--topbar); padding: 0 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.drawer-head h3 { font-size: 15px; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: color-mix(in srgb, var(--surface-2) 40%, var(--surface)); }

.modal-wrap { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px; }
.modal {
  width: min(480px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius-xl); box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .1); border: 1px solid var(--border);
  transform: scale(.98); opacity: 0; transition: opacity .15s, transform .15s;
}
.modal.wide { width: min(760px, 100%); }
.modal.show { transform: none; opacity: 1; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 20px 4px; }
.modal-head h3 { font-size: 15px; font-weight: 600; }
.modal-head p { color: var(--muted); margin-top: 2px; font-size: 13px; }
.modal-body { padding: 12px 20px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: color-mix(in srgb, var(--surface-2) 40%, var(--surface)); border-radius: 0 0 var(--radius-xl) var(--radius-xl); }
.modal-icon { width: 36px; height: 36px; border-radius: var(--radius); display: grid; place-items: center; flex-shrink: 0; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.modal-icon.danger { color: var(--red-text); }
.modal-icon.success { color: var(--green-text); }
.email-frame { width: 100%; height: 60vh; border: 1px solid var(--border); border-radius: var(--radius); background: #f4f4f5; }

/* Detail blocks */
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }
.notes { white-space: pre-wrap; word-break: break-word; background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13px; color: var(--text-2); }
.hero { display: flex; gap: 14px; align-items: flex-start; }
.hero h2 { font-size: 20px; font-weight: 600; letter-spacing: -.011em; word-break: break-all; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.stat { padding: 12px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 15px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.section-title { font-size: 14px; font-weight: 600; color: var(--text); margin: 24px 0 12px; }
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 1px; background: var(--border); }
.tl-item { position: relative; padding: 0 0 16px; }
.tl-item::before { content: ''; position: absolute; left: -20px; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--surface); border: 1px solid var(--border-strong); }
.tl-item.green::before { border-color: var(--green); }
.tl-title { font-size: 14px; white-space: nowrap; }
.stat .s { font-size: 12px; font-weight: 500; margin-top: 2px; }
/* Money still owed: shown right under the actions so it can't be missed */
.unpaid-banner { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding: 12px 16px; border-radius: var(--radius); background: color-mix(in srgb, var(--orange) 5%, var(--surface)); color: var(--text); border: 1px solid color-mix(in srgb, var(--orange) 30%, transparent); font-size: 14px; }
.unpaid-banner > svg { width: 18px; height: 18px; flex: none; color: var(--orange-text); }
.unpaid-banner b { color: var(--text); }
/* Renewal history: one card per term, newest first, the first term at the bottom */
.terms { display: flex; flex-direction: column; gap: 10px; }
.term { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.term.unpaid { border-color: color-mix(in srgb, var(--orange) 30%, transparent); background: color-mix(in srgb, var(--orange) 5%, var(--surface)); }
.term.first { background: transparent; border-style: dashed; }
.term-head { display: flex; align-items: center; gap: 8px; }
.term-dates { font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
.term-money { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.term-money span { display: block; font-size: 11.5px; color: var(--muted); }
.term-money b { font-size: 13.5px; font-variant-numeric: tabular-nums; }

/* ---------- Dropdown menu ---------- */
.menu {
  position: fixed; z-index: 100; min-width: 192px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: pop .1s ease-out;
}
@keyframes pop { from { opacity: 0; } }
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 10px; border: 0; border-radius: var(--radius-sm); background: transparent;
  font-size: 13.5px; color: var(--text-2); cursor: pointer; text-align: left; text-decoration: none;
}
.menu button:hover, .menu a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.menu button svg, .menu a svg { color: currentColor; }
.menu .danger, .menu .danger svg { color: var(--red-text); }
.menu .danger:hover { background: var(--red-soft); color: var(--red-text); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  min-width: 260px; max-width: 384px; padding: 12px 12px 12px 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  font-size: 13.5px; line-height: 20px;
  animation: toastIn .2s ease-out;
}
.toast.out { animation: toastOut .2s forwards; }
.toast .ti { display: grid; place-items: center; flex-shrink: 0; }
.toast.success .ti { color: var(--green-text); }
.toast.error .ti { color: var(--red-text); }
.toast.info .ti { color: var(--muted); }
.toast .ti svg { width: 18px; height: 18px; stroke-width: 2; }
.toast .tmsg { flex: 1; }
.toast button { background: transparent; border: 0; color: var(--text); font-weight: 500; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); }
.toast button:hover { background: var(--surface-2); }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } }
@keyframes toastOut { to { opacity: 0; } }

/* ---------- Command palette ---------- */
.cmdk-wrap { position: fixed; inset: 0; z-index: 150; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.cmdk {
  width: min(620px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .15);
  overflow: hidden; animation: pop .1s ease-out;
}
.cmdk-input { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.cmdk-input svg { color: var(--muted); width: 18px; height: 18px; }
.cmdk-input input { flex: 1; height: 52px; border: 0; outline: 0; background: transparent; font-size: 15px; }
.cmdk-results { max-height: 420px; overflow-y: auto; padding: 6px; }
.cmdk-group { font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 10px 4px; }
.cmdk-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.cmdk-item.hl { background: var(--surface-2); }
.cmdk-item .t { font-weight: 500; }
.cmdk-item .s { font-size: 12px; color: var(--muted); }
.cmdk-foot { display: flex; gap: 16px; padding: 8px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--surface-2) 40%, var(--surface)); }

/* ---------- Dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 24px; align-items: stretch; }
/* Both columns end on the same line: the last card in the shorter column grows to fill */
.dash-col > .card:last-child { flex: 1; display: flex; flex-direction: column; }
.dash-col > .card:last-child > .card-body { flex: 1; display: flex; flex-direction: column; }
.dash-col > .card:last-child .chart-box { flex: 1; min-height: 260px; height: auto; }
.dash-grid.measuring { align-items: start; }
.dash-grid.measuring .dash-col > .card:last-child, .dash-grid.measuring .dash-col > .card:last-child .chart-box { flex: none; }
.dash-col { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.chart-box { position: relative; height: 260px; }
.donut-box { position: relative; height: 180px; }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.donut-center .v { font-size: 24px; font-weight: 600; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.donut-center .l { font-size: 12px; color: var(--muted); }
.type-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 13px; }
.type-row .bar { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.type-row .bar span { display: block; height: 100%; border-radius: 99px; }
.alert-banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius); background: color-mix(in srgb, var(--orange) 5%, var(--surface)); border: 1px solid color-mix(in srgb, var(--orange) 30%, transparent); color: var(--text); margin-bottom: 24px; font-size: 14px; }
.alert-banner > svg { color: var(--orange-text); width: 18px; height: 18px; }
.alert-banner .btn { margin-left: auto; }
.setup-card { margin-bottom: 24px; }
.setup-step { display: flex; align-items: center; gap: 12px; padding: 11px 20px; border-top: 1px solid var(--border); }
.card-head + .setup-step { border-top: 0; }
.setup-step .n { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 500; color: var(--faint); border: 1px dashed var(--border-strong); }
.setup-step .n svg { width: 14px; height: 14px; }
.setup-step .t { font-weight: 500; font-size: 13.5px; }
.setup-step.next .n { border-style: solid; border-color: var(--text-2); color: var(--text); }
.setup-step.done .n { background: var(--green-soft); border: 1px solid color-mix(in srgb, var(--green) 25%, transparent); color: var(--green-text); }
.setup-step.done .t { color: var(--muted); font-weight: 500; }

/* ---------- Calendar ---------- */
.calendar-only { display: none; }
.subs-calendar .calendar-only { display: block; }
.subs-calendar .list-only { display: none !important; }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.cal-head h3 { font-size: 18px; font-weight: 600; letter-spacing: -.011em; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-dow { padding: 0 12px; height: 36px; display: flex; align-items: center; font-size: 12px; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.cal-day { min-height: 118px; padding: 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-day:nth-child(7n + 7) { border-right: 0; }
.cal-day.out { background: color-mix(in srgb, var(--surface-2) 50%, var(--surface)); }
.cal-day.out .cal-num { color: var(--faint); }
.cal-num { font-size: 12px; font-weight: 500; color: var(--text-2); width: 24px; height: 24px; display: grid; place-items: center; border-radius: var(--radius-sm); font-variant-numeric: tabular-nums; }
.cal-day.today .cal-num { background: var(--primary); color: var(--primary-fg); }
.cal-ev {
  display: flex; align-items: center; gap: 5px; padding: 2px 6px; border-radius: 4px;
  font-size: 12px; font-weight: 500; cursor: pointer; min-width: 0;
  background: color-mix(in srgb, var(--c) 10%, transparent); color: var(--text);
  box-shadow: inset 2px 0 0 var(--c);
}
.cal-ev:hover { background: color-mix(in srgb, var(--c) 18%, transparent); }
.cal-ev svg { width: 12px; height: 12px; flex: none; color: var(--text-2); }
.cal-ev, .cal-legend .dot { --c: var(--muted); }
.cal-ev.active, .cal-legend .dot.active { --c: var(--green); }
.cal-ev.due, .cal-legend .dot.due { --c: var(--amber); }
.cal-ev.critical, .cal-legend .dot.critical { --c: var(--orange); }
.cal-ev.expired, .cal-legend .dot.expired { --c: var(--red); }
.cal-ev.pending, .cal-legend .dot.pending { --c: var(--muted); }
.cal-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 12px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.cal-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend .dot { width: 8px; height: 8px; border-radius: 2px; background: var(--c); }
.cal-ev span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-more { font-size: 11.5px; color: var(--muted); padding-left: 4px; cursor: pointer; }
.cal-more:hover { color: var(--text); }

/* ---------- Clients ---------- */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.client-card { padding: 20px; cursor: pointer; transition: border-color .15s, background .15s; display: flex; flex-direction: column; gap: 16px; }
.client-card:hover { border-color: var(--border-strong); }
.client-card .meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.client-card .meta .l { font-size: 12px; color: var(--muted); }
.client-card .meta .v { font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.contact-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Settings ---------- */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--topbar) + 8px); display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--text-2); font-size: 13.5px; font-weight: 500; text-decoration: none; }
.settings-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.settings-nav a.active { background: color-mix(in srgb, var(--surface-3) 70%, transparent); color: var(--text); }
.settings-nav a svg { color: currentColor; opacity: .8; }
.settings-panel { display: flex; flex-direction: column; gap: 24px; }
.settings-panel .card-body { display: flex; flex-direction: column; gap: 20px; }
.code-box { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); border: 1px solid var(--border); }
.code-box code { flex: 1; font-family: var(--mono); font-size: 12px; overflow-x: auto; white-space: nowrap; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; color: var(--text-2); }
.steps li::marker { color: var(--muted); font-weight: 500; }
.placeholder-list { display: flex; flex-wrap: wrap; gap: 6px; }
.placeholder-list code { font-family: var(--mono); font-size: 12px; padding: 2px 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; }
.placeholder-list code:hover { border-color: var(--border-strong); color: var(--text); }
.color-input { width: 40px; height: 40px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.field-builder-row { display: grid; grid-template-columns: 1fr 130px 36px; gap: 8px; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; }
.icon-grid button { height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; display: grid; place-items: center; color: var(--text-2); }
.icon-grid button:hover { background: var(--surface-2); }
.icon-grid button.on { border-color: var(--text-2); background: var(--surface-3); color: var(--text); }
.dropzone { border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 32px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; background: color-mix(in srgb, var(--surface-2) 50%, var(--surface)); }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Lock screen ---------- */
.lock-page {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.lock-card { width: 100%; max-width: 300px; text-align: center; }
.lock-card .brand-mark { width: 40px; height: 40px; border-radius: var(--radius); margin: 0 auto 20px; }
.lock-card .brand-mark svg { width: 20px; height: 20px; }
.lock-card h1 { font-size: 20px; font-weight: 600; letter-spacing: -.011em; }
.lock-card .sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 32px 0 12px; }
.pin-dots span { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); transition: background .1s, border-color .1s; }
.pin-dots span.on { background: var(--text); border-color: var(--text); }
.pin-dots.error span { border-color: var(--red); background: var(--red); }
.pin-dots.ok span { border-color: var(--green); background: var(--green); }
.pin-msg { height: 20px; font-size: 13px; color: var(--red-text); font-weight: 500; }
.shake { animation: shake .42s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 20px; }
.key {
  height: 64px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--surface);
  font-size: 26px; font-weight: 500; cursor: pointer; color: var(--text); font-variant-numeric: tabular-nums;
  display: grid; place-items: center; transition: background .1s;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none;
}
.key:hover { background: var(--surface-2); }
.key:active, .key.press { background: var(--surface-3); }
.key.fn { background: transparent; border-color: transparent; color: var(--text-2); }
.key.fn:hover { background: var(--surface-2); }
.key.fn svg { width: 22px; height: 22px; }
.lock-foot { margin-top: 32px; font-size: 12px; color: var(--faint); }
@media (min-width: 1024px) { .key { height: 56px; font-size: 22px; } }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); background: var(--surface); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .topbar { gap: 8px; }
  .topbar-brand { display: inline-flex; }
  .topbar-brand .brand-mark { width: 24px; height: 24px; }
  .topbar-brand .brand-mark svg { width: 14px; height: 14px; }
  .search-trigger { width: 36px; height: 36px; margin-left: auto; padding: 0; justify-content: center; border-color: transparent; background: transparent; color: var(--text-2); }
  .search-trigger span, .search-trigger kbd { display: none; }
  .view { padding: 4px 16px 96px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); height: calc(56px + env(safe-area-inset-bottom));
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: color-mix(in srgb, var(--surface) 95%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 0 4px env(safe-area-inset-bottom);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10.5px; font-weight: 500; color: var(--muted); text-decoration: none; }
  .bottom-nav a svg { width: 20px; height: 20px; }
  .bottom-nav a.active { color: var(--text); }
  .bottom-nav .fab { width: 36px; height: 36px; margin: 0 auto; border-radius: var(--radius); background: var(--primary); color: var(--primary-fg); display: grid; place-items: center; }
  .bulkbar { margin-left: 0; bottom: calc(64px + env(safe-area-inset-bottom)); }
  .toasts { top: 12px; bottom: auto; left: 16px; right: 16px; align-items: center; }
  .toast { max-width: none; }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  /* Phones: the settings sections become an underline tab strip that scrolls sideways */
  .settings-nav { position: static; flex-direction: row; gap: 20px; overflow-x: auto; overflow-y: hidden; margin: 0 -16px; padding: 0 16px; box-shadow: inset 0 -1px 0 var(--border); }
  .settings-nav a { white-space: nowrap; flex-shrink: 0; height: auto; padding: 4px 0 10px; border-radius: 0; border-bottom: 2px solid transparent; color: var(--muted); }
  .settings-nav a svg { display: none; }
  .settings-nav a:hover { background: none; }
  .settings-nav a.active { background: none; border-bottom-color: var(--text); color: var(--text); }
  .table-desktop { display: none; }
  .mlist { display: block; }
  .page-head h2 { font-size: 20px; }
  /* Phones: actions stay level with the title; the subtitle wraps underneath instead of being cut off */
  .page-head { gap: 12px; margin: 20px 0; align-items: flex-start; }
  .page-title p { white-space: normal; }
  .page-actions .segmented button { padding: 0 10px; }
}
@media (max-width: 640px) {
  .kpi { padding: 16px; }
  .kpi-value { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .dl { grid-template-columns: 110px 1fr; }
  .toolbar .search { width: 100%; }
  .filters { width: 100%; }
  .filters .select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .cal-day { min-height: 64px; padding: 4px; }
  .cal-ev span { display: none; }
  .cal-ev { padding: 0; height: 8px; border-left-width: 0; border-radius: 4px; background: var(--c); }
  .cal-dow { padding: 8px 4px; text-align: center; font-size: 10px; }
  .modal-wrap { align-items: end; padding: 0; }
  .modal { width: 100%; border-radius: var(--radius-xl) var(--radius-xl) 0 0; max-height: 92vh; }
  .modal-foot { border-radius: 0; }
  input, select, textarea { font-size: 16px !important; }
  .drawer-body { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.show-sm { display: none; }
@media (max-width: 640px) { .hide-sm { display: none; } .show-sm { display: inline; } #new-btn { width: 36px; padding: 0; } }
.type-tile { transition: border-color .12s, background .12s; }
.type-tile:hover { border-color: var(--border-strong); }
.type-tile.on { border-color: var(--text-2) !important; background: var(--surface-2) !important; color: var(--text) !important; box-shadow: inset 0 0 0 1px var(--text-2); }
.mcard .cell-title, .mcard .cell-sub { max-width: none; }
.mcard .row .tnum, .mcard .days { white-space: nowrap; }
.mcard .cell-sub + .row { flex-wrap: wrap; row-gap: 4px; }
.settings-layout > * { min-width: 0; }
.switch-row { align-items: center; }
.switch-row > .stack { min-width: 0; }
.filters .input { width: auto; }

/* Small inline action that reads as a link */
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 500; color: var(--accent-text); cursor: pointer; text-underline-offset: 2px; }
.link-btn:hover { text-decoration: underline; }
.more-opts > summary { cursor: pointer; font-size: 13px; color: var(--muted); list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.more-opts > summary::-webkit-details-marker { display: none; }
.more-opts > summary::before { content: '›'; display: inline-block; transition: transform .15s; font-size: 15px; }
.more-opts[open] > summary::before { transform: rotate(90deg); }
.more-opts > summary:hover { color: var(--text); }

/* ---------- Shared pieces with a phone layout ---------- */
.toolbar .select.fit { width: auto; }
.renews-on { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.renews-on svg { color: var(--muted); }
.renews-on b { color: var(--text); }
.renews-on .link-btn { margin-left: auto; font-size: 13px; }
.chips-input { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 40px; padding: 5px 6px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); box-shadow: var(--shadow-sm); cursor: text; }
.chips-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.field.invalid .chips-input { border-color: color-mix(in srgb, var(--red) 70%, transparent); }
.chips-input .chip { height: 26px; padding: 0 4px 0 8px; gap: 4px; cursor: default; max-width: 100%; background: var(--surface-2); }
.chips-input .chip button { border: 0; background: none; color: inherit; cursor: pointer; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 4px; padding: 0; }
.chips-input .chip button:hover { background: color-mix(in srgb, currentColor 15%, transparent); }
.chips-input .chip svg { width: 13px; height: 13px; }
.chips-input input[type=email] { flex: 1; min-width: 160px; height: 28px; border: 0; outline: 0; background: transparent; padding: 0 6px; font-size: 13.5px; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
.pair > .field { min-width: 0; }
.type-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.type-pick .type-tile { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; text-align: left; min-width: 0; }
.type-pick .type-tile .type-icon.sm { width: 24px; height: 24px; border: 0; background: transparent; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.stat-row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.settings-nav { scrollbar-width: none; }
.settings-nav::-webkit-scrollbar { display: none; }

@media (max-width: 1200px) {
  /* One column: put what needs doing first (attention, unpaid) above the charts */
  .dash-grid > .dash-col { display: contents; }
  .dash-grid > .dash-col > .card { order: var(--o, 9); }
  .dash-grid [data-order="1"] { --o: 1; } .dash-grid [data-order="2"] { --o: 2; } .dash-grid [data-order="3"] { --o: 3; }
  .dash-grid [data-order="4"] { --o: 4; } .dash-grid [data-order="5"] { --o: 5; }
}

@media (max-width: 640px) {
  .card-head { flex-wrap: wrap; }
  .card-head.wrap .legend { width: 100%; }
  .card-head.wrap .spacer { display: none; }
  .toolbar .select.fit { flex: 1; min-width: 0; }
  .toolbar .spacer { display: none; }
  /* Checkbox lines up with the service icon instead of floating in the middle of the card */
  .mcheck { align-items: flex-start; padding-top: 22px; }
  .type-pick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Renew and More across the top, the other three in an even row underneath */
  .detail-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .detail-actions [data-act="renew"] { grid-row: 1; grid-column: 1 / 3; }
  .detail-actions [data-act="more"] { grid-row: 1; grid-column: 3; width: auto; }
  .detail-actions .btn { padding: 0 8px; min-width: 0; gap: 6px; }
  .stat-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .stat-row.four { grid-template-columns: 1fr 1fr; }
  .stat { padding: 10px 12px; min-width: 0; }
  .stat .v { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .contact-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); width: 100%; }
  .contact-actions .btn.icon { width: auto; }
  .cal-ev svg { display: none; }
  .modal-foot .btn { flex: 1; }
  .modal-foot { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .drawer-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .cmdk-foot, .cmdk-input kbd { display: none; }
}
