/* DESIGN TOKENS
   All colors live here as CSS custom properties. Rules below reference
   tokens only — adding a theme means adding one override block, never
   touching component styles. Dark is the default (:root); other themes
   override via [data-theme="..."] set on <html> — the theme helpers
   (THEMES/applyTheme) live in src/api.js, and index.html has a pre-paint
   script that restores the saved theme before first render.
   Soft badge tints are derived with color-mix() from the hue tokens so
   each theme defines ~6 hues instead of 40 badge colors. */

:root {
    /* Dark (default) */
    --bg:            #0b1220;   /* app background */
    --surface:       #151e2e;   /* cards, panels, modals */
    --surface-2:     #1b2537;   /* headers, alt fills */
    --surface-3:     #26334a;   /* hover fills */
    --border:        #2a3850;
    --border-soft:   #1f2b3f;
    --text:          #e2e8f0;
    --text-2:        #a9b6c9;   /* secondary */
    --text-3:        #6f7f96;   /* muted */

    --accent:        #3b82f6;
    --accent-hover:  #5b96f8;
    --on-accent:     #ffffff;

    --danger:        #ef4444;
    --danger-hover:  #dc2626;
    --success:       #10b981;
    --warning:       #f59e0b;

    /* Top nav — its own tokens so it can stay dark in the light theme */
    --nav-bg:        #101a2b;
    --nav-surface:   #243349;
    --nav-surface-2: #2e4059;
    --nav-text:      #e2e8f0;
    --nav-text-2:    #8fa0b8;

    /* Hues for soft badges (brighter than accent shades so they read on dark) */
    --hue-blue:  #60a5fa;
    --hue-green: #34d399;
    --hue-amber: #fbbf24;
    --hue-red:   #f87171;
    --hue-pink:  #f472b6;
    --hue-slate: #94a3b8;

    --shadow-1: 0 1px 3px rgba(0,0,0,0.35);
    --shadow-2: 0 2px 8px rgba(0,0,0,0.45);
    --shadow-3: 0 10px 25px rgba(0,0,0,0.55);

    color-scheme: dark;  /* native scrollbars/inputs match the theme */
}

[data-theme="light"] {
    --bg:            #f8fafc;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --surface-3:     #e2e8f0;
    --border:        #e2e8f0;
    --border-soft:   #f1f5f9;
    --text:          #334155;
    --text-2:        #4b5563;
    --text-3:        #9ca3af;

    --accent:        #3b82f6;
    --accent-hover:  #2563eb;

    --nav-bg:        #1e293b;
    --nav-surface:   #334155;
    --nav-surface-2: #475569;
    --nav-text:      #e2e8f0;
    --nav-text-2:    #94a3b8;

    --hue-blue:  #1d4ed8;
    --hue-green: #065f46;
    --hue-amber: #92400e;
    --hue-red:   #dc2626;
    --hue-pink:  #9d174d;
    --hue-slate: #475569;

    --shadow-1: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-2: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-3: 0 10px 25px rgba(0,0,0,0.25);

    color-scheme: light;
}

[data-theme="ocean"] {
    --bg:            #081a1e;
    --surface:       #0f262c;
    --surface-2:     #132e35;
    --surface-3:     #1d3f48;
    --border:        #1f414a;
    --border-soft:   #16333b;
    --text:          #dcf0f2;
    --text-2:        #9fbfc4;
    --text-3:        #64858c;

    --accent:        #14b8a6;
    --accent-hover:  #2dd4bf;

    --nav-bg:        #0a2126;
    --nav-surface:   #1a3d45;
    --nav-surface-2: #234c56;
    --nav-text:      #dcf0f2;
    --nav-text-2:    #7fa3aa;

    --hue-blue:  #22d3ee;
    --hue-green: #34d399;
    --hue-amber: #fbbf24;
    --hue-red:   #f87171;
    --hue-pink:  #f472b6;
    --hue-slate: #94b0b6;
}

[data-theme="forest"] {
    --bg:            #0c1510;
    --surface:       #14211a;
    --surface-2:     #182a20;
    --surface-3:     #23392c;
    --border:        #27402f;
    --border-soft:   #1c3023;
    --text:          #e2efe6;
    --text-2:        #a6bfae;
    --text-3:        #6b8573;

    --accent:        #22c55e;
    --accent-hover:  #4ade80;

    --nav-bg:        #101c15;
    --nav-surface:   #223a2b;
    --nav-surface-2: #2c4a37;
    --nav-text:      #e2efe6;
    --nav-text-2:    #86a190;

    --hue-blue:  #60a5fa;
    --hue-green: #4ade80;
    --hue-amber: #fbbf24;
    --hue-red:   #f87171;
    --hue-pink:  #f472b6;
    --hue-slate: #9ab0a1;
}

[data-theme="crimson"] {
    --bg:            #170c0e;
    --surface:       #241317;
    --surface-2:     #2b171c;
    --surface-3:     #3b2027;
    --border:        #402229;
    --border-soft:   #2f181e;
    --text:          #f0e2e5;
    --text-2:        #c4a9b0;
    --text-3:        #96707a;

    --accent:        #ef4444;
    --accent-hover:  #f87171;

    /* danger needs to stay readable against the red accent — shift it deeper */
    --danger:        #b91c1c;
    --danger-hover:  #991b1b;

    --nav-bg:        #1d0f13;
    --nav-surface:   #3a1e25;
    --nav-surface-2: #4a2630;
    --nav-text:      #f0e2e5;
    --nav-text-2:    #b88f98;

    --hue-blue:  #60a5fa;
    --hue-green: #34d399;
    --hue-amber: #fbbf24;
    --hue-red:   #f87171;
    --hue-pink:  #f472b6;
    --hue-slate: #b09aa0;
}

[data-theme="midnight"] {
    /* Deeper, bluer take on the default dark — navy blacks, richer accent */
    --bg:            #040915;
    --surface:       #0a1326;
    --surface-2:     #0e1a33;
    --surface-3:     #172647;
    --border:        #1d2e52;
    --border-soft:   #131f3d;
    --text:          #dce5f5;
    --text-2:        #a0b1cf;
    --text-3:        #647698;

    --accent:        #2563eb;
    --accent-hover:  #3b82f6;

    --nav-bg:        #060d1d;
    --nav-surface:   #142344;
    --nav-surface-2: #1c2f5a;
    --nav-text:      #dce5f5;
    --nav-text-2:    #8497ba;

    --hue-blue:  #60a5fa;
    --hue-green: #34d399;
    --hue-amber: #fbbf24;
    --hue-red:   #f87171;
    --hue-pink:  #f472b6;
    --hue-slate: #94a3c0;

    --shadow-1: 0 1px 3px rgba(0,0,0,0.45);
    --shadow-2: 0 2px 8px rgba(0,0,0,0.55);
    --shadow-3: 0 10px 25px rgba(0,0,0,0.65);
}

[data-theme="amethyst"] {
    /* Deep purple — violet accent on plum-black surfaces */
    --bg:            #120c1d;
    --surface:       #1c1330;
    --surface-2:     #231840;
    --surface-3:     #32245c;
    --border:        #392a63;
    --border-soft:   #281c49;
    --text:          #ebe4f7;
    --text-2:        #b7a9d4;
    --text-3:        #7d6fa0;

    --accent:        #a855f7;
    --accent-hover:  #c084fc;

    --nav-bg:        #160f26;
    --nav-surface:   #2b1e4e;
    --nav-surface-2: #382863;
    --nav-text:      #ebe4f7;
    --nav-text-2:    #9a8bc0;

    --hue-blue:  #60a5fa;
    --hue-green: #34d399;
    --hue-amber: #fbbf24;
    --hue-red:   #f87171;
    --hue-pink:  #e879f9;
    --hue-slate: #a79bc4;
}

