/**
 * UD CRM Design System — theme.css v1
 * Unified design tokens + component library for all CRM H5 pages
 * Based on Apple iOS Dark Mode palette · Mobile-First · iPhone 14 Pro (390px)
 *
 * Usage: <link rel="stylesheet" href="/theme.css">
 * All pages MUST load this file and remove conflicting :root overrides
 */

/* ─── 1. DESIGN TOKENS ────────────────────────────────────────────────────── */
:root {
  /* Backgrounds (Apple iOS layered dark) */
  --bg-main:      #000000;   /* page background */
  --bg-surface:   #1c1c1e;   /* card / list item */
  --bg-elevated:  #2c2c2e;   /* modal / floating panel */
  --bg-input:     #3a3a3c;   /* input fields */
  --bg-hover:     #3a3a3c;   /* hover/active state */

  /* Brand & semantic colours */
  --blue:         #0a84ff;   /* primary actions */
  --green:        #30d158;   /* success / Won / Paid */
  --orange:       #ff9f0a;   /* warning / pending */
  --red:          #ff453a;   /* danger / overdue / HIGH risk */
  --purple:       #bf5af2;   /* AI features */
  --teal:         #5ac8fa;   /* info / secondary */
  --yellow:       #ffd60a;   /* highlight / star */
  --indigo:       #5e5ce6;   /* milestone / calendar */

  /* Aliases for semantic use */
  --color-primary:   var(--blue);
  --color-success:   var(--green);
  --color-warning:   var(--orange);
  --color-danger:    var(--red);
  --color-ai:        var(--purple);

  /* Typography */
  --text-primary:    #f2f2f7;
  --text-secondary:  #8e8e93;
  --text-tertiary:   #636366;
  --text-inverse:    #000000;
  --text-link:       var(--blue);

  /* Borders & separators */
  --border:          #38383a;
  --border-focus:    var(--blue);
  --separator:       rgba(255,255,255,.08);

  /* Spacing scale (Base 4px) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Legacy aliases (for backward compat during migration) */
  --bg:    var(--bg-main);
  --card:  var(--bg-surface);
  --card2: var(--bg-elevated);
  --text:  var(--text-primary);
  --text2: var(--text-secondary);
  /* Music page back-compat aliases (UDCRM unification 2026-06-08) */
  --fg:           var(--text-primary);
  --muted:        var(--text-secondary);
  --sub:          var(--text-tertiary);
  --line:         var(--border);
  --accent:       var(--blue);
  --accent-soft:  rgba(10,132,255,.13);
  --tap-min:      44px;
  --brand:        var(--blue);
  --brand2:       var(--indigo);
  --ink:          var(--text-primary);
  --ink2:         var(--text-secondary);
  --ink3:         var(--text-tertiary);

  /* Border radius */
  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  20px;
  --r-pill: 999px;

  /* Typography scale */
  --fs-xs:  11px;
  --fs-sm:  13px;
  --fs-md:  15px;
  --fs-lg:  17px;
  --fs-xl:  20px;
  --fs-2xl: 24px;
  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semi:   600;
  --fw-bold:   700;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
  --shadow-md:  0 4px 12px rgba(0,0,0,.5);
  --shadow-lg:  0 8px 30px rgba(0,0,0,.6);

  /* Transitions */
  --ease:       cubic-bezier(.4,0,.2,1);
  --duration:   200ms;
  --trans:      var(--duration) var(--ease);

  /* Touch target minimum */
  --touch-min:  44px;

  /* Z-index layers */
  --z-modal:    100;
  --z-overlay:  90;
  --z-toast:    200;
  --z-nav:      80;
}

/* ─── 2. RESET & BASE ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', 'PingFang TC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft JhengHei', 'Heiti TC', 'Source Han Sans TC', 'Noto Sans CJK TC', 'Noto Sans CJK SC', sans-serif;
  font-size: var(--fs-md);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

a { color: var(--text-link); text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  font: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  outline: none;
  -webkit-appearance: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--border-focus); }
/* CHECKBOX_NATIVE_V1 2026-06-11: the blanket -webkit-appearance:none above used
   to hit checkboxes/radios too — they rendered as empty rounded boxes with NO
   visible checked state (accent-color is ignored when appearance is none), so
   選擇類 UI（AI 一鍵填充 modal 等）looked permanently unselected on desktop. */
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: auto;
  appearance: auto;
}

/* ─── 3. TYPOGRAPHY ───────────────────────────────────────────────────────── */
.t-xs    { font-size: var(--fs-xs); }
.t-sm    { font-size: var(--fs-sm); }
.t-md    { font-size: var(--fs-md); }
.t-lg    { font-size: var(--fs-lg); }
.t-xl    { font-size: var(--fs-xl); }
.t-bold  { font-weight: var(--fw-bold); }
.t-semi  { font-weight: var(--fw-semi); }
.t-med   { font-weight: var(--fw-medium); }
.t-1     { color: var(--text-primary); }
.t-2     { color: var(--text-secondary); }
.t-3     { color: var(--text-tertiary); }
.t-blue  { color: var(--blue); }
.t-green { color: var(--green); }
.t-red   { color: var(--red); }
.t-orange{ color: var(--orange); }
.t-purple{ color: var(--purple); }
.t-center{ text-align: center; }
.t-right { text-align: right; }

/* ─── 4. LAYOUT HELPERS ───────────────────────────────────────────────────── */
.flex        { display: flex; }
.flex-col    { display: flex; flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between{ display: flex; align-items: center; justify-content: space-between; }
.flex-gap-1  { gap: var(--sp-1); }
.flex-gap-2  { gap: var(--sp-2); }
.flex-gap-3  { gap: var(--sp-3); }
.flex-gap-4  { gap: var(--sp-4); }
.flex-1      { flex: 1; }
.wrap        { flex-wrap: wrap; }
.g-1         { gap: var(--sp-1); }
.g-2         { gap: var(--sp-2); }
.g-4         { gap: var(--sp-4); }

.p-1  { padding: var(--sp-1); }
.p-2  { padding: var(--sp-2); }
.p-3  { padding: var(--sp-3); }
.p-4  { padding: var(--sp-4); }
.px-4 { padding-left: var(--sp-4); padding-right: var(--sp-4); }
.py-2 { padding-top: var(--sp-2); padding-bottom: var(--sp-2); }
.py-3 { padding-top: var(--sp-3); padding-bottom: var(--sp-3); }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }

