/* ============================================================================
   Leverage AI — Design System  (single source of truth for both dashboards)
   ----------------------------------------------------------------------------
   Clean & light, in the Stripe / Mercury idiom: white surfaces on a cool-gray
   canvas, deep-slate text, one blue brand accent, soft cool-tinted shadows,
   an 8px spacing grid, and generous whitespace. Replaces the ~1,700 lines of
   duplicated inline <style> that used to live in each app's base.html.

   Both the owner dashboard and the admin console link this file via /static.
   Light + dark themes share one token set; dark overrides them under
   [data-theme="dark"] (see below). No legacy aliases — git is history.
   ============================================================================ */

/* ----------------------------------- Tokens ----------------------------------- */
:root {
    /* Surfaces */
    --canvas:        #f6f8fb;   /* app background (cool gray) */
    --surface:       #ffffff;   /* cards, nav, inputs */
    --surface-subtle:#fbfcfe;   /* table zebra, hovers */
    --surface-sunken:#f2f5f9;   /* table headers, wells */

    /* Text */
    --text:          #1a2233;   /* primary (deep slate) */
    --text-secondary:#4b5566;
    --text-muted:    #646c7d;   /* captions, placeholders (WCAG AA on white/canvas) */
    --text-faint:    #aab2c2;

    /* Borders */
    --border:        #e6eaf0;
    --border-strong: #d4dae4;

    /* Brand accent — Leverage AI blue */
    --accent:        #2563eb;
    --accent-hover:  #1d4ed8;
    --accent-fg:     #ffffff;
    --accent-soft:   #eef3ff;   /* tinted background */
    --accent-ring:   rgba(37, 99, 235, 0.20);

    /* Semantic */
    --green:    #15a34a;  --green-soft:  #e7f6ec;
    --amber:    #d97706;  --amber-soft:  #fdf0dc;
    --red:      #dc2626;  --red-soft:    #fdecec;
    --purple:   #7c3aed;  --purple-soft: #f1ebfe;

    /* Radii */
    --r-sm: 6px;
    --r:    8px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-pill: 999px;

    /* Shadows — soft, cool-slate tinted (Stripe-like depth) */
    --shadow-xs: 0 1px 2px rgba(20, 30, 55, 0.06);
    --shadow-sm: 0 1px 3px rgba(20, 30, 55, 0.08), 0 1px 2px rgba(20, 30, 55, 0.04);
    --shadow:    0 2px 6px rgba(20, 30, 55, 0.06), 0 4px 16px rgba(20, 30, 55, 0.07);
    --shadow-md: 0 6px 24px rgba(20, 30, 55, 0.10);
    --shadow-lg: 0 16px 40px rgba(20, 30, 55, 0.14);

    /* Type */
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Hanken Grotesk", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;

    --nav-h: 60px;

    /* Theme-aware composites (overridden in dark) */
    --nav-bg: rgba(255, 255, 255, 0.85);   /* translucent nav over the blur */
    --warn-text: #9a5b06;                   /* amber text on amber-soft (banners, notes) */
    --success-text: #0f7a37;                /* green text on green-soft (appointments) */
    --danger-text: #b91c1c;                 /* red text on red-soft (badges) */
    color-scheme: light;
}

/* ----------------------------------- Dark theme ------------------------------------
   Same tokens, dark values. A tiny inline <head> script sets data-theme on <html>
   from localStorage or the OS preference (no flash), and the nav toggle flips it. */
[data-theme="dark"] {
    --canvas:        #0e131d;
    --surface:       #171d2a;
    --surface-subtle:#1b2230;
    --surface-sunken:#212a3a;

    --text:          #e9edf4;
    --text-secondary:#b7c0d0;
    --text-muted:    #8b95a8;
    --text-faint:    #5a6477;

    --border:        #2a3342;
    --border-strong: #3a4458;

    --accent:        #4f8cff;
    --accent-hover:  #6ea0ff;
    --accent-fg:     #ffffff;
    --accent-soft:   #18253c;
    --accent-ring:   rgba(79, 140, 255, 0.30);

    --green:  #34d399;  --green-soft:  #112a20;
    --amber:  #fbbf24;  --amber-soft:  #2c2110;
    --red:    #f87171;  --red-soft:    #2c1717;
    --purple: #a78bfa;  --purple-soft: #1f1833;

    --nav-bg: rgba(20, 26, 38, 0.85);
    --warn-text: #fbbf24;
    --success-text: #34d399;
    --danger-text: #f87171;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.40), 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow:    0 2px 6px rgba(0, 0, 0, 0.40), 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.50);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.60);

    color-scheme: dark;
}

/* ----------------------------------- Reset ------------------------------------ */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--canvas);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-hover); }

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--text); font-weight: 700; letter-spacing: -0.015em; line-height: 1.22; }

::selection { background: var(--accent-soft); }

/* Custom scrollbars — light, unobtrusive */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-pill); border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

