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

:root {
    /* Brand navy — re-anchored from the old consumer indigo (#4F46E5) to a
       calmer, more trustworthy operational blue. "Only urgency glows": the
       chrome stays disciplined navy/slate so emergency red is the one signal
       that draws the eye. */
    --primary: #2554C7;
    --primary-dark: #1e44a3;
    --primary-darker: #17357e;
    --bg: #eef1f6;
    --card: #ffffff;
    --text: #16202e;
    --text-light: #64748b;
    --border: #e5e7eb;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --info: #2563eb;
    --emergency: #dc2626;
    --radius: 12px;
    --sidebar-w: 240px;

    /* Type stacks — CSP blocks external fonts, so we stay on fast native
       stacks but split out a mono face for operational telemetry (record IDs,
       timestamps, log lines) so scanned data reads like an instrument panel. */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

    /* Neutral text ramp + link + subtle surfaces — names the slate shades that
       were scattered as magic hexes across page-level <style> blocks. */
    --text-strong: #0f172a;
    --text-mid:    #475569;
    --text-soft:   #64748b;
    --text-faint:  #94a3b8;
    --link:        #2563eb;
    --surface-muted: #f8fafc;
    --line-soft:   #f1f5f9;

    /* ---- Shared design system (parallels the widget's --cb-* tokens) ---- */
    --sidebar-bg:   #0f1c31;   /* deep control-room navy — was #1a1a2e (indigo cast) */
    --sidebar-bg-2: #0b1626;   /* footer / gradient floor */
    --sidebar-line: rgba(148, 178, 224, 0.12);

    /* Accent derivations (admin primary is fixed, so these are literal) */
    --primary-tint:   rgba(37, 84, 199, 0.08);
    --primary-tint-2: rgba(37, 84, 199, 0.045);
    --primary-line:   rgba(37, 84, 199, 0.22);
    --primary-glow:   rgba(37, 84, 199, 0.32);
    --primary-soft:   #eef3fd;   /* tinted surface for icon tiles, active rows */

    /* Elevation scale */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.10);
    --shadow-lg: 0 16px 40px -12px rgba(15, 23, 42, 0.22);

    /* Focus ring */
    --ring: 0 0 0 3px rgba(37, 84, 199, 0.20);

    /* Type scale (px) */
    --fs-xs: 12px;
    --fs-sm: 13px;
    --fs-base: 14px;
    --fs-md: 16px;
    --fs-lg: 18px;
    --fs-xl: 24px;
    --fs-2xl: 30px;

    /* Spacing scale — 4px base */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;

    /* Radius scale (--radius kept for compatibility) */
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 100px;

    /* Motion */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.45, 0.56, 1);
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Layout */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #13233d 0%, var(--sidebar-bg) 44%, var(--sidebar-bg-2) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: inset -1px 0 0 var(--sidebar-line);
}

.sidebar-header {
    padding: 22px 20px 18px;
    border-bottom: 1px solid var(--sidebar-line);
}

/* Brand lockup — a Polaris (4-point compass star) mark is the one
   restrained brand signature; the wordmark type stays quiet beside it. */
.sidebar-brand { display: flex; align-items: center; gap: 11px; }
.sidebar-star {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(140deg, var(--primary) 0%, var(--primary-darker) 100%);
    box-shadow: 0 4px 12px -3px rgba(37, 84, 199, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.sidebar-star svg { width: 20px; height: 20px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25)); }
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.22; min-width: 0; }
.sidebar-brand-name {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.sidebar-subtitle {
    font-size: 11.5px;
    color: rgba(203, 217, 240, 0.55);
    letter-spacing: 0.02em;
}

.nav-menu {
    list-style: none;
    padding: 12px 10px;
    flex: 1;
    overflow-y: auto;
}

/* Item 24: sidebar section headings + queue count badges. */
.nav-group {
    padding: 14px 12px 5px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
}
.nav-menu li.nav-group:first-child { padding-top: 4px; }
.nav-badge {
    margin-left: auto;
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 100px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    line-height: 16px;
}
.nav-menu li a.active .nav-badge { background: rgba(255, 255, 255, 0.28); }

/* Item 26: availability day toggles + slot-chip editor. */
.day-toggle { position: relative; display: inline-flex; cursor: pointer; }
.day-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.day-toggle span {
    display: inline-block; padding: 7px 14px;
    border: 1px solid var(--border); border-radius: 100px;
    font-size: 13px; color: var(--text); transition: all .15s ease;
}
.day-toggle input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }
.day-toggle input:focus-visible + span { box-shadow: 0 0 0 3px rgba(37, 84, 199, 0.22); }
.slot-editor { display: flex; flex-direction: column; gap: 10px; }
.slot-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.slot-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 8px 6px 12px; border: 1px solid var(--border);
    border-radius: 100px; font-size: 13px; font-variant-numeric: tabular-nums;
}
.slot-chip-x { border: none; background: none; cursor: pointer; font-size: 16px; line-height: 1; color: var(--muted, #64748b); padding: 0 2px; }
.slot-chip-x:hover { color: var(--danger); }
.slot-add { display: flex; gap: 8px; align-items: center; }
.slot-time-input { padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: inherit; }

/* Item 30: loading skeletons for async modal content (activity timelines). */
.dm-skeleton { display: flex; flex-direction: column; gap: 8px; padding: 6px 0 2px; }
.dm-skeleton-line {
    height: 12px; border-radius: 6px;
    background: linear-gradient(90deg, var(--border) 25%, #f1f5f9 37%, var(--border) 63%);
    background-size: 400% 100%; animation: dmShimmer 1.4s ease infinite;
}
.dm-skeleton-line:nth-child(2) { width: 82%; }
.dm-skeleton-line:nth-child(3) { width: 64%; }
@keyframes dmShimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.nav-menu li a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: var(--fs-base);
    font-weight: 500;
    transition: background 160ms var(--ease), color 160ms var(--ease);
}

.nav-menu li a:hover {
    background: rgba(148, 178, 224, 0.10);
    color: #fff;
}

.nav-menu li a.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 6px 16px -8px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.nav-menu li a:focus-visible {
    outline: none;
    color: #fff;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.55);
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
}

.nav-menu li a.active .nav-icon { opacity: 1; }

.nav-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* ---- Mobile topbar + menu button (hidden on desktop) ---- */
.admin-topbar { display: none; }
.admin-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.10);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 160ms var(--ease), transform 120ms var(--ease);
}
.admin-menu-btn svg { width: 22px; height: 22px; }
.admin-menu-btn:hover { background: rgba(255,255,255,0.18); }
.admin-menu-btn:active { transform: scale(0.94); }
.admin-menu-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.6);
}

/* ---- Drawer scrim (hidden on desktop) ---- */
.sidebar-scrim { display: none; }

.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--sidebar-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}
.sidebar-user-avatar {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
    color: #dbe6fb;
    background: rgba(148, 178, 224, 0.16);
    text-transform: uppercase;
}
.sidebar-user-name {
    font-size: 13px;
    font-weight: 500;
    color: rgba(226, 232, 240, 0.82);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-logout {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    color: rgba(203, 217, 240, 0.6);
    text-decoration: none;
    transition: background 160ms var(--ease), color 160ms var(--ease);
}
.sidebar-logout svg { width: 17px; height: 17px; }
.sidebar-logout span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sidebar-logout:hover { background: rgba(220, 38, 38, 0.16); color: #fecaca; }
.sidebar-logout:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5); }

.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0; /* let this flex item shrink so wide tables scroll inside their card, not the page */
    padding: 24px 32px;
    max-width: calc(100% - var(--sidebar-w));
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-header p {
    color: var(--text-light);
    font-size: 14px;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card h2 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.stat-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.data-table th {
    text-align: left;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 11px 14px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.data-table td {
    padding: 12px 14px;
    font-size: var(--fs-base);
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

/* Edge padding so rows breathe inside the card, not flush to the rule */
.data-table th:first-child,
.data-table td:first-child { padding-left: 18px; }
.data-table th:last-child,
.data-table td:last-child { padding-right: 18px; }

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr {
    transition: background 140ms var(--ease);
}

.data-table tr:hover td {
    background: var(--primary-tint-2);
}

.truncate {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: var(--primary);
    color: #fff;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    box-shadow: var(--shadow-xs);
    transition: background 180ms var(--ease),
                box-shadow 180ms var(--ease),
                transform 120ms var(--ease),
                filter 180ms var(--ease);
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px -4px var(--primary-glow);
}

.btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shadow-xs);
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    filter: grayscale(0.3);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-lg {
    padding: 12px 28px;
    font-size: 16px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #b91c1c;
    box-shadow: 0 6px 16px -4px rgba(220, 38, 38, 0.35);
}

.btn-danger:focus-visible {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.22);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    background: var(--bg);
    color: var(--text-light);
    text-transform: capitalize;
}
/* Status dot inherits the badge's text color — turns flat pills into a
   scannable control-panel signal without per-variant markup. */
.badge::before,
.status-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 auto;
    opacity: 0.85;
}