.w-full  { width: 100%; }
.h-full  { height: 100%; }
.hidden  { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ─── 5. BUTTONS ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--touch-min);
  padding: 0 var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: var(--fw-semi);
  transition: opacity var(--trans), transform var(--trans);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .75; transform: scale(.97); }
.btn:disabled { opacity: .35; pointer-events: none; }

.btn-primary  { background: var(--blue);   color: #fff; }
.btn-success  { background: var(--green);  color: #fff; }
.btn-danger   { background: var(--red);    color: #fff; }
.btn-warning  { background: var(--orange); color: #000; }
.btn-ghost    { background: rgba(255,255,255,.08); color: var(--text-primary); }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text-primary); }
.btn-ai       { background: linear-gradient(135deg, var(--purple), var(--blue)); color: #fff; }

.btn-sm { min-height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-lg { min-height: 52px; padding: 0 var(--sp-6); font-size: var(--fs-lg); }
.btn-full { width: 100%; border-radius: var(--r-lg); }

/* ── Logo size constraint (2026-05-16) — injectLogo in theme_toggle.js injects
   the UD logo. Without explicit sizes the native PNG (~600px) fills screen. ── */
.crm-logo-inline, .crm-logo-fixed {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.crm-logo-fixed {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 999;
}
.crm-logo-inline img, .crm-logo-fixed img {
  width: 32px !important;
  height: 32px !important;
  max-width: 32px !important;
  max-height: 32px !important;
  object-fit: contain;
  display: block;
}

/* ─── 6. CARDS ────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  border: 1px solid var(--separator);
}
.card + .card { margin-top: var(--sp-2); }
.card-elevated {
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
}
.card-clickable {
  cursor: pointer;
  transition: background var(--trans);
}
.card-clickable:active { background: var(--bg-elevated); }

/* ─── 7. BADGES / STATUS PILLS ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  white-space: nowrap;
}
.badge-blue    { background: rgba(10,132,255,.15); color: var(--blue); }
.badge-green   { background: rgba(48,209,88,.15);  color: var(--green); }
.badge-orange  { background: rgba(255,159,10,.15); color: var(--orange); }
.badge-red     { background: rgba(255,69,58,.15);  color: var(--red); }
.badge-purple  { background: rgba(191,90,242,.15); color: var(--purple); }
.badge-gray    { background: rgba(142,142,147,.15);color: var(--text-secondary); }
.badge-teal    { background: rgba(90,200,250,.15); color: var(--teal); }

/* Status-specific badges */
.badge-lead         { @extend .badge-teal; }
.badge-prospecting  { background: rgba(90,200,250,.15); color: var(--teal); }
.badge-qualification{ background: rgba(10,132,255,.15); color: var(--blue); }
.badge-proposal     { background: rgba(191,90,242,.15); color: var(--purple); }
.badge-negotiation  { background: rgba(255,159,10,.15); color: var(--orange); }
.badge-won          { background: rgba(48,209,88,.15);  color: var(--green); }
.badge-lost         { background: rgba(255,69,58,.15);  color: var(--red); }
.badge-draft        { background: rgba(142,142,147,.15);color: var(--text-secondary); }
.badge-sent         { background: rgba(10,132,255,.15); color: var(--blue); }
.badge-approved     { background: rgba(48,209,88,.15);  color: var(--green); }
.badge-confirmed    { background: rgba(48,209,88,.15);  color: var(--green); }
.badge-invoiced     { background: rgba(255,214,10,.15); color: var(--yellow); }
.badge-paid         { background: rgba(48,209,88,.2);   color: var(--green); font-weight: var(--fw-bold); }
.badge-cancelled    { background: rgba(255,69,58,.15);  color: var(--red); }

/* ─── 8. FORM COMPONENTS ──────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
}
.form-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .02em;
}
.form-label .required { color: var(--red); margin-left: 2px; }
.form-input {
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--fs-md);
  transition: border-color var(--trans);
}
.form-input:focus { border-color: var(--border-focus); }
.form-input::placeholder { color: var(--text-tertiary); }
.form-input.error { border-color: var(--red); }

.form-textarea {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--fs-md);
  resize: vertical;
  min-height: 80px;
  transition: border-color var(--trans);
}
.form-textarea:focus { border-color: var(--border-focus); }

.form-select {
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--fs-md);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238e8e93' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-4) center;
  padding-right: 40px;
}
.form-select:focus { border-color: var(--border-focus); }

.form-hint { font-size: var(--fs-xs); color: var(--text-tertiary); margin-top: 2px; }
.form-error { font-size: var(--fs-xs); color: var(--red); margin-top: 2px; }

/* Form section grouping */
.form-section {
  background: var(--bg-surface);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.form-section-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--separator);
}

/* Inline field row */
.field-row {
  display: flex;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.field-row .form-group { flex: 1; margin-bottom: 0; }

/* ─── 9. MODAL / BOTTOM SHEET ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: var(--z-overlay);
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--trans);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal-sheet {
  width: 100%;
  max-height: 90dvh;
  background: var(--bg-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform var(--trans);
  box-shadow: var(--shadow-lg);
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--text-tertiary);
  border-radius: var(--r-pill);
  margin: var(--sp-2) auto;
  flex-shrink: 0;
  opacity: .4;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--separator);
  flex-shrink: 0;
}
.modal-title { font-size: var(--fs-lg); font-weight: var(--fw-semi); }
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--separator);
  display: flex;
  gap: var(--sp-3);
  flex-shrink: 0;
  background: var(--bg-surface);
}

/* Full-screen overlay panel (slide from right) */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-main);
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--trans);
}
.panel-overlay.open { transform: translateX(0); }
.panel-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  min-height: 56px;
  border-bottom: 1px solid var(--separator);
  flex-shrink: 0;
}
.panel-back {
  font-size: 24px;
  color: var(--blue);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
}
.panel-title { font-size: var(--fs-lg); font-weight: var(--fw-semi); flex: 1; }
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  -webkit-overflow-scrolling: touch;
}

/* ─── 10. LIST ITEMS ──────────────────────────────────────────────────────── */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-2);
  cursor: pointer;
  transition: background var(--trans);
  border: 1px solid transparent;
}
.list-item:active { background: var(--bg-elevated); }
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-size: var(--fs-md); font-weight: var(--fw-medium); }
.list-item-sub   { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: 2px; }
.list-item-meta  { font-size: var(--fs-xs); color: var(--text-tertiary); margin-top: 2px; }
.list-item-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }

/* Amount display */
.amount { font-size: var(--fs-md); font-weight: var(--fw-semi); color: var(--text-primary); }
.amount-lg { font-size: var(--fs-xl); font-weight: var(--fw-bold); }
.amount-green { color: var(--green); }

/* ─── 11. TOP NAV ─────────────────────────────────────────────────────────── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  background: var(--bg-main);
  border-bottom: 1px solid var(--separator);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  min-height: 52px;
}
.top-nav-title { font-size: var(--fs-lg); font-weight: var(--fw-semi); flex: 1; }
.top-nav-back  {
  display: flex; align-items: center;
  font-size: var(--fs-md); color: var(--blue);
  min-width: var(--touch-min); min-height: var(--touch-min);
}

/* ─── 12. TAB BAR / SEGMENT CONTROL ──────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-4);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  padding: 6px var(--sp-4);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  transition: all var(--trans);
  min-height: 34px;
  cursor: pointer;
}
.tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

/* ─── 13. SEARCH BAR ──────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-input);
  border-radius: var(--r-md);
  padding: 0 var(--sp-3);
  margin: var(--sp-2) var(--sp-4);
  min-height: 40px;
}
.search-icon { color: var(--text-tertiary); flex-shrink: 0; }
.search-input {
  flex: 1;
  background: transparent;
  border: none;
  font-size: var(--fs-md);
  color: var(--text-primary);
  min-height: 40px;
}
.search-input::placeholder { color: var(--text-tertiary); }

/* ─── 14. KPI / STAT CARDS ────────────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
}
.kpi-card {
  background: var(--bg-surface);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-2);
  text-align: center;
}
.kpi-value { font-size: var(--fs-xl); font-weight: var(--fw-bold); color: var(--text-primary); }
.kpi-label { font-size: var(--fs-xs); color: var(--text-secondary); margin-top: 2px; }

/* ─── 15. STEPPER ─────────────────────────────────────────────────────────── */
.stepper {
  display: flex;
  align-items: center;
  padding: var(--sp-4) var(--sp-4) 0;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 0;
}
.stepper::-webkit-scrollbar { display: none; }
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 48px;
  position: relative;
}
.step::before {
  content: '';
  position: absolute;
  top: 14px;
  right: 50%;
  left: -50%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.step:first-child::before { display: none; }
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: var(--text-secondary);
  z-index: 1;
  transition: all var(--trans);
}
.step.active .step-dot   { background: var(--blue);  border-color: var(--blue);  color: #fff; }
.step.done .step-dot     { background: var(--green); border-color: var(--green); color: #fff; }
.step.done::before       { background: var(--green); }
.step-label {
  font-size: 9px;
  color: var(--text-tertiary);
  margin-top: 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 56px;
}
.step.active .step-label { color: var(--blue); font-weight: var(--fw-semi); }
.step.done .step-label   { color: var(--green); }

/* ─── 16. TOAST NOTIFICATION ──────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: var(--sp-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
  width: calc(100% - var(--sp-8));
  max-width: 360px;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elevated);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  box-shadow: var(--shadow-lg);
  animation: _toast-in .25s var(--ease) forwards;
}
.toast.out { animation: _toast-out .2s var(--ease) forwards; }
.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--blue); }
.toast-warn    { border-left: 3px solid var(--orange); }

@keyframes _toast-in  { from { opacity:0; transform:translateY(-8px); } to { opacity:1; transform:translateY(0); } }
@keyframes _toast-out { from { opacity:1; } to { opacity:0; transform:translateY(-8px); } }

/* ─── 17. AI NBA CARD ─────────────────────────────────────────────────────── */
/* (Matches ai_native.js CSS classes — keep in sync) */
.ai-nba-card {
  background: rgba(10,132,255,.06);
  border-left: 3px solid var(--blue);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  padding: var(--sp-3) var(--sp-3);
  margin: var(--sp-2) 0;
  font-size: var(--fs-sm);
  line-height: 1.5;
  animation: _ai-fade .3s ease;
}
.ai-nba-card.risk-HIGH   { background: rgba(255,69,58,.06);  border-color: var(--red); }
.ai-nba-card.risk-MEDIUM { background: rgba(255,159,10,.06); border-color: var(--orange); }
.ai-nba-card.risk-LOW    { background: rgba(48,209,88,.06);  border-color: var(--green); }
.ai-nba-header { display:flex; align-items:center; gap:6px; font-weight:var(--fw-bold); margin-bottom:4px; color:var(--blue); }
.ai-nba-card.risk-HIGH   .ai-nba-header { color: var(--red); }
.ai-nba-card.risk-MEDIUM .ai-nba-header { color: var(--orange); }
.ai-nba-card.risk-LOW    .ai-nba-header { color: var(--green); }
.ai-nba-insight  { color: var(--text-primary); margin-bottom: 4px; }
.ai-nba-action   { color: var(--text-secondary); font-size: var(--fs-xs); }
.ai-nba-btn      { display:inline-block; margin-top:6px; padding:5px 12px; border-radius:var(--r-pill); font-size:var(--fs-xs); font-weight:var(--fw-semi); color:#fff; background:var(--blue); cursor:pointer; }
.ai-nba-spinner  { display:inline-block; width:14px; height:14px; border:2px solid rgba(255,255,255,.2); border-top-color:#fff; border-radius:50%; animation:_spin .6s linear infinite; }
.ai-nba-loading  { display:flex; align-items:center; gap:var(--sp-2); font-size:var(--fs-sm); color:var(--text-secondary); padding:var(--sp-2) 0; }

@keyframes _ai-fade { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:translateY(0); } }
@keyframes _spin    { to { transform: rotate(360deg); } }

/* ─── 18. DETAIL ROW ──────────────────────────────────────────────────────── */
.det-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--separator);
}
.det-row:last-child { border-bottom: none; }
.det-label { font-size: var(--fs-sm); color: var(--text-secondary); flex-shrink: 0; min-width: 80px; }
.det-value { font-size: var(--fs-sm); color: var(--text-primary); text-align: right; word-break: break-word; }

/* ─── 19. EMPTY STATE ─────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-12) var(--sp-4);
  text-align: center;
  gap: var(--sp-3);
}
.empty-icon  { font-size: 48px; opacity: .4; }
.empty-title { font-size: var(--fs-lg); font-weight: var(--fw-semi); color: var(--text-secondary); }
.empty-sub   { font-size: var(--fs-sm); color: var(--text-tertiary); }

/* ─── 20. LOADING / SPINNER ───────────────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,.1);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: _spin .7s linear infinite;
  margin: var(--sp-8) auto;
}
.spinner-sm { width: 18px; height: 18px; border-width: 2px; margin: 0; }
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-toast);
}

/* ─── 21. DIVIDER ─────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--separator); margin: var(--sp-4) 0; }
.divider-label {
  display: flex; align-items: center; gap: var(--sp-3);
  color: var(--text-tertiary); font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: .05em;
  margin: var(--sp-4) 0;
}
.divider-label::before, .divider-label::after {
  content: ''; flex: 1; height: 1px; background: var(--separator);
}

/* ─── 22. FAB (Floating Action Button) ───────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--sp-6) + env(safe-area-inset-bottom));
  right: var(--sp-4);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 16px rgba(10,132,255,.4);
  z-index: var(--z-nav);
  transition: transform var(--trans), box-shadow var(--trans);
}
.fab:active { transform: scale(.94); box-shadow: 0 2px 8px rgba(10,132,255,.3); }

/* ─── 23. SAFE AREA UTILITIES ─────────────────────────────────────────────── */
.safe-top    { padding-top:    env(safe-area-inset-top); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
.pb-safe     { padding-bottom: calc(var(--sp-6) + env(safe-area-inset-bottom)); }

/* ─── 24. SCROLLABLE CONTENT AREA ────────────────────────────────────────── */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.scroll-area::-webkit-scrollbar { display: none; }

/* ─── 25. PIPELINE FUNNEL STAGE ───────────────────────────────────────────── */
.stage-bar {
  display: flex;
  gap: 2px;
  padding: var(--sp-2) var(--sp-4);
}
.stage-segment {
  flex: 1;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--bg-elevated);
  transition: background var(--trans);
}
.stage-segment.filled { background: var(--blue); }
.stage-segment.won    { background: var(--green); }
.stage-segment.lost   { background: var(--red); }

/* ─── 26. PAGE CONTAINER ──────────────────────────────────────────────────── */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--bg-main);
}
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  -webkit-overflow-scrolling: touch;
}
.page-content::-webkit-scrollbar { display: none; }