/* ----------------------------------- Nav -------------------------------------- */
.nav {
    background: var(--nav-bg);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
    height: var(--nav-h);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    margin-right: 32px;
    white-space: nowrap;
    color: var(--text);
}
.nav-brand:hover { color: var(--text); }
.nav-brand-mark { display: block; flex-shrink: 0; }
.nav-brand-text { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.nav-brand-sub {
    font-size: 11px; font-weight: 600; color: var(--accent);
    background: var(--accent-soft); padding: 2px 7px; border-radius: var(--r-pill);
    letter-spacing: 0.02em; text-transform: uppercase;
}
/* nav-menu wraps the links + sign-out. On desktop it's a layout passthrough
   (its children become flex items of .nav); on mobile it becomes the hamburger
   dropdown panel (see the responsive block). */
.nav-menu { display: contents; }
.nav-burger, .nav-toggle { display: none; }   /* burger only appears on mobile */
.nav-links { display: flex; align-items: center; gap: 2px; height: 100%; }
.nav-links a {
    display: inline-flex; align-items: center; gap: 7px;
    height: 100%; padding: 0 14px;
    color: var(--text-secondary); font-size: 13.5px; font-weight: 550;
    border-bottom: 2px solid transparent; transition: color .15s, border-color .15s;
}
.nav-links a:hover { color: var(--text); }
.nav-links a.active { color: var(--accent); border-bottom-color: var(--accent); }
.nav-end {
    display: flex; align-items: center; gap: 12px;
    margin-left: auto; padding-left: 12px; flex-shrink: 0;
}
.nav-client-name { font-size: 12.5px; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.nav-signout { color: var(--text-muted); font-size: 13px; font-weight: 500; white-space: nowrap; }
.nav-signout:hover { color: var(--text); }
.nav-theme-toggle {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    width: 34px; height: 34px; flex-shrink: 0; font: inherit;
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    border-radius: var(--r-sm); transition: color .15s, background .15s;
}
.nav-theme-toggle:hover { color: var(--text); background: var(--surface-sunken); }
.nav-theme-toggle svg { flex-shrink: 0; }
.nav-theme-label { display: none; }   /* icon-only on desktop; labeled row on mobile */

/* Account dropdown (CSS-only via <details>) */
.nav-account { position: relative; }
.nav-account > summary { list-style: none; cursor: pointer; }
.nav-account > summary::-webkit-details-marker { display: none; }
.nav-account-trigger {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 3px 8px 3px 3px; border-radius: var(--r-pill);
    transition: background .15s;
}
.nav-account-trigger:hover { background: var(--surface-sunken); }
.nav-account-avatar {
    width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
    font-family: var(--font-display);
}
.nav-account-caret { color: var(--text-faint); transition: transform .15s; }
.nav-account[open] .nav-account-caret { transform: rotate(180deg); }
.nav-account-menu {
    position: absolute; top: calc(100% + 8px); right: 0; min-width: 184px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-md); box-shadow: var(--shadow-md); padding: 6px; z-index: 50;
    display: flex; flex-direction: column;
}
.nav-account-menu a {
    padding: 9px 12px; border-radius: var(--r-sm); font-size: 13.5px;
    font-weight: 550; color: var(--text-secondary); white-space: nowrap;
}
.nav-account-menu a:hover { background: var(--surface-sunken); color: var(--text); }
.nav-account-signout { color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 4px; padding-top: 11px; }

/* ----------------------------------- Home summary strip ----------------------- */
.stat-strip {
    display: flex; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-md); box-shadow: var(--shadow-sm); margin-bottom: 18px; overflow: hidden;
}
.strip-item {
    flex: 1; display: flex; align-items: baseline; gap: 8px; padding: 14px 18px;
    border-left: 1px solid var(--border); color: var(--text);
}
.strip-item:first-child { border-left: none; }
.strip-item:hover { background: var(--surface-subtle); }
.strip-num { font-family: var(--font-display); font-size: 24px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.strip-label { font-size: 12.5px; color: var(--text-muted); font-weight: 550; }
.strip-sub { color: var(--text-faint); font-weight: 450; }
.strip-item-alert .strip-num { color: var(--red); }
@media (max-width: 640px) {
    .strip-item { flex-direction: column; align-items: flex-start; gap: 2px; padding: 11px 12px; }
    .strip-num { font-size: 20px; }
    .strip-label { font-size: 11px; }
}
/* Phones: 2×2 grid instead of four squeezed columns */
@media (max-width: 560px) {
    .stat-strip { display: grid; grid-template-columns: 1fr 1fr; }
    .strip-item { border-left: none; border-top: 1px solid var(--border); }
    .strip-item:nth-child(-n+2) { border-top: none; }
    .strip-item:nth-child(even) { border-left: 1px solid var(--border); }
}

/* ---- Agent home: business identity + status hero + activity feed ---- */
.dash-greeting { margin: 2px 0 18px; }
.dash-biz-name {
    font-size: 30px; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em;
    background: linear-gradient(120deg, var(--text), #3b82f6 140%);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.dash-biz-sub { color: var(--text-muted); font-size: 15px; margin-top: 6px; max-width: 52ch; }
@media (max-width: 640px) {
    .dash-greeting { margin-bottom: 14px; }
    .dash-biz-name { font-size: 23px; }
    .dash-biz-sub { font-size: 13.5px; }
}
.agent-hero {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; padding: 18px 20px; margin-bottom: 18px;
}
.agent-hero-main { display: flex; align-items: center; gap: 14px; min-width: 0; }
.agent-avatar {
    flex: none; width: 44px; height: 44px; border-radius: 12px; color: #fff;
    display: grid; place-items: center; background: linear-gradient(135deg, #3b82f6, #1d4ed8);
}
.agent-title { font-size: 18px; font-weight: 700; line-height: 1.2; }
.agent-status {
    font-size: 13.5px; font-weight: 550; margin-top: 4px;
    display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
}
.agent-status-live { color: var(--green); }
.agent-status-setup { color: var(--amber); }
.agent-number { font-weight: 700; color: var(--text); }
.agent-hero-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.live-dot, .setup-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.live-dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.setup-dot { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
@media (max-width: 640px) {
    .agent-hero { flex-direction: column; align-items: stretch; }
    .agent-hero-actions .btn { flex: 1; justify-content: center; }
}

.activity-feed { list-style: none; margin: 0; padding: 0; }
.activity-row {
    display: flex; align-items: center; gap: 14px; padding: 13px 18px;
    border-top: 1px solid var(--border); cursor: pointer;
}
.activity-row:first-child { border-top: none; }
.activity-row:hover { background: var(--surface-subtle); }
.activity-icon { flex: none; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; }
.activity-booked    { color: var(--green);  background: var(--green-soft); }
.activity-message   { color: var(--purple); background: var(--purple-soft); }
.activity-escalated { color: var(--amber);  background: var(--amber-soft); }
.activity-answered  { color: var(--accent); background: var(--accent-soft); }
.activity-main { flex: 1; min-width: 0; }
.activity-headline { font-weight: 600; font-size: 14px; }
.activity-sub {
    font-size: 12.5px; color: var(--text-muted); margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.activity-who { font-weight: 550; color: var(--text-secondary); }
.activity-time { flex: none; font-size: 12px; color: var(--text-faint); white-space: nowrap; }

/* count chip used in nav (e.g. open escalations) */
.nav-pill {
    background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
    border-radius: var(--r-pill); padding: 1px 7px; line-height: 1.6;
}

/* ----------------------------------- Layout ----------------------------------- */
.container { max-width: 1120px; margin: 28px auto; padding: 0 24px; }

.page-header {
    display: flex; justify-content: space-between; align-items: center;
    gap: 16px; margin-bottom: 22px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }
.page-header .count { font-size: 15px; font-weight: 400; color: var(--text-muted); margin-left: 6px; }
.page-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 2px; }

.section-heading { font-size: 15px; font-weight: 650; margin-bottom: 12px; }
.section-heading-spaced { margin-top: 32px; }
.section-help { margin: -4px 0 10px; }

/* Breadcrumb (back-links inside object views) */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--text-secondary); font-weight: 500; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { color: var(--text-faint); }

/* ----------------------------------- Cards ------------------------------------ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    padding: 22px;
    margin-bottom: 18px;
}
.card-flush { padding: 0; overflow: hidden; }
.card-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 15px; font-weight: 650; }
.card-pad { padding: 20px; }
.card-danger { border: 1px solid var(--red); border-left: 4px solid var(--red); }
.danger-item-title { font-weight: 650; margin-bottom: 8px; }
.danger-item-text { margin-bottom: 14px; }
.confirm-slug-input { width: 280px; }

/* ----------------------------------- Tables ----------------------------------- */
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left; padding: 9px 18px;
    font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); background: var(--surface-sunken);
    border-bottom: 1px solid var(--border);
}
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.col-shrink { width: 1%; }
td.col-actions { text-align: right; padding-right: 18px; }
td {
    padding: 11px 18px; border-bottom: 1px solid var(--border);
    font-size: 13.5px; vertical-align: middle; color: var(--text);
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-subtle); }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 650; background: var(--surface-sunken); border-top: 1px solid var(--border-strong); }