[data-theme="ember"] {
    /* Warm charcoal-brown darks, campfire-orange accent */
    --bg:            #16100b;
    --surface:       #221913;
    --surface-2:     #2a1f17;
    --surface-3:     #3b2c20;
    --border:        #422f21;
    --border-soft:   #2f2218;
    --text:          #f2e8e0;
    --text-2:        #c8b3a3;
    --text-3:        #94806f;

    --accent:        #f97316;
    --accent-hover:  #fb923c;

    --nav-bg:        #1b130d;
    --nav-surface:   #362617;
    --nav-surface-2: #46311e;
    --nav-text:      #f2e8e0;
    --nav-text-2:    #b3987f;

    --hue-blue:  #60a5fa;
    --hue-green: #34d399;
    --hue-amber: #fbbf24;
    --hue-red:   #f87171;
    --hue-pink:  #f472b6;
    --hue-slate: #b0a396;
}

[data-theme="latte"] {
    /* Warm cream light theme — coffee-brown accent, dark espresso nav */
    --bg:            #f6f1e9;
    --surface:       #fffdf8;
    --surface-2:     #f6f1e9;
    --surface-3:     #e9e0d2;
    --border:        #e2d8c8;
    --border-soft:   #efe8dc;
    --text:          #443c32;
    --text-2:        #5f564a;
    --text-3:        #a0968a;

    --accent:        #b45309;
    --accent-hover:  #92400e;

    --nav-bg:        #362c22;
    --nav-surface:   #4a3d30;
    --nav-surface-2: #5c4c3c;
    --nav-text:      #f2e8e0;
    --nav-text-2:    #b8a794;

    /* deep hues so badges read on cream (same move as the light theme) */
    --hue-blue:  #1d4ed8;
    --hue-green: #065f46;
    --hue-amber: #92400e;
    --hue-red:   #dc2626;
    --hue-pink:  #9d174d;
    --hue-slate: #57534e;

    --shadow-1: 0 1px 3px rgba(60,45,25,0.12);
    --shadow-2: 0 2px 8px rgba(60,45,25,0.1);
    --shadow-3: 0 10px 25px rgba(60,45,25,0.25);

    color-scheme: light;
}

[data-theme="synthwave"] {
    /* Retrowave — deep violet night, hot-pink accent, cyan-leaning badges */
    --bg:            #150a2e;
    --surface:       #1f1140;
    --surface-2:     #261650;
    --surface-3:     #372070;
    --border:        #3d2578;
    --border-soft:   #2b1a58;
    --text:          #f3e8ff;
    --text-2:        #c3aee8;
    --text-3:        #8570b3;

    --accent:        #ff2ea6;
    --accent-hover:  #ff5cbd;

    --nav-bg:        #190d38;
    --nav-surface:   #321c66;
    --nav-surface-2: #402581;
    --nav-text:      #f3e8ff;
    --nav-text-2:    #a58fd6;

    --hue-blue:  #22d3ee;
    --hue-green: #2dd4bf;
    --hue-amber: #fbbf24;
    --hue-red:   #fb7185;
    --hue-pink:  #f0abfc;
    --hue-slate: #a79bd0;
}

[data-theme="neon"] {
    /* High contrast — true black, electric green. Bright accent needs dark
       button text, so --on-accent flips (the crimson-overrides-danger move). */
    --bg:            #000000;
    --surface:       #0a0f0a;
    --surface-2:     #101710;
    --surface-3:     #1a241a;
    --border:        #2b3d2b;
    --border-soft:   #182218;
    --text:          #f2fff2;
    --text-2:        #b8d8b8;
    --text-3:        #7fae7f;

    --accent:        #00e676;
    --accent-hover:  #33ff99;
    --on-accent:     #001a0d;

    --nav-bg:        #050805;
    --nav-surface:   #142014;
    --nav-surface-2: #1e2f1e;
    --nav-text:      #f2fff2;
    --nav-text-2:    #8fbb8f;

    --hue-blue:  #4dd2ff;
    --hue-green: #4dff88;
    --hue-amber: #ffd24d;
    --hue-red:   #ff5c5c;
    --hue-pink:  #ff5cd6;
    --hue-slate: #a8c0a8;
}

[data-theme="onyx"] {
    /* Black & gold — the luxury one. Gold accent takes dark ink text. */
    --bg:            #0a0a0c;
    --surface:       #131316;
    --surface-2:     #18181c;
    --surface-3:     #232329;
    --border:        #2e2e36;
    --border-soft:   #1e1e24;
    --text:          #ece9e2;
    --text-2:        #b3ae9f;
    --text-3:        #7a7568;

    --accent:        #d4af37;
    --accent-hover:  #e6c65c;
    --on-accent:     #1a1405;

    --nav-bg:        #0d0d10;
    --nav-surface:   #232326;
    --nav-surface-2: #2e2e33;
    --nav-text:      #ece9e2;
    --nav-text-2:    #9a9484;

    --hue-blue:  #60a5fa;
    --hue-green: #34d399;
    --hue-amber: #eab308;
    --hue-red:   #f87171;
    --hue-pink:  #f472b6;
    --hue-slate: #a8a293;
}

/* Derived soft tints — badge backgrounds computed from hue + surface */
:root {
    --soft-blue:  color-mix(in srgb, var(--hue-blue)  16%, var(--surface));
    --soft-green: color-mix(in srgb, var(--hue-green) 16%, var(--surface));
    --soft-amber: color-mix(in srgb, var(--hue-amber) 16%, var(--surface));
    --soft-red:   color-mix(in srgb, var(--hue-red)   16%, var(--surface));
    --soft-pink:  color-mix(in srgb, var(--hue-pink)  16%, var(--surface));
    --soft-slate: color-mix(in srgb, var(--hue-slate) 16%, var(--surface));
    --accent-soft: color-mix(in srgb, var(--accent) 14%, var(--surface));
    --focus-ring:  color-mix(in srgb, var(--accent) 20%, transparent);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }

/* ── Login ── */
/* Overflow-safe centering: margin:auto on the card (not align-items:center on
   the screen) — when the card outgrows a phone viewport (e.g. activation with
   the terms box expanded), auto margins collapse and the whole card stays
   scrollable. Centered-flex would clip the top AND strand the submit button
   off-screen on iOS (the bug a real customer hit on an iPhone, 2026-08-04). */