.badge-active { background: #dcfce7; color: #16a34a; }
.badge-closed { background: #fee2e2; color: #dc2626; }
.badge-processed { background: #dcfce7; color: #16a34a; }
.badge-processing { background: #fef3c7; color: #92400e; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-failed { background: #fee2e2; color: #dc2626; }

/* Forms */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 12.5px;
    letter-spacing: 0.1px;
    margin-bottom: 5px;
    color: var(--text);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="number"],
.form-group input[type="url"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
    font-family: inherit;
    transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
    background: var(--card);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

.form-group input[type="color"] {
    width: 60px;
    height: 36px;
    padding: 2px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.help-text {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

/* Search */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar input {
    flex: 1;
    padding: 9px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
    transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

/* Pagination */
.pagination {
    display: flex;
    gap: 6px;
    margin-top: 16px;
    justify-content: center;
}

/* Toggle grid */
.toggle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background 0.2s;
}

.toggle-label:hover {
    background: var(--bg);
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-error {
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

/* Upload zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--primary);
    background: rgba(37, 84, 199, 0.03);
}

.upload-icon {
    font-size: 40px;
    margin-bottom: 8px;
}

.upload-zone p {
    font-size: 14px;
    color: var(--text-light);
}

.progress-bar {
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0 8px;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

/* Chat thread in admin */
.chat-thread {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    display: flex;
    max-width: 80%;
}

.chat-message.chat-user {
    align-self: flex-end;
}

.chat-message.chat-assistant {
    align-self: flex-start;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.6;
}

.chat-user .chat-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-assistant .chat-bubble {
    background: var(--bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.chat-role {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 4px;
    opacity: 0.7;
}

.chat-meta {
    font-size: 11px;
    margin-top: 4px;
    opacity: 0.6;
}

/* Info grid */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 8px;
    font-size: 14px;
}

.info-grid div {
    padding: 6px 0;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
    font-size: 14px;
}

.text-error {
    color: var(--danger);
}

/* Responsive */
@media (max-width: 768px) {
    /* Fixed top bar carries the hamburger + brand */
    .admin-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        position: fixed;
        top: 0; left: 0; right: 0;
        height: 56px;
        padding: 0 12px;
        padding-top: env(safe-area-inset-top);
        height: calc(56px + env(safe-area-inset-top));
        background: var(--sidebar-bg);
        color: #fff;
        z-index: 200;
        box-shadow: 0 1px 0 rgba(255,255,255,0.06), var(--shadow-md);
    }
    .admin-topbar-title {
        font-size: var(--fs-md);
        font-weight: 700;
        letter-spacing: -0.01em;
    }

    /* Sidebar becomes an off-canvas drawer */
    .sidebar {
        width: min(284px, 84vw);
        transform: translateX(-100%);
        transition: transform 260ms var(--ease);
        box-shadow: var(--shadow-lg);
        z-index: 300;
        padding-top: env(safe-area-inset-top);
        will-change: transform;
    }
    .sidebar.is-open { transform: translateX(0); }

    /* Scrim behind the open drawer */
    .sidebar-scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
        z-index: 250;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 220ms var(--ease), visibility 220ms var(--ease);
    }
    .sidebar-scrim.is-open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    body.admin-no-scroll { overflow: hidden; }

    .main-content {
        margin-left: 0;
        max-width: 100%;
        padding: 16px;
        padding-top: calc(56px + env(safe-area-inset-top) + 16px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
    .sidebar-scrim { transition: opacity 80ms linear; }
}

/* ===== Settings tabs ===== */
.settings-tabs-wrap {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: -8px -32px 20px;
    padding: 12px 32px 0;
    background: linear-gradient(to bottom, var(--bg) 0%, var(--bg) 70%, rgba(238, 241, 246, 0.85) 100%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.settings-tabs {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}
.settings-tabs::-webkit-scrollbar { display: none; }

.settings-tab {
    flex: 0 0 auto;
    padding: 10px 16px 12px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-light);
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: color 200ms cubic-bezier(0.4, 0, 0.2, 1),
                border-color 200ms cubic-bezier(0.4, 0, 0.2, 1),
                background 200ms cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: -1px;
    border-radius: 8px 8px 0 0;
    letter-spacing: -0.005em;
}

.settings-tab:hover {
    color: var(--text);
    background: rgba(15, 23, 42, 0.03);
}

.settings-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: none;
}

.settings-tab:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 84, 199, 0.18);
}

.settings-tab-mobile { display: none; }
.settings-tab-mobile select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%2364748b' d='M6 8.5L1.5 4h9z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    cursor: pointer;
}
.settings-tab-mobile select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 84, 199, 0.12);
}

/* Tab panels — hidden by default, shown when .active */
.tab-panel { display: none; animation: settingsPanelIn 220ms cubic-bezier(0.4, 0, 0.2, 1); }
.tab-panel.active { display: block; }

@keyframes settingsPanelIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Save bar at the bottom of the form */
.settings-save-bar {
    margin-top: 8px;
    padding: 16px 0 0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
.settings-save-bar .btn {
    box-shadow: 0 4px 12px -2px rgba(37, 84, 199, 0.35);
    transition: transform 180ms cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1),
                background 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
.settings-save-bar .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px -4px rgba(37, 84, 199, 0.50);
}
.settings-save-bar .btn:active {
    transform: translateY(0) scale(0.99);
}

/* Responsive: switch tabs to a select on small screens */
@media (max-width: 720px) {
    .settings-tabs-wrap {
        margin: -8px -16px 16px;
        padding: 12px 16px 12px;
    }
    .settings-tabs { display: none; }
    .settings-tab-mobile { display: block; }
    .settings-save-bar { justify-content: stretch; }
    .settings-save-bar .btn { width: 100%; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
    .tab-panel { animation: none; }
    .settings-save-bar .btn { transition: none; }
}

/* ============================================================
   UNIFIED DETAIL MODAL SYSTEM (.dm-*)
   ------------------------------------------------------------
   Used by: leads, service requests, appointments, quotes.
   Goals: consistent admin/CRM feel, sticky header + footer
   with operational actions, scannable badges, mobile fullscreen.
   Selectors are scoped under .dm-modal so we can't bleed.
   ============================================================ */

.dm-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.50);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: dmFadeIn 180ms cubic-bezier(0.4, 0, 0.2, 1);
}
.dm-modal.dm-open { display: flex; }

@keyframes dmFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.dm-wrap {
    position: relative;
    width: 100%;
    max-width: 720px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    margin: 18px;
    animation: dmCardIn 220ms cubic-bezier(0.34, 1.45, 0.56, 1);
}
.dm-wrap.dm-wide { max-width: 980px; } /* For quotes / estimates */

@keyframes dmCardIn {
    from { opacity: 0; transform: translateY(8px) scale(0.985); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.dm-card {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 24px 60px -12px rgba(15, 23, 42, 0.30),
        0 8px 20px -8px rgba(15, 23, 42, 0.12);
    overflow: hidden;
    min-height: 0;
}

/* ---------- Sticky header ---------- */
.dm-header {
    flex-shrink: 0;
    padding: 18px 24px 16px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
    background: #fff;
    position: relative;
    z-index: 2;
}
.dm-header-main { flex: 1; min-width: 0; }
.dm-eyebrow {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin: 0 0 4px;
}
.dm-title {
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.01em;
    word-break: break-word;
}
.dm-title-id {
    color: #94a3b8;
    font-weight: 500;
    margin-left: 6px;
    font-family: var(--font-mono);
    font-size: 0.9em;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}
.dm-meta-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    font-size: 12.5px;
    color: #64748b;
}
.dm-meta-row .dm-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #cbd5e1;
}

/* ---------- Close (X) button — top-right of header ---------- */
.dm-close {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    transition: background 200ms cubic-bezier(0.4, 0, 0.2, 1),
                color 200ms cubic-bezier(0.4, 0, 0.2, 1),
                transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.dm-close:hover { background: #f1f5f9; color: #0f172a; }
.dm-close:active { transform: scale(0.92); background: #e2e8f0; }
.dm-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 84, 199, 0.18);
}

/* ---------- Body (scrollable) ---------- */
.dm-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px 24px;
    background: #fafbfc;
    scrollbar-width: thin;
    scrollbar-color: rgba(15, 23, 42, 0.16) transparent;
}
.dm-body::-webkit-scrollbar { width: 6px; }
.dm-body::-webkit-scrollbar-track { background: transparent; }
.dm-body::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.14);
    border-radius: 100px;
}

/* ---------- Top alert (e.g. emergency) ---------- */
.dm-alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 16px;
}
.dm-alert-emergency {
    background: linear-gradient(135deg, #fef2f2 0%, #ffe4e4 100%);
    border: 1px solid #fecaca;
    color: #991b1b;
}
.dm-alert-emergency .dm-alert-icon {
    font-size: 18px;
    line-height: 1;
}

/* ---------- Summary cards (e.g. quote totals) ---------- */
.dm-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}
.dm-summary-card {
    background: #fff;
    border: 1px solid #e8ebf1;
    border-radius: 12px;
    padding: 14px 14px 12px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}