tr.row-link { cursor: pointer; }
tr.row-link:hover { background: var(--surface-subtle); }
tr.row-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ----------------------------------- Badges ----------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: var(--r-pill);
    font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
    border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge-active,   .badge-booked   { background: var(--green-soft);  color: var(--success-text); }
.badge-escalated { background: var(--amber-soft);  color: var(--warn-text); }
.badge-resolved, .badge-neutral  { background: var(--surface-sunken); color: var(--text-secondary); }
.badge-completed { background: var(--accent-soft); color: var(--accent-hover); }
.badge-danger    { background: var(--red-soft); color: var(--danger-text); }
.badge-plain::before { display: none; }

/* ----------------------------------- Buttons ---------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 8px 15px; border-radius: var(--r); border: 1px solid transparent;
    font-family: inherit; font-size: 13.5px; font-weight: 600; line-height: 1.2;
    cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s, color .15s;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.btn svg { flex-shrink: 0; }

.btn-primary { background: var(--accent); color: var(--accent-fg); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-fg); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-subtle); border-color: var(--text-faint); color: var(--text); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-sunken); color: var(--text); }

.btn-success { background: #0f7a37; color: #fff; }   /* darker green — white-on-green passes AA */
.btn-success:hover { background: #0c6a2f; color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #c01f1f; color: #fff; }

/* subtle destructive — neutral until hover */
.btn-delete-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-delete-ghost:hover { background: var(--red-soft); color: var(--danger-text); border-color: transparent; }

.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn-lg { padding: 11px 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-flex-end { align-self: flex-end; margin-bottom: 2px; }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; }

/* ----------------------------------- Forms ------------------------------------ */
.input, input[type="text"], input[type="password"], input[type="number"],
input[type="email"], input[type="search"], select, textarea {
    width: 100%; padding: 9px 12px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--r);
    font-family: inherit; font-size: 14px; line-height: 1.4;
    transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 80px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
select { appearance: none; -webkit-appearance: none; background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a93a6' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 11px center; padding-right: 34px; cursor: pointer; }

label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }

/* Settings field (shared macro) */
.settings-grid { display: grid; gap: 18px; }
.settings-grid-2 { grid-template-columns: 1fr 1fr; }
.settings-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.settings-field-narrow { margin: 0; max-width: 460px; }
.settings-field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.req-marker {
    display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: var(--r-pill);
    font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase;
    color: var(--accent); background: var(--accent-soft); vertical-align: middle;
}
.settings-field .help { font-size: 12px; color: var(--text-muted); margin-top: 6px; line-height: 1.45; }
.settings-field.bool { display: flex; align-items: center; gap: 9px; }
.settings-field.bool label { margin: 0; }
.settings-field.bool input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.settings-advanced { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.settings-advanced > summary {
    cursor: pointer; list-style: none; font-size: 13px; font-weight: 600;
    color: var(--text-secondary); display: flex; align-items: center; gap: 8px;
}
.settings-advanced > summary::-webkit-details-marker { display: none; }
.settings-advanced > summary::before { content: "+"; font-weight: 700; width: 1ch; text-align: center; color: var(--text-muted); }
.settings-advanced[open] > summary::before { content: "\2212"; }  /* minus */

/* Sticky save bar — long settings forms keep Save in reach at every width
   (backed, so fields scroll under it instead of the button floating over one) */
.settings-save-row {
    position: sticky; bottom: 0; z-index: 20;
    margin-top: 16px; padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--nav-bg); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
}

/* Filter bar */
.filter-form { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.filter-form input, .filter-form select { width: auto; min-width: 180px; }
.filter-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }

/* Search input with a leading magnifier (any input.search field) */
input.search {
    padding-left: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a93a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: 12px center; background-size: 16px;
}

/* List toolbar — one unified search field + an auto-applying filter select.
   Replaces stacks of separate phone/name inputs and a Filter button. */
.list-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.list-toolbar-search { flex: 1 1 auto; min-width: 0; max-width: 440px; }
.list-toolbar select { flex: none; width: auto; min-width: 150px; }
.list-toolbar .btn { flex: none; }
@media (max-width: 560px) {
    .list-toolbar { gap: 8px; flex-wrap: wrap; }
    .list-toolbar-search { flex: 1 1 100%; max-width: none; }
    .list-toolbar select { flex: 1 1 auto; }
}

/* Active-filter chips */
.filter-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -4px 0 16px; }
.filter-chips-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.filter-chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
    background: var(--accent-soft); color: var(--accent-hover);
    border-radius: var(--r-pill); font-size: 12.5px; font-weight: 550;
}
.filter-chip:hover { background: var(--accent-soft); color: var(--accent-hover); }
.filter-chip-x { font-size: 13px; line-height: 1; opacity: .7; }
.filter-chip-clear { font-size: 12.5px; color: var(--text-muted); text-decoration: underline; }