.login-screen { min-height: 100vh; display: flex; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%); overflow: auto; color: white; padding: 1rem; }
.login-card { background: var(--surface); border-radius: 0.75rem; padding: 3rem; width: 100%; max-width: 420px; box-shadow: 0 25px 60px rgba(0,0,0,0.4); color: var(--text); margin: auto; }
@media (max-width: 480px) {
  .login-card { padding: 1.75rem 1.25rem; }
}
.login-logo { text-align: center; margin-bottom: 2rem; }
/* Logo is an <img> of assets/logo.svg — the badge background is baked into the SVG */
.login-logo-mark { width: 72px; height: 72px; display: inline-block; margin-bottom: 1rem; filter: drop-shadow(0 4px 12px rgba(59,130,246,0.35)); }
.login-logo h1 { font-size: 1.375rem; font-weight: 700; color: var(--text); }
.login-logo p { font-size: 0.8rem; color: var(--text-3); margin-top: 0.25rem; letter-spacing: 0.05em; text-transform: uppercase; }
.login-error { background: var(--soft-red); border: 1px solid color-mix(in srgb, var(--hue-red) 35%, var(--surface)); color: var(--hue-red); padding: 0.75rem 1rem; border-radius: 0.375rem; font-size: 0.875rem; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.login-submit { width: 100%; padding: 0.875rem; background: var(--accent); color: var(--on-accent); border: none; border-radius: 0.375rem; font-size: 0.9375rem; font-weight: 600; cursor: pointer; transition: background 0.2s; margin-top: 0.5rem; }
.login-submit:hover { background: var(--accent-hover); }
.login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Layout: icon rail + main column (rail UI, 2026-08-09) ── */
.crm-container { height: 100vh; display: flex; }
/* Must be a flex column: full-height views (.account-detail-view, .tasks-page)
   rely on flex sizing so their bodies get a bounded height and can scroll. */
.main-col { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; background: var(--bg); }

/* The rail — icon-only nav strip, the app's only navigation. Reuses the nav
   tokens so it stays dark across light themes, same as the old top nav did. */
.rail { width: 52px; background: var(--nav-bg); border-right: 1px solid var(--border-soft); display: flex; flex-direction: column; align-items: center; padding: 0.5rem 0; flex-shrink: 0; z-index: 100; }
.rail-logo { width: 36px; height: 36px; border-radius: 0.5rem; display: flex; align-items: center; justify-content: center; margin-bottom: 0.875rem; overflow: hidden; }
.rail-logo img { max-width: 36px; max-height: 36px; object-fit: contain; display: block; }
.rail-btn { position: relative; width: 40px; height: 40px; margin: 2px 0; border: none; background: none; color: var(--nav-text-2); border-radius: 0.5rem; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; text-decoration: none; }
.rail-btn:hover { background: var(--nav-surface); color: var(--nav-text); }
.rail-btn.active { background: var(--nav-surface-2); color: var(--accent); }
.rail-btn.active::before { content: ''; position: absolute; left: -6px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--accent); }
/* Instant tooltip — no hover delay, sits just right of the rail */
.rail-btn::after { content: attr(data-tip); position: absolute; left: 50px; top: 50%; transform: translateY(-50%); background: var(--surface-3); color: var(--text); font-size: 0.75rem; font-weight: 600; padding: 0.3rem 0.55rem; border-radius: 0.375rem; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 0.1s; box-shadow: var(--shadow-2); z-index: 200; }
.rail-btn:hover::after { opacity: 1; }
.rail-badge { position: absolute; top: 3px; right: 3px; min-width: 15px; height: 15px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 0.6rem; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 3px; }

/* Topbar — view title + global search + workspace identity + user chip */
.topbar { height: 48px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.75rem; padding: 0 1.25rem; flex-shrink: 0; }
.topbar-title { font-size: 1rem; font-weight: 700; color: var(--text); margin: 0; white-space: nowrap; }
.topbar-crumb { color: var(--text-3); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-search { margin-left: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: 0.5rem; padding: 0.4rem 0.75rem; width: 260px; color: var(--text-3); font-size: 0.85rem; display: flex; gap: 0.5rem; align-items: center; cursor: pointer; font-family: inherit; transition: border-color 0.15s; flex-shrink: 0; }
.topbar-search:hover { border-color: var(--accent); color: var(--text-2); }
.topbar-search-label { flex: 1; text-align: left; }
.topbar-search-kbd { font-size: 0.7rem; border: 1px solid var(--border); border-radius: 0.25rem; padding: 0 4px; font-family: inherit; }
/* Topbar utility icons (fullscreen / settings / sign out) — top right */
.topbar-icon-btn { background: none; border: none; color: var(--text-3); cursor: pointer; padding: 0.375rem 0.5rem; border-radius: 0.375rem; font-size: 1rem; transition: all 0.15s; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.topbar-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.topbar-icon-btn.active { background: var(--accent); color: var(--on-accent); }

.search-box { width: 100%; padding: 0.75rem; border: 1px solid var(--border); border-radius: 0.375rem; font-size: 0.875rem; background: var(--surface); color: var(--text); }
.search-box:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }

/* ── Account split screen: account column + docked doc pane ── */
.account-detail-split { flex: 1; display: flex; overflow: hidden; min-height: 0; }
/* The pane reuses DocDetailModal's content with pane chrome instead of a
   modal overlay — same document, docked beside the account. */
.doc-pane { width: 44%; min-width: 420px; max-width: 720px; border-left: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; }
.doc-pane-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface-2); flex-shrink: 0; }
.doc-pane-body { flex: 1; overflow-y: auto; padding: 1.25rem; }

/* ── Popout window mode (?focus=1): just the doc, no app chrome ── */
.focus-shell { height: 100vh; display: flex; background: var(--bg); }
.focus-shell .doc-pane { width: 100%; max-width: none; min-width: 0; border-left: none; }

/* ── Billing view: Quotes/Invoices grouped behind one nav tab ── */
.billing-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.billing-toggle { display: flex; width: 260px; margin: 1rem 1.5rem 0; border: 1px solid var(--border); border-radius: 0.375rem; overflow: hidden; flex-shrink: 0; }