/* ─── 27. TOPNAV CRAMPED-FIX (NAVCSS 2026-05-10) ──────────────────────────
   Universal overrides so the top nav of every CRM page survives narrow
   viewports without truncating button labels. Pure CSS — no HTML edits.

   Covers:
     • .crm-topnav family   (hub, oppty, index, leads)
     • .cm-header / .cm-nav-row  (commission)
     • Defensive [class*="topnav"] catch-all for future pages
   ──────────────────────────────────────────────────────────────────────── */

.crm-topnav,
.cm-header,
.cm-nav-row,
[class*="topnav"]:not(.crm-topnav-btn):not(.crm-topnav-left):not(.crm-topnav-right):not(.crm-topnav-spacer) {
  overflow-x: auto !important;
  overflow-y: hidden;
  flex-wrap: nowrap !important;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-top: max(6px, env(safe-area-inset-top)) !important;
  min-height: 40px;
  -webkit-overflow-scrolling: touch;
}
.crm-topnav::-webkit-scrollbar,
.cm-header::-webkit-scrollbar,
.cm-nav-row::-webkit-scrollbar,
[class*="topnav"]::-webkit-scrollbar { display: none; }

/* Inner left/right groups must also flow horizontally and not block scroll */
.crm-topnav-left,
.crm-topnav-right {
  flex-wrap: nowrap !important;
  gap: 4px;
}
.crm-topnav-left  { flex-shrink: 0; }
.crm-topnav-right { flex-shrink: 0; }

/* The middle spacer must yield space to buttons before forcing scroll */
.crm-topnav-spacer {
  flex: 0 1 auto !important;
  min-width: 4px !important;
}

/* All top-nav buttons: keep on one line, allow ellipsis when too long,
   never let them shrink below their padding/icon. */