/* Date range — one-click preset pills (replaces the dual native date-pickers).
   A custom span lives behind a no-JS <details> for the rare exact-range need. */
.date-range { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-sunken); border-radius: var(--r); }
.segmented .seg {
    padding: 6px 13px; font-size: 13px; font-weight: 550; color: var(--text-muted);
    border-radius: var(--r-sm); white-space: nowrap; transition: color .12s, background .12s;
}
.segmented .seg:hover { color: var(--text); }
.segmented .seg.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-xs); }
.range-custom > summary {
    list-style: none; cursor: pointer; font-size: 12.5px; color: var(--text-muted);
    display: inline-flex; align-items: center; gap: 5px;
}
.range-custom > summary::-webkit-details-marker { display: none; }
.range-custom > summary::before { content: "+"; font-weight: 600; width: 1ch; text-align: center; }
.range-custom[open] > summary::before { content: "\2212"; }  /* minus */
.range-custom > summary:hover { color: var(--text); }
.range-custom-fields { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ----------------------------------- Stats ------------------------------------ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
    position: relative; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-md); box-shadow: var(--shadow-sm); padding: 18px 20px;
    transition: box-shadow .15s, transform .15s; overflow: hidden;
}
a .stat-card:hover, .stat-card.is-link:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--border-strong); }
.stat-card-blue::before   { background: var(--accent); }
.stat-card-green::before  { background: var(--green); }
.stat-card-amber::before { background: var(--amber); }
.stat-card-red::before    { background: var(--red); }
.stat-card-purple::before { background: var(--purple); }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--text-secondary); margin-top: 6px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.stat-sublabel { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; font-weight: 450; line-height: 1.35; }
/* Tap-to-dial carrier code (getting-started) */
.tel-code { color: var(--accent); text-decoration: none; }
.tel-code:hover { text-decoration: underline; }
/* Collapsible cost breakdown (admin client overview) */
.cost-breakdown > summary { cursor: pointer; list-style-position: inside; }
.cost-breakdown > summary:hover { color: var(--accent); }
/* Inline caller name/notes editor (admin conversations list) */
.customer-note { font-size: 12px; color: var(--accent); margin-top: 3px; }
.row-edit { margin-top: 6px; }
.row-edit > summary { cursor: pointer; font-size: 12px; color: var(--text-muted); list-style: none; display: inline-block; }
.row-edit > summary::-webkit-details-marker { display: none; }
.row-edit > summary::before { content: "✎ "; }
.row-edit > summary:hover { color: var(--accent); }
.row-edit[open] > summary { margin-bottom: 8px; }
.row-edit-form { display: flex; flex-direction: column; gap: 4px; max-width: 340px; padding: 4px 0 8px; }
.row-edit-form label { font-size: 11.5px; color: var(--text-muted); font-weight: 550; margin: 0; }
.row-edit-form input, .row-edit-form textarea { font-size: 13px; }
.row-edit-form button { align-self: flex-start; margin-top: 4px; }

/* Weekly business-hours editor */
.hours-presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.hours-presets-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.hours-preset {
    padding: 5px 12px; border-radius: var(--r-pill);
    background: var(--surface); color: var(--text-secondary);
    border: 1px solid var(--border-strong); font-family: inherit;
    font-size: 12.5px; font-weight: 550; line-height: 1.4; cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}