/* ── Tags / badges ── */
.tag, .badge { background: var(--accent); color: var(--on-accent); padding: 0.25rem 0.5rem; border-radius: 0.25rem; font-size: 0.75rem; font-weight: 500; }
.badge.secondary { background: var(--surface-3); color: var(--text-2); }
.badge.success { background: var(--success); color: white; }
.tag.priority-high { background: #ef4444; color: white; }
.tag.priority-urgent { background: #dc2626; color: white; }

/* Billing-stage badges (derived-only header state) — outline style so they
   read as machine state, distinct from the solid hand-colored tag pills. */
.badge.stage-badge { background: transparent; border: 1px solid; font-weight: 600; }
.badge.stage-quoted   { color: #8b5cf6; border-color: #8b5cf644; background: #8b5cf614; }
.badge.stage-pending  { color: #f59e0b; border-color: #f59e0b44; background: #f59e0b14; }
.badge.stage-invoiced { color: #3b82f6; border-color: #3b82f644; background: #3b82f614; }
.badge.stage-paid     { color: #10b981; border-color: #10b98144; background: #10b98114; }
.badge.urgent-flare   { background: var(--danger); color: white; font-weight: 700; }
/* Service pills — pipeline-conferred "WEB: ACTIVE" status chips. Muted tag
   treatment (rail UI pass): tinted text + thin border, no solid fill — the
   component passes the tag color inline. Never rendered for manual tags. */
.badge.service-pill   { background: transparent; border: 1px solid; font-weight: 700; letter-spacing: 0.03em; }

/* ── Empty / Loading states ── */
.empty-state { text-align: center; padding: 2rem; color: var(--text-3); }
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; display: block; }
.empty-state-title { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-2); }
.empty-state-message { margin-bottom: 1.5rem; }
.loading-state { text-align: center; padding: 2rem; color: var(--text-3); }
.loading-state i { font-size: 1.5rem; margin-bottom: 0.5rem; display: block; }

/* ── Buttons ── */
.btn { padding: 0.75rem 1.5rem; border: none; border-radius: 0.375rem; font-weight: 500; cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; line-height: 1; white-space: nowrap; /* labels never break mid-button — the row wraps instead */ }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-3); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-small { padding: 0.5rem 0.75rem; font-size: 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; margin-top: 1.5rem; /* wrap beats clipping in narrow panes (docked doc view) */ }

/* ── Modals ── */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: var(--surface); border-radius: 0.5rem; max-width: 90vw; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-3); }
.modal-medium { max-width: 600px; width: 90%; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1.5rem 2rem; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 1.25rem; font-weight: 600; margin: 0; }
.modal-close-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-3); padding: 0.25rem; line-height: 1; }
.modal-close-btn:hover { color: var(--text); }
.modal-body { padding: 2rem; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.form-group { display: flex; flex-direction: column; }
.form-group.full-width { grid-column: span 2; }
.form-label { font-weight: 500; margin-bottom: 0.5rem; color: var(--text-2); font-size: 0.875rem; }
.form-input { padding: 0.75rem; border: 1px solid var(--border); border-radius: 0.375rem; font-size: 0.875rem; transition: all 0.2s; width: 100%; background: var(--surface); color: var(--text); }
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.form-input:read-only { background: var(--surface-2); color: var(--text-3); cursor: default; }
.form-textarea { min-height: 100px; resize: vertical; }
.form-section { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: none; margin-bottom: 0; }
.form-section h4 { font-size: 0.9375rem; font-weight: 600; color: var(--text-2); margin-bottom: 1rem; }
.api-error { background: var(--soft-red); border: 1px solid color-mix(in srgb, var(--hue-red) 35%, var(--surface)); color: var(--hue-red); padding: 0.75rem 1rem; border-radius: 0.375rem; font-size: 0.875rem; margin-bottom: 1rem; }
/* Type-ahead account picker */
.account-picker { position: relative; }
.account-picker-chip { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 0.375rem; background: var(--surface); }
.account-picker-menu { position: absolute; z-index: 40; top: calc(100% + 2px); left: 0; right: 0; max-height: 260px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 0.375rem; box-shadow: 0 8px 24px rgba(0,0,0,0.25); }
.account-picker-item { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.875rem; }
.account-picker-item:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.account-picker-empty { padding: 0.6rem 0.75rem; font-size: 0.8125rem; color: var(--text-3); }

/* Deep links: doc numbers / account names are real <a> (so the browser can
   open them in tabs) — strip anchor styling, keep the surrounding look. */
.doc-link { text-decoration: none; color: inherit; }
.doc-link:hover { text-decoration: underline; }

.row-clickable { cursor: pointer; }
/* Whole row is the click target: stronger tint + accent hairlines top/bottom
   so the hovered row reads as one outlined unit (sides meet the table edge). */
.row-clickable:hover td {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    box-shadow: inset 0 1px 0 color-mix(in srgb, var(--accent) 40%, transparent),
                inset 0 -1px 0 color-mix(in srgb, var(--accent) 40%, transparent);
}
.api-success { background: color-mix(in srgb, var(--hue-green) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--hue-green) 35%, var(--surface)); color: var(--hue-green); padding: 0.75rem 1rem; border-radius: 0.375rem; font-size: 0.875rem; margin-bottom: 1rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
    /* No room for side-by-side on a phone — the doc pane stacks below. */
    .account-detail-split { flex-direction: column; }
    .doc-pane { width: 100%; min-width: 0; max-width: none; border-left: none; border-top: 1px solid var(--border); }
    .form-grid { grid-template-columns: 1fr; }
    .form-group.full-width { grid-column: span 1; }
    /* Search shrinks to its icon; the rail itself already fits a phone. */
    .topbar-search { width: auto; }
    .topbar-search-label, .topbar-search-kbd { display: none; }
}

/* ── Settings tables (the drawer shell these once framed died with AdminPanel v0.16 / SettingsModal v0.32) ── */
.user-table, .admin-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.user-table th, .admin-table th { text-align: left; padding: 0.75rem 1rem; background: var(--surface-2); border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-2); font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.04em; }
.user-table td, .admin-table td { padding: 0.875rem 1rem; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.user-table tr:hover td, .admin-table tr:hover td { background: var(--surface-2); }
.user-table tr.inactive td, .admin-table tr.inactive td { opacity: 0.5; }
.role-badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 0.25rem; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.role-badge.rep { background: var(--soft-blue); color: var(--hue-blue); }
.role-badge.manager { background: var(--soft-green); color: var(--hue-green); }
.role-badge.admin { background: var(--soft-pink); color: var(--hue-pink); }
.inline-select { padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: 0.25rem; font-size: 0.8125rem; background: var(--surface); color: var(--text); cursor: pointer; }
.inline-select:focus { outline: none; border-color: var(--accent); }
.btn-icon-sm, .btn-icon { background: none; border: none; cursor: pointer; padding: 0.3rem 0.4rem; border-radius: 0.25rem; font-size: 0.8125rem; transition: all 0.15s; color: var(--text-3); }
.btn-icon-sm:hover, .btn-icon:hover { background: var(--surface-3); color: var(--text); }
.btn-icon-sm.danger:hover, .btn-icon.danger:hover { background: var(--soft-red); color: var(--hue-red); }
.reassign-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 0.5rem; padding: 1.25rem; margin-top: 1.5rem; }
.reassign-box h4 { font-size: 0.9375rem; font-weight: 600; color: var(--text-2); margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.reassign-row { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.my-accounts-toggle { display: flex; align-items: center; gap: 0; border: 1px solid var(--border); border-radius: 0.375rem; overflow: hidden; margin-bottom: 1rem; }
.toggle-btn { flex: 1; padding: 0.5rem; border: none; background: var(--surface); cursor: pointer; font-size: 0.8125rem; color: var(--text-3); transition: all 0.15s; text-align: center; }
.toggle-btn.active { background: var(--accent); color: var(--on-accent); font-weight: 500; }
.toggle-btn:not(.active):hover { background: var(--surface-2); }

/* ── Contacts ── */
.contact-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 0.5rem; padding: 0.875rem 1rem; margin-bottom: 0.625rem; }
.contact-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.5rem; }
.contact-card-name { font-weight: 600; font-size: 0.9375rem; }
.contact-card-title { font-size: 0.8125rem; color: var(--text-3); }
.contact-card-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.contact-card-detail { display: flex; align-items: center; gap: 0.375rem; font-size: 0.8125rem; color: var(--text-2); margin-bottom: 0.2rem; }
.contact-card-detail i { width: 1rem; color: var(--text-3); flex-shrink: 0; font-size: 0.75rem; }
.contact-card-detail a { color: var(--accent); text-decoration: none; }
.contact-card-detail a:hover { text-decoration: underline; }
.primary-badge { display: inline-block; background: var(--soft-blue); color: var(--hue-blue); font-size: 0.65rem; font-weight: 700; padding: 0.1rem 0.4rem; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em; margin-left: 0.375rem; }

/* ── Inline email/phone editor ── */
.ep-row { display: flex; gap: 0.375rem; align-items: center; margin-bottom: 0.375rem; }
.ep-row input, .ep-row select { padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 0.25rem; font-size: 0.8125rem; background: var(--surface); color: var(--text); }
.ep-row input { flex: 1; }
.ep-row select { width: 90px; }