.crm-topnav .crm-topnav-btn,
.crm-topnav button,
.cm-header .cm-back,
.cm-nav-row .cm-back,
.cm-nav-row button,
.cm-nav-row a {
  flex-shrink: 0 !important;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* "← 返回" and "🏠 Hub" must always show their full label —
   detect by id, title or text-content selectors. */
.crm-topnav-btn[id*="Back" i],
.crm-topnav-btn[id*="Hub"  i],
.crm-topnav-btn[title*="返回"],
.crm-topnav-btn[title*="Hub" i],
.cm-back[id*="Back" i],
.cm-back[id*="Hub"  i],
.cm-back[title*="返回"],
.cm-back[title*="Hub" i],
.crm-nav-keep-label {
  max-width: none !important;
  min-width: max-content;
  text-overflow: clip;
}

/* Mobile breakpoint — tighter buttons, smaller font, tighter gap. */
@media (max-width: 520px) {
  .crm-topnav,
  .cm-nav-row {
    gap: 3px !important;
  }
  .crm-topnav .crm-topnav-btn,
  .crm-topnav button,
  .cm-header .cm-back,
  .cm-nav-row .cm-back,
  .cm-nav-row button,
  .cm-nav-row a {
    padding: 4px 6px !important;
    font-size: 11px !important;
    max-width: 90px;
  }
  .crm-topnav-btn[id*="Back" i],
  .crm-topnav-btn[id*="Hub"  i],
  .cm-back[id*="Back" i],
  .cm-back[id*="Hub"  i],
  .crm-nav-keep-label {
    max-width: none !important;
    min-width: max-content;
  }
}
/* ─── END TOPNAV CRAMPED-FIX ──────────────────────────────────────────── */


/* ── Issue 3 fix (2026-05-10 Edward round 3) — aggressive icon-only mode ── */
/* At ≤ 480px viewport, force icon-only on all crm-topnav-btn EXCEPT keep-label
   ones (← 返回 / 🏠 Hub). Strips text labels to first emoji/icon only. */
@media (max-width: 480px) {
  .crm-topnav { gap: 2px !important; padding: 5px 6px !important; }
  .crm-topnav .crm-topnav-btn:not(.crm-nav-keep-label):not([id*="Back" i]):not([id*="Hub" i]):not([title*="返回"]):not([title*="Hub" i]) {
    padding: 3px 5px !important;
    font-size: 13px !important;
    max-width: 36px !important;
    min-width: 28px !important;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: clip;
  }
  .crm-topnav .crm-topnav-btn[id*="Back" i],
  .crm-topnav .crm-topnav-btn[id*="Hub" i],
  .crm-topnav .crm-topnav-btn[title*="返回"],
  .crm-topnav .crm-topnav-btn[title*="Hub" i],
  .crm-topnav .crm-nav-keep-label {
    padding: 4px 8px !important;
    font-size: 11px !important;
    max-width: none !important;
    min-width: max-content !important;
  }
}
/* ── /Issue 3 fix ──────────────────────────────────────────────────────── */


/* ─── 28. LIGHT-MODE TOKEN REMAP (DAY-MODE CONTRAST FIX 2026-05-10) ──────────
   Root cause: theme.css was dark-only at :root level; per-page light overrides
   only remapped LEGACY tokens (--bg, --card, --text), leaving iOS tokens
   (--bg-main, --text-primary, --text-secondary, etc.) at dark values, which
   made card body text invisible on white surfaces in day mode (am_meetings,
   leads, oppty, others). Status / priority / source pills were also
   unreadable: rgba(brand,.15) on white + brand-color text = ~3:1 contrast,
   below WCAG AA. Skeleton-loader gray on white was equally invisible.

   This block adds a single fleet-wide light-mode override so every page
   inherits readable defaults; per-page overrides above still apply where
   pages already do their own remap.
   ──────────────────────────────────────────────────────────────────────── */
body.crm-light {
  /* Backgrounds — Tailwind gray-100 page / white surface (matches page conventions) */
  --bg-main:      #f3f4f6;
  --bg-surface:   #ffffff;
  --bg-elevated:  #ffffff;
  --bg-input:     #ffffff;
  --bg-hover:     #f3f4f6;

  /* Text — dark on light (Tailwind gray-900 / 600 / 500) */
  --text-primary:    #111827;
  --text-secondary:  #4b5563;
  --text-tertiary:   #6b7280;
  --text-inverse:    #ffffff;

  /* Borders & separators */
  --border:          #e5e7eb;
  --separator:       rgba(0,0,0,.08);

  /* Legacy aliases re-resolve via the iOS tokens above (no extra mapping needed) */
  --accent-soft:  rgba(10,132,255,.10);   /* lighter for white bg (2026-06-08) */

  /* Shadows tuned for white surface (stronger, lower opacity) */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:  0 8px 30px rgba(0,0,0,.14);

  /* Body itself uses the remapped tokens */
  background: var(--bg-main);
  color: var(--text-primary);
}

/* Inputs/textarea/select default border in light mode (override base reset) */
body.crm-light input,
body.crm-light textarea,
body.crm-light select {
  background: var(--bg-input);
  color: var(--text-primary);
  border-color: var(--border);
}

/* ── Pill / badge text in light mode ────────────────────────────────────────
   In dark mode, .badge-blue uses rgba(0,122,255,.15) bg + var(--blue) text.
   That same combination on a white surface gives ~3:1 contrast (fails AA).
   Darken the foreground text color in light mode so pills are readable.
   ──────────────────────────────────────────────────────────────────────── */
body.crm-light .badge-blue,
body.crm-light .t-blue,
body.crm-light .badge-qualification,
body.crm-light .badge-sent           { color: #1d4ed8; }      /* indigo-700 */
body.crm-light .badge-green,
body.crm-light .t-green,
body.crm-light .badge-won,
body.crm-light .badge-approved,
body.crm-light .badge-confirmed,
body.crm-light .badge-paid,
body.crm-light .amount-green         { color: #15803d; }      /* green-700 */
body.crm-light .badge-orange,
body.crm-light .t-orange,
body.crm-light .badge-negotiation    { color: #c2410c; }      /* orange-700 */
body.crm-light .badge-red,
body.crm-light .t-red,
body.crm-light .badge-lost,
body.crm-light .badge-cancelled      { color: #b91c1c; }      /* red-700 */
body.crm-light .badge-purple,
body.crm-light .t-purple,
body.crm-light .badge-proposal       { color: #6d28d9; }      /* violet-700 */
body.crm-light .badge-teal,
body.crm-light .badge-prospecting    { color: #0e7490; }      /* cyan-700 */
body.crm-light .badge-gray,
body.crm-light .badge-draft          { color: #4b5563; }      /* gray-600 */
body.crm-light .badge-invoiced       { color: #b45309; }      /* amber-700 */

/* AI NBA card header colors — same darkening for readability on light bg */
body.crm-light .ai-nba-header                       { color: #1d4ed8; }
body.crm-light .ai-nba-card.risk-HIGH .ai-nba-header   { color: #b91c1c; }
body.crm-light .ai-nba-card.risk-MEDIUM .ai-nba-header { color: #c2410c; }
body.crm-light .ai-nba-card.risk-LOW .ai-nba-header    { color: #15803d; }

/* Spinner: dark-mode uses rgba(255,255,255,.1) which is invisible on white.
   Switch the track ring to dark so the rotating segment is visible. */
body.crm-light .spinner { border-color: rgba(0,0,0,.1); border-top-color: var(--blue); }

/* Tab inactive border / text uses --border + --text-secondary which now resolve
   to light values via the token remap above. No extra rule needed for .tab. */

/* Step-dot inactive — uses --bg-elevated (now white) and --border (now gray-200);
   text uses --text-secondary (now gray-600). All readable via cascade. */

/* Stepper track: --border resolves to #e5e7eb in light. Visible on gray-100 bg. */

/* Stage segment: var(--bg-elevated) now white — visible track on gray-100 page bg. */

/* List item separator inherit. */

/* Modal-handle: was var(--text-tertiary) opacity .4 — works in both modes. */

/* Toast: bg now white via --bg-elevated; shadow strong via --shadow-lg remap. */

/* Loading-overlay: rgba(0,0,0,.5) — fine in both modes. */
/* ── /Light-mode token remap ──────────────────────────────────────────── */


/* ─── 29. PER-PAGE PILL OVERRIDES IN LIGHT MODE (DAY-MODE CONTRAST FIX) ──────
   Chips/pills that use literal hex (#0a84ff etc.) or var(--blue) text without
   any token alias still render faint on white in light mode. These rules
   darken the foreground only when body.crm-light is active. They live here
   (rather than in each page) so the fleet-wide fix is a single file.
   ──────────────────────────────────────────────────────────────────────── */

/* leads.html — status / priority / source filter chips (off state) */
body.crm-light .out3-chip[data-color="blue"]:not(.on)  { color:#1d4ed8; border-color:rgba(29,78,216,.45); }
body.crm-light .out3-chip[data-color="yellow"]:not(.on){ color:#b45309; border-color:rgba(180,83,9,.45); }
body.crm-light .out3-chip[data-color="green"]:not(.on) { color:#15803d; border-color:rgba(21,128,61,.45); }
body.crm-light .out3-chip[data-color="red"]:not(.on)   { color:#b91c1c; border-color:rgba(185,28,28,.45); }
body.crm-light .out3-chip[data-color="purple"]:not(.on){ color:#6d28d9; border-color:rgba(109,40,217,.45); }
body.crm-light .out3-chip[data-color="orange"]:not(.on){ color:#c2410c; border-color:rgba(194,65,12,.45); }
body.crm-light .out3-chip[data-color="teal"]:not(.on)  { color:#0e7490; border-color:rgba(14,116,144,.45); }
body.crm-light .out3-chip[data-color="grey"]:not(.on)  { color:#4b5563; border-color:rgba(75,85,99,.45); }
body.crm-light .out3-chiplbl                            { color:#4b5563; }
body.crm-light .out3-toolrow .out3-summary              { color:#4b5563; }
body.crm-light .out3-toolrow .out3-clearbtn             { color:#4b5563; }

/* leads.html — priority text (.priority-high etc.) */
body.crm-light .priority-high   { color:#b91c1c; }
body.crm-light .priority-medium { color:#c2410c; }

/* am_meetings.html — chip-scheduled / qualified / rejected / ai */
body.crm-light .chip-scheduled  { color:#c2410c; }
body.crm-light .chip-qualified  { color:#15803d; }
body.crm-light .chip-rejected   { color:#b91c1c; }
body.crm-light .chip-ai         { color:#6d28d9; }

/* am_meetings.html — day-chip (overdue / today / tomorrow / future) */
body.crm-light .day-chip.overdue  { color:#b91c1c; }
body.crm-light .day-chip.today    { color:#c2410c; }
body.crm-light .day-chip.tomorrow { color:#0e7490; }
body.crm-light .day-chip.future   { color:#15803d; }

/* am_meetings.html — action button text (act-q/r/l/o/v) */
body.crm-light .act-q { color:#15803d; border-color:rgba(21,128,61,.40); }
body.crm-light .act-r { color:#b91c1c; border-color:rgba(185,28,28,.35); }
body.crm-light .act-l { color:#1d4ed8; border-color:rgba(29,78,216,.40); }
body.crm-light .act-o { color:#6d28d9; border-color:rgba(109,40,217,.40); }
body.crm-light .act-v { color:#0e7490; border-color:rgba(14,116,144,.40); }
/* ── /Per-page pill overrides ─────────────────────────────────────────── */

/* ─────────────────────────────────────────────────────────────────────────
   Phase C — Opaque-background safety net for .crm-topnav
   Prevents first-paint flash of translucent (rgba) backgrounds before
   topnav_v2.js runs and sets inline background:var(--bg).
   Uses !important to defeat in-page <style> blocks that set rgba(...,.92).
   ───────────────────────────────────────────────────────────────────────── */
.crm-topnav,
.cm-header,
.cm-nav-row,
[class*="topnav"]:not(.crm-topnav-btn):not(.crm-topnav-left):not(.crm-topnav-right):not(.crm-topnav-spacer) {
  background: var(--bg, #0d0d0d) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
body.crm-light .crm-topnav,
body.crm-light .cm-header,
body.crm-light .cm-nav-row,
body.crm-light [class*="topnav"]:not(.crm-topnav-btn):not(.crm-topnav-left):not(.crm-topnav-right):not(.crm-topnav-spacer) {
  background: var(--bg, #ffffff) !important;
}

/* ── Round-12 P0 (Edward 2026-05-11): theme-aware nav bar — light mode bug fix ── */
/* Stronger than var(--bg) because some pages override --bg in inline <style>. */
body.crm-light .crm-topnav,
body.crm-light .cm-header,
body.crm-light .cm-nav-row,
body.crm-light [class*="topnav"]:not(.crm-topnav-btn):not(.crm-topnav-left):not(.crm-topnav-right):not(.crm-topnav-spacer) {
  background: #ffffff !important;
  border-bottom: 1px solid #e5e7eb !important;
  color: #111827 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
body.crm-dark .crm-topnav,
body.crm-dark .cm-header,
body.crm-dark .cm-nav-row,
body.crm-dark [class*="topnav"]:not(.crm-topnav-btn):not(.crm-topnav-left):not(.crm-topnav-right):not(.crm-topnav-spacer) {
  background: #0d0d0d !important;
  border-bottom: 1px solid #38383a !important;
  color: #f2f2f7 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
body.crm-light .crm-topnav-btn,
body.crm-light .cm-back {
  background: rgba(0,0,0,0.06) !important;
  color: #111827 !important;
  border-color: #e5e7eb !important;
}
body.crm-dark .crm-topnav-btn,
body.crm-dark .cm-back {
  background: rgba(255,255,255,0.08) !important;
  color: #f2f2f7 !important;
  border-color: #38383a !important;
}
body.crm-light .crm-topnav a,
body.crm-light .crm-topnav button,
body.crm-light .crm-topnav-title,
body.crm-light [data-topnav-title] {
  color: #111827 !important;
}
body.crm-dark .crm-topnav a,
body.crm-dark .crm-topnav button,
body.crm-dark .crm-topnav-title,
body.crm-dark [data-topnav-title] {
  color: #f2f2f7 !important;
}
/* DEMO_HUB_USER_PILL_CONTRAST_V1 2026-06-10 — login_widget user-pill span color rescue */
body.crm-light .crm-topnav [data-login-widget="1"] > span{color:#15803d !important}
body.crm-dark  .crm-topnav [data-login-widget="1"] > span{color:#30d158 !important}
/* Overflow ⋯ menu panel */
body.crm-light [data-topnav-overflow-panel] {
  background: #ffffff !important;
  border: 1px solid #e5e7eb !important;
  color: #111827 !important;
  box-shadow: 0 6px 24px rgba(0,0,0,.18) !important;
}
body.crm-light [data-topnav-overflow-panel] button {
  color: #111827 !important;
}
body.crm-light [data-topnav-overflow-panel] button:hover {
  background: #f3f4f6 !important;
}
/* ── /Round-12 P0 nav-bar theme fix ── */


/* ── Round-12 P0 (Edward Bug F 2026-05-11): theme-aware detail-header / topbar /
   action-bar — covers .ov-header (quote/oppty/lead detail sheets), .topbar
   (stats/oppty list pages), and any [class*="header"] with hardcoded rgba dark bg. ── */
body.crm-light .ov-header,
body.crm-light .topbar,
body.crm-light .top-bar,
body.crm-light .det-header,
body.crm-light .detail-header,
body.crm-light .sheet-header,
body.crm-light .modal-header {
  background: #ffffff !important;
  border-bottom: 1px solid #e5e7eb !important;
  color: #111827 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
body.crm-dark .ov-header,
body.crm-dark .topbar,
body.crm-dark .top-bar,
body.crm-dark .det-header,
body.crm-dark .detail-header,
body.crm-dark .sheet-header,
body.crm-dark .modal-header {
  background: #0d0d0d !important;
  border-bottom: 1px solid #38383a !important;
  color: #f2f2f7 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
body.crm-light .ov-header .title .t1,
body.crm-light .ov-header .title .t2,
body.crm-light .topbar h1,
body.crm-light .topbar .date {
  color: #111827 !important;
}
body.crm-dark .ov-header .title .t1,
body.crm-dark .ov-header .title .t2,
body.crm-dark .topbar h1,
body.crm-dark .topbar .date {
  color: #f2f2f7 !important;
}
body.crm-light .ov-header .action-btn,
body.crm-light .hdr-action-scroll .action-btn {
  background: rgba(10,132,255,0.12) !important;
  color: #0a84ff !important;
}
body.crm-dark .ov-header .action-btn,
body.crm-dark .hdr-action-scroll .action-btn {
  background: rgba(10,132,255,0.20) !important;
  color: #5ac8fa !important;
}
.overlay > .ov-header { padding-top: max(14px, env(safe-area-inset-top)) !important; }
/* ── /Bug F nav theme fix ── */

/* ── 2026-05-16 Safety-net light-mode overrides (v2 + text contrast) ──── */
/* Ensures card/row components show white bg + dark text in light mode,
   even if CSS variable cascade is blocked by local :root overrides.        */
body.crm-light .row,
body.crm-light .kpi-row,
body.crm-light .sp-card,
body.crm-light .modal-card,
body.crm-light .card { background: #ffffff !important; border-color: #e5e7eb !important; color: #111827 !important; }

/* Secondary / meta text — dark enough for WCAG AA on white */
body.crm-light .row-when,
body.crm-light .row-meta,
body.crm-light .row-notes,
body.crm-light .row-name { color: #374151 !important; }
body.crm-light .row-when { color: #6b7280 !important; }

body.crm-light .tab { background: rgba(0,0,0,.05); color: #374151; }
body.crm-light .tab.active { background: rgba(10,132,255,.12); color: #1d4ed8; border-color: rgba(10,132,255,.3); }
body.crm-light .row-meta .chip { background: rgba(0,0,0,.06); color: #374151; }
body.crm-light .sumcard { background: rgba(0,0,0,.04); color: #111827; border: 1px solid #e5e7eb; }
body.crm-light .sumcard .n { color: #111827; }
body.crm-light .sumcard .l { color: #4b5563; }
body.crm-light select,
body.crm-light input,
body.crm-light textarea { background: #ffffff; color: #111827; border-color: #d1d5db; }
body.crm-light .crm-topnav { background: rgba(255,255,255,.97) !important; border-bottom-color: #e5e7eb !important; }
body.crm-light .crm-topnav-btn { background: rgba(0,0,0,.05) !important; color: #374151 !important; border-color: #d1d5db !important; }
/* ── /Safety-net ─────────────────────────────────────────────────────────── */

/* Issue K: generic hover-card in light mode (manager team cards use inline bg:var(--card2)) */
body.crm-light .hover-card {
  background: #ffffff !important;
  border-color: #e5e7eb !important;
  color: #111827 !important;
}
body.crm-light .hover-card:active,
body.crm-light .hover-card:hover { background: #f9fafb !important; }
body.crm-dark .hover-card {
  background: #2c2c2e !important;
  border-color: #3a3a3c !important;
  color: #f2f2f7 !important;
}


/* ─── D1_PAGE_CONTAINER 2026-05-30 — shared max-width container for all CRM pages ─── */
.crm-page-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px;
  box-sizing: border-box;
}
@media (min-width: 1024px) {
  .crm-page-container { max-width: 1100px; padding: 24px; }
}
@media (min-width: 1440px) {
  .crm-page-container { max-width: 1280px; padding: 28px; }
}

/* ─── P3FIX_FLOATING_PILL_CLEANUP_V1 (2026-06-06) ──────────────────────────
 * Aggressive sitewide cleanup: kills the empty floating pill bug where
 * <div id="toast" class="toast"> leaks visible with opacity:1 because
 * the .toast animation:_toast-in...forwards keyframe holds the final state
 * even when no message is in flight. We force-hide when the element has no
 * content AND no explicit show/active class.
 * Applied via !important to override the animation's final-frame state.
 */
[id="toast"]:empty,
[id$="-toast"]:empty,
.toast:empty,
.toast:not(.show):not(.active):not(.in):not(.visible):not(.out):empty {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  animation: none !important;
  transform: translateX(-50%) translateY(-200%) !important;
}

/* Even when there IS content (e.g. a stale toast left over from a previous
 * page action), if not actively marked as show/active, still hide. The
 * :not() chain covers the common state-class names across the codebase. */
.toast:not(.show):not(.active):not(.in):not(.visible):not(.out):not(.toast-success):not(.toast-error):not(.toast-info):not(.toast-warn) {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* And belt-and-braces: any non-floating inline pill div (typical pattern of
 * inline status indicators that JS forgets to clear) gets hidden when empty. */
[class*="floating-pill"]:empty,
[class*="status-pill"]:empty,
[id*="-pill"]:empty {
  display: none !important;
}


/* ─── MUSIC_PORTAL_UNIFY_APPLIED_20260615 — music-portal brand + attendance status tokens ───
   Single source for the 5 LIVE music pages (schedule/attendance/salary/student_profile/fee_tier_admin).
   Dark = original _music_shared palette; light = 700-weight for AA contrast on white. */
:root {
  --music-accent:       var(--blue);   /* MUSIC_BLUE_V1 2026-07-22: unified to CRM iOS blue (was #ff9a3c) */
  --music-accent-soft:  rgba(10,132,255,.13);
  --music-present:      #4caf50;
  --music-late:         #ffb300;
  --music-absent:       #e53935;
  --music-makeup:       #2196f3;
  --music-sick:         #ab47bc;
  --music-cancel:       #757575;
}
body.crm-light {
  --music-accent:       var(--blue);   /* MUSIC_BLUE_V1: CRM blue in light too (was #c2410c) */
  --music-accent-soft:  rgba(10,132,255,.10);
  --music-present:      #15803d;   /* green-700 */
  --music-late:         #b45309;   /* amber-700 */
  --music-absent:       #b91c1c;   /* red-700 */
  --music-makeup:       #1d4ed8;   /* indigo-700 */
  --music-sick:         #6d28d9;   /* violet-700 */
  --music-cancel:       #4b5563;   /* gray-600 */
}

/* ─── WhatsApp simulator palette — embedded parent-query widget (attendance.html) ───
   Faithful WhatsApp Web brand colours; single-sourced so the simulator stays brand-accurate
   while pages keep 0 hardcoded hex. Added MUSIC_PORTAL_UNIFY 2026-06-15. */
:root {
  --wa-chip-bg:      #2a3942;
  --wa-chip-fg:      #e9edef;
  --wa-chip-border:  #3b4a54;
  --wa-chip-hover:   #374248;
  --wa-green:        #00a884;
  --wa-hist-bg:      #0b141a;
  --wa-hist-border:  #1f2c33;
  --wa-hint:         #8696a0;
  --wa-bubble-me:    #005c4b;
  --wa-bubble-bot:   #202c33;
  --wa-bubble-fg:    #e9edef;
  --wa-meta:         #8696a0;
}
body.crm-light {
  --wa-chip-bg:      #f0f2f5;
  --wa-chip-fg:      #111b21;
  --wa-chip-border:  #d1d7db;
  --wa-chip-hover:   #e6e8eb;
  --wa-hist-bg:      #e5ddd5;
  --wa-hist-border:  #d1c7bd;
  --wa-hint:         #667781;
  --wa-bubble-me:    #d9fdd3;
  --wa-bubble-bot:   #ffffff;
  --wa-bubble-fg:    #111b21;
  --wa-meta:         #667781;
}


/* ═══════════════════ TOKEN_UNFREEZE_V1 2026-07-22 (Batch 0) ═══════════════════
   The legacy aliases above are declared at :root with var() references. Custom
   properties substitute at the DECLARING element, so they froze at the dark
   values and body.crm-light never reached them (the "re-resolve" comment in the
   light block was wrong). Re-declaring on body makes them resolve against the
   CURRENT theme's tokens. Scoped to body.crm-light ONLY: dark mode's cascade is
   untouched (pages with custom :root alias values e.g. quote's --bg:#0d0d0d keep
   them verbatim in dark), so dark is byte-identical by construction. Music pages
   keep their orange: _music_demo_ux.css loads later and re-declares on body. */
body.crm-light {
  --color-primary: var(--blue); --color-success: var(--green);
  --color-warning: var(--orange); --color-danger: var(--red); --color-ai: var(--purple);
  --text-link: var(--blue); --border-focus: var(--blue);
  --bg: var(--bg-main); --card: var(--bg-surface); --card2: var(--bg-elevated);
  --text: var(--text-primary); --text2: var(--text-secondary);
  --fg: var(--text-primary); --muted: var(--text-secondary); --sub: var(--text-tertiary);
  --line: var(--border); --accent: var(--blue); --brand: var(--blue); --brand2: var(--indigo);
  --ink: var(--text-primary); --ink2: var(--text-secondary); --ink3: var(--text-tertiary);
}

/* Batch 0 — approved light text tokens (AA: secondary 8:1, tertiary 7:1) */
body.crm-light { --text-secondary:#374151; --text-tertiary:#4b5563; }

/* Batch 0 — global light input/field rules (WCAG AA) */
body.crm-light input, body.crm-light textarea, body.crm-light select {
  background-color: var(--bg-input); color: var(--text-primary);
  border-color: #d1d5db; caret-color: var(--blue);
}
body.crm-light input::placeholder, body.crm-light textarea::placeholder { color:#6b7280; opacity:1; }
body.crm-light select option { background:#ffffff; color:#111827; }
body.crm-light input:focus, body.crm-light textarea:focus, body.crm-light select:focus {
  border-color: var(--blue);
}

/* ═══ SEMANTIC_TEXT_LIGHT_V1 2026-07-22 (Batch 1) ═══
   Pages colour KPI numbers with inline dark-theme semantic colours
   (style="color:#ff9f0a" / var(--yellow) / var(--green)). On light surfaces those
   sit at 1.4–2.5:1. Attribute-substring overrides swap in AA-dark variants in
   light mode only — no page markup touched, dark mode untouched. */
body.crm-light [style*="color:#ff9f0a"], body.crm-light [style*="color: #ff9f0a"] { color:#c2410c !important; }
body.crm-light [style*="color:var(--yellow)"], body.crm-light [style*="color: var(--yellow)"] { color:#a16207 !important; }
body.crm-light [style*="color:var(--green)"], body.crm-light [style*="color: var(--green)"] { color:#15803d !important; }
body.crm-light [style*="color:#30d158"], body.crm-light [style*="color: #30d158"] { color:#15803d !important; }
body.crm-light [style*="color:#ff453a"], body.crm-light [style*="color: #ff453a"] { color:#b91c1c !important; }
body.crm-light [style*="color:#ffd60a"], body.crm-light [style*="color: #ffd60a"] { color:#a16207 !important; }
/* shared ai_autofill banners/badges: brighten-tinted text -> dark variants in light */
body.crm-light .ai-autofill-banner.success, body.crm-light .ai-confidence-badge.high { color:#15803d; }
body.crm-light .ai-autofill-banner.warn, body.crm-light .ai-confidence-badge.medium { color:#92400e; }
body.crm-light .ai-autofill-banner.error { color:#b91c1c; }