.hours-preset:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.hours-preset:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.hours-grid { display: flex; flex-direction: column; }
.hours-row {
    display: grid; grid-template-columns: 92px 118px 1fr; align-items: center; gap: 14px;
    padding: 8px 0; border-top: 1px solid var(--border); min-height: 52px;
}
.hours-row:first-child { border-top: none; }
.hours-day { font-weight: 600; font-size: 14px; }
.hours-times { display: flex; align-items: center; gap: 8px; }
.hours-times select { width: auto; max-width: 130px; }
.hours-sep { color: var(--text-muted); font-size: 13px; }
.hours-closed-note { display: none; font-size: 13px; color: var(--text-faint); }
.hours-row.is-off .hours-times { display: none; }
.hours-row.is-off .hours-closed-note { display: block; }
/* Overnight / 24h flag — replaces the old cryptic footnote */
.hours-flag {
    padding: 2px 9px; border-radius: var(--r-pill); white-space: nowrap;
    background: var(--amber-soft); color: var(--warn-text);
    font-size: 11px; font-weight: 650;
}
/* Copy this day's hours to every open day */
.hours-copy {
    margin-left: 6px; padding: 4px 10px; border-radius: var(--r-sm);
    background: none; border: none; font-family: inherit;
    font-size: 12px; font-weight: 550; color: var(--text-muted); cursor: pointer;
    white-space: nowrap; transition: color .15s, background .15s;
}
.hours-copy:hover { color: var(--accent); background: var(--accent-soft); }
.hours-copy:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
/* Open/closed switch — the state word is part of the tap target */
.hours-toggle { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.hours-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.hours-toggle-track { width: 36px; height: 20px; flex: none; background: var(--border-strong); border-radius: var(--r-pill); transition: background .15s; display: inline-block; position: relative; }
.hours-toggle-dot { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: var(--shadow-xs); }
.hours-toggle input:checked ~ .hours-toggle-track { background: var(--green); }
.hours-toggle input:checked ~ .hours-toggle-track .hours-toggle-dot { transform: translateX(16px); }
.hours-toggle input:focus-visible ~ .hours-toggle-track { box-shadow: 0 0 0 3px var(--accent-ring); }
.hours-toggle-state::after { content: "Closed"; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.hours-row:not(.is-off) .hours-toggle-state::after { content: "Open"; color: var(--success-text); }
/* "Callers will hear" live preview — the settings page speaks the product */
.hours-preview {
    display: flex; gap: 10px; align-items: flex-start;
    margin-top: 16px; padding: 12px 14px;
    background: var(--accent-soft); border: 1px solid var(--border); border-radius: var(--r);
}
.hours-preview-icon { color: var(--accent); flex: none; margin-top: 1px; display: inline-flex; }
.hours-preview-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 2px; }
.hours-preview-text { font-size: 13.5px; line-height: 1.5; color: var(--text); font-style: italic; }
@media (max-width: 560px) {
    .hours-row {
        grid-template-columns: 1fr auto; grid-template-areas: "day toggle" "times times";
        row-gap: 8px; padding: 12px 0; min-height: 0;
    }
    .hours-day { grid-area: day; } .hours-toggle { grid-area: toggle; } .hours-times { grid-area: times; flex-wrap: wrap; }
    .hours-row.is-off { grid-template-areas: "day toggle"; }
    .hours-row.is-off .hours-closed-note { display: none; }   /* the labeled switch already says Closed */
    .hours-copy { min-height: 38px; margin-left: auto; }
}

/* Guided booking steps (admin booking tab) */
.booking-step { padding: 18px 0; border-top: 1px solid var(--border); }
.booking-step:first-of-type { padding-top: 0; border-top: none; }
.booking-step-label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; margin-bottom: 12px; }
.step-num { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.booking-status { font-weight: 650; }
.booking-status-green { color: var(--green); }
.booking-status-amber { color: var(--amber); }
.stat-card-hero { grid-column: span 2; background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.stat-card-hero .stat-value { font-size: 36px; }

/* ----------------------------------- Chat / transcript ------------------------ */
.transcript-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.transcript-head-icon { display: inline-flex; color: var(--accent); }
.transcript-head-label { font-family: var(--font-display); font-weight: 700; font-size: 14px; color: var(--text); }
.transcript-head-meta { font-size: 12px; color: var(--text-muted); }
.messages-container { background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-md); padding: 22px; }
.msg-row { display: flex; flex-direction: column; margin-bottom: 14px; }
.msg-row-user { align-items: flex-end; }
.msg-row-assistant, .msg-row-tool { align-items: flex-start; }
.msg-time { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.msg {
    max-width: 76%; padding: 10px 14px; border-radius: 14px;
    font-size: 14px; line-height: 1.6; word-wrap: break-word; box-shadow: var(--shadow-xs);
}
.msg-user { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-assistant { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }
.msg-tool {
    background: var(--surface-sunken); border: 1px solid var(--border); color: var(--text-secondary);
    font-family: var(--mono); font-size: 12px; border-radius: var(--r); max-width: 70%; margin-left: 20px;
}
.tool-details { margin-left: 20px; max-width: 72%; margin-bottom: 14px; }
.tool-details summary { font-size: 12px; color: var(--text-muted); cursor: pointer; font-weight: 550; padding: 4px 0; }
.tool-details summary:hover { color: var(--text-secondary); }
.tool-details .msg-tool { margin-left: 0; margin-top: 4px; }

.date-divider { text-align: center; margin: 22px 0; position: relative; }
.date-divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--border); }
.date-divider span {
    position: relative; background: var(--canvas); padding: 0 12px;
    font-size: 11px; font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;
}

/* ----------------------------------- Customer thread (timeline) --------------- */
/* Intercom/Front-style: a customer = one contact with a vertical call timeline. */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; margin-bottom: 18px; }
.timeline-dot {
    position: absolute; left: -28px; top: 2px; width: 20px; height: 20px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--border-strong);
    display: flex; align-items: center; justify-content: center;
}
.timeline-dot-booked { border-color: var(--green); color: var(--green); }
.timeline-dot-escalated { border-color: var(--amber); color: var(--amber); }
.timeline-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
    box-shadow: var(--shadow-xs); padding: 14px 16px; transition: box-shadow .15s, border-color .15s;
}
.timeline-card:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.timeline-meta { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); }

/* Customer cell (name + phone + issue stack inside a table row) */
td.customer-cell { position: relative; padding-left: 22px; min-width: 220px; }
td.customer-cell .unread-dot { position: absolute; left: 14px; top: 16px; }
.customer-name-link, td.customer-cell .customer-name-link {
    display: block; font-weight: 650; font-size: 14px; color: var(--text); line-height: 1.3; margin-bottom: 1px;
}
.customer-name-link:hover { color: var(--accent); }
td.customer-cell .customer-phone { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; margin-bottom: 2px; }
td.customer-cell .customer-issue {
    font-size: 12.5px; color: var(--text-secondary); line-height: 1.35; max-width: 320px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.unread-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ----------------------------------- Pagination ------------------------------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 22px; }
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px;
    padding: 0 11px; border-radius: var(--r-sm); font-size: 13px; font-weight: 550;
}
.pagination a { background: var(--surface); border: 1px solid var(--border); color: var(--text-secondary); }
.pagination a:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-subtle); }
.pagination .current { background: var(--accent); color: #fff; }
.pagination .page-ellipsis { color: var(--text-faint); }

/* ----------------------------------- Empty state ------------------------------ */
.empty-state { padding: 64px 24px; text-align: center; }
.empty-state-compact { padding: 32px 24px; }
.empty-state-icon {
    width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-soft); color: var(--accent);
}
.empty-state-title { font-size: 16px; font-weight: 650; margin-bottom: 4px; }
.empty-state-text { color: var(--text-muted); font-size: 14px; max-width: 380px; margin: 0 auto; }