/* ── Attachments ── */
.attachments-section { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.attachments-section h4 { font-size: 0.9375rem; font-weight: 600; color: var(--text-2); margin-bottom: 0.875rem; display: flex; align-items: center; gap: 0.5rem; justify-content: space-between; }
.attachment-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.625rem 0.75rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 0.375rem; margin-bottom: 0.5rem; }
.attachment-icon { width: 2.25rem; height: 2.25rem; border-radius: 0.375rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.875rem; }
.attachment-icon.img  { background: var(--soft-pink);  color: var(--hue-pink); }
.attachment-icon.pdf  { background: var(--soft-red);   color: var(--hue-red); }
.attachment-icon.doc  { background: var(--soft-blue);  color: var(--hue-blue); }
.attachment-icon.xls  { background: var(--soft-green); color: var(--hue-green); }
.attachment-icon.zip  { background: var(--soft-amber); color: var(--hue-amber); }
.attachment-icon.file { background: var(--soft-slate); color: var(--hue-slate); }
.attachment-info { flex: 1; min-width: 0; }
.attachment-name { font-weight: 500; font-size: 0.8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-meta { font-size: 0.7rem; color: var(--text-3); margin-top: 0.1rem; }
.upload-zone { border: 2px dashed var(--border); border-radius: 0.5rem; padding: 1.25rem; text-align: center; cursor: pointer; transition: all 0.2s; color: var(--text-3); font-size: 0.875rem; }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.upload-zone input[type=file] { display: none; }

/* ── Topbar user chip — lives on a surface now (not the dark nav), so it
   takes surface tokens; the avatar keeps the accent. ── */
.nav-user-chip { display: flex; align-items: center; gap: 0.375rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0.25rem 0.625rem 0.25rem 0.25rem; cursor: default; flex-shrink: 0; }
.nav-avatar { width: 1.625rem; height: 1.625rem; background: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--on-accent); font-size: 0.6875rem; font-weight: 700; flex-shrink: 0; letter-spacing: 0; }
.nav-user-name { font-size: 0.8125rem; font-weight: 500; color: var(--text); white-space: nowrap; }
.nav-role-tag { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); background: var(--surface-3); padding: 0.1rem 0.375rem; border-radius: 999px; white-space: nowrap; }

/* ── Global Search Overlay ── */
.search-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 3000; display: flex; flex-direction: column; align-items: center; padding-top: 5rem; }
.search-overlay-box { background: var(--surface); border-radius: 0.75rem; width: 90%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,0.4); overflow: hidden; }
.search-overlay-input-row { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.search-overlay-input-row i { color: var(--text-3); font-size: 1rem; flex-shrink: 0; }
.search-overlay-input { flex: 1; border: none; outline: none; font-size: 1rem; color: var(--text); background: transparent; }
.search-overlay-input::placeholder { color: var(--text-3); }
.search-results { max-height: 60vh; overflow-y: auto; }
.search-section { border-bottom: 1px solid var(--border-soft); }
.search-section-title { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); padding: 0.75rem 1.25rem 0.25rem; }
.search-result-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.625rem 1.25rem; cursor: pointer; transition: background 0.1s; }
.search-result-item:hover { background: var(--surface-2); }
.search-result-icon { width: 2rem; height: 2rem; border-radius: 0.375rem; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; flex-shrink: 0; }
.search-result-icon.account { background: var(--soft-blue);  color: var(--hue-blue); }
.search-result-icon.contact { background: var(--soft-green); color: var(--hue-green); }
.search-result-icon.task    { background: var(--soft-amber); color: var(--hue-amber); }
.search-result-icon.comm    { background: var(--soft-pink);  color: var(--hue-pink); }
.search-result-main { flex: 1; min-width: 0; }
.search-result-name { font-weight: 500; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-sub  { font-size: 0.75rem; color: var(--text-3); }
.search-empty { padding: 2rem; text-align: center; color: var(--text-3); font-size: 0.875rem; }

/* ── Dashboard ── */
.view-content { flex: 1; overflow-y: auto; padding: 1.5rem; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border-radius: 0.5rem; padding: 1.25rem; box-shadow: var(--shadow-2); border: 1px solid var(--border); }
.stat-card-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); margin-bottom: 0.5rem; }
.stat-card-value { font-size: 2rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card-value.danger { color: var(--danger); }
.stat-card-value.warning { color: var(--warning); }
.stat-card-value.success { color: var(--success); }
.stat-card-sub { font-size: 0.75rem; color: var(--text-3); margin-top: 0.375rem; }
.dashboard-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
.dashboard-card { background: var(--surface); border-radius: 0.5rem; box-shadow: var(--shadow-2); border: 1px solid var(--border); overflow: hidden; }
.dashboard-card-header { padding: 0.875rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.875rem; color: var(--text-2); display: flex; align-items: center; gap: 0.5rem; }
.dashboard-list-item { display: flex; justify-content: space-between; align-items: flex-start; padding: 0.625rem 1rem; border-bottom: 1px solid var(--border-soft); font-size: 0.8125rem; gap: 0.5rem; }
.dashboard-list-item:last-child { border-bottom: none; }
.dashboard-list-item-main { flex: 1; min-width: 0; }
.dashboard-list-item-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dashboard-list-item-sub  { font-size: 0.75rem; color: var(--text-3); }
.dashboard-list-item-right { flex-shrink: 0; text-align: right; }

/* ── Tags ── */
.account-tags-row { display: flex; flex-wrap: wrap; gap: 0.375rem; align-items: center; margin-top: 0.5rem; }
.tag-pill { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.2rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; white-space: nowrap; }
/* Sidebar tag filter — clickable chips, OR-match across selected tags */
.tag-filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; margin-bottom: 0.75rem; }
.tag-filter-chip { cursor: pointer; font-family: inherit; }
.tag-filter-chip:hover { filter: brightness(1.2); }
.tag-filter-clear { background: none; border: none; cursor: pointer; color: var(--text-3); font-size: 0.7rem; text-decoration: underline; padding: 0; }
.tag-filter-clear:hover { color: var(--text-2); }
.tag-pill-remove { background: none; border: none; cursor: pointer; color: inherit; opacity: 0.6; padding: 0; line-height: 1; font-size: 0.75rem; }
.tag-pill-remove:hover { opacity: 1; }
.tag-selector { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }
.tag-selector select { flex: 1; padding: 0.375rem 0.5rem; border: 1px solid var(--border); border-radius: 0.375rem; font-size: 0.8125rem; background: var(--surface); color: var(--text); cursor: pointer; }
.tag-selector select:focus { outline: none; border-color: var(--accent); }

/* ── Merge Modal ── */
.merge-target-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 0.375rem; margin-top: 0.5rem; }
.merge-target-item { padding: 0.75rem 1rem; cursor: pointer; border-bottom: 1px solid var(--border-soft); display: flex; gap: 0.75rem; align-items: center; transition: background 0.1s; }
.merge-target-item:last-child { border-bottom: none; }
.merge-target-item:hover { background: var(--surface-2); }
.merge-target-item.selected { background: var(--accent-soft); border-color: var(--accent); }

/* ── Products / List Views ── */
.list-view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; gap: 1rem; flex-wrap: wrap; }
.list-view-title  { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.list-view-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; background: var(--surface); border-radius: 0.5rem; overflow: hidden; box-shadow: var(--shadow-2); }
.data-table th { text-align: left; padding: 0.75rem 1rem; background: var(--surface-2); border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-2); font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.data-table td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ── Status badges ── */
.status-badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 0.25rem; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.status-badge.draft    { background: var(--soft-slate); color: var(--hue-slate); }
.status-badge.sent     { background: var(--soft-blue);  color: var(--hue-blue); }
.status-badge.accepted { background: var(--soft-green); color: var(--hue-green); }
.status-badge.declined { background: var(--soft-red);   color: var(--hue-red); }
.status-badge.expired  { background: var(--soft-amber); color: var(--hue-amber); }
.status-badge.paid     { background: var(--soft-green); color: var(--hue-green); }
.status-badge.partial  { background: var(--soft-amber); color: var(--hue-amber); }
.status-badge.overdue  { background: var(--soft-red);   color: var(--hue-red); }
.status-badge.void     { background: var(--soft-slate); color: var(--hue-slate); }
.status-badge.active   { background: var(--soft-green); color: var(--hue-green); }
.status-badge.inactive { background: var(--soft-slate); color: var(--hue-slate); }