.dm-summary-card.dm-summary-primary {
    background: linear-gradient(135deg, #eef3fd 0%, #dfe9fb 100%);
    border-color: #c3d5f5;
}
.dm-summary-label {
    font-size: 10.5px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 4px;
}
.dm-summary-card.dm-summary-primary .dm-summary-label { color: var(--primary); }
.dm-summary-value {
    font-size: 20px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.15;
    letter-spacing: -0.015em;
    font-feature-settings: 'tnum' 1;
}
.dm-summary-card.dm-summary-primary .dm-summary-value { color: var(--primary-darker); }
.dm-summary-sub {
    font-size: 11px;
    color: #64748b;
    margin-top: 2px;
}

/* ---------- Content section (card-style) ---------- */
.dm-section {
    background: #fff;
    border: 1px solid #e8ebf1;
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 12px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}
.dm-section + .dm-section { margin-top: 0; }

.dm-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.dm-section-title {
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    margin: 0;
}
.dm-section-title-icon {
    color: #94a3b8;
    margin-right: 6px;
    font-size: 12px;
}

/* ---------- Definition grid (label / value rows) ---------- */
.dm-grid {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 8px 14px;
    font-size: 13.5px;
    margin: 0;
}
.dm-dt {
    color: #94a3b8;
    font-weight: 500;
    align-self: start;
    padding-top: 1px;
    margin: 0;
}
.dm-dd {
    color: #1e293b;
    word-break: break-word;
    line-height: 1.5;
    margin: 0;
}
.dm-dd strong { color: #0f172a; font-weight: 600; }
.dm-dd a { color: #2563eb; text-decoration: none; }
.dm-dd a:hover { text-decoration: underline; }

/* ---------- Long-text block (issue description, notes) ---------- */
.dm-text-block {
    font-size: 13.5px;
    line-height: 1.65;
    color: #1e293b;
    white-space: pre-wrap;
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px 14px;
}

/* ---------- AI summary (placeholder for Task 6) ---------- */
.dm-ai-summary {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: linear-gradient(135deg, #f3f7fd 0%, #eef3fb 100%);
    border: 1px solid #dbe6f8;
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
}
.dm-ai-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-darker));
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 14px;
}
.dm-ai-text {
    font-size: 13px;
    color: #1e3a5f;
    font-style: italic;
    line-height: 1.5;
    flex: 1;
}

/* ---------- AI summary row in lead / service-request tables ---------- */
.ai-summary-row > td {
    padding: 6px 14px 8px;
    background: linear-gradient(to right, #f3f7fd 0%, #eef3fb 100%);
    border-bottom: 0;
}
.ai-summary-row.emg-row > td {
    background: linear-gradient(to right, #fff5f5 0%, #fef2f2 100%);
}
.ai-summary-row + tr > td {
    border-top: 0;
}
.ai-summary {
    font-size: 12.5px;
    color: #64748b;
    font-style: italic;
    margin-top: 4px;
    line-height: 1.45;
}
.ai-summary em {
    font-style: italic;
    color: #1e3a5f;
}

/* ---------- Photo / attachments ---------- */
.dm-photo img {
    max-width: 100%;
    max-height: 280px;
    border-radius: 10px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 4px 12px -4px rgba(15, 23, 42, 0.10);
    display: block;
    cursor: zoom-in;
    transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
.dm-photo a:hover img { transform: scale(1.01); }

/* ---------- Empty state inside a section ---------- */
.dm-empty {
    text-align: center;
    padding: 18px 8px;
    color: #94a3b8;
    font-size: 13px;
    font-style: italic;
}
.dm-empty-icon {
    display: block;
    font-size: 22px;
    margin-bottom: 6px;
    opacity: 0.55;
    font-style: normal;
}

/* ---------- Inline notes editor ---------- */
.dm-notes {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 11px 13px;
    font-size: 13.5px;
    font-family: inherit;
    resize: vertical;
    color: #1e293b;
    background: #fafbfc;
    transition: background 200ms, border-color 200ms, box-shadow 200ms;
    line-height: 1.5;
}
.dm-notes:focus {
    outline: none;
    background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 84, 199, 0.12);
}

/* ---------- Sticky footer (operational actions) ---------- */
.dm-footer {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    background: #fff;
    box-shadow: 0 -1px 0 rgba(15, 23, 42, 0.06);
    position: relative;
    z-index: 2;
}
.dm-footer-spacer { flex: 1; min-width: 8px; }

/* Action buttons (multiple variants) */
.dm-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background 180ms cubic-bezier(0.4, 0, 0.2, 1),
                color 180ms cubic-bezier(0.4, 0, 0.2, 1),
                border-color 180ms cubic-bezier(0.4, 0, 0.2, 1),
                transform 120ms cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 180ms cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    line-height: 1.2;
}
.dm-action:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 84, 199, 0.18);
}
.dm-action:active { transform: scale(0.97); }

.dm-action-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 4px 10px -2px rgba(37, 84, 199, 0.40);
}
.dm-action-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px -4px rgba(37, 84, 199, 0.50);
    filter: brightness(1.05);
}

.dm-action-secondary {
    background: #fff;
    color: #334155;
    border-color: #e2e8f0;
}
.dm-action-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
}