/* ----------------------------------- Flash ------------------------------------ */
.flash {
    display: flex; align-items: center; gap: 10px; padding: 11px 16px; margin-bottom: 18px;
    border-radius: var(--r); font-size: 13.5px; font-weight: 550; border: 1px solid transparent;
    animation: flash-in .25s ease;
}
.flash-success { background: var(--green-soft); color: var(--success-text); border-color: var(--border); }
.flash-info { background: var(--accent-soft); color: var(--accent-hover); border-color: var(--border); }
.flash-error { background: var(--red-soft); color: var(--danger-text); border-color: var(--border); }
.flash-close { margin-left: auto; background: none; border: none; cursor: pointer; font-size: 18px; line-height: 1; color: inherit; opacity: .55; }
.flash-close:hover { opacity: 1; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Impersonation banner (admin previewing an owner) */
.impersonation-banner {
    background: var(--amber-soft); color: var(--warn-text); border-bottom: 1px solid var(--border-strong);
    text-align: center; padding: 8px 16px; font-size: 13px; font-weight: 600;
}
.impersonation-banner a { color: var(--warn-text); text-decoration: underline; }

/* ----------------------------------- Notes (owner) ---------------------------- */
.notes-card { background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--r-md); padding: 16px; }
.notes-card label { color: var(--text-secondary); font-weight: 600; }
.notes-card textarea { border-color: var(--border); background: var(--surface); }
.notes-card textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ----------------------------------- Tabs (object sub-nav) -------------------- */
/* Used for admin per-tenant sub-navigation and grouped settings sections. */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab {
    display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; white-space: nowrap;
    color: var(--text-secondary); font-size: 13.5px; font-weight: 550;
    border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .tab-count { font-size: 11px; font-weight: 650; color: var(--text-muted); background: var(--surface-sunken); border-radius: var(--r-pill); padding: 1px 7px; }

/* ----------------------------------- Detail rows (key / value) ---------------- */
/* Replaces ad-hoc "Label: value" stacks. Clean two-column key/value display. */
.detail-grid { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; align-items: baseline; }
.detail-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-value { font-size: 14px; color: var(--text); }
.detail-value.empty { color: var(--text-faint); }

/* ----------------------------------- Object layout (main + aside) ------------- */
/* Detail pages: primary content + a sticky context sidebar (customer info,
   booked appointment, etc.). Collapses to one column on tablet/phone. */
.object-layout { display: grid; grid-template-columns: 1fr 320px; gap: 22px; align-items: start; }
.object-aside { position: sticky; top: calc(var(--nav-h) + 22px); display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 900px) {
    .object-layout { grid-template-columns: 1fr; }
    .object-aside { position: static; }
}
/* On phone, show the aside (customer context + booking) above the transcript.
   The owner wants "who/what/booked-when" before scrolling the transcript. */
@media (max-width: 560px) {
    .object-aside { order: -1; }
}

/* ----------------------------------- Booking / appointment chip --------------- */
/* "Booked Thu Jun 26, 8–10am · HouseCall Pro" — appointment time + the CRM it
   landed in. .appt-system carries the external_system name. */
.appt {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px;
    background: var(--green-soft); border: 1px solid #bfe6cd; border-radius: var(--r);
}
.appt-icon { color: var(--green); flex-shrink: 0; }
.appt-when { font-weight: 650; color: var(--success-text); font-size: 13.5px; }
.appt-system { font-size: 12px; color: var(--text-secondary); }
.appt-system b { color: var(--text); font-weight: 600; }

/* ----------------------------------- Utilities -------------------------------- */
.muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }
.text-normal { font-weight: normal; }
.text-secondary { color: var(--text-secondary); }
.truncate { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.hide { display: none; }
.mono { font-family: var(--mono); }

/* ----------------------------------- Auth pages ------------------------------- */
/* Centered card layout for /login, /set-password, /forgot-password.            */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 24px; background: var(--canvas);
}
.auth-card {
    width: 100%; max-width: 400px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-lg); box-shadow: var(--shadow-md); padding: 36px 32px;
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-logo-text { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.auth-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.auth-sub { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 22px; }
.auth-field { margin-bottom: 16px; }
.auth-field label { display: block; margin-bottom: 6px; }
.auth-actions { margin-top: 20px; }
.auth-link { display: block; text-align: center; margin-top: 14px; font-size: 13px; color: var(--text-muted); }
.auth-link:hover { color: var(--accent); }

/* ----------------------------------- Responsive ------------------------------- */
/* Prevent iOS zoom on focus — inputs must be ≥16px on small screens. */
@media (max-width: 768px) {
    input, select, textarea { font-size: 16px; }

    /* Nav on mobile: brand left, hamburger right. The links + sign-out collapse
       into a dropdown panel toggled by a CSS-only checkbox — no horizontal
       scrolling, nothing hidden off-screen, sign-out clearly separated. */
    .nav { padding: 0 14px; }
    .nav-brand { margin-right: 8px; flex-shrink: 0; }
    .nav-burger {
        display: inline-flex; align-items: center; justify-content: center;
        margin-left: auto; margin-right: -8px; flex-shrink: 0; position: relative;
        width: 42px; height: 42px; border-radius: var(--r-sm);
        color: var(--text-secondary); cursor: pointer;
    }
    .nav-burger:hover { color: var(--text); background: var(--surface-sunken); }
    /* Needs-attention count surfaced on the burger so it's visible without opening the menu */
    .nav-burger-badge {
        position: absolute; top: 3px; right: 1px; min-width: 17px; height: 17px; padding: 0 5px;
        display: inline-flex; align-items: center; justify-content: center;
        background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700;
        border-radius: var(--r-pill); line-height: 1; box-shadow: 0 0 0 2px var(--surface);
    }
    /* When the drawer is open, the count is already visible inside — hide the dot */
    .nav-toggle:checked ~ .nav-burger .nav-burger-badge { display: none; }

    /* Dropdown panel: full-bleed under the nav, stacked vertically, hidden until
       the burger is tapped. Negative side margins cancel the nav's padding. */
    .nav-menu {
        display: none;
        position: absolute; top: 100%; left: 0; right: 0; margin: 0 -14px;
        flex-direction: column; align-items: stretch;
        background: var(--surface); border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-md); padding: 6px 0;
    }
    .nav-toggle:checked ~ .nav-menu { display: flex; }

    .nav-links { flex-direction: column; align-items: stretch; gap: 0; height: auto; }
    .nav-links a {
        height: auto; padding: 13px 18px; font-size: 15px; font-weight: 550;
        justify-content: flex-start; gap: 8px; border-bottom: none;
    }
    .nav-links a.active { color: var(--accent); background: var(--accent-soft); border-bottom: none; }

    .nav-end {
        flex-direction: column; align-items: stretch; gap: 0;
        margin: 4px 0 0; padding: 4px 0 0; border-top: 1px solid var(--border);
    }
    .nav-client-name { display: block; font-size: 15px; color: var(--text); font-weight: 600; }
    .nav-signout { padding: 13px 18px; font-size: 15px; }

    /* Account menu expands inline inside the mobile drawer (not an absolute dropdown) */
    .nav-account { width: 100%; }
    .nav-account-trigger { width: 100%; padding: 13px 18px; border-radius: 0; gap: 10px; }
    .nav-account-caret { margin-left: auto; }
    .nav-account-menu {
        position: static; box-shadow: none; border: none; border-radius: 0;
        padding: 0; min-width: 0; background: var(--surface-sunken);
    }
    .nav-account-menu a { padding: 12px 18px 12px 46px; font-size: 15px; }
    .nav-account-signout { margin-top: 0; }
    /* Theme toggle becomes a full-width labeled row in the dropdown (not a tiny square) */
    .nav-theme-toggle { width: 100%; height: auto; justify-content: flex-start; padding: 13px 18px; border-radius: 0; font-size: 15px; color: var(--text-secondary); }
    .nav-theme-label { display: inline; }

    .container { padding: 0 14px; margin: 16px auto; }
    .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
    .page-header h2 { font-size: 19px; }

    .filter-form { flex-direction: column; align-items: stretch; }
    .filter-form input, .filter-form select { width: 100%; min-width: 0; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .stat-card-hero { grid-column: span 2; }
    .stat-value { font-size: 25px; }

    .card-flush { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    th, td { padding: 11px 14px; }

    /* 44px tap targets (iOS HIG) */
    .btn { min-height: 44px; padding: 11px 16px; }
    .btn-sm { min-height: 38px; }

    .msg { max-width: 88%; }
    .msg-tool, .tool-details { max-width: 100%; margin-left: 0; }

    /* Settings: tighter card padding on mobile */
    .card { padding: 16px; }
    /* Admin settings hard-code multi-column grids inline (1fr 1fr / 1fr 1fr 1fr);
       collapse them all to one column on phones/tablets so fields stop getting
       squished — owner forms are already single-column. !important is required to
       beat the per-grid inline grid-template-columns. */
    .settings-grid { gap: 16px; grid-template-columns: 1fr !important; }

    /* Sub-nav tabs (admin per-tenant): clean horizontal scroll on mobile — hide
       the scrollbar, keep momentum scroll, and fade the right edge as a hint that
       there are more tabs off-screen (instead of a tab cut mid-word). */
    .tabs { -webkit-overflow-scrolling: touch; scrollbar-width: none;
        -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
        mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
    .tabs::-webkit-scrollbar { display: none; }
}

@media (max-width: 560px) {
    .nav-brand-text, .nav-brand-sub { display: none; }
    /* Keep stat cards two-up on phones — one-per-row made long pages of half-empty
       cards. The hero keeps the full row. */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px 16px; }
    .stat-value { font-size: 22px; }
    .stat-label { flex-wrap: wrap; row-gap: 0; }
    .stat-card-hero { grid-column: span 2; }
    .stat-card-hero .stat-value { font-size: 28px; }
    .col-hide-sm { display: none; }

    /* Getting-started: phone number hero + action row */
    .gs-number-row { flex-direction: column; align-items: flex-start; gap: 12px; }

    /* Conversation page: name + status + edit btn row can wrap */
    .conv-header-row { flex-wrap: wrap; gap: 8px; }

    /* Notes card: prevent overflow */
    .notes-card { overflow: hidden; }
    .notes-card textarea { word-break: break-word; }

    /* Timeline: tighten left padding so cards don't clip on the right */
    .timeline { padding-left: 22px; }
    .timeline-dot { left: -22px; }
    .timeline-card { padding: 12px; }

    /* Customer/conversation aside: ensure no overflow */
    .object-aside .detail-grid { overflow-wrap: break-word; word-break: break-word; }
    .detail-value { overflow-wrap: break-word; word-break: break-word; }

    /* Settings: the sticky save bar goes full-bleed + full-width button on phones */
    .settings-save-row { margin-left: -14px; margin-right: -14px; padding-left: 14px; padding-right: 14px; }
    .settings-save-row .btn { width: 100%; justify-content: center; }
}
@media (max-width: 1200px) { .col-hide-lg { display: none; } }
@media (max-width: 900px) { .col-hide-md { display: none; } }

/* ----------------------------------- Accessibility ---------------------------- */
/* Keyboard focus on controls the cascade missed. */
.nav-links a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--r-sm); }
.filter-chip-x:focus-visible,
.flash-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