/* ── Quote / Invoice Builder ── */
.builder-modal { max-width: 860px; width: 95vw; }
.line-items-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; margin-bottom: 0.75rem; }
.line-items-table th { text-align: left; padding: 0.5rem; background: var(--surface-2); border-bottom: 2px solid var(--border); font-size: 0.75rem; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.line-items-table td { padding: 0.375rem 0.5rem; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.line-items-table td input, .line-items-table td select { width: 100%; padding: 0.35rem 0.4rem; border: 1px solid var(--border); border-radius: 0.25rem; font-size: 0.8125rem; background: var(--surface); color: var(--text); }
.line-items-table td input:focus, .line-items-table td select:focus { outline: none; border-color: var(--accent); }
.totals-block { margin-left: auto; width: 260px; }
.totals-row { display: flex; justify-content: space-between; padding: 0.375rem 0; font-size: 0.875rem; color: var(--text-2); border-bottom: 1px solid var(--border-soft); }
.totals-row.total-final { font-weight: 700; color: var(--text); font-size: 1rem; border-bottom: none; padding-top: 0.5rem; }

/* ── Customer Number ── */
.customer-number-badge { font-size: 0.7rem; font-weight: 700; font-family: 'SF Mono', 'Fira Code', monospace; color: var(--text-3); background: var(--surface-2); border: 1px solid var(--border); border-radius: 0.25rem; padding: 0.1rem 0.4rem; letter-spacing: 0.04em; white-space: nowrap; flex-shrink: 0; }
.customer-number-lg { font-size: 0.8125rem; padding: 0.2rem 0.6rem; }

/* ── Activity Feed ── */
.activity-item { display: flex; gap: 0.875rem; padding: 0.875rem 0; border-bottom: 1px solid var(--border-soft); align-items: flex-start; }
.activity-item:last-child { border-bottom: none; }
.activity-item.completed-task { background: var(--soft-green); border-radius: 0.375rem; padding: 0.875rem; margin-bottom: 0.375rem; border-bottom: none; border: 1px solid color-mix(in srgb, var(--hue-green) 35%, var(--surface)); }
.activity-icon { width: 2rem; height: 2rem; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.8125rem; }
.activity-icon.comm { background: var(--soft-blue); color: var(--hue-blue); }
.activity-icon.task-done { background: var(--soft-green); color: var(--hue-green); }
.activity-body { flex: 1; min-width: 0; }
.activity-title { font-weight: 600; font-size: 0.9rem; color: var(--text); margin-bottom: 0.2rem; }
.activity-sub { font-size: 0.8rem; color: var(--text-3); margin-bottom: 0.2rem; }
.activity-content { font-size: 0.8125rem; color: var(--text-2); margin-bottom: 0.375rem; line-height: 1.4; }
.activity-meta { display: flex; gap: 0.375rem; align-items: center; flex-wrap: wrap; }
.activity-right { display: flex; flex-direction: column; align-items: flex-end; gap: 0.375rem; flex-shrink: 0; }
.activity-date { font-size: 0.75rem; color: var(--text-3); white-space: nowrap; }

/* Unread (mailbox says isRead=false) — derived from --accent so it matches
   whatever theme is active, same color-mix trick as .completed-task. */
.activity-item.unread { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--surface)); border-radius: 0.375rem; padding: 0.875rem; margin-bottom: 0.375rem; }
.unread-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 0.4rem; vertical-align: middle; flex-shrink: 0; }

/* Email threads — older messages stack under the newest, behind a toggle. */
.activity-thread { border-bottom: 1px solid var(--border-soft); }
.activity-thread .activity-item { border-bottom: none; }
.thread-toggle { background: none; border: none; color: var(--accent); font-size: 0.78rem; cursor: pointer; padding: 0 0 0.625rem 2.875rem; display: flex; align-items: center; gap: 0.375rem; }
.thread-toggle:hover { color: var(--accent-hover); }
.activity-item.thread-child { margin-left: 1.25rem; padding-left: 1rem; border-left: 2px solid color-mix(in srgb, var(--accent) 35%, var(--surface)); }

/* ── Tasks Page ── */
.tasks-page { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.tasks-filter-bar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.625rem 1.5rem; display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; flex-wrap: wrap; }
.filter-chip { padding: 0.3rem 0.875rem; border: 1px solid var(--border); border-radius: 1rem; background: var(--surface); color: var(--text-3); font-size: 0.8125rem; font-weight: 500; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.filter-chip.danger { border-color: color-mix(in srgb, var(--hue-red) 50%, var(--surface)); color: var(--hue-red); }
.tasks-list { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; }
/* One contained list with divider rows, not a floating card per task
   (rail UI pass) — overdue/today rows keep their tint as full-width bands. */
.tasks-list-container { background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem; overflow: hidden; }
.task-row { background: var(--surface); border-bottom: 1px solid var(--border-soft); display: flex; align-items: stretch; overflow: hidden; transition: background 0.15s; }
.task-row:last-child { border-bottom: none; }
.task-row:hover { background: var(--surface-2); }
.task-row.overdue { background: color-mix(in srgb, var(--hue-red) 7%, var(--surface)); }
.task-row.today { background: color-mix(in srgb, var(--hue-amber) 7%, var(--surface)); }
.task-row-priority { width: 5px; flex-shrink: 0; }
.task-row-body { flex: 1; padding: 0.875rem 1rem; min-width: 0; }
.task-row-main { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.375rem; flex-wrap: wrap; }
.task-account-link { background: none; border: none; color: var(--accent); font-weight: 600; font-size: 0.875rem; cursor: pointer; padding: 0; display: inline-flex; align-items: center; gap: 0.3rem; transition: color 0.15s; flex-shrink: 0; }
.task-account-link:hover { color: var(--accent-hover); text-decoration: underline; }
.task-row-divider { color: var(--text-3); font-size: 0.75rem; }
.task-row-title { font-size: 0.9rem; color: var(--text); font-weight: 500; }
.task-row-notes { font-size: 0.8125rem; color: var(--text-3); margin-bottom: 0.4rem; }
.task-row-meta { display: flex; gap: 0.375rem; align-items: center; flex-wrap: wrap; }
.task-prio-badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 0.25rem; font-size: 0.7rem; font-weight: 600; color: white; text-transform: capitalize; }
.task-due-label { font-size: 0.75rem; color: var(--text-3); display: inline-flex; align-items: center; gap: 0.25rem; }
.task-due-label.overdue { color: var(--hue-red); font-weight: 600; }
.task-due-label.today { color: var(--hue-amber); font-weight: 600; }
.task-row-actions { display: flex; gap: 0.5rem; align-items: center; padding: 0 1rem; flex-shrink: 0; }

@media (max-width: 768px) {
    .dashboard-cols { grid-template-columns: 1fr; }
    .builder-modal { width: 100vw; max-width: 100vw; border-radius: 0; }
}

/* ── Account Detail View ── */
.account-detail-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
/* flex-wrap: with the account-list pane (and/or doc pane) open there isn't room for
   title + badges + actions on one line — wrapping beats clipping the rightmost buttons */