.dm-action-success {
    background: #dcfce7;
    color: #15803d;
    border-color: #bbf7d0;
}
.dm-action-success:hover { background: #bbf7d0; color: #14532d; }

.dm-action-warning {
    background: #fef3c7;
    color: #92400e;
    border-color: #fde68a;
}
.dm-action-warning:hover { background: #fde68a; color: #78350f; }

.dm-action-danger {
    background: #fff;
    color: #b91c1c;
    border-color: #fecaca;
}
.dm-action-danger:hover { background: #fef2f2; border-color: #fca5a5; }

.dm-action-ghost {
    background: transparent;
    color: #64748b;
    border-color: transparent;
}
.dm-action-ghost:hover { background: #f1f5f9; color: #0f172a; }

.dm-action[disabled],
.dm-action.dm-loading {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
    pointer-events: none;
}
.dm-action.dm-active-state {
    outline: 2px solid currentColor;
    outline-offset: -2px;
}

/* ============================================================
   UNIFIED BADGE SYSTEM (.dm-badge)
   ------------------------------------------------------------
   Use across tables and inside modal headers. Each variant
   includes a leading icon glyph for instant scannability.
   ============================================================ */
.dm-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.2px;
    line-height: 1.5;
    white-space: nowrap;
    text-transform: capitalize;
}
/* One dot + a color-coded label — no emoji, instantly scannable. The dot
   inherits the badge's text color, so color + label carry the meaning. */
.dm-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 auto;
}
.dm-badge-new         { background: #dbeafe; color: #1e40af; }
.dm-badge-emergency   { background: #fee2e2; color: #991b1b; }
.dm-badge-contacted   { background: #fef3c7; color: #92400e; }
.dm-badge-booked,
.dm-badge-confirmed   { background: #dcfce7; color: #166534; }
.dm-badge-pending     { background: #fef3c7; color: #92400e; }
.dm-badge-completed   { background: #ccfbf1; color: #115e59; }
.dm-badge-closed      { background: #f1f5f9; color: #475569; }
.dm-badge-cancelled,
.dm-badge-no_show     { background: #fee2e2; color: #991b1b; }
.dm-badge-spam        { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }
.dm-badge-qualified   { background: #dcfce7; color: #15803d; }
.dm-badge-repair      { background: #dbeafe; color: #1d4ed8; }
.dm-badge-install     { background: #dcfce7; color: #15803d; }
.dm-badge-maintenance { background: #fef3c7; color: #b45309; }

/* Generic neutral badge */
.dm-badge-neutral    { background: #f1f5f9; color: #475569; }

/* Priority chip (independent from status — visible on emergencies) */
.dm-priority {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px 2px 6px;
    border-radius: 6px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.dm-priority::before {
    content: "▲";
    font-size: 9px;
}
.dm-priority-emergency { background: #fee2e2; color: #991b1b; }
.dm-priority-high      { background: #ffedd5; color: #9a3412; }
.dm-priority-medium    { background: #fef3c7; color: #92400e; }
.dm-priority-low       { background: #f1f5f9; color: #475569; }

/* ============================================================
   MOBILE: fullscreen modal, stacked footer, bigger touch
   ============================================================ */
@media (max-width: 720px) {
    .dm-modal { padding: 0; align-items: stretch; justify-content: stretch; }
    .dm-wrap { margin: 0; max-width: 100%; max-height: 100%; height: 100dvh; }
    .dm-card { border-radius: 0; max-height: 100%; }

    .dm-header { padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top)); }
    .dm-title { font-size: 18px; }

    .dm-body {
        padding: 16px 14px 18px;
        padding-left: calc(14px + env(safe-area-inset-left));
        padding-right: calc(14px + env(safe-area-inset-right));
    }

    .dm-section { padding: 14px 14px; }
    .dm-grid { grid-template-columns: 110px 1fr; font-size: 14px; }

    .dm-footer {
        padding: 12px 14px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        gap: 8px;
    }
    .dm-action { padding: 10px 14px; font-size: 13.5px; min-height: 40px; }

    .dm-summary-cards { grid-template-columns: 1fr 1fr; }
    .dm-summary-value { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
    .dm-modal, .dm-wrap { animation: none; }
}

/* ============================================================
 * Admin UX overhaul — Dashboard / Conversations / Leads polish
 * ============================================================ */

/* ---------- Page header refinements ---------- */
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.page-header-count {
    font-size: 13px;
    color: #64748b;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.card-head h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}
.card-subtitle {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 500;
}
.card-link {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
.card-link:hover { text-decoration: underline; }

/* ---------- Dashboard KPI cards ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.kpi-card {
    position: relative;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 18px 18px 16px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    display: block;
    text-decoration: none;
    color: inherit;
}
/* Top accent rail: a calm attention signal. Appears on hover for normal cards;
   stays lit for urgent cards (emergency / follow-up) so the eye lands there first. */
.kpi-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--primary);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.2s var(--ease);
}
.kpi-clickable:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px -8px rgba(15, 23, 42, 0.18);
    border-color: #bcd0f5;
}
.kpi-clickable:hover::before { transform: scaleX(1); }
.kpi-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.kpi-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #f1f5f9;
    font-size: 14px;
}
.kpi-label {
    font-size: 12.5px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.kpi-value {
    font-size: 30px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.1;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}
.kpi-foot {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 6px;
}
/* Alert variant for emergency count */
.kpi-card--alert .kpi-icon { background: #fee2e2; }
.kpi-card--alert-on {
    border-color: #fca5a5;
    background: linear-gradient(180deg, #fff 0%, #fff5f5 100%);
}
.kpi-card--alert-on .kpi-value { color: #b91c1c; }
.kpi-card--alert-on::before { background: var(--danger); transform: scaleX(1); }
/* Follow-up variant — amber when there are quotes waiting for a callback */
.kpi-card--followup .kpi-icon { background: #fef3c7; }
.kpi-card--followup-on {
    border-color: #fcd34d;
    background: linear-gradient(180deg, #fff 0%, #fffbeb 100%);
}
.kpi-card--followup-on .kpi-value { color: #b45309; }
.kpi-card--followup-on::before { background: var(--warning); transform: scaleX(1); }

/* ---------- Quick action shortcuts ---------- */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}
.quick-action {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: #0f172a;
    font-weight: 600;
    font-size: 14px;
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.quick-action:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px -6px rgba(37, 84, 199, 0.25);
}
.quick-action-icon {
    width: 36px; height: 36px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    border-radius: 8px;
    font-size: 18px;
}

/* ---------- Dashboard split: activity feed + recent convos ---------- */
.dash-split {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 16px;
}
@media (max-width: 960px) { .dash-split { grid-template-columns: 1fr; } }

.activity-feed {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.activity-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
    align-items: flex-start;
}
.activity-item:last-child { border-bottom: 0; }
.activity-icon {
    flex-shrink: 0;
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: #f1f5f9;
    font-size: 14px;
}
.activity-emergency .activity-icon { background: #fee2e2; }
.activity-quote     .activity-icon { background: #cffafe; }
.activity-appointment .activity-icon { background: #dbeafe; }
.activity-lead      .activity-icon { background: #fef3c7; }
.activity-service   .activity-icon { background: #ecfeff; }
.activity-body {
    flex: 1;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    min-width: 0;
}
.activity-title {
    color: #0f172a;
    text-decoration: none;
    font-size: 13.5px;
    line-height: 1.45;
    flex: 1;
    min-width: 0;
}
.activity-title:hover { color: var(--primary); }
.activity-time {
    flex-shrink: 0;
    font-size: 11.5px;
    color: #94a3b8;
}

/* ---------- Recent conversations list (dashboard right column) ---------- */
.convo-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.convo-list-item { border-bottom: 1px solid #f1f5f9; }
.convo-list-item:last-child { border-bottom: 0; }
.convo-list-item a {
    display: block;
    padding: 11px 0;
    color: inherit;
    text-decoration: none;
}
.convo-list-item a:hover .convo-name { color: var(--primary); }
.convo-list-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
}
.convo-name {
    font-weight: 600;
    font-size: 13.5px;
    color: #0f172a;
    transition: color 0.15s ease;
}
.convo-time { font-size: 11.5px; color: #94a3b8; }
.convo-preview {
    font-size: 12.5px;
    color: #64748b;
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

/* ---------- Dev metrics block (demoted on dashboard) ---------- */
.dev-metrics-block {
    margin-top: 20px;
    border-top: 1px dashed #e2e8f0;
    padding-top: 12px;
}
.dev-metrics-block summary {
    cursor: pointer;
    font-size: 13px;
    color: #94a3b8;
    font-weight: 500;
    padding: 8px 0;
    user-select: none;
}
.dev-metrics-block summary:hover { color: #64748b; }
.dev-metrics-block[open] summary { color: #475569; margin-bottom: 8px; }
.dev-metrics-card { background: #f8fafc; }
.dev-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}
.dev-metric-label {
    font-size: 11.5px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.dev-metric-value {
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
}
.dev-metrics-sub {
    font-size: 13px;
    color: #475569;
    margin: 12px 0 8px;
    font-weight: 600;
}

/* ---------- Intent badges (Conversations + Leads + detail) ---------- */
.intent-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 100px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.2px;
    line-height: 1.5;
    white-space: nowrap;
}
.intent-handoff     { background: #fef3c7; color: #b45309; }
.intent-lead        { background: #dcfce7; color: #15803d; }
.intent-general     { background: #f1f5f9; color: #475569; }

/* ---------- Status badges (Lead, Conversation) ---------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 8px;
    border-radius: 100px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.2px;
    line-height: 1.5;
    white-space: nowrap;
}
.status-new        { background: #dbeafe; color: #1d4ed8; }
.status-active     { background: #dcfce7; color: #16a34a; }
.status-contacted  { background: #cffafe; color: #0e7490; }
.status-closed     { background: #f1f5f9; color: #64748b; }
.status-spam       { background: #fee2e2; color: #b91c1c; }

/* ---------- Filter pills (intent filter row) ---------- */
.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 18px;
}
.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 100px;
    background: #f1f5f9;
    color: #475569;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.filter-pill:hover { background: #e2e8f0; }
.filter-pill.is-active {
    background: #0f172a;
    color: #fff;
    border-color: #0f172a;
}
.filter-pill-count {
    font-size: 11px;
    background: rgba(15, 23, 42, 0.08);
    padding: 1px 7px;
    border-radius: 100px;
    font-weight: 700;
}
.filter-pill.is-active .filter-pill-count {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}
.filter-pill--handoff.is-active     { background: #b45309; border-color: #b45309; }
.filter-pill--lead.is-active        { background: #15803d; border-color: #15803d; }
.filter-pill--general.is-active     { background: #475569; border-color: #475569; }

/* ---------- Refined data tables for Conversations + Leads ---------- */
.conv-table-wrap { overflow-x: auto; }
.conv-table th,
.leads-table th {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 11px 14px;
}
.conv-table td,
.leads-table td {
    padding: 14px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
}
.conv-table tr:hover td,
.leads-table tr:hover td { background: #fafbff; }
.conv-table .num,
.leads-table .num { text-align: right; }
.cell-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cell-primary {
    font-weight: 600;
    color: #0f172a;
    font-size: 14px;
}
.cell-secondary {
    font-size: 12px;
    color: #64748b;
}
.cell-link {
    color: #2563eb;
    text-decoration: none;
    font-size: 13.5px;
}
.cell-link:hover { text-decoration: underline; }
.cell-muted { color: #94a3b8; font-style: italic; }
.cell-preview {
    max-width: 360px;
    color: #475569;
    font-size: 13.5px;
    line-height: 1.5;
}
.conv-preview-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cell-time {
    color: #64748b;
    font-size: 12.5px;
    white-space: nowrap;
}
.cell-actions {
    white-space: nowrap;
    text-align: right;
}

/* ---------- Conversation detail layout ---------- */
.conv-detail {
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 100px; /* space for sticky workflow bar */
}
.conv-detail-header { margin-bottom: 18px; }
.conv-back-link {
    display: inline-block;
    color: #64748b;
    text-decoration: none;
    font-size: 13px;
    margin-bottom: 10px;
}
.conv-back-link:hover { color: var(--primary); }
.conv-title {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
}
.conv-detail-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 12.5px;
    color: #64748b;
}
.conv-detail-dot {
    width: 3px; height: 3px;
    background: #cbd5e1;
    border-radius: 50%;
}

.conv-summary-card {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    background: linear-gradient(135deg, #f3f7fd 0%, #eef3fb 100%);
    border: 1px solid #dbe6f8;
}
.conv-summary-icon {
    flex-shrink: 0;
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-darker));
    color: #fff;
    display: grid; place-items: center;
    font-size: 16px;
}
.conv-summary-body { flex: 1; }
.conv-summary-body h3 {
    margin: 0 0 6px;
    font-size: 13px;
    font-weight: 700;
    color: #1e3a5f;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.conv-summary-body p {
    margin: 0;
    color: #1e3a5f;
    font-size: 14px;
    line-height: 1.55;
    font-style: italic;
}
.conv-summary-note {
    display: block;
    margin-top: 8px;
    color: #6b7280;
    font-size: 11.5px;
    font-style: normal;
}

.conv-detail-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 16px;
    align-items: start;
}
@media (max-width: 960px) {
    .conv-detail-grid { grid-template-columns: 1fr; }
}

.crm-card { background: #fff; }
.crm-grid {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 8px 12px;
    margin: 0;
    font-size: 13.5px;
}
.crm-grid dt {
    color: #64748b;
    font-weight: 500;
}
.crm-grid dd {
    margin: 0;
    color: #0f172a;
    word-break: break-word;
}
.crm-grid dd a { color: #2563eb; text-decoration: none; }
.crm-grid dd a:hover { text-decoration: underline; }
.crm-grid--small { font-size: 12.5px; }
.crm-grid--small dt { font-size: 11.5px; }

.crm-links {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.crm-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}
.crm-link:hover { text-decoration: underline; }

.crm-tech-summary {
    cursor: pointer;
    font-size: 13px;
    color: #64748b;
    font-weight: 600;
    user-select: none;
}
.crm-card[open] .crm-tech-summary { margin-bottom: 12px; color: #475569; }

.crm-notes-input {
    width: 100%;
    min-height: 110px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.55;
    resize: vertical;
    outline: none;
    background: #fcfcfd;
}
.crm-notes-input:focus { border-color: var(--primary); background: #fff; }
.crm-notes-status {
    margin: 8px 0 0;
    font-size: 12px;
    color: #64748b;
    min-height: 16px;
}
.crm-notes-status--ok  { color: #16a34a; }
.crm-notes-status--err { color: #dc2626; }

/* ---------- Sticky workflow action bar (Conversation detail) ---------- */
.workflow-bar {
    position: fixed;
    left: 240px; /* sidebar width */
    right: 0;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -4px 16px -6px rgba(15, 23, 42, 0.08);
    z-index: 50;
}
.workflow-bar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}
.workflow-bar-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #475569;
}
.workflow-bar-label { font-weight: 600; color: #0f172a; }
.workflow-bar-tag {
    background: #cffafe;
    color: #0e7490;
    padding: 2px 10px;
    border-radius: 100px;
    font-size: 11.5px;
    font-weight: 600;
}
.workflow-bar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
@media (max-width: 960px) {
    .workflow-bar { left: 0; }
    .workflow-bar-inner { padding: 10px 14px; }
}

/* ---------- CRM-style detail modal (Lead modal extension) ---------- */
.dm-card--crm .dm-eyebrow { text-transform: capitalize; }
.dm-footer--sticky {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 14px 18px;
    z-index: 2;
    flex-wrap: wrap;
}

/* ============================================================
 * Empty state polish (used by all 3 pages now)
 * ============================================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 36px 20px 28px;
    text-align: center;
    color: #64748b;
}
.empty-state h3 {
    margin: 8px 0 4px;
    font-size: 15px;
    color: #334155;
    font-weight: 700;
}
.empty-state p {
    margin: 0;
    font-size: 13.5px;
    max-width: 360px;
    line-height: 1.55;
}
.empty-state .empty-icon {
    font-size: 38px;
    margin-bottom: 6px;
    opacity: 0.7;
}

/* ============================================================
 * System Health page (admin/debug.php)
 * ============================================================ */

/* ---------- Top-level verdict banner ---------- */
.health-banner {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 20px 22px;
    border-radius: 14px;
    margin-bottom: 20px;
    border: 1px solid;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.health-banner-icon {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 24px;
    font-weight: 700;
    color: #fff;
}
.health-banner-body { flex: 1; min-width: 0; }
.health-banner-body h2 {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 700;
}
.health-banner-body p {
    margin: 0;
    font-size: 13.5px;
    color: #475569;
    line-height: 1.5;
}
.health-banner-counts {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.health-count {
    padding: 5px 11px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.3px;
}
.health-count--ok   { background: #dcfce7; color: #14532d; }
.health-count--warn { background: #fef3c7; color: #78350f; }
.health-count--fail { background: #fee2e2; color: #7f1d1d; }

.health-banner--healthy  { background: linear-gradient(135deg, #f0fdf4, #ecfdf5); border-color: #bbf7d0; }
.health-banner--healthy .health-banner-icon  { background: #16a34a; }
.health-banner--healthy h2 { color: #14532d; }

.health-banner--warning  { background: linear-gradient(135deg, #fffbeb, #fff7ed); border-color: #fcd34d; }
.health-banner--warning .health-banner-icon  { background: #d97706; }
.health-banner--warning h2 { color: #78350f; }

.health-banner--broken   { background: linear-gradient(135deg, #fef2f2, #fff1f2); border-color: #fca5a5; }
.health-banner--broken .health-banner-icon   { background: #dc2626; }
.health-banner--broken h2 { color: #7f1d1d; }

/* ---------- System check rows ---------- */
.check-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.check-item {
    display: flex;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
    align-items: flex-start;
}
.check-item:last-child { border-bottom: 0; }
.check-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}
.check-item--ok   .check-icon { background: #22c55e; }
.check-item--warn .check-icon { background: #f59e0b; }
.check-item--fail .check-icon { background: #ef4444; }
.check-body { flex: 1; min-width: 0; }
.check-name {
    font-weight: 600;
    font-size: 13.5px;
    color: #0f172a;
    margin-bottom: 2px;
}
.check-msg {
    font-size: 13px;
    color: #475569;
    line-height: 1.5;
    word-break: break-word;
}
.check-fix {
    margin-top: 6px;
    padding: 8px 12px;
    background: #fffbeb;
    border-left: 3px solid #fcd34d;
    border-radius: 0 6px 6px 0;
    font-size: 12.5px;
    color: #78350f;
    line-height: 1.5;
}
.check-item--fail .check-fix {
    background: #fef2f2;
    border-left-color: #fca5a5;
    color: #7f1d1d;
}

@media (max-width: 640px) {
    .health-banner {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }
    .health-banner-counts { width: 100%; }
}

/* ---------- Activity Timeline ---------- */
.activity-timeline {
    position: relative;
    padding-left: 28px;
}
.activity-timeline::before {
    content: '';
    position: absolute;
    left: 11px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: #e2e8f0;
    border-radius: 1px;
}
.at-item {
    position: relative;
    display: flex;
    gap: 10px;
    padding: 8px 0;
}
.at-item + .at-item {
    border-top: none;
}
.at-icon {
    position: absolute;
    left: -28px;
    top: 10px;
    width: 22px;
    height: 22px;
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    z-index: 1;
}
.at-content {
    flex: 1;
    min-width: 0;
}
.at-desc {
    font-size: 13px;
    color: #1e293b;
    line-height: 1.45;
}
.at-meta {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
    font-size: 11px;
    color: #94a3b8;
}
.at-actor {
    font-weight: 600;
    color: #64748b;
}
.at-dot {
    font-size: 8px;
}

/* ============================================================
 * Profile page (admin/profile.php)
 * ============================================================ */

.profile-page {
    max-width: 720px;
    margin: 0 auto;
}

/* ---------- Identity card ---------- */
.profile-identity {
    display: flex;
    gap: 22px;
    align-items: flex-start;
    padding: 26px 26px 22px;
}
.profile-avatar {
    flex-shrink: 0;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-darker));
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -1px;
    box-shadow: 0 8px 20px -8px rgba(37, 84, 199, 0.45);
    text-transform: uppercase;
}
.profile-identity-body {
    flex: 1;
    min-width: 0;
}
.profile-username {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}
.profile-handle {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 10px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-radius: 100px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}
.profile-meta {
    margin: 16px 0 0;
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 8px 14px;
    font-size: 13.5px;
}
.profile-meta dt {
    color: #64748b;
    font-weight: 500;
}
.profile-meta dd {
    margin: 0;
    color: #0f172a;
}
.profile-meta-hint {
    margin-left: 8px;
    color: #94a3b8;
    font-size: 12px;
}

/* ---------- Password field + show-toggle ---------- */
.password-field {
    position: relative;
    display: flex;
    align-items: center;
}
.password-field input {
    flex: 1;
    padding-right: 44px !important; /* room for the toggle button */
}
.password-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: #64748b;
    font-size: 16px;
    display: grid;
    place-items: center;
    transition: background 0.15s ease, color 0.15s ease;
}
.password-toggle:hover { background: #f1f5f9; color: #0f172a; }
.password-toggle.is-revealed { color: var(--primary); }

.profile-form .form-group:last-of-type { margin-bottom: 20px; }

@media (max-width: 640px) {
    .profile-identity { flex-direction: column; gap: 16px; padding: 22px; }
    .profile-meta { grid-template-columns: 1fr; gap: 4px 0; }
    .profile-meta dt { margin-top: 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px; }
    .profile-meta dd { font-weight: 500; }
}

/* ===== Toast notifications ===== */
#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 500;
    color: #fff;
    background: #1e293b;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    pointer-events: auto;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34,1.45,0.56,1), opacity 0.3s ease;
    max-width: 380px;
}
.toast-visible { transform: translateX(0); opacity: 1; }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-success { background: #166534; }
.toast-error { background: #991b1b; }
.toast-warning { background: #92400e; }
.toast-info { background: #1e40af; }

/* ===== Skeleton loaders ===== */
@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}
.skeleton-row {
    display: flex;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.skeleton-cell {
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, #e2e8f0 0%, #f1f5f9 50%, #e2e8f0 100%);
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-cell:nth-child(1) { width: 30%; }
.skeleton-cell:nth-child(2) { width: 20%; }
.skeleton-cell:nth-child(3) { width: 15%; }
.skeleton-cell:nth-child(4) { width: 25%; }

/* ===================================================================
   Utility classes — promote the most-repeated inline style="" patterns
   out of the .php templates. Keep only genuinely dynamic values inline.
   =================================================================== */
.cell-sub        { display: block; color: var(--text-light); margin-top: var(--space-1); }
.cell-strong     { font-weight: 600; color: var(--text-strong); }
.cell-time       { color: var(--text-soft); font-size: var(--fs-xs); white-space: nowrap; }
.field-mini-label{ display: block; font-size: 11px; font-weight: 600; color: var(--text-soft); margin-bottom: var(--space-1); }
.nowrap          { white-space: nowrap; }
.text-faint      { color: var(--text-faint); }
.text-soft       { color: var(--text-soft); }
.text-strong     { color: var(--text-strong); }
.fs-2xs          { font-size: 11px; }
.fs-xs           { font-size: var(--fs-xs); }
.fs-sm           { font-size: var(--fs-sm); }
.tnums           { font-variant-numeric: tabular-nums; }
/* Operational telemetry: record IDs / machine identifiers are set in mono so
   they read like work-order numbers on a dispatch board — a quiet nod to the
   admin context. Reserved for identifiers, never headline metrics. */
.mono            { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tlink           { color: var(--link); text-decoration: none; }
.tlink:hover     { text-decoration: underline; }
.mb-2            { margin-bottom: var(--space-2); }
.mb-3            { margin-bottom: var(--space-3); }
.mb-4            { margin-bottom: var(--space-4); }

/* ===================================================================
   Listing pages — unified table / tabs / toolbar / pagination / toast.
   Shared by service-requests, appointments and quotes, which previously
   each carried a near-identical per-page <style> block. Markup keeps its
   existing .sr-/.ap-/.qt- class names; they now resolve to these tokenized
   rules. Adds tabular numerals + keyboard focus rings the old blocks lacked.
   =================================================================== */
.sr-header, .ap-header, .qt-header {
    display: flex; align-items: flex-end; gap: var(--space-4);
    margin-bottom: var(--space-5); flex-wrap: wrap;
}
.sr-header h1, .ap-header h1, .qt-header h1 {
    margin: 0; font-size: var(--fs-xl); font-weight: 700;
    letter-spacing: -0.02em; color: var(--text-strong);
}
.sr-meta, .ap-meta, .qt-meta { font-size: var(--fs-sm); color: var(--text-soft); }
.sr-meta .emg { color: var(--danger); font-weight: 600; }

/* Filter tabs */
.sr-tabs, .ap-tabs, .qt-tabs {
    display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-5);
}
.sr-tab, .ap-tab, .qt-tab {
    padding: 6px var(--space-4); border-radius: var(--radius-full);
    font-size: var(--fs-xs); font-weight: 600; text-decoration: none;
    border: 1.5px solid var(--border); color: var(--text-mid);
    background: var(--card); transition: all 150ms var(--ease); white-space: nowrap;
}
.sr-tab:hover, .ap-tab:hover, .qt-tab:hover { border-color: var(--text-faint); color: var(--text-strong); }
.sr-tab.active, .ap-tab.active, .qt-tab.active {
    background: var(--text-strong); color: #fff; border-color: var(--text-strong);
}
.sr-tab.emg-tab { border-color: #fecaca; color: var(--danger); }
.sr-tab.emg-tab.active { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Appointments sort row */
.ap-sort { display: flex; align-items: center; gap: var(--space-2); margin: -6px 0 var(--space-4); }
.ap-sort-label { font-size: var(--fs-xs); color: var(--text-faint); font-weight: 600; }
.ap-sort-opt {
    padding: var(--space-1) var(--space-3); border-radius: var(--radius-full);
    font-size: var(--fs-xs); font-weight: 600; text-decoration: none;
    border: 1.5px solid var(--border); color: var(--text-mid);
    background: var(--card); transition: all 150ms var(--ease);
}
.ap-sort-opt:hover { border-color: var(--text-faint); color: var(--text-strong); }
.ap-sort-opt.active { background: var(--link); color: #fff; border-color: var(--link); }

/* Service-requests new-record banner */
#srNewBanner {
    display: none; align-items: center; gap: var(--space-2);
    background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-4); font-size: var(--fs-sm); color: #1d4ed8;
    margin-bottom: var(--space-3); cursor: pointer; font-weight: 500;
}
#srNewBanner:hover { background: #dbeafe; }

/* Listing tables */
.sr-table-wrap, .ap-table-wrap, .qt-table-wrap { overflow-x: auto; }
.sr-table, .ap-table, .qt-table {
    width: 100%; border-collapse: collapse; font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
}
.sr-table th, .ap-table th, .qt-table th {
    text-align: left; padding: var(--space-2) var(--space-4); font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint);
    border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
.sr-table td, .ap-table td, .qt-table td {
    padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--surface-muted);
    vertical-align: middle; color: var(--text-mid);
}
.sr-table tbody tr, .ap-table tbody tr, .qt-table tbody tr { transition: background 120ms var(--ease); }
.sr-table tbody tr:hover, .ap-table tbody tr:hover, .qt-table tbody tr:hover { background: var(--surface-muted); }
/* Emergency rows: a restrained left signal-rail + barely-there tint instead
   of a heavy full-red fill. The rail is the operator's "look here" cue. */
.sr-table tbody tr.emg-row { background: #fffbfb; }
.sr-table tbody tr.emg-row:hover { background: #fff5f5; }
.sr-table tbody tr.emg-row td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.qt-price { font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; }

/* Inline status select */
.sr-status-sel, .ap-status-sel, .qt-status-sel {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: var(--space-1) var(--space-2); font-size: var(--fs-xs);
    background: var(--card); color: var(--text-mid); cursor: pointer;
}
.sr-status-sel:focus, .ap-status-sel:focus, .qt-status-sel:focus { outline: none; border-color: var(--text-faint); box-shadow: var(--ring); }

/* Row action buttons on service-requests / appointments / quotes now use the
   global button system (.btn.btn-sm.btn-secondary + .btn-danger-outline), so
   the old .sr-btn/.ap-btn/.qt-btn rules were retired for a single source. */

/* Empty state */
.sr-empty, .ap-empty, .qt-empty { text-align: center; padding: 48px var(--space-5); color: var(--text-faint); font-size: var(--fs-base); }
.sr-empty-icon, .ap-empty-icon, .qt-empty-icon { font-size: 36px; display: block; margin-bottom: var(--space-2); }

/* Pagination */
.sr-pagination, .ap-pagination, .qt-pagination { display: flex; gap: var(--space-2); margin-top: var(--space-4); flex-wrap: wrap; }
.sr-page-btn, .ap-page-btn, .qt-page-btn {
    padding: var(--space-1) var(--space-3); border-radius: var(--radius-sm); font-size: var(--fs-xs);
    font-weight: 600; border: 1.5px solid var(--border); color: var(--text-mid);
    text-decoration: none; background: var(--card); transition: all 150ms var(--ease);
}
.sr-page-btn:hover, .sr-page-btn.active,
.ap-page-btn:hover, .ap-page-btn.active,
.qt-page-btn:hover, .qt-page-btn.active { background: var(--text-strong); color: #fff; border-color: var(--text-strong); }

/* Keyboard focus rings the per-page blocks never had */
.sr-tab:focus-visible, .ap-tab:focus-visible, .qt-tab:focus-visible,
.ap-sort-opt:focus-visible,
.sr-page-btn:focus-visible, .ap-page-btn:focus-visible, .qt-page-btn:focus-visible {
    outline: none; box-shadow: var(--ring);
}

/* Shared bottom-right toast (was three identical #srToast/#apToast/#qtToast rules) */
#srToast, #apToast, #qtToast {
    position: fixed; bottom: var(--space-6); right: var(--space-6); background: var(--text-strong);
    color: #fff; padding: var(--space-2) var(--space-5); border-radius: var(--radius-sm);
    font-size: var(--fs-sm); font-weight: 500; opacity: 0; pointer-events: none;
    transform: translateY(8px); transition: opacity .25s var(--ease), transform .25s var(--ease);
    z-index: 99999; box-shadow: var(--shadow-lg);
}
#srToast.show, #apToast.show, #qtToast.show { opacity: 1; transform: translateY(0); }

/* ===================================================================
   Auth / sign-in screen (login.php) — now loads admin.css and uses the
   shared tokens instead of its old hardcoded #4F46E5 palette.
   =================================================================== */
.auth-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: var(--space-5);
    background: radial-gradient(130% 130% at 50% -10%, #17305a 0%, var(--sidebar-bg) 60%);
}
.auth-card {
    width: 100%; max-width: 380px; background: var(--card);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    padding: var(--space-8) var(--space-8) var(--space-6);
}
.auth-brand { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-6); }
.auth-logo {
    width: 42px; height: 42px; border-radius: var(--radius-md); display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff;
    box-shadow: 0 6px 16px -4px var(--primary-glow); flex: 0 0 auto;
}
.auth-logo svg { width: 22px; height: 22px; }
.auth-brand-text h1 { font-size: var(--fs-lg); font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; color: var(--text-strong); }
.auth-brand-text p { font-size: var(--fs-xs); color: var(--text-soft); margin-top: 2px; }
.auth-title { font-size: var(--fs-md); font-weight: 700; color: var(--text-strong); margin-bottom: var(--space-1); }
.auth-sub { font-size: var(--fs-sm); color: var(--text-soft); margin-bottom: var(--space-5); }
.auth-error {
    display: flex; align-items: center; gap: var(--space-2); background: #fef2f2; color: var(--danger);
    border: 1px solid #fecaca; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
    font-size: var(--fs-sm); margin-bottom: var(--space-4);
}
.auth-error svg { width: 16px; height: 16px; flex: 0 0 auto; }
.btn-block { width: 100%; justify-content: center; }
.auth-foot { text-align: center; margin-top: var(--space-5); font-size: var(--fs-xs); color: var(--text-faint); }

/* Knowledge-base URL-import card (was page-level magic numbers / #4F46E5) */
.kb-url-row { display: flex; gap: var(--space-2); align-items: stretch; }
.kb-url-row input[type="url"] {
    flex: 1; padding: var(--space-3) var(--space-4); border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: var(--fs-base); outline: none;
    transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.kb-url-row input[type="url"]:focus { border-color: var(--primary); box-shadow: var(--ring); }
.kb-url-row .btn { white-space: nowrap; }
.kb-url-progress { margin-top: var(--space-4); }
.kb-url-progress .progress-bar {
    width: 100%; height: 8px; background: var(--border);
    border-radius: var(--radius-full); overflow: hidden; margin-bottom: var(--space-2);
}
.kb-url-progress .progress-fill {
    height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius-full); transition: width 0.4s var(--ease); width: 0;
}
.kb-url-progress p { margin: 0; font-size: var(--fs-sm); color: var(--text-mid); }
.kb-url-progress .err { color: var(--danger); }
.kb-url-progress .ok  { color: #16a34a; font-weight: 600; }

/* ============================================================
 * Admin icon system + list-screen action/flag refinements
 * (Dashboard, Conversations, Leads, Service Requests, Appointments)
 * ============================================================ */

/* Base line-icon — colour comes from the container via currentColor. */
.a-ic { width: 18px; height: 18px; display: block; flex-shrink: 0; }

/* Dashboard KPI icon tiles */
.kpi-icon { color: #64748b; }
.kpi-icon .a-ic { width: 17px; height: 17px; }
.kpi-icon-leads  { color: var(--primary); background: var(--primary-soft); }
.kpi-icon-appts  { color: #1d4ed8; background: #dbeafe; }
.kpi-icon-quotes { color: #0e7490; background: #cffafe; }
.kpi-icon-convos { color: #0284c7; background: #e0f2fe; }
.kpi-card--alert .kpi-icon    { color: #dc2626; }
.kpi-card--followup .kpi-icon { color: #b45309; }

/* Quick-action icons */
.quick-action-icon { color: #475569; }
.quick-action-icon .a-ic { width: 19px; height: 19px; }

/* Activity-feed icons — colour matches the tinted circle */
.activity-icon { color: #64748b; }
.activity-icon .a-ic { width: 16px; height: 16px; }
.activity-emergency   .activity-icon { color: #dc2626; }
.activity-quote       .activity-icon { color: #0e7490; }
.activity-appointment .activity-icon { color: #1d4ed8; }
.activity-lead        .activity-icon { color: #b45309; }
.activity-service     .activity-icon { color: #0e7490; }

/* Empty-state + new-record banner SVG sizing */
.empty-icon .a-ic,
.sr-empty-icon .a-ic,
.ap-empty-icon .a-ic,
.qt-empty-icon .a-ic { width: 34px; height: 34px; color: #cbd5e1; margin: 0 auto; }
#srNewBanner .a-ic { width: 16px; height: 16px; }

/* ------------------------------------------------------------------
   Canonical button variants (single source of truth). The whole admin
   uses ONE button system:
     .btn / .btn-primary   → solid navy — the single main action
     .btn-secondary        → white, bordered, dark text (View/Edit/Export/
                             Import/Clear/Cancel and other non-primary actions)
     .btn-danger           → solid red — only when destructive IS the main action
     .btn-danger-outline   → red border/text — the default table "Delete"
     .btn-icon             → square icon-only (must carry aria-label/title)
   Older .btn-soft / .btn-soft-danger names are kept as aliases so nothing
   breaks; new markup should prefer the canonical names above.
   ------------------------------------------------------------------ */
.btn-soft,
.btn-secondary {
    background: #fff; color: var(--text-mid);
    border-color: var(--border); box-shadow: none;
}
.btn-soft:hover,
.btn-secondary:hover {
    background: var(--surface-muted); color: var(--text-strong);
    border-color: #cbd5e1; box-shadow: none; transform: none;
}
.btn-soft:focus-visible,
.btn-secondary:focus-visible { box-shadow: var(--ring); }
.btn-soft-danger,
.btn-danger-outline {
    background: #fff; color: var(--danger);
    border-color: #fecaca; box-shadow: none;
}
.btn-soft-danger:hover,
.btn-danger-outline:hover {
    background: #fef2f2; color: #b91c1c;
    border-color: #fca5a5; box-shadow: none; transform: none;
}
.btn-soft-danger:focus-visible,
.btn-danger-outline:focus-visible { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.22); }

/* Icon-only button — square, centred glyph, no text. Combine with a variant
   (.btn-secondary / .btn-danger-outline) for colour. Always give it an
   aria-label/title since there's no visible label. */
.btn-icon {
    padding: 0;
    width: 36px;
    height: 36px;
    justify-content: center;
    flex: 0 0 auto;
}
.btn-icon.btn-sm { width: 30px; height: 30px; border-radius: 6px; }
.btn-icon .a-ic { width: 16px; height: 16px; }
.btn-icon.btn-sm .a-ic { width: 15px; height: 15px; }

/* Small inline table flag (out-of-service-area, etc.) */
.tbl-flag {
    display: inline-flex; align-items: center; gap: 4px;
    margin-top: 3px; padding: 1px 7px;
    border-radius: var(--radius-full);
    font-size: 10.5px; font-weight: 700; letter-spacing: 0.2px;
    white-space: nowrap;
}
.tbl-flag-warn { background: #fef3c7; color: #92400e; }

/* Appointments: slot time is the scannable focus, booked date stays muted */
.ap-when { display: flex; flex-direction: column; gap: 1px; }
.ap-when-time {
    font-weight: 700; color: #0f172a; font-size: 14px;
    font-variant-numeric: tabular-nums;
}
.ap-when-date { font-size: 12px; color: #64748b; }


/* ============================================================
 * Styled confirmation dialog (.ns-confirm) — replaces the native
 * browser confirm() so destructive actions get a calm, on-brand,
 * keyboard-accessible prompt. Behaviour is identical: proceed only
 * on explicit confirm. The safe (Cancel) button is focused first on
 * destructive prompts so a stray Enter never deletes anything.
 * ============================================================ */
.ns-confirm {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.52);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 180ms var(--ease);
}
.ns-confirm.is-open { opacity: 1; }
.ns-confirm-card {
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px 24px 20px;
    transform: translateY(10px) scale(0.98);
    opacity: 0;
    transition: transform 240ms var(--ease-spring), opacity 180ms var(--ease);
}
.ns-confirm.is-open .ns-confirm-card { transform: translateY(0) scale(1); opacity: 1; }
.ns-confirm-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    margin-bottom: 14px;
}
.ns-confirm-icon svg { width: 22px; height: 22px; }
.ns-confirm--danger .ns-confirm-icon { background: #fee2e2; color: var(--danger); }
.ns-confirm--warning .ns-confirm-icon { background: #fef3c7; color: #b45309; }
.ns-confirm-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0 0 6px;
    letter-spacing: -0.01em;
}
.ns-confirm-msg {
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--text-mid);
    margin: 0 0 20px;
}
.ns-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.ns-confirm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: background 160ms var(--ease), border-color 160ms var(--ease),
                color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.ns-confirm-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.ns-confirm-cancel {
    background: var(--card);
    color: var(--text-mid);
    border-color: var(--border);
}
.ns-confirm-cancel:hover { background: var(--surface-muted); color: var(--text-strong); border-color: #cbd5e1; }
.ns-confirm-ok {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px -3px var(--primary-glow);
}
.ns-confirm-ok:hover { background: var(--primary-dark); }
.ns-confirm-ok:focus-visible { box-shadow: 0 0 0 3px rgba(37, 84, 199, 0.35); }
.ns-confirm--danger .ns-confirm-ok {
    background: var(--danger);
    box-shadow: 0 4px 12px -3px rgba(220, 38, 38, 0.40);
}
.ns-confirm--danger .ns-confirm-ok:hover { background: #b91c1c; }
.ns-confirm--danger .ns-confirm-ok:focus-visible { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.35); }

@media (max-width: 480px) {
    .ns-confirm-actions { flex-direction: column-reverse; }
    .ns-confirm-btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
    .ns-confirm, .ns-confirm-card { transition: opacity 90ms linear; }
    .ns-confirm-card { transform: none; }
}


/* ===================================================================
   SECOND-PASS POLISH — shared components that retire per-page inline
   styles, hardcoded hex, button-styled selects, and emoji icons.
   Everything here is tokenized so pages stop carrying visual values.
   =================================================================== */

/* ---- Toast / SVG icon sizing (toast glyphs are now inline SVG) ---- */
.toast-icon { display: inline-flex; }
.toast-icon .a-ic { width: 17px; height: 17px; }

/* Icons that sit inside buttons scale down to match the label */
.btn .a-ic { width: 15px; height: 15px; }
.btn-sm .a-ic { width: 14px; height: 14px; }

/* Small inline icon that flows with a line of text (status glyphs, hints) */
.ic-inline { width: 13px; height: 13px; vertical-align: -2px; }

/* Upload dropzone icon (was 📄) */
.upload-icon .a-ic { width: 38px; height: 38px; color: var(--text-faint); margin: 0 auto; }

/* ---- Inline <code> now reads as telemetry without per-tag font styles ---- */
code { font-family: var(--font-mono); font-size: 0.92em; }

/* ---- Callout / notice box — replaces the repeated
   `<div class="card" style="background:#…;color:#…">` info banners. ---- */
.callout {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    line-height: 1.55;
    margin-bottom: var(--space-4);
    border: 1px solid transparent;
}
.callout > p, .callout-body > p { margin: 0; }
.callout a { font-weight: 600; color: inherit; text-decoration: underline; }
.callout-icon { flex: 0 0 auto; display: inline-flex; margin-top: 1px; }
.callout-icon .a-ic { width: 17px; height: 17px; }
.callout-body { min-width: 0; }
.callout-info    { background: var(--surface-muted); color: var(--text-mid); border-color: var(--border); }
.callout-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.callout-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.callout-danger  { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

/* ---- Toolbars / action rows — one flex idiom for filter + button rows ---- */
.toolbar { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.toolbar--split { justify-content: space-between; align-items: flex-end; gap: var(--space-4); }
.toolbar--end { justify-content: flex-end; }
.form-actions { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-4); }
.form-actions--between { justify-content: space-between; }

/* ---- Form-control <select> — the on-brand replacement for `<select class="btn">`.
   A select is not a button; it gets a proper field affordance + chevron. ---- */
.select {
    appearance: none;
    -webkit-appearance: none;
    padding: 8px 34px 8px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    font-family: inherit;
    color: var(--text);
    background-color: var(--card);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%2364748b' d='M6 8.5L1.5 4h9z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
    transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.select:hover { border-color: #cbd5e1; }
.select:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.select--block { width: 100%; max-width: 320px; }

/* ---- Card that wraps a table flush to its edges ---- */
.card--flush { padding: 0; overflow: hidden; }
.card--flush .data-table { margin: 0; }

/* ---- Code / log output blocks (was inline `background:#0f172a;color:#cbd5e1…`) ---- */
.code-block {
    margin: 0;
    background: var(--text-strong);
    color: #cbd5e1;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    line-height: 1.7;
    overflow: auto;
    font-family: var(--font-mono);
}

/* ---- Log severity pills — colour is now class-driven, not built inline ---- */
.log-level {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: #f1f5f9;
    color: #475569;
}
.log-level--error,
.log-level--critical,
.log-level--alert,
.log-level--emergency { background: #fee2e2; color: #b91c1c; }
.log-level--warning   { background: #fef3c7; color: #92400e; }
.log-level--info,
.log-level--notice    { background: #dbeafe; color: #1d4ed8; }
.log-level--debug     { background: #f1f5f9; color: #475569; }
.log-ctx {
    display: inline-flex;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    background: #e2e8f0;
    color: #475569;
}
.log-ctx strong { margin-right: 4px; }
.log-ctx-row { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.log-row { cursor: pointer; }
.log-detail-cell { background: var(--surface-muted); padding: 12px 16px; }
.log-raw { margin: 0; font-family: var(--font-mono); font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; color: var(--text-mid); }

/* ---- Filter rows + standalone form controls (logs, other filters) ---- */
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filter-field { flex: 0 0 auto; }
.filter-field--grow { flex: 1; min-width: 180px; }
.input {
    width: 100%;
    padding: 8px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }

/* ---- Caption bar + scroll wrapper for tables inside a flush card ---- */
.table-caption {
    font-size: 12px;
    color: var(--text-soft);
    padding: 10px 16px;
    border-bottom: 1px solid var(--line-soft);
    background: var(--surface-muted);
}
.table-scroll { overflow-x: auto; }
.cell-msg { max-width: 500px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-subject { font-size: 12.5px; max-width: 280px; }
.page-info { padding: 6px 12px; font-size: 13px; color: var(--text-soft); }
.inline-label { font-size: var(--fs-sm); color: var(--text-mid); margin-right: 6px; }
.table-sm { font-size: 13px; }
/* Indented helper line under a checkbox label */
.hint-indent { display: block; color: var(--text-soft); margin-top: 4px; margin-left: 24px; }

/* ---- Read-only / muted table code cell ---- */
.cell-mono { font-family: var(--font-mono); font-size: 12px; }
.cell-error { font-size: 12px; color: var(--danger); max-width: 340px; word-break: break-word; }
/* Muted, single-line truncated secondary cell text (descriptions, specialties) */
.cell-note { font-size: 12px; color: var(--text-faint); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Monospace editors (JSON / schema / attribute textareas) */
.code-input { font-family: var(--font-mono); font-size: 12.5px; }
/* Light inline help / pre block (paired with dark .code-block for output) */
.pre-note { margin: 0; font-family: var(--font-mono); font-size: 11.5px; background: var(--surface-muted); color: var(--text-mid); padding: 10px; border-radius: 6px; overflow: auto; }
/* Clickable <summary> */
.summary-link { cursor: pointer; font-size: var(--fs-sm); color: var(--text-mid); }
.summary-link:hover { color: var(--text-strong); }
/* Narrow numeric input (sort order, etc.) */
.input-narrow { max-width: 120px; }
/* Row of toggle checkboxes */
.toggle-row { display: flex; gap: 20px; flex-wrap: wrap; }
/* Inline form-error block (JS toggles its display) */
.form-error { color: var(--danger); font-size: 13px; margin-top: 10px; white-space: pre-wrap; }

/* Standalone (non-.dm-modal) card width variants — retire per-modal max-width */
.dm-card--sm { max-width: 500px; }
.dm-card--md { max-width: 640px; }
.dm-card--lg { max-width: 720px; }
/* Modal close button now holds an SVG glyph */
.dm-close .a-ic { width: 18px; height: 18px; }

/* Diagnostics: a passing retrieval row stays tinted green even on hover */
.data-table tr.row-hit > td { background: #dcfce7; }

/* KPI value that renders a status mark instead of a number (System Health) */
.kpi-value .a-ic { width: 26px; height: 26px; }

/* ---- Form layout grids (was inline `grid-template-columns:1fr 1fr`) ---- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-3); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-4); }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---- Small utilities that retire one-off inline declarations ---- */
.w-full       { width: 100%; }
.pre-wrap     { white-space: pre-wrap; }
.break-all    { word-break: break-all; }
.fw-600       { font-weight: 600; }
.fw-normal    { font-weight: 400; }
.items-end    { align-items: flex-end; }
.flex-2       { flex: 2; }
.flex-none    { flex: 0 0 auto; }
.check-row    { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; }
.inline-block { display: inline-block; }
.ml-auto      { margin-left: auto; }
.ml-1         { margin-left: var(--space-1); }
.ml-2         { margin-left: var(--space-2); }
.mt-2         { margin-top: var(--space-2); }
.mt-auto      { margin-top: auto; }
.mb-1         { margin-bottom: var(--space-1); }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.mb-0         { margin-bottom: 0; }
.items-center { align-items: center; }
.file-input   { font-size: 12.5px; max-width: 210px; }
.o-65         { opacity: 0.65; }
.o-70         { opacity: 0.70; }
.txt-success  { color: #15803d; }
.txt-danger   { color: #b91c1c; }
.txt-warning  { color: #b45309; }

/* Slightly snugger card used above listing tables (tabs sit inside) */
.card--snug { padding: 20px 20px 16px; }

/* AI-summary table rows: a quiet sparkle mark replaces the 🤖 emoji */
.ai-summary { display: flex; align-items: flex-start; gap: 6px; }
.ai-summary .a-ic { width: 13px; height: 13px; color: #94a3b8; flex: 0 0 auto; margin-top: 2px; }

/* ---- Badge/status rendered as a toggle <button> (catalog / intake-flows) ---- */
.status-toggle { border: 0; cursor: pointer; font-family: inherit; }
.status-badge .a-ic, .badge .a-ic { width: 12px; height: 12px; }
.tbl-flag .a-ic { width: 11px; height: 11px; }

/* ---- Modal (.dm-*) SVG icon adoption ---- */
.dm-section-title { display: flex; align-items: center; gap: 6px; }
.dm-section-title-icon { display: inline-flex; color: #94a3b8; margin: 0; }
.dm-section-title-icon .a-ic { width: 14px; height: 14px; }
.dm-ai-icon .a-ic { width: 15px; height: 15px; }
.dm-alert-icon { display: inline-flex; }
.dm-alert-icon .a-ic { width: 18px; height: 18px; }
.dm-action .a-ic { width: 15px; height: 15px; }
.dm-empty-icon .a-ic { width: 26px; height: 26px; margin: 0 auto; color: #cbd5e1; }
.dm-summary-value--sm { font-size: 15px; line-height: 1.3; }
/* In-area / out-of-area inline flag inside the Location section */
.dm-area-flag { margin-left: 4px; font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.dm-area-flag .a-ic { width: 12px; height: 12px; }
.dm-area-flag--ok  { color: #15803d; }
.dm-area-flag--out { color: #b91c1c; }

/* ---- Conversation summary card sparkle ---- */
.conv-summary-icon .a-ic { width: 18px; height: 18px; }

/* ---- Empty-state SVG (was emoji) ---- */
.empty-icon .a-ic { width: 40px; height: 40px; color: #cbd5e1; margin: 0 auto; }

/* ---- Dashboard / debug KPI + health SVG sizing ---- */
.health-banner-icon .a-ic { width: 26px; height: 26px; }
.check-icon .a-ic { width: 15px; height: 15px; }

/* ---- Profile password reveal toggle ---- */
.password-toggle .a-ic { width: 18px; height: 18px; }

/* ---- Live-handoff reply box (conversation detail) ---- */
.handoff-reply-box { padding: 16px; border-top: 1px solid var(--border); background: #fefce8; }
.handoff-reply-label {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; font-weight: 600; color: #92400e; margin-bottom: 8px;
}
.handoff-reply-label .a-ic { width: 14px; height: 14px; }
.handoff-reply-row { display: flex; gap: 8px; }
.handoff-reply-input {
    flex: 1; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
    background: var(--card); color: var(--text);
    transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.handoff-reply-input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.handoff-reply-foot { margin-top: 8px; }

/* ---- Contacted tag in the sticky workflow bar ---- */
.workflow-bar-tag { display: inline-flex; align-items: center; gap: 4px; }
.workflow-bar-tag .a-ic { width: 13px; height: 13px; }

/* ---- Admin (agent) reply bubble in the thread ---- */
.chat-message.chat-admin { align-self: flex-end; }
.chat-bubble--admin,
.chat-admin .chat-bubble {
    background: #fef3c7; border: 1px solid #fde68a; color: #78350f;
    border-bottom-right-radius: 4px;
}

/* ---- Setup presets cards ---- */
.preset-card { display: flex; flex-direction: column; }
.preset-card.is-active { border: 2px solid var(--primary); }
.preset-tagline { color: var(--text-mid); font-size: 14px; margin: 8px 0 4px; }
.preset-examples { color: var(--text-faint); font-size: 12.5px; margin: 0 0 12px; }
.preset-detail { font-size: 12.5px; color: var(--text-mid); background: var(--surface-muted); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 12px; }

/* ---- Message-rating marks in the conversation thread (was 👍/👎) ---- */
.msg-rating {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
}
.msg-rating .a-ic { width: 13px; height: 13px; }
.msg-rating--up   { color: #16a34a; }
.msg-rating--down { color: #dc2626; }


/* ===================================================================
   UI CONSISTENCY PASS — one look for tables, row actions, pagination
   and filter tabs across every listing screen. These rules deliberately
   sit last so they reconcile the older per-page systems (.sr-/.ap-/.qt-,
   .data-table, .filter-pill) into a single visual language without having
   to hand-edit each historical block.
   =================================================================== */

/* ---- Row-action cells: identical gap + alignment on every table ----
   Kept as a real table-cell (no display:flex, which would drop table-cell
   semantics) and spaced with a margin between adjacent controls, so every
   listing page gets the same rhythm between View / Edit / Delete. */
.cell-actions {
    text-align: right;
    white-space: nowrap;
    vertical-align: middle;
}
.cell-actions > * + * { margin-left: 6px; }
/* Optional inline flex wrapper when actions need to wrap on narrow screens */
.row-actions {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

/* ---- Unified listing-table header + row rhythm ----
   The sr/ap/qt tables historically had a border-only header; bring them onto
   the same tinted header + edge padding as the shared .data-table so all
   listing pages read as one product. */
.sr-table th, .ap-table th, .qt-table th {
    background: #f8fafc;
    color: var(--text-light);
    font-size: var(--fs-xs);
    letter-spacing: 0.5px;
    padding: 11px 14px;
    border-bottom: 1px solid #e2e8f0;
}
.sr-table td, .ap-table td, .qt-table td { padding: 12px 14px; }
.sr-table th:first-child, .sr-table td:first-child,
.ap-table th:first-child, .ap-table td:first-child,
.qt-table th:first-child, .qt-table td:first-child { padding-left: 18px; }
.sr-table th:last-child, .sr-table td:last-child,
.ap-table th:last-child, .ap-table td:last-child,
.qt-table th:last-child, .qt-table td:last-child { padding-right: 18px; }
.sr-table tbody tr:hover, .ap-table tbody tr:hover, .qt-table tbody tr:hover { background: var(--primary-tint-2); }
/* Keep the restrained emergency signal-rail (not a heavy pink fill) */
.sr-table tbody tr.emg-row:hover { background: #fff5f5; }

/* ---- Canonical pagination — outline pills, solid-navy active ----
   Replaces both the leads/conversations style (solid-blue .btn.btn-sm number
   buttons) and keeps parity with the sr/ap/qt page buttons. */
.page-btn,
.sr-page-btn, .ap-page-btn, .qt-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    font-weight: 600;
    border: 1.5px solid var(--border);
    color: var(--text-mid);
    text-decoration: none;
    background: var(--card);
    transition: all 150ms var(--ease);
}
.page-btn:hover,
.sr-page-btn:hover, .ap-page-btn:hover, .qt-page-btn:hover {
    border-color: var(--text-faint);
    color: var(--text-strong);
    background: var(--surface-muted);
}
.page-btn.active,
.sr-page-btn.active, .ap-page-btn.active, .qt-page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.page-btn:focus-visible,
.page-btn.active:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---- Unified filter tabs/pills — one height, radius, resting + active ----
   .filter-pill (leads/conversations) and .sr-/.ap-/.qt-tab (listing pages)
   now share the same soft-grey resting chip and the same near-black active
   state, so the navy sidebar stays the only true-blue anchor in the chrome. */
.sr-tab, .ap-tab, .qt-tab {
    padding: 6px 14px;
    font-size: 12.5px;
    font-weight: 600;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid transparent;
    border-radius: var(--radius-full);
}
.sr-tab:hover, .ap-tab:hover, .qt-tab:hover {
    background: #e2e8f0;
    color: #0f172a;
    border-color: transparent;
}
.sr-tab.active, .ap-tab.active, .qt-tab.active {
    background: #0f172a;
    color: #fff;
    border-color: #0f172a;
}
/* Emergency filter tab keeps a red identity in both states */
.sr-tab.emg-tab { background: #fef2f2; color: var(--danger); border-color: transparent; }
.sr-tab.emg-tab:hover { background: #fee2e2; color: var(--danger); }
.sr-tab.emg-tab.active { background: var(--danger); color: #fff; border-color: var(--danger); }