/* Live-refresh indicator goes red when the tab can't reach the server. */
.refresh-indicator.is-offline { color: var(--red); }

/* Honor reduced-motion (kills the live-dot pulse + transitions on request). */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}

/* Mobile: lift small-button + glyph tap targets to the 44px iOS minimum. */
@media (max-width: 768px) {
    .btn-sm { min-height: 44px; }
    .flash-close, .filter-chip-x {
        min-width: 44px; min-height: 44px;
        display: inline-flex; align-items: center; justify-content: center;
    }
}

/* ----------------------------------- Mobile stacked-card tables --------------- */
/* Under 560px the customer/booking/escalation tables reflow to compact cards.
   The customer-cell (name + phone + issue) is the card header; the remaining
   <td>s flow inline below it as small label:value pairs that wrap — so a row
   takes ~3 tight lines instead of 5 full-width labeled rows. */
@media (max-width: 560px) {
    .card-flush { overflow-x: visible; }

    /* Table chrome disappears — rows become cards */
    table { display: block; }
    thead { display: none; }
    tbody { display: block; }
    tfoot { display: block; }

    tbody tr {
        display: flex; flex-wrap: wrap; align-items: baseline;
        column-gap: 14px; row-gap: 4px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-md);
        margin: 0 0 8px;
        padding: 12px 14px;
        box-shadow: var(--shadow-xs);
    }
    /* Remove per-cell bottom border; the card border handles separation */
    tbody tr td { border-bottom: none; }

    /* The customer-cell (rich markup) is the full-width card header */
    td.customer-cell {
        flex: 1 1 100%; display: block; min-width: 0;
        padding: 0 0 8px 20px; margin-bottom: 4px;
        border-bottom: 1px solid var(--border);
    }
    td.customer-cell .unread-dot { top: 5px; left: 4px; }
    td.customer-cell .customer-issue { white-space: normal; max-width: none; }

    /* Secondary cells flow inline as compact label:value pairs (wrapping).
       min-width:0 lets a long value (e.g. an appointment) shrink + wrap
       instead of forcing the card wider than the screen. */
    td[data-label] {
        display: inline-flex; align-items: baseline; gap: 5px;
        width: auto; min-width: 0; padding: 0;
        font-size: 12.5px; color: var(--text-secondary);
    }
    td[data-label]::before {
        content: attr(data-label);
        font-size: 10.5px; font-weight: 650; text-transform: uppercase;
        letter-spacing: 0.04em; color: var(--text-faint); flex-shrink: 0;
    }
    /* The appointment (only long value) gets its own full-width wrapping line */
    td.col-hide-md[data-label] { flex: 1 1 100%; }
    /* Empty data-label (action cells) — no label prefix, own full-width line */
    td[data-label=""] { flex: 1 1 100%; padding: 4px 0 0; }
    td[data-label=""]::before { display: none; }

    /* col-hide-sm tds would normally be hidden — keep them visible inside cards
       (they carry data-labels now). Scope to tbody so other uses are unaffected. */
    tbody td.col-hide-sm { display: inline-flex; }

    /* tfoot "Total" row → its own summary card (matching the row cards) instead of
       a cramped inline box. The first cell ("Total") is the header; empty filler
       cells are hidden; the rest flow as label:value pairs like the row cards.
       Scoped out of table-static, which keeps a normal table on mobile. */
    table:not(.table-static) tfoot tr {
        display: flex; flex-wrap: wrap; align-items: baseline;
        column-gap: 14px; row-gap: 4px;
        background: var(--surface-sunken);
        border: 1px solid var(--border-strong);
        border-radius: var(--r-md);
        margin: 8px 0 0; padding: 12px 14px;
    }
    table:not(.table-static) tfoot td { border: none; }
    table:not(.table-static) tfoot td:not([data-label]) { display: none; }
    table:not(.table-static) tfoot td:first-child {
        display: block; flex: 1 1 100%;
        font-size: 10.5px; font-weight: 700; text-transform: uppercase;
        letter-spacing: 0.04em; color: var(--text-faint);
        padding: 0 0 6px; border-bottom: 1px solid var(--border);
    }
    table:not(.table-static) tfoot td[data-label] {
        display: inline-flex; align-items: baseline; gap: 5px;
        width: auto; min-width: 0; padding: 0;
        font-size: 12.5px; font-weight: 650; color: var(--text);
    }
    table:not(.table-static) tfoot td[data-label]::before {
        content: attr(data-label);
        font-size: 10.5px; font-weight: 650; text-transform: uppercase;
        letter-spacing: 0.04em; color: var(--text-faint); flex-shrink: 0;
    }

    /* Compact comparison tables (e.g. admin "Cost breakdown by service") opt OUT
       of the card reflow — they're narrow numeric tables that read better as a
       normal table on mobile than one card per row (which mangled the Total row
       into a cramped inline box). */
    table.table-static { display: table; width: 100%; }
    table.table-static thead { display: table-header-group; }
    table.table-static tbody { display: table-row-group; }
    table.table-static tfoot { display: table-footer-group; }
    table.table-static tr {
        display: table-row; background: none; border: none;
        border-radius: 0; margin: 0; padding: 0; box-shadow: none;
    }
    table.table-static th, table.table-static td { display: table-cell; padding: 9px 10px; }
    table.table-static tbody td { border-bottom: 1px solid var(--border); }
    table.table-static td.col-hide-sm, table.table-static th.col-hide-sm { display: none; }
    table.table-static tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
}