.account-detail-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 1rem 1.5rem; display: flex; align-items: center; gap: 1rem; row-gap: 0.5rem; flex-wrap: wrap; flex-shrink: 0; }
.account-detail-back { background: none; border: 1px solid var(--border); color: var(--text-3); padding: 0.375rem 0.75rem; border-radius: 0.375rem; cursor: pointer; font-size: 0.875rem; display: flex; align-items: center; gap: 0.375rem; transition: all 0.15s; }
.account-detail-back:hover { background: var(--surface-2); color: var(--text); border-color: var(--surface-3); }
.account-detail-title { font-size: 1.125rem; font-weight: 700; color: var(--text); flex: 1; min-width: 12rem; }
.account-detail-actions { display: flex; gap: 0.5rem; margin-left: auto; }
.account-detail-tabs { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 1.5rem; display: flex; gap: 0; flex-shrink: 0; }
.account-detail-tab { padding: 0.75rem 1rem; font-size: 0.875rem; font-weight: 500; color: var(--text-3); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s; display: flex; align-items: center; gap: 0.375rem; }
.account-detail-tab:hover { color: var(--text); }
.account-detail-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.account-detail-body { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* ── Accounts landing — full-width table (rail UI, 2026-08-09) ── */
.accounts-landing { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; }
.accounts-toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.accounts-search { flex: 1; min-width: 220px; width: auto; padding: 0.6rem 0.9rem; }
.accounts-toolbar-seg { margin-bottom: 0; flex-shrink: 0; }
.accounts-toolbar-seg .toggle-btn { flex: none; padding: 0.5rem 0.9rem; }
.accounts-count-note { font-size: 0.75rem; color: var(--text-3); margin-bottom: 0.5rem; }
.accounts-table-name { font-weight: 600; color: var(--text); }
/* No link underline — the row highlight is the affordance; the <a> exists
   only for cmd/middle-click open-in-tab. */
.accounts-table-name:hover { text-decoration: none; }
.accounts-table-type { text-transform: capitalize; color: var(--text-2); }
.accounts-table-contact { color: var(--text-2); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.accounts-table-status { display: flex; gap: 0.375rem; align-items: center; flex-wrap: wrap; }
.accounts-table-rep { color: var(--text-2); white-space: nowrap; }

/* ── Account detail info grid — ONE surface with field rows (rail UI pass),
   not a card per field. Scoped: .detail-info-card elsewhere (Integrations,
   Providers, payment links) keeps its card look. ── */
.detail-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2.5rem; margin-bottom: 1.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 0.625rem; padding: 0.375rem 1.25rem; max-width: 980px; }
.detail-info-grid > .detail-info-card { background: none; border: none; border-radius: 0; padding: 0.8rem 0; border-bottom: 1px solid var(--border-soft); }
.detail-info-grid > .detail-info-card:nth-last-child(-n+2) { border-bottom: none; }
.detail-info-card { background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem; padding: 1rem; }
.detail-info-label { font-size: 0.75rem; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.25rem; }
.detail-info-value { font-size: 0.9375rem; color: var(--text); }
.detail-section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.detail-section-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ── Team cards (Admin > Teams tab) ── */
.team-card { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem; overflow: hidden; margin-bottom: 0.75rem; }
.team-card-bar { width: 6px; flex-shrink: 0; }
.team-card-body { flex: 1; padding: 0.875rem 1rem; }
.team-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 0.625rem; }
.team-card-name { font-weight: 600; font-size: 0.9375rem; color: var(--text); }
.team-card-desc { font-size: 0.8125rem; color: var(--text-3); }
.team-members-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; margin-top: 0.5rem; }
.team-member-chip { display: inline-flex; align-items: center; gap: 0.25rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9999px; padding: 0.125rem 0.5rem 0.125rem 0.625rem; font-size: 0.75rem; color: var(--text-2); }
.team-member-remove { background: none; border: none; cursor: pointer; color: var(--text-3); font-size: 0.875rem; line-height: 1; padding: 0; margin-left: 0.125rem; display: flex; align-items: center; }
.team-member-remove:hover { color: var(--danger); }
.team-add-member-select { font-size: 0.75rem; border: 1px dashed var(--border); border-radius: 9999px; padding: 0.125rem 0.5rem; color: var(--text-3); background: var(--surface); cursor: pointer; }
.team-add-member-select:focus { outline: none; border-color: var(--accent); color: var(--text); }

/* ── Admin panel — themed form cards, note boxes, color swatches ──
   Tokens only in admin styles — new themes pick these up for free. */
.admin-form-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 0.5rem; padding: 1.25rem; margin-bottom: 1.5rem; }
.admin-form-card h4, .admin-form-card h5 { color: var(--accent); margin-bottom: 1rem; }
.note-box { font-size: 0.8125rem; border-radius: 0.375rem; padding: 0.5rem 0.75rem; word-break: break-all; color: var(--text); }
.note-box.success { background: var(--soft-green); border: 1px solid color-mix(in srgb, var(--hue-green) 35%, var(--surface)); }
.note-box.danger  { background: var(--soft-red);   border: 1px solid color-mix(in srgb, var(--hue-red) 35%, var(--surface)); color: var(--hue-red); }
/* Audit-log action badges */
.badge.audit-insert { background: var(--soft-green); color: var(--hue-green); }
.badge.audit-update { background: var(--soft-blue);  color: var(--hue-blue); }
.badge.audit-delete { background: var(--soft-red);   color: var(--hue-red); }
/* Preset color swatches (teams/tags) — replaces the native OS color dialog */
.color-swatch-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; }
.color-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); padding: 0; cursor: pointer; flex-shrink: 0; transition: transform 0.1s, box-shadow 0.1s; }
.color-swatch:hover { transform: scale(1.12); }
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 3px var(--focus-ring); }

/* ── Settings modal (theme picker) ── */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.75rem; }
.theme-swatch { border: 2px solid var(--border); border-radius: 0.5rem; padding: 0.625rem; cursor: pointer; background: var(--surface); transition: all 0.15s; text-align: left; }
.theme-swatch:hover { border-color: var(--accent-hover); }
.theme-swatch.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.theme-swatch-preview { height: 44px; border-radius: 0.375rem; margin-bottom: 0.5rem; display: flex; overflow: hidden; border: 1px solid rgba(0,0,0,0.2); }
.theme-swatch-preview span { flex: 1; }
.theme-swatch-name { font-size: 0.8125rem; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 0.375rem; }
.theme-swatch-name i { color: var(--accent); font-size: 0.75rem; }
.settings-hint, .form-hint { font-size: 0.8125rem; color: var(--text-3); margin-top: 1rem; }

/* ── Workspace Settings (full-page card home + sections) ──
   Card-first by design: plain-language tiles with live status lines, not a
   console tab bar. Tokens only, so every theme gets it for free. */
.settings-page { max-width: 920px; margin: 0 auto; width: 100%; }
.settings-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.settings-title { font-size: 1.375rem; font-weight: 700; color: var(--text); margin: 0; }
.settings-subtitle { font-size: 0.875rem; color: var(--text-3); margin-top: 0.25rem; }
.settings-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 0.875rem; }
.settings-group + .settings-group { margin-top: 1.75rem; }
.settings-group-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin-bottom: 0.625rem; }
.settings-card { display: flex; align-items: center; gap: 1rem; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 0.625rem; padding: 1.125rem 1.25rem; cursor: pointer; transition: all 0.15s; font-family: inherit; color: var(--text); }
.settings-card:hover { border-color: var(--accent); background: var(--accent-soft); box-shadow: var(--shadow-2); }
.settings-card-icon { width: 2.75rem; height: 2.75rem; border-radius: 0.625rem; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 1.125rem; flex-shrink: 0; }
.settings-card-icon.platform { background: var(--soft-pink); color: var(--hue-pink); }
.settings-card-main { flex: 1; min-width: 0; }
.settings-card-title { font-weight: 600; font-size: 0.9375rem; margin-bottom: 0.2rem; }
.settings-card-blurb { font-size: 0.8125rem; color: var(--text-3); line-height: 1.35; }
.settings-card-status { font-size: 0.75rem; color: var(--text-3); margin-top: 0.375rem; display: flex; align-items: center; gap: 0.3rem; }
.settings-card-status.ok { color: var(--hue-green); }
.settings-card-chevron { color: var(--text-3); font-size: 0.8125rem; flex-shrink: 0; }
.settings-group-label { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin: 1.75rem 0 0.75rem; }
.settings-section-body { background: var(--surface); border: 1px solid var(--border); border-radius: 0.625rem; padding: 1.5rem; }
.settings-form { max-width: 720px; }
.settings-advanced-toggle { background: none; border: none; color: var(--text-2); font-size: 0.9375rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; padding: 0; font-family: inherit; }
.settings-advanced-toggle:hover { color: var(--text); }
.logo-preview-box { width: 220px; min-height: 72px; border: 1px dashed var(--border); border-radius: 0.5rem; display: flex; align-items: center; justify-content: center; padding: 0.75rem; background: var(--surface-2); }
.logo-preview-box img { max-width: 100%; max-height: 90px; display: block; }

/* Document Style — levers left, live PDF preview right (stacks when narrow) */
.docstyle-layout { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: flex-start; }
.docstyle-controls { flex: 1 1 300px; min-width: 280px; }
.docstyle-preview { flex: 1 1 380px; min-width: 320px; position: sticky; top: 1rem; }
.docstyle-preview-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); margin-bottom: 0.5rem; }
.docstyle-preview iframe { width: 100%; aspect-ratio: 8.5 / 11; border: 1px solid var(--border); border-radius: 0.5rem; background: #ffffff; }
.docstyle-preview-empty { width: 100%; aspect-ratio: 8.5 / 11; border: 1px dashed var(--border); border-radius: 0.5rem; display: flex; align-items: center; justify-content: center; color: var(--text-3); background: var(--surface-2); }
.docstyle-font-chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }

/* Logo library — one card per logo, placement chips underneath */
.logo-library { display: flex; gap: 1rem; flex-wrap: wrap; }
.logo-card { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.875rem; border: 1px solid var(--border); border-radius: 0.625rem; background: var(--surface-2); width: 252px; }
.logo-card .logo-preview-box { width: 100%; }
.logo-card-name { font-size: 0.8125rem; padding: 0.375rem 0.5rem; }
.logo-card-placements { display: flex; flex-direction: column; gap: 0.375rem; align-items: stretch; }
.logo-card-placements .filter-chip { text-align: left; }

/* Bounced outbound email — loud by design: "sent" must never hide a bounce */
.activity-item.bounced { outline: 1px solid #dc2626; outline-offset: -1px; border-radius: 0.5rem; }
/* Outbound email delivery state — one badge, three states (see deliveryState
   in api.js). Failure stays loud (solid red); success and in-flight stay quiet
   tints, so a wall of delivered mail never shouts over a single bounce. */
.delivery-badge { display: inline-flex; align-items: center; gap: 0.3rem; margin-left: 0.5rem; padding: 0.1rem 0.5rem; border-radius: 0.75rem; font-size: 0.7rem; font-weight: 600; white-space: nowrap; }
.delivery-badge.failed    { background: #dc2626; color: #fff; }
.delivery-badge.confirmed { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.delivery-badge.pending   { background: color-mix(in srgb, var(--text-3) 18%, transparent); color: var(--text-3); }
/* Topbar workspace identity (tenant name + version, right of the search) */
.nav-workspace-name { font-size: 0.875rem; font-weight: 600; color: var(--text-2); white-space: nowrap; }
/* Deployed version chip — deliberately quiet: orientation, not decoration */
.nav-version { font-size: 0.6875rem; font-weight: 500; color: var(--text-3); white-space: nowrap; align-self: center; }
@media (max-width: 900px) { .nav-workspace-name, .nav-version { display: none; } }

/* ── What's New modal + beta badge ── */
.beta-badge { font-size: 0.6em; font-weight: 700; letter-spacing: 0.08em; vertical-align: middle; margin-left: 0.5rem; padding: 0.2em 0.5em; border-radius: 0.375rem; color: var(--warning); border: 1px solid var(--warning); }
.whatsnew-entry { margin-bottom: 1.25rem; }
.whatsnew-entry-header { display: flex; align-items: baseline; gap: 0.625rem; margin-bottom: 0.375rem; }
.whatsnew-version { font-size: 0.75rem; font-weight: 700; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 0.15em 0.5em; border-radius: 0.375rem; }
.whatsnew-title { font-weight: 600; color: var(--text); }
.whatsnew-entry ul { margin: 0; padding-left: 1.25rem; color: var(--text-2); font-size: 0.875rem; }
.whatsnew-entry li { margin-bottom: 0.25rem; }
.whatsnew-beta-notice { font-size: 0.8125rem; color: var(--text-2); background: color-mix(in srgb, var(--warning) 10%, transparent); border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent); border-radius: 0.5rem; padding: 0.75rem; margin-top: 1rem; }
.whatsnew-beta-notice i { color: var(--warning); margin-right: 0.25rem; }
.whatsnew-actions { display: flex; justify-content: flex-end; margin-top: 1.25rem; }

/* Feature guide (expandable "everything this CRM can do" — FeatureGuide.jsx) */
.whatsnew-guide-toggle { display: flex; align-items: center; gap: 0.5rem; width: 100%; margin-top: 1rem; padding: 0.625rem 0.75rem; font-size: 0.875rem; font-weight: 600; color: var(--text); background: color-mix(in srgb, var(--accent) 8%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); border-radius: 0.5rem; cursor: pointer; }
.whatsnew-guide-toggle:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.whatsnew-guide-toggle .fa-compass { color: var(--accent); }
.whatsnew-guide-toggle .fa-chevron-down, .whatsnew-guide-toggle .fa-chevron-up { margin-left: auto; font-size: 0.75rem; color: var(--text-2); }
.feature-guide { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.375rem; }
.feature-guide-category { border: 1px solid var(--border); border-radius: 0.5rem; overflow: hidden; }
.feature-guide-header { display: flex; align-items: center; gap: 0.625rem; width: 100%; padding: 0.625rem 0.75rem; font-size: 0.875rem; color: var(--text); background: transparent; border: none; cursor: pointer; text-align: left; }
.feature-guide-header:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.feature-guide-icon { width: 1.125rem; text-align: center; color: var(--accent); }
.feature-guide-name { font-weight: 600; }
.feature-guide-count { font-size: 0.6875rem; font-weight: 700; color: var(--text-2); background: color-mix(in srgb, var(--text) 8%, transparent); padding: 0.1em 0.5em; border-radius: 999px; }
.feature-guide-chevron { margin-left: auto; font-size: 0.6875rem; color: var(--text-2); }
.feature-guide-list { padding: 0.25rem 0.75rem 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
.feature-guide-item-name { font-size: 0.8125rem; font-weight: 600; color: var(--text); }
.feature-guide-item-blurb { font-size: 0.8125rem; color: var(--text-2); }

/* ── Instance ribbon ──────────────────────────────────────────────────────────
   Environment label ("STAGING") served by /api/health when the box sets
   INSTANCE_LABEL. Corner ribbon, always on top, deliberately loud — a labeled
   environment must never pass for production at a glance. */
.instance-ribbon {
  position: fixed;
  top: 14px;
  right: -34px;
  z-index: 9999;
  transform: rotate(45deg);
  background: #d97706;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.25rem 2.5rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  pointer-events: none; /* never blocks clicks on what's under the corner */
}