/* ----------------------------------- Shared utility classes ------------------- */
/* Timeline card link — replaces inline style="display: block; text-decoration: none; color: inherit" */
.timeline-card-link { display: block; text-decoration: none; color: inherit; }

/* Name edit form — hidden until toggled via JS (.hide / JS toggle) */
.name-edit-form { display: none; }
.name-edit-form.is-visible { display: flex; }

/* Inline name-edit input width cap */
.name-edit-input { max-width: 280px; }

/* Notes form spacing */
.notes-form { margin-top: 10px; }

/* Stats page — outcome bar chart rows */
.outcome-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.outcome-label { font-size: 12.5px; color: var(--text-muted); width: 140px; flex-shrink: 0; }
.outcome-bar-track {
    flex: 1; background: var(--surface-sunken);
    border-radius: var(--r-pill); height: 8px; overflow: hidden;
}
.outcome-bar-fill {
    height: 100%; border-radius: var(--r-pill); transition: width .4s;
}
.outcome-count { font-size: 12.5px; color: var(--text-muted); width: 70px; text-align: right; flex-shrink: 0; }

@media (max-width: 480px) {
    /* Tighten outcome row label/count so bar track has room to breathe */
    .outcome-label { width: 110px; }
    .outcome-count { width: 56px; }
}
