/* ═══════════════════════════════════════════════════════════════
   Odin — Field Service Agent
   LG Brand Design System: light, warm, premium, minimal
   Fonts: LGEI Headline + LGEI Text
   ═══════════════════════════════════════════════════════════════ */

/* ── @font-face ──────────────────────────────────────────────── */

@font-face {
    font-family: 'LGEI Headline';
    src: url('/static/fonts/LGEIHeadlineTTF-Regular.ttf') format('truetype');
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: 'LGEI Headline';
    src: url('/static/fonts/LGEIHeadlineTTF-Semibold.ttf') format('truetype');
    font-weight: 600;
    font-display: swap;
}
@font-face {
    font-family: 'LGEI Headline';
    src: url('/static/fonts/LGEIHeadlineTTF-Bold.ttf') format('truetype');
    font-weight: 700;
    font-display: swap;
}
@font-face {
    font-family: 'LGEI Text';
    src: url('/static/fonts/LGEITextTTF-Light.ttf') format('truetype');
    font-weight: 300;
    font-display: swap;
}
@font-face {
    font-family: 'LGEI Text';
    src: url('/static/fonts/LGEITextTTF-Regular.ttf') format('truetype');
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: 'LGEI Text';
    src: url('/static/fonts/LGEITextTTF-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-display: swap;
}
@font-face {
    font-family: 'LGEI Text';
    src: url('/static/fonts/LGEITextTTF-Bold.ttf') format('truetype');
    font-weight: 700;
    font-display: swap;
}

/* ── Design tokens ───────────────────────────────────────────── */

:root {
    /* LG Brand Colors */
    --lg-heritage:    #A50034;
    --lg-active:      #EA1917;

    /* Odin gradient stops (derived from LG brand gradients) */
    --odin-grad-start: #A50034;
    --odin-grad-mid:   #D41438;
    --odin-grad-end:   #EA1917;

    /* Surfaces — warm, light */
    --bg-page:        #F0ECE4;
    --bg-white:       #FFFFFF;
    --bg-card:        #FFFFFF;
    --bg-chat:        #FAF9F7;
    --bg-hover:       #F6F3ED;
    --bg-elevated:    #FAF7F0;
    --bg-input:       #FFFFFF;
    --surface-1:      #FFFFFF;
    --surface-2:      #EDE9E0;
    --surface-3:      #E3DFD4;

    /* Text */
    --text-primary:   #1B1A1E;
    --text-secondary: #646464;
    --text-muted:     #999590;
    --text-inverse:   #FFFFFF;

    /* Borders */
    --border:         #CBC8C2;
    --border-light:   #E6E1D6;

    /* Semantic */
    --green:          #1A8754;
    --green-bg:       #E8F5EE;
    --red:            #D32F2F;
    --red-bg:         #FDE8E8;
    --amber:          #E6A817;
    --amber-bg:       #FFF8E1;

    /* Chart / report card colors */
    --chart-blue:       #2196F3;
    --chart-orange:     #FF9800;
    --chart-green:      #4CAF50;
    --chart-red:        #EF5350;
    --chart-amber:      #FFA726;
    --chart-green-light:#66BB6A;
    --chart-green-cell: rgba(76, 175, 80, 0.18);
    --chart-green-text: #2e7d32;
    --chart-amber-cell: rgba(255, 193, 7, 0.18);
    --chart-amber-text: #f57f17;
    --chart-red-cell:   rgba(244, 67, 54, 0.12);
    --chart-red-text:   #c62828;

    /* Shadows */
    --shadow-sm:      0 1px 3px rgba(27, 26, 30, 0.06);
    --shadow-md:      0 4px 12px rgba(27, 26, 30, 0.08);
    --shadow-lg:      0 4px 20px rgba(27, 26, 30, 0.12);

    /* Layout */
    --header-h:       64px;
    --chat-header-h:  52px;
    --radius:         8px;
    --radius-lg:      16px;
    --radius-pill:    100px;

    /* Typography */
    --font-headline:  'LGEI Headline', 'Georgia', serif;
    --font-text:      'LGEI Text', system-ui, -apple-system, sans-serif;
    --font-mono:      'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

    /* Transitions */
    --ease:           cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Dark theme ──────────────────────────────────────────────── */

[data-theme="dark"] {
    --bg-page:        #1a1a1e;
    --bg-white:       #242428;
    --bg-card:        #242428;
    --bg-chat:        #1e1e22;
    --bg-hover:       #2e2e34;
    --bg-elevated:    #2A2A30;
    --bg-input:       #2a2a30;
    --surface-1:      #1f2024;
    --surface-2:      #34353A;
    --surface-3:      #404148;

    --text-primary:   #E8E6E3;
    --text-secondary: #A8A5A0;
    --text-muted:     #706D68;
    --text-inverse:   #1B1A1E;

    --border:         #3E3D42;
    --border-light:   #333338;

    --green:          #34D399;
    --green-bg:       rgba(52, 211, 153, 0.12);
    --red:            #F87171;
    --red-bg:         rgba(248, 113, 113, 0.12);
    --amber:          #FBBF24;
    --amber-bg:       rgba(251, 191, 36, 0.12);

    --chart-blue:       #42A5F5;
    --chart-orange:     #FFB74D;
    --chart-green:      #66BB6A;
    --chart-red:        #EF5350;
    --chart-amber:      #FFCA28;
    --chart-green-light:#81C784;
    --chart-green-cell: rgba(102, 187, 106, 0.18);
    --chart-green-text: #81C784;
    --chart-amber-cell: rgba(255, 202, 40, 0.18);
    --chart-amber-text: #FFCA28;
    --chart-red-cell:   rgba(239, 83, 80, 0.15);
    --chart-red-text:   #EF5350;

    --shadow-sm:      0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md:      0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg:      0 4px 20px rgba(0, 0, 0, 0.5);
}

/* ── Reset ───────────────────────────────────────────────────── */

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

body {
    font-family: var(--font-text);
    background: var(--bg-page);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    font-weight: 400;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ═══════════════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════════════ */

header {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 100;
}

.header-inner {
    height: var(--header-h);
    max-width: 100%;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
}

.header-logo .logo {
    height: 32px;
}

.header-sep {
    width: 1px;
    height: 28px;
    background: var(--border);
    flex-shrink: 0;
}

.header-title {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.title-name {
    font-family: var(--font-headline);
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.title-sub {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.header-spacer {
    flex: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}

/* Theme toggle */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 200ms var(--ease);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
}

/* Account button & panel */
.account-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 300px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.account-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
}

.account-user-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--lg-heritage);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.account-user-icon svg {
    stroke: white;
}

.account-email {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.account-auth-method {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.account-section {
    padding: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
}

.account-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.account-usage-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.usage-label {
    font-size: 12px;
    color: var(--text-secondary);
    width: 50px;
    flex-shrink: 0;
}

.usage-track {
    flex: 1;
    height: 6px;
    background: var(--bg-page);
    border-radius: 3px;
    overflow: hidden;
}

.usage-fill {
    height: 100%;
    background: var(--lg-heritage);
    border-radius: 3px;
    transition: width 300ms var(--ease);
    min-width: 0;
}

.usage-fill.warning {
    background: var(--amber);
}

.usage-fill.critical {
    background: var(--red);
}

.usage-text {
    font-size: 11px;
    color: var(--text-muted);
    width: 60px;
    text-align: right;
    flex-shrink: 0;
}

.account-usage-stats {
    display: flex;
    gap: 16px;
}

.usage-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.usage-stat-label {
    font-size: 11px;
    color: var(--text-muted);
}

.usage-stat-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.account-actions {
    display: flex;
    gap: 6px;
}

.account-actions .acct-btn {
    flex: 1;
    display: inline-block;
    box-sizing: border-box;
    text-align: center;
    padding: 8px 0;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s var(--ease);
}

.account-actions .acct-btn:hover {
    color: var(--text-primary);
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
}

.account-actions .acct-btn:active {
    transform: scale(0.97);
    box-shadow: none;
}

.account-actions .acct-btn-danger:hover {
    color: var(--red);
    border-color: var(--red);
    background: var(--red-bg);
}

/* Status badge */
.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    background: var(--green-bg);
    font-size: 11px;
    font-weight: 600;
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Sidebar toggle ── */

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: all 200ms var(--ease);
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
}

/* ── Buttons ─────────────────────────────────────────────────── */

.btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 7px 16px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-family: var(--font-text);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: all 250ms var(--ease);
}

.btn-outline:hover {
    background: var(--bg-hover);
    border-color: #A8A5A0;
}

.btn-sm {
    padding: 5px 14px;
    font-size: 12px;
}

/* ═══════════════════════════════════════════════════════════════
   APP LAYOUT (sidebar + main)
   ═══════════════════════════════════════════════════════════════ */

.app-layout {
    display: flex;
    height: calc(100vh - var(--header-h));
}

main {
    display: flex;
    flex: 1;
    min-width: 0;
}

/* Role-permissions gate: when the user lacks `chat`, hide the chat pane +
   divider and let the dashboard take the full main width. */
.app-layout main.no-chat #dashboard {
    flex: 1 1 auto;
    width: 100%;
}
.app-layout main.no-chat #chat,
.app-layout main.no-chat .divider-v {
    display: none !important;
}

.divider-v {
    width: 5px;
    background: var(--border-light);
    flex-shrink: 0;
    cursor: col-resize;
    transition: background 0.15s ease;
    position: relative;
}
.divider-v:hover,
.divider-v.dragging {
    background: var(--lg-active);
}
/* Invisible wider hit area for easier grab */
.divider-v::after {
    content: '';
    position: absolute;
    top: 0;
    left: -4px;
    right: -4px;
    bottom: 0;
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════ */

.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-white);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 250ms var(--ease), min-width 250ms var(--ease), opacity 250ms var(--ease);
    overflow: hidden;
    z-index: 50;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

/* Sidebar action buttons — vertical stack, circle icons with hover labels */
.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-action-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: var(--text-primary);
}

.action-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    transition: all 200ms var(--ease);
    flex-shrink: 0;
}

.sidebar-action-btn:hover .action-icon {
    background: var(--bg-hover);
    border-color: var(--text-muted);
    animation: iconBounce 0.35s var(--ease);
}

@keyframes iconBounce {
    0% { transform: scale(1); }
    40% { transform: scale(1.18); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.action-label {
    font-family: var(--font-text);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
}

.action-shortcut {
    font-family: var(--font-text);
    font-size: 9px;
    color: var(--text-muted);
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: 3px;
    padding: 1px 4px;
    opacity: 0;
    transition: opacity 200ms var(--ease);
    white-space: nowrap;
}

.sidebar-action-btn:hover .action-shortcut {
    opacity: 1;
}

/* Reports button active state */
.sidebar-action-btn.reports-active .action-icon {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--bg-white);
}

/* Search panel (slides open when search icon clicked) */
.sidebar-search-panel {
    margin-top: 10px;
    overflow: hidden;
    animation: slideDown 0.2s var(--ease);
}

@keyframes slideDown {
    from { opacity: 0; max-height: 0; }
    to { opacity: 1; max-height: 50px; }
}

.sidebar-search-input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-family: var(--font-text);
    font-size: 12px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 200ms var(--ease);
}

.sidebar-search-input:focus {
    border-color: var(--lg-heritage);
}

.sidebar-search-input::placeholder {
    color: var(--text-muted);
}

/* History section header */
.sidebar-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    flex-shrink: 0;
    position: relative;
}

.history-label {
    font-family: var(--font-text);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.history-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.history-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 150ms var(--ease), background 150ms var(--ease), transform 200ms var(--ease);
}

.sidebar-history-header:hover .history-toggle-btn {
    opacity: 1;
}

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

.history-toggle-btn.collapsed {
    transform: rotate(-90deg);
}

.history-settings-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 150ms var(--ease), color 150ms var(--ease);
}

.history-settings-btn[hidden] {
    display: none;
}

.history-settings-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.history-settings-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 12px;
    min-width: 180px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-settings-menu[hidden] {
    display: none;
}

.history-settings-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 6px 8px 2px;
}

.history-settings-option {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    font-family: var(--font-text);
    font-size: 13px;
    text-align: left;
    padding: 7px 10px;
    border-radius: 4px;
    transition: background 120ms var(--ease);
}

.history-settings-option:hover {
    background: var(--bg-hover);
}

.history-settings-option.active {
    background: var(--bg-hover);
    color: var(--lg-active);
    font-weight: 600;
}

.conversation-list.collapsed {
    display: none;
}

/* ── Project selector ── */

.project-selector {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-light);
    gap: 8px;
    flex-shrink: 0;
}

.project-dropdown {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-family: var(--font-text);
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
    transition: border-color 200ms var(--ease);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23999590' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.project-dropdown:focus {
    border-color: var(--lg-heritage);
}

.project-settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: all 200ms var(--ease);
}

.project-settings-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
}

/* ── Project modal ── */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.2s var(--ease);
}

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

.modal-panel {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 440px;
    width: 90%;
    padding: 24px;
    animation: modalSlideIn 0.25s var(--ease);
}

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

.modal-panel h3 {
    font-family: var(--font-headline);
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

.modal-field {
    margin-bottom: 16px;
}

.modal-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.modal-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-family: var(--font-text);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-input);
    outline: none;
    transition: border-color 200ms var(--ease);
}

.modal-input:focus {
    border-color: var(--lg-heritage);
}

.modal-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-family: var(--font-text);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-input);
    outline: none;
    resize: vertical;
    transition: border-color 200ms var(--ease);
}

.modal-textarea:focus {
    border-color: var(--lg-heritage);
}

.modal-help {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-text);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    border: 1px solid transparent;
    transition: all 200ms var(--ease);
}

.btn-primary {
    background: var(--lg-heritage);
    color: var(--text-inverse);
    border-color: var(--lg-heritage);
}

.btn-primary:hover {
    background: #8a002c;
    border-color: #8a002c;
}

.btn-danger-text {
    color: var(--red);
    border-color: var(--red);
}

.btn-danger-text:hover {
    background: var(--red-bg);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-group-header {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 12px 10px 6px;
}

.conversation-item {
    display: flex;
    align-items: center;
    padding: 10px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 150ms var(--ease);
    position: relative;
    gap: 8px;
}

.conversation-item:hover {
    background: var(--bg-hover);
}

.conversation-item.active {
    background: var(--bg-page);
    border-left: 3px solid var(--lg-active);
    padding-left: 7px;
}

.conv-info {
    flex: 1;
    min-width: 0;
}

.conv-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.conv-date {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

.conv-star {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all 150ms var(--ease);
    flex-shrink: 0;
    font-size: 14px;
    line-height: 1;
}

.conversation-item:hover .conv-star,
.conv-star.starred {
    opacity: 1;
}

.conv-star.starred {
    color: var(--amber);
}

.conv-star:hover {
    color: var(--amber);
}

.conv-export {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all 150ms var(--ease);
    flex-shrink: 0;
    font-size: 14px;
    line-height: 1;
}

.conversation-item:hover .conv-export {
    opacity: 1;
}

.conv-export:hover {
    background: var(--bg-page);
    color: var(--text-primary);
}

.conv-delete {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all 150ms var(--ease);
    flex-shrink: 0;
    font-size: 14px;
    line-height: 1;
}

.conversation-item:hover .conv-delete {
    opacity: 1;
}

.conv-delete:hover {
    background: var(--red-bg);
    color: var(--red);
}

.conv-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD (left ~60%)
   ═══════════════════════════════════════════════════════════════ */

#dashboard {
    flex: 3;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-page);
}

#dashboard-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Empty state ── */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: calc(100vh - var(--header-h) - 48px);
    text-align: center;
}

.empty-icon {
    margin-bottom: 20px;
    opacity: 0.6;
}

.empty-state h2 {
    font-family: var(--font-headline);
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ── Dashboard panels ── */

.dashboard-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    animation: panelIn 0.35s var(--ease);
    transition: box-shadow 250ms var(--ease);
}

.dashboard-panel:hover {
    box-shadow: var(--shadow-md);
}

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

.panel-header {
    padding: 14px 20px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
    font-family: var(--font-text);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-header::before {
    content: '';
    width: 3px;
    height: 14px;
    border-radius: 2px;
    background: var(--lg-active);
    flex-shrink: 0;
}

.panel-badge {
    background: var(--lg-active);
    color: var(--text-inverse);
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
    margin-left: auto;
}

.panel-body {
    padding: 20px;
}

/* ── Charts ── */

.dashboard-chart {
    width: 100%;
    border-radius: var(--radius);
    display: block;
}

/* ── US choropleth map ── */

.us-map-container {
    width: 100%;
    max-height: 360px;
    overflow: hidden;
}

.us-map-wrapper {
    position: relative;
    width: 100%;
}

.us-map-svg {
    width: 100%;
    height: auto;
    max-height: 340px;
    display: block;
}

.us-map-state {
    cursor: pointer;
    transition: opacity 150ms var(--ease), filter 150ms var(--ease);
    stroke-linejoin: round;
}

.us-map-state:hover {
    opacity: 0.85;
    filter: brightness(1.15);
    stroke: var(--text-primary);
    stroke-width: 2;
}

.us-map-state.no-data {
    cursor: default;
    opacity: 0.5;
}

.us-map-tooltip {
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    pointer-events: none;
    z-index: 100;
    box-shadow: var(--shadow-md);
    font-size: 12px;
    line-height: 1.5;
    min-width: 140px;
    max-width: 220px;
}

.us-map-tt-title {
    font-family: var(--font-text);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.us-map-tt-value {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.us-map-tt-target {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
}

.us-map-tt-target.good { color: var(--green); }
.us-map-tt-target.bad  { color: var(--red); }

.us-map-tt-nodata {
    color: var(--text-muted);
    font-style: italic;
}

.us-map-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 0 4px;
    flex-wrap: wrap;
}

.us-map-legend-bar {
    width: 160px;
    height: 10px;
    border-radius: 5px;
    flex-shrink: 0;
}

.us-map-legend-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.us-map-target-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    width: 100%;
    text-align: center;
}

/* ── Leaflet interactive map (Phase 2) ── */

.leaflet-map-container {
    width: 100%;
    height: 500px;
    border-radius: var(--radius);
    z-index: 1;
    border: 1px solid var(--border-light);
}

.leaflet-map-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.map-state-select,
.map-metric-select {
    padding: 6px 10px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-family: var(--font-text);
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
    transition: border-color 200ms var(--ease);
}
.map-state-select:focus,
.map-metric-select:focus {
    border-color: var(--lg-heritage);
}

.map-state-select {
    min-width: 140px;
    font-weight: 600;
}

.map-date-label,
.map-channel-label {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-page);
    padding: 3px 8px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-light);
}

.map-coverage-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.map-coverage-toggle input[type="checkbox"] {
    accent-color: var(--lg-heritage);
}

.map-back-btn {
    font-size: 11px;
    padding: 4px 10px;
}

.map-loading {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

.leaflet-map-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 0;
    font-size: 11px;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.map-legend-label {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.map-legend-good  { color: var(--green); font-weight: 600; }
.map-legend-bad   { color: var(--red); font-weight: 600; }
.map-legend-target { font-weight: 600; color: var(--text-secondary); }
.map-legend-count {
    color: var(--text-muted);
    font-style: italic;
}
.map-legend-min, .map-legend-max {
    font-variant-numeric: tabular-nums;
}
.map-legend-bar {
    width: 80px;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #DC2626, #D97706, #059669);
}

.map-tooltip {
    font-family: var(--font-text);
    font-size: 12px;
    line-height: 1.5;
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-light) !important;
    border-radius: var(--radius) !important;
    padding: 6px 10px !important;
    box-shadow: var(--shadow-md);
}

/* Override Leaflet's default control styling to match theme */
.leaflet-container {
    font-family: var(--font-text);
    background: var(--bg-page);
}
.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-light) !important;
}
.leaflet-control-zoom a:hover {
    background: var(--bg-page) !important;
}
.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.7) !important;
    font-size: 9px !important;
}
[data-theme="dark"] .leaflet-control-attribution {
    background: rgba(30, 30, 34, 0.7) !important;
    color: var(--text-muted) !important;
}
[data-theme="dark"] .leaflet-control-attribution a {
    color: var(--text-muted) !important;
}

.ranked-overall {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 0 0 12px;
    font-variant-numeric: tabular-nums;
}

.ranked-overall strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* ── Data tables ── */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.data-table th {
    background: var(--bg-page);
    color: var(--text-secondary);
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-light);
    position: sticky;
    top: 0;
    white-space: nowrap;
}

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    white-space: nowrap;
}

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

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.table-scroll {
    max-height: 400px;
    overflow: auto;
}

/* ── Key-value table (single-row results) ── */

.kv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.kv-table + .kv-table {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.kv-table tr {
    transition: background 150ms var(--ease);
}

.kv-table tr:hover {
    background: var(--bg-hover);
}

.kv-table td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
}

.kv-label {
    width: 40%;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.kv-value {
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    font-weight: 500;
}

/* ── KPI cards ── */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.kpi-card {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 20px 16px;
    text-align: center;
    transition: box-shadow 250ms var(--ease), border-color 250ms var(--ease);
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border);
}

.kpi-grid .kpi-card:first-child {
    grid-column: span 2;
}

.kpi-grid .kpi-card:first-child .kpi-value {
    font-size: 40px;
}

.kpi-value {
    font-family: var(--font-headline);
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.kpi-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}

.kpi-delta {
    font-size: 13px;
    margin-top: 8px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
}

.kpi-delta.positive {
    color: var(--green);
    background: var(--green-bg);
}

.kpi-delta.negative {
    color: var(--red);
    background: var(--red-bg);
}

/* ── Focus areas / risk items ── */

.focus-list { list-style: none; }

.focus-item {
    padding: 12px 16px;
    border-left: 3px solid var(--border);
    background: var(--bg-white);
    margin-bottom: 8px;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 13px;
    transition: background 150ms var(--ease);
}

.focus-item:hover {
    background: var(--bg-hover);
}

.focus-item .focus-title {
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--text-primary);
}

.focus-item .focus-detail {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
}

.severity-high   { border-left-color: var(--red); }
.severity-medium { border-left-color: var(--amber); }
.severity-low    { border-left-color: var(--green); }

/* ── Briefing dashboard ── */

.briefing-period {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-page);
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.briefing-period strong {
    color: var(--text-primary);
    font-weight: 600;
}

.briefing-period .period-vs {
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Briefing KPI grid */
.briefing-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.briefing-kpi {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 14px 12px;
    text-align: center;
    transition: border-color 200ms var(--ease), box-shadow 200ms var(--ease);
    position: relative;
}

.briefing-kpi:hover {
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
}

.briefing-kpi.improving {
    border-top: 3px solid var(--green);
}

.briefing-kpi.worsening {
    border-top: 3px solid var(--red);
}

.briefing-kpi.stable {
    border-top: 3px solid var(--border);
}

.briefing-kpi .bk-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.briefing-kpi .bk-value {
    font-family: var(--font-headline);
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.briefing-kpi .bk-delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-top: 6px;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
}

.briefing-kpi .bk-delta.improving {
    color: var(--green);
    background: var(--green-bg);
    border-top: none;
}

.briefing-kpi .bk-delta.worsening {
    color: var(--red);
    background: var(--red-bg);
    border-top: none;
}

.briefing-kpi .bk-delta.stable {
    color: var(--text-muted);
    background: var(--bg-page);
    border-top: none;
}

.briefing-kpi .bk-prior {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.briefing-kpi .bk-target {
    font-size: 10px;
    font-weight: 600;
    margin-top: 6px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    display: inline-block;
}

.briefing-kpi .bk-target.target-met {
    color: var(--green);
    background: var(--green-bg);
}

.briefing-kpi .bk-target.target-miss {
    color: var(--red);
    background: var(--red-bg);
}

/* Flags panel */
.briefing-flags {
    background: var(--amber-bg);
    border: 1px solid rgba(230, 168, 23, 0.25);
    border-radius: var(--radius);
    padding: 12px 16px;
}

.briefing-flags .flags-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--amber);
    margin-bottom: 8px;
}

.briefing-flags ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.briefing-flags li {
    font-size: 13px;
    color: var(--text-primary);
    padding: 4px 0;
    padding-left: 16px;
    position: relative;
}

.briefing-flags li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--amber);
}

/* Risk brief sections */
.risk-section {
    margin-bottom: 16px;
}

.risk-section:last-child {
    margin-bottom: 0;
}

.risk-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
}

.risk-section-title.risks { color: var(--red); }
.risk-section-title.opportunities { color: var(--green); }
.risk-section-title.coaching { color: var(--amber); }
.risk-section-title.markets { color: var(--green); }

.risk-item {
    padding: 10px 14px;
    background: var(--bg-white);
    border-left: 3px solid var(--border);
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 6px;
    font-size: 13px;
}

.risk-item.risk { border-left-color: var(--red); }
.risk-item.opportunity { border-left-color: var(--green); }
.risk-item.coaching { border-left-color: var(--amber); }
.risk-item.market { border-left-color: var(--green); }

.risk-item .ri-title {
    font-weight: 600;
    color: var(--text-primary);
}

.risk-item .ri-detail {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.risk-item .ri-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 1px 6px;
    border-radius: var(--radius-pill);
    margin-right: 6px;
}

.ri-badge.high { background: var(--red-bg); color: var(--red); }
.ri-badge.medium { background: var(--amber-bg); color: var(--amber); }
.ri-badge.low { background: var(--green-bg); color: var(--green); }

/* Strategic recommendation callout */
.recommendation-box {
    background: linear-gradient(135deg, rgba(165,0,52,0.04), rgba(234,25,23,0.04));
    border: 1px solid rgba(165,0,52,0.15);
    border-radius: var(--radius);
    padding: 14px 16px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.6;
    font-weight: 500;
}

/* Grouped briefing table */
.briefing-group-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.briefing-group-table th {
    background: var(--bg-page);
    color: var(--text-secondary);
    padding: 8px 10px;
    text-align: center;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 2px solid var(--border-light);
}

.briefing-group-table th:first-child {
    text-align: left;
}

.briefing-group-table td {
    padding: 8px 10px;
    text-align: center;
    border-bottom: 1px solid var(--border-light);
}

.briefing-group-table td:first-child {
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
}

.briefing-group-table .delta-improving {
    color: var(--green);
    font-weight: 600;
}

.briefing-group-table .delta-worsening {
    color: var(--red);
    font-weight: 600;
}

/* ── Trend dashboard ── */

.trend-headline {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    line-height: 1.5;
}

.trend-observations {
    list-style: none;
    padding: 0;
    margin: 0 0 16px 0;
}

.trend-observations li {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 6px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.trend-observations li.delta-improving { color: var(--green); }
.trend-observations li.delta-worsening { color: var(--red); }

.trend-chart-container {
    height: 280px;
    margin: 12px 0 16px;
    position: relative;
}

.data-table .delta-improving { color: var(--green); font-weight: 600; }
.data-table .delta-worsening { color: var(--red); font-weight: 600; }

/* ── Report download ── */

.report-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--lg-active);
    color: var(--text-inverse);
    padding: 12px 24px;
    border-radius: var(--radius-pill);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.01em;
    transition: all 250ms var(--ease);
}

.report-link:hover {
    background: var(--lg-heritage);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* ═══════════════════════════════════════════════════════════════
   CHAT (right ~40%)
   ═══════════════════════════════════════════════════════════════ */

#chat {
    flex: 2;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    min-width: 380px;
    border-left: 1px solid var(--border-light);
}

/* Collapsed by the #chatToggle in the page header. Intentionally no width/flex
   transition — the dashboard hosts a `repeat(auto-fill, minmax(280px, 1fr))`
   grid (Reports cards) that repacks at every column threshold as width changes,
   which makes any animated collapse flicker badly. Snap-collapse avoids that.
   !important overrides the inline flex/min-width set by the resizable-divider drag. */
#chat.collapsed {
    flex: 0 0 0 !important;
    min-width: 0 !important;
    width: 0 !important;
    border-left: none;
    pointer-events: none;
    overflow: hidden;
}

/* When chat is collapsed, the v-divider would be a useless drag handle next to nothing. */
main:has(#chat.collapsed) .divider-v {
    display: none;
}

/* ── Chat header ── */

.chat-header {
    height: var(--chat-header-h);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.odin-icon-sm {
    flex-shrink: 0;
}

.chat-header-title {
    font-family: var(--font-headline);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.chat-header-badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--lg-heritage);
    background: linear-gradient(135deg, rgba(165,0,52,0.08), rgba(234,25,23,0.08));
    padding: 4px 10px;
    border-radius: var(--radius-pill);
}

/* ── Messages area ── */

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
}

/* ── Welcome hero ── */

.welcome-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 48px 24px 32px;
    min-height: 100%;
}

.welcome-icon {
    margin-bottom: 24px;
    animation: welcomeFadeIn 0.6s var(--ease);
}

@keyframes welcomeFadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to   { opacity: 1; transform: scale(1); }
}

.welcome-title {
    font-family: var(--font-headline);
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

.welcome-sub {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
    max-width: 320px;
    line-height: 1.6;
    margin-bottom: 28px;
}

/* ── Prompt chips ── */

.prompt-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 380px;
    padding: 4px;
}

.prompt-chip {
    background: var(--bg-white);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    font-family: var(--font-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 200ms var(--ease);
    white-space: nowrap;
}

.prompt-chip:hover {
    background: var(--text-primary);
    color: var(--text-inverse);
    border-color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.prompt-chip:active {
    transform: translateY(0);
}

.prompt-chip.primary {
    background: var(--lg-heritage);
    border-color: var(--lg-heritage);
    color: #FFFFFF;
    font-weight: 600;
}

.prompt-chip.primary:hover {
    background: #8a002c;
    border-color: #8a002c;
    color: #FFFFFF;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.prompt-chips-label {
    font-family: var(--font-headline);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
    margin-top: 20px;
    margin-bottom: 8px;
    text-align: center;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 380px;
}

.prompt-chips-label::before,
.prompt-chips-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-light);
}

/* ── Messages ── */

.message {
    margin-bottom: 20px;
    max-width: 92%;
    line-height: 1.6;
    animation: msgIn 0.25s var(--ease);
}

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

.message.user {
    margin-left: auto;
    background: var(--text-primary);
    color: var(--text-inverse);
    padding: 12px 18px;
    border-radius: 20px 20px 4px 20px;
    font-size: 14px;
    font-weight: 400;
}

.message.bot {
    padding: 0;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.bot-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(165,0,52,0.1), rgba(234,25,23,0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.bot-avatar svg {
    width: 16px;
    height: 16px;
}

.bot-body {
    flex: 1;
    min-width: 0;
}

.message-content {
    font-size: 14px;
    padding: 14px 18px;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: 4px 20px 20px 20px;
    color: var(--text-primary);
    font-weight: 400;
    box-shadow: var(--shadow-sm);
}

.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content strong { font-weight: 600; }

.message-content code {
    background: var(--bg-page);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--lg-heritage);
    border: 1px solid var(--border-light);
}

.message-content pre {
    background: var(--bg-page);
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    margin: 8px 0;
    border: 1px solid var(--border-light);
}

.message-content pre code {
    background: none;
    padding: 0;
    border: none;
    font-size: inherit;
    color: inherit;
}

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin-bottom: 4px;
}

/* Markdown section titles (bold-only lines like "Recommended Actions:") */
.message-content .md-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 16px 0 8px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-subtle);
    letter-spacing: 0.01em;
}

.message-content .md-section-title:first-child {
    margin-top: 0;
}

/* Ordered action lists — visually distinct */
.message-content ol.md-actions {
    margin: 8px 0 12px 0;
    padding-left: 24px;
    border-left: 3px solid var(--lg-heritage);
    background: color-mix(in srgb, var(--bg-page) 50%, transparent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding-top: 8px;
    padding-bottom: 8px;
}

.message-content ol.md-actions li {
    margin-bottom: 6px;
    padding-left: 4px;
    line-height: 1.5;
}

/* Tables inside chat messages */
.message-content .table-scroll {
    margin: 10px 0;
    max-height: 300px;
}

.message-content .data-table {
    font-size: 12px;
}

.message-content .data-table th {
    padding: 6px 10px;
    font-size: 10px;
}

.message-content .data-table td {
    padding: 6px 10px;
    font-size: 12px;
}

/* Tighten line spacing in chat */
.message-content br + br { display: none; }

/* ── Tool call pills ── */

.tool-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.tool-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.tool-pill .spinner {
    width: 8px;
    height: 8px;
    border: 1.5px solid var(--border);
    border-top-color: var(--lg-active);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.tool-pill.done {
    background: var(--green-bg);
    border-color: rgba(26, 135, 84, 0.2);
    color: var(--green);
}

.tool-pill.done .spinner { display: none; }

.tool-pill.done::before {
    content: '\2713';
    font-weight: 700;
    font-size: 10px;
}

/* ── Typing indicator ── */

.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--border);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Input area ── */

#input-area {
    padding: 16px 20px 12px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-white);
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--bg-chat);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 18px;
    transition: border-color 250ms var(--ease), box-shadow 250ms var(--ease);
}

.input-wrapper:focus-within {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 1px var(--text-primary);
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 400;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 120px;
    overflow-y: auto;
    padding: 6px 0;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 38px;
    height: 38px;
    background: var(--text-primary);
    color: var(--text-inverse);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 250ms var(--ease);
}

.btn-send:hover {
    background: var(--lg-active);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-send:disabled {
    background: var(--border-light);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.input-footer {
    text-align: center;
    padding-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

/* ── File upload ── */

.btn-attach {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 200ms var(--ease);
}
.btn-attach:hover { color: var(--text-primary); background: var(--bg-hover); }

.file-preview-area {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
}

.file-preview-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 200px;
}
.file-preview-pill img { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; }
.file-icon { font-size: 16px; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.file-remove {
    background: transparent; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 14px; padding: 0 2px; line-height: 1;
}
.file-remove:hover { color: var(--red); }
.upload-spinner {
    width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--lg-heritage);
    border-radius: 50%; animation: spin 0.6s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Drag over state */
#chat.drag-over { outline: 2px dashed var(--lg-heritage); outline-offset: -4px; }

/* Attachments in user messages */
.user-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.attachment-thumb { width: 64px; height: 64px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-light); }
.attachment-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachment-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; background: rgba(255,255,255,0.15); border-radius: var(--radius-pill);
    font-size: 12px;
}

/* ═══════════════════════════════════════════════════════════════
   SCROLLBARS
   ═══════════════════════════════════════════════════════════════ */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: #A8A5A0; }

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
    main { flex-direction: column; }
    .divider-v { display: none; }
    #dashboard { flex: 1; max-height: 40vh; }
    #chat { flex: 1; min-width: auto; border-left: none; border-top: 1px solid var(--border-light); }
    .kpi-grid .kpi-card:first-child { grid-column: span 1; }
    .kpi-grid .kpi-card:first-child .kpi-value { font-size: 32px; }
    .title-sub { display: none; }
    .header-inner { padding: 0 16px; gap: 12px; }
    .welcome-title { font-size: 22px; }
    .prompt-chips { max-width: 300px; }

    /* Sidebar becomes overlay on mobile */
    .sidebar {
        position: fixed;
        top: var(--header-h);
        left: 0;
        bottom: 0;
        z-index: 200;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.collapsed {
        box-shadow: none;
    }

}

/* ═══════════════════════════════════════════════════════════════
   BUG REPORT TOAST
   ═══════════════════════════════════════════════════════════════ */

.bug-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--green);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: toastIn 0.3s var(--ease);
}

.bug-toast a {
    color: white;
    text-decoration: underline;
    font-weight: 600;
}

.bug-toast.is-error {
    background: var(--lg-heritage);
}

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

/* ── Architecture Diagram ────────────────────────────────────── */

.btn-icon.active {
    background: var(--bg-hover);
    color: var(--lg-heritage);
}

.arch-diagram {
    padding: 24px;
    max-width: 900px;
    margin: 0 auto;
    font-family: var(--font-text);
}

.arch-diagram h2 {
    text-align: center;
    margin-bottom: 24px;
    font-family: var(--font-headline);
    font-weight: 600;
}

.arch-section {
    margin-bottom: 16px;
}

.arch-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-left: 4px;
}

.arch-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.arch-connector {
    text-align: center;
    color: var(--text-secondary);
    font-size: 18px;
    margin: 4px 0;
    line-height: 1;
}

.arch-node {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    min-width: 120px;
    text-align: center;
}

.arch-node:hover {
    border-color: var(--lg-heritage);
    box-shadow: 0 2px 12px rgba(165, 0, 52, 0.15);
    transform: translateY(-1px);
}

.arch-node.selected {
    border-color: var(--lg-heritage);
    box-shadow: 0 0 0 2px rgba(165, 0, 52, 0.2);
}

.arch-node-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

.arch-node-subtitle {
    font-size: 11px;
    color: var(--text-secondary);
}

.arch-node-badge {
    display: inline-block;
    background: var(--lg-heritage);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    margin-top: 4px;
}

/* Tooltip on hover */
.arch-node .arch-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-white);
    border: 1.5px solid var(--lg-heritage);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: normal;
    box-shadow: 0 4px 16px rgba(165, 0, 52, 0.12);
    z-index: 100;
    pointer-events: none;
    min-width: 280px;
    max-width: 420px;
    width: max-content;
}

.arch-node:hover .arch-tooltip {
    display: block;
}

/* Layer bands */
.arch-layer {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.arch-layer:hover {
    border-color: var(--lg-heritage);
}

.arch-layer.selected {
    border-color: var(--lg-heritage);
    box-shadow: 0 0 0 2px rgba(165, 0, 52, 0.2);
}

.arch-layer-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.arch-layer-name {
    font-weight: 600;
    font-size: 13px;
}

.arch-layer-tools {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.arch-layer-tool {
    font-size: 11px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 8px;
    color: var(--text-secondary);
}

/* Hover tooltip for layers */
.arch-layer .arch-tooltip {
    display: none;
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translate(-50%, -100%);
    background: var(--bg-white);
    border: 1.5px solid var(--lg-heritage);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: normal;
    box-shadow: 0 4px 16px rgba(165, 0, 52, 0.12);
    z-index: 100;
    pointer-events: none;
    min-width: 320px;
    max-width: 480px;
    width: max-content;
}

.arch-layer:hover .arch-tooltip {
    display: block;
}

/* Detail panel (expanded on click) */
.arch-detail {
    background: var(--bg-card);
    border: 1.5px solid var(--lg-heritage);
    border-radius: 12px;
    padding: 20px 24px;
    margin-top: 16px;
    animation: archDetailIn 0.15s ease;
}

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

.arch-detail h3 {
    font-family: var(--font-headline);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--lg-heritage);
}

.arch-detail p {
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 8px;
}

.arch-detail .arch-detail-stats {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin: 12px 0;
}

.arch-detail .arch-stat {
    background: var(--bg-page);
    border-radius: 8px;
    padding: 8px 14px;
    text-align: center;
}

.arch-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--lg-heritage);
}

.arch-stat-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.arch-detail .arch-example {
    font-style: italic;
    color: var(--text-secondary);
    font-size: 13px;
    border-left: 3px solid var(--lg-heritage);
    padding-left: 12px;
    margin-top: 12px;
}

/* ── Blog View ──────────────────────────────────────────────── */

.blog-view {
    padding: 24px;
    max-width: 900px;
    margin: 0 auto;
}

.blog-header {
    display: flex;
    align-items: baseline;
    gap: 16px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 12px;
}

.blog-header h2 {
    margin: 0;
    font-size: 20px;
    color: var(--text-primary);
}

.blog-commit-badge {
    background: rgba(76, 175, 80, 0.12);
    color: #4CAF50;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
}

[data-theme="dark"] .blog-commit-badge {
    background: rgba(76, 175, 80, 0.15);
    color: #81C784;
}

.blog-entry {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.blog-entry--latest {
    border-left: 4px solid #4CAF50;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.1);
}

.blog-entry--collapsed {
    border-left: 4px solid var(--border-light);
}

.blog-entry--expanded {
    border-left: 4px solid var(--border);
}

.blog-entry-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.2s ease;
}

.blog-entry--collapsed .blog-entry-header:hover {
    background: var(--bg-hover);
}

.blog-entry-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.blog-entry-title-group h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.blog-latest-badge {
    background: #4CAF50;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.blog-expand-indicator {
    color: var(--text-muted);
    font-size: 14px;
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}

.blog-entry-meta {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 12px;
}

.blog-entry-body {
    padding: 0 16px 16px;
}

.blog-summary ul {
    list-style: disc;
    padding-left: 20px;
    margin: 0 0 16px 0;
}

.blog-summary li {
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

.blog-highlights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.blog-highlight-group {
    padding: 12px;
    background: var(--bg-hover);
    border-radius: 6px;
}

.blog-highlight-group h4 {
    margin: 0 0 8px 0;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--lg-heritage);
}

.blog-highlight-group ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.blog-highlight-group li {
    margin-bottom: 4px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.4;
}

.blog-footer {
    font-size: 11px;
    color: var(--text-muted);
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

/* === Response feedback widget ============================================ */
:root {
    --feedback-up: #2e7d32;          /* green */
    --feedback-down: #c62828;        /* red */
    --feedback-neutral: var(--text-muted, #888);
    --feedback-form-bg: var(--surface-2, #f4f4f6);
    --feedback-form-border: var(--border, #d8d8dc);
}
[data-theme="dark"] {
    --feedback-up: #66bb6a;
    --feedback-down: #ef5350;
    --feedback-form-bg: var(--surface-2, #1f2024);
    --feedback-form-border: var(--border, #2a2b30);
}

.feedback-widget {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--feedback-neutral);
}
.feedback-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--feedback-neutral);
    border-radius: 4px;
    line-height: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.feedback-btn:hover {
    background: var(--feedback-form-bg);
}
.feedback-btn.active.up { color: var(--feedback-up); }
.feedback-btn.active.down { color: var(--feedback-down); }
.feedback-summary {
    color: var(--feedback-neutral);
    margin-left: 8px;
}
.feedback-topic-chip {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--feedback-form-bg);
    border: 1px solid var(--feedback-form-border);
    font-size: 11px;
    margin-right: 6px;
}

/* Inline thumbs-down form */
.feedback-form {
    margin-top: 8px;
    padding: 10px;
    background: var(--feedback-form-bg);
    border: 1px solid var(--feedback-form-border);
    border-radius: 6px;
}
.feedback-form label {
    display: block;
    font-size: 12px;
    margin-bottom: 4px;
    color: var(--text-muted, #555);
}
.feedback-form select,
.feedback-form textarea {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 8px;
    padding: 6px;
    background: var(--bg, #fff);
    color: var(--text, #111);
    border: 1px solid var(--feedback-form-border);
    border-radius: 4px;
    font: inherit;
}
.feedback-form .feedback-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.feedback-form button {
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--feedback-form-border);
    cursor: pointer;
    background: var(--bg, #fff);
    color: var(--text, #111);
}
.feedback-form button.primary {
    background: var(--lg-active, #A50034);
    color: #fff;
    border-color: var(--lg-active, #A50034);
}
.feedback-form button.primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Impersonation Banner ─────────────────────────────────────── */
.impersonation-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
  background: var(--lg-red, #A50034);
  color: #fff;
  padding: 6px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.impersonation-banner[hidden] {
  display: none;
}

.impersonation-banner button {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

.impersonation-banner button:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* === Reports placeholder (post-wipe) === */
.reports-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--text-secondary);
}
.reports-placeholder h2 {
    color: var(--text-primary);
    margin: 0 0 0.5rem 0;
}

/* ------------ Productivity dashboard ------------ */

.productivity {
    padding: 16px 24px;
    color: var(--text-primary);
}

.productivity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.productivity-header h2 {
    margin: 0;
    color: var(--text-primary);
}

.productivity-summary {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.prod-kpi {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    flex: 1 1 0;
    text-align: center;
}

.prod-kpi-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.prod-kpi-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.prod-kpi-warn .prod-kpi-value { color: var(--amber); }

.productivity-tree {
    font-size: 13px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.prod-row {
    display: grid;
    grid-template-columns: 2fr 100px 120px 120px;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
}

.prod-row-header {
    background: var(--bg-hover);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
    cursor: default;
    /* Sticky so header stays visible while scrolling the rollup tree. */
    position: sticky;
    top: 0;
    z-index: 2;
}

.prod-row-rsm  { font-weight: 600; background: var(--bg-hover); }
.prod-row-asm  { padding-left: 32px; background: var(--bg-chat); }

/* Freeze the row-label column so it stays visible during horizontal scroll.
   Each row-type override sets the matching background so the sticky cell
   can occlude what scrolls past behind it. */
.prod-row > :first-child {
    position: sticky;
    left: 0;
    z-index: 1;
}
.prod-row-header > :first-child {
    background: var(--bg-hover);
    z-index: 3;
}
.prod-row-rsm > :first-child { background: var(--bg-hover); }
.prod-row-asm > :first-child { background: var(--bg-chat); }

.prod-cell-name { display: flex; align-items: center; gap: 6px; }
.prod-cell-num  { text-align: center; font-variant-numeric: tabular-nums; }

.prod-chevron { display: inline-block; width: 12px; color: var(--text-secondary); }

.tier-green   { color: var(--green); font-weight: 600; }
.tier-yellow  { color: var(--amber); font-weight: 600; }
.tier-red     { color: var(--red);   font-weight: 600; }
.tier-neutral { color: var(--text-primary); }

.prod-daily-loading,
.prod-daily-err {
    padding: 24px;
    color: var(--text-secondary);
    text-align: center;
}

.prod-daily {
    background: var(--bg-hover);
    padding: 8px 16px 16px 56px;
    border-bottom: 1px solid var(--border);
}

.prod-daily-table {
    width: 360px;
    border-collapse: collapse;
    margin-top: 8px;
}

.prod-daily-table th,
.prod-daily-table td {
    padding: 4px 12px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
    text-align: left;
}

.prod-daily-table th { color: var(--text-secondary); font-weight: 600; font-size: 11px; text-transform: uppercase; }

.prod-daily-zero td { color: var(--text-secondary); opacity: 0.55; }

/* ── Reports landing shell ───────────────────────────────────── */

.reports-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.reports-shell-header {
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

.reports-pane-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

.reports-shell-content {
    flex: 1;
    /* Intentionally NOT overflow: auto — the parent #dashboard already owns
       page-level scrolling, and creating a second scroll context here would
       break position: sticky on table headers (the sticky container would be
       this element, which doesn't actually scroll). */
}

.reports-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
    padding: 1rem 1.25rem;
}

.reports-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
    text-align: left;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
    font: inherit;
    color: inherit;
}

.reports-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    border-color: var(--border);
}

.reports-card:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 2px;
}

.reports-card-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.98rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.reports-card-title-icon {
    display: inline-flex;
    align-items: center;
    color: var(--lg-heritage);
    flex-shrink: 0;
}

.reports-card-desc {
    color: var(--text-secondary);
    font-size: 0.84rem;
    line-height: 1.35;
}

.reports-card-tag {
    margin-top: auto;
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.reports-card-views {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.reports-card-view-chip {
    font: inherit;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    border-radius: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.reports-card-view-chip:hover {
    background: var(--bg-card);
    border-color: var(--lg-active);
    color: var(--text-primary);
}

.reports-card-view-chip:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 1px;
}

/* ── Reports breadcrumb + card slot ─────────────────────────── */

.reports-breadcrumb {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.reports-breadcrumb-actions {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.reports-breadcrumb-back {
    color: var(--lg-active);
    text-decoration: none;
    font-weight: 500;
}

.reports-breadcrumb-back:hover,
.reports-breadcrumb-back:focus-visible {
    text-decoration: underline;
}

.reports-breadcrumb-current {
    color: var(--text-primary);
    font-weight: 500;
}

.reports-card-slot {
    height: 100%;
}

/* Productivity — picker, charts, tech list */
.productivity-controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.productivity-controls label { display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; color: var(--text-secondary); }
.productivity-controls select { padding: 0.3rem 0.5rem; border: 1px solid var(--border); background: var(--bg-input); color: var(--text-primary); border-radius: 4px; }
.prod-clear-btn {
    align-self: end; padding: 0.35rem 0.9rem;
    border: 1px solid var(--lg-heritage); background: var(--lg-heritage); color: #fff;
    border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
    letter-spacing: 0.02em;
}
.prod-clear-btn:hover { background: var(--lg-active); border-color: var(--lg-active); }
.prod-run-btn {
    align-self: end; padding: 0.35rem 1.1rem;
    border: 1px solid var(--green); background: var(--green); color: #fff;
    border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 700;
    letter-spacing: 0.02em;
    transition: filter 0.15s var(--ease);
}
.prod-run-btn:hover { filter: brightness(1.08); }
.prod-run-btn.is-dirty { box-shadow: 0 0 0 0 rgba(26, 135, 84, 0.6); animation: rtat-run-pulse 1.4s var(--ease) infinite; }

.productivity-content { padding: 1rem 0; }
.prod-loading, .prod-empty, .prod-error { padding: 24px; text-align: center; color: var(--text-secondary); }
.prod-error { color: var(--red); }

.prod-chart-wrap { position: relative; height: 420px; padding: 1rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 1rem; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06); display: flex; flex-direction: column; }
.prod-chart-wrap > canvas { flex: 1; min-height: 0; }
.prod-chart-toolbar { display: flex; justify-content: flex-end; align-items: center; margin-bottom: 0.5rem; }
.prod-toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-secondary); cursor: pointer; user-select: none; }
.prod-toggle input[type="checkbox"] { margin: 0; cursor: pointer; }

/* border-collapse must be `separate` for sticky <th> to work in all browsers
   (collapsed borders disable cell positioning). Keep border-spacing: 0 so
   the look is identical to collapsed. */
.prod-tech-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; }
.prod-tech-table th, .prod-tech-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
/* Sticky column headers — stays visible while user scrolls the table body. */
.prod-tech-table thead th { position: sticky; top: 0; background: var(--bg-card); z-index: 2; box-shadow: inset 0 -1px 0 var(--border); }
.prod-tech-table th:nth-child(n+4), .prod-tech-table td:nth-child(n+4) { text-align: center; font-variant-numeric: tabular-nums; }
.prod-tech-table th.prod-sortable { cursor: pointer; user-select: none; color: var(--text-secondary); font-weight: 600; }
.prod-tech-table th.prod-sortable:hover { color: var(--text-primary); }
.prod-row-header .prod-sortable { cursor: pointer; user-select: none; }
.prod-row-header .prod-sortable:hover { color: var(--text-primary); }
.prod-name-link { cursor: pointer; text-decoration: underline dotted transparent; text-underline-offset: 3px; }
.prod-name-link:hover { text-decoration-color: currentColor; color: var(--lg-heritage); }

/* Top 10 Cities: chevron column + city name = first two cols left-aligned;
   numeric columns from col 3 onward are centered. (Same column count as
   before — chevron replaced the dropped Phase column.) */
.prod-tech-table--top-cities th:nth-child(n+3),
.prod-tech-table--top-cities td:nth-child(n+3) { text-align: center; font-variant-numeric: tabular-nums; }
.prod-tech-table--top-cities td.prod-toggle-col,
.prod-tech-table--top-cities th.prod-toggle-col { width: 1.75rem; padding-right: 0; cursor: pointer; }
.prod-city-row { cursor: pointer; }
.prod-city-row:hover .prod-chevron { color: var(--lg-heritage); }
.prod-city-row.is-expanded { background: var(--surface-2); }
.prod-tech-table--nested { width: 100%; margin: 0.25rem 0 0.25rem 1rem; }
/* Timeseries (month/week/day): bucket label left, all numeric columns centered. */
.prod-tech-table--timeseries th:nth-child(n+2),
.prod-tech-table--timeseries td:nth-child(n+2) { text-align: center; font-variant-numeric: tabular-nums; }
/* Transposed timeseries: dates run across the top, metric labels down the
   left. Treat the leftmost column as a row header (left-aligned, semibold). */
.prod-tech-table--transposed .prod-ts-corner { text-align: left; }
.prod-tech-table--transposed .prod-ts-row-label {
    text-align: left;
    font-weight: 600;
    background: var(--surface-2);
    white-space: nowrap;
}
/* YoY month view: subtle border between each (prev | curr) month-pair. */
.prod-tech-table--timeseries th.prod-ts-pair-edge,
.prod-tech-table--timeseries td.prod-ts-pair-edge { border-left: 1px solid var(--border); }
/* YoY month view: tighter cell padding so 36 data columns fit comfortably. */
.prod-tech-table--yoy th,
.prod-tech-table--yoy td { padding: 0.25rem 0.4rem; font-size: 0.82rem; }
.prod-tech-table--yoy .prod-ts-row-label { padding-right: 0.6rem; }
/* Allow the table to scroll horizontally when there are many date columns
   (especially the day grain, which can have ~30 columns). */
#prod-ts-table { overflow-x: auto; }
/* Period-over-period trend arrow on the Productivity row. */
.prod-trend { font-size: 0.75em; line-height: 1; vertical-align: baseline; margin-left: 0.15em; }
.prod-trend-up   { color: #2e7d32; }   /* green */
.prod-trend-down { color: #c62828; }   /* red */

/* RNM detail expander on the Tech table */
.prod-rnm-toggle {
    cursor: pointer;
    color: var(--text-primary);
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

.prod-rnm-toggle:hover {
    color: var(--chart-blue);
}

.prod-rnm-toggle.is-expanded {
    color: var(--chart-blue);
    font-weight: 600;
    text-decoration: none;
}

td.prod-rnm-cell.is-expanded {
    background: var(--bg-hover);
}

tr.prod-rnm-detail > td {
    padding: 0;
    background: var(--bg-hover);
}

/* Clickable cell that opens the comment modal — kept color-neutral so the
 * tier class (kpi-tier-green / kpi-tier-red) drives the text color. */
.kpi-comment-link {
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

.kpi-comment-link:hover {
    text-decoration-color: currentColor;
    text-decoration-thickness: 2px;
}

/* NPS comment modal — list of detractor follow-up verbatims (No IN 4,7,10) */
.nps-comment-body {
    max-height: 50vh;
    overflow-y: auto;
    margin: 0 0 12px;
    font-size: 14px;
    color: var(--text-primary);
}

.nps-comment-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

.nps-comment-item:last-child {
    border-bottom: none;
}

.nps-comment-q {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.nps-comment-text {
    white-space: pre-wrap;
    line-height: 1.5;
}

.prod-rnm-slot {
    padding: 12px 16px;
    color: var(--text-secondary);
    font-size: 13px;
}

.prod-rnm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    background: var(--bg-card);
}

.prod-rnm-table th,
.prod-rnm-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

/* The RNM detail table is rendered inside an expanded row of .prod-tech-table,
   so the parent's `td:nth-child(n+4) { text-align: center }` rule (line ~3688)
   leaks in via the descendant combinator and centers Product/Repair Code/etc.
   This selector raises specificity to override the parent rule. */
.prod-tech-table .prod-rnm-table th,
.prod-tech-table .prod-rnm-table td {
    text-align: left;
}

.prod-rnm-table th {
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-hover);
}

/* Top-10-Cities RNM detail uses prod-tech-table--nested (not prod-rnm-table)
   so the n+4 center-align rule still applies. Model (col 4) and Product
   (col 5) are long text strings — left-align them so they don't read ragged. */
.prod-rnm-detail .prod-tech-table--nested th:nth-child(4),
.prod-rnm-detail .prod-tech-table--nested td:nth-child(4),
.prod-rnm-detail .prod-tech-table--nested th:nth-child(5),
.prod-rnm-detail .prod-tech-table--nested td:nth-child(5) {
    text-align: left;
}
/* RTAT (col 3) is a single integer — center it like the other numeric cols. */
.prod-rnm-detail .prod-tech-table--nested th:nth-child(3),
.prod-rnm-detail .prod-tech-table--nested td:nth-child(3) {
    text-align: center;
}

.prod-rnm-notice {
    padding: 8px 12px;
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
}

/* Productivity state map — choropleth above the State / Market tree on
   the General Market breakdown. */
.prod-map { width: 100%; max-width: 720px; margin: 0.5rem auto 1rem; }
.prod-map svg { display: block; width: 100%; height: auto; }
.prod-map svg path { stroke: var(--bg-card); stroke-width: 0.6; transition: filter 0.1s ease; cursor: default; }
.prod-map svg path[data-tier]      { fill: var(--text-secondary); }  /* default before paint */
.prod-map svg path[data-tier="green"]   { fill: var(--green); }
.prod-map svg path[data-tier="yellow"]  { fill: var(--amber); }
.prod-map svg path[data-tier="red"]     { fill: var(--red); }
.prod-map svg path[data-tier="neutral"] { fill: var(--border); }
.prod-map svg path[data-tier="none"]    { fill: var(--border); }     /* state not in response */
.prod-map svg path[data-clickable="true"] { cursor: pointer; }
.prod-map svg path[data-clickable="true"]:hover { filter: brightness(1.15); }

/* Floating tooltip rendered as a sibling div, positioned via JS. */
.prod-map-tooltip {
    position: absolute; z-index: 5; pointer-events: none;
    background: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 0.4rem 0.6rem; font-size: 0.82rem; line-height: 1.35;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    white-space: nowrap;
}
.prod-map-tooltip-title { font-weight: 600; margin-bottom: 0.1rem; }
.prod-map-tooltip-row   { color: var(--text-secondary); }

/* Legend strip below the map. */
.prod-map-legend { display: flex; justify-content: center; gap: 0.75rem; margin-top: -0.25rem; margin-bottom: 1rem; font-size: 0.82rem; color: var(--text-secondary); }
.prod-map-legend-swatch { display: inline-block; width: 0.85rem; height: 0.85rem; border-radius: 2px; vertical-align: middle; margin-right: 0.25rem; }
.prod-map-error { color: var(--text-secondary); font-size: 0.85rem; text-align: center; padding: 1.5rem 0; margin: 0; }

/* RTAT card */
.rtat-shell { display: flex; flex-direction: column; height: 100%; gap: 12px; color: var(--text-primary); }
.rtat-header { display: flex; justify-content: flex-start; align-items: center; gap: 16px; flex-wrap: wrap; }
.rtat-controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.rtat-clear-btn {
    align-self: end; padding: 0.35rem 0.9rem;
    border: 1px solid var(--lg-heritage); background: var(--lg-heritage); color: #fff;
    border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
    letter-spacing: 0.02em;
}
.rtat-clear-btn:hover { background: var(--lg-active); border-color: var(--lg-active); }
.rtat-run-btn {
    align-self: end; padding: 0.35rem 1.1rem;
    border: 1px solid var(--green); background: var(--green); color: #fff;
    border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 700;
    letter-spacing: 0.02em;
    transition: filter 0.15s var(--ease);
}
.rtat-run-btn:hover { filter: brightness(1.08); }
/* Pulses when filters are dirty (changed since last Run). */
.rtat-run-btn.is-dirty { box-shadow: 0 0 0 0 rgba(26, 135, 84, 0.6); animation: rtat-run-pulse 1.4s var(--ease) infinite; }
@keyframes rtat-run-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(26, 135, 84, 0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(26, 135, 84, 0); }
    100% { box-shadow: 0 0 0 0   rgba(26, 135, 84, 0); }
}
.rtat-control { display: flex; flex-direction: column; gap: 2px; font-size: 0.85em; color: var(--text-secondary); }
.rtat-control input, .rtat-control select { padding: 4px 6px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text-primary); border-radius: 4px; font: inherit; }
.rtat-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.rtat-summary-pill { padding: 4px 10px; border-radius: 12px; background: var(--bg-card); border: 1px solid var(--border); font-size: 0.9em; color: var(--text-primary); }
.rtat-kpi {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    flex: 1 1 0;
    text-align: center;
}
.rtat-kpi-label { font-size: 11px; text-transform: uppercase; color: var(--text-secondary); }
.rtat-kpi-value { font-size: 18px; font-weight: 600; color: var(--text-primary); }
.rtat-empty { padding: 24px; text-align: center; color: var(--text-secondary); }
.rtat-body { overflow: auto; color: var(--text-primary); }

.rtat-tree {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.rtat-row {
    display: grid;
    grid-template-columns: 24px minmax(180px, 2fr) minmax(60px, 1fr) minmax(60px, 1fr) minmax(60px, 1fr) minmax(80px, 1fr) minmax(80px, 1fr);
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}
.rtat-row-bucket { text-align: right; font-variant-numeric: tabular-nums; }
.rtat-row-volume, .rtat-row-rate { text-align: right; font-variant-numeric: tabular-nums; }
.rtat-row-header {
    background: var(--bg-hover);
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 2;
}
.rtat-row-rsm { background: var(--bg-hover); font-weight: 600; }
.rtat-row-asm { padding-left: 32px; background: var(--bg-chat); }
.rtat-row-toggle {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; font: inherit; padding: 2px 6px;
}

/* Freeze the row-label (name) column so it stays visible during horizontal
   scroll. Each row-type override sets the matching background so the sticky
   cell can occlude what scrolls past behind it. */
.rtat-row > :nth-child(2) {
    position: sticky;
    left: 0;
    z-index: 1;
}
.rtat-row-header > :nth-child(2) {
    background: var(--bg-hover);
    z-index: 3;
}
.rtat-row-rsm > :nth-child(2) { background: var(--bg-hover); }
.rtat-row-asm > :nth-child(2) { background: var(--bg-chat); }

/* Tier coloring on the rate cell. */
.rtat-tier-green   { color: var(--green); }
.rtat-tier-yellow  { color: var(--amber); }
.rtat-tier-red     { color: var(--red); }
.rtat-tier-neutral { color: var(--text-secondary); }

.rtat-ts-table { width: 100%; border-collapse: separate; border-spacing: 0; margin-bottom: 16px; color: var(--text-primary); }
.rtat-ts-table th, .rtat-ts-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.rtat-ts-table th { font-weight: 600; background: var(--bg-card); position: sticky; top: 0; color: var(--text-primary); }

/* Frozen first column on metric/KPI tables — keeps row labels visible during
   horizontal scroll. Strategic 3D handles its own sticky cols separately.
   Direct-child selectors prevent nested .prod-rnm-table from inheriting.
   `:first-child` (no element name) matches both <td> and <th> — transposed
   views use <th class="prod-ts-row-label"> as their row label. */
.prod-tech-table > thead > tr:first-child > :first-child,
.prod-tech-table > tbody > tr > :first-child,
.rtat-ts-table > thead > tr:first-child > :first-child,
.rtat-ts-table > tbody > tr > :first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--bg-card);
}
/* Header's first cell sits at the intersection — needs to clear both axes. */
.prod-tech-table > thead > tr:first-child > :first-child,
.rtat-ts-table > thead > tr:first-child > :first-child { z-index: 3; }
/* Expanded RNM-detail row spans the full width via colspan; sticking the only
   cell to left:0 would yank its contents to the left edge. Keep it static. */
.prod-tech-table > tbody > tr.prod-rnm-detail > td:first-child {
    position: static;
    background: var(--bg-hover);
}
/* Expanded city row has a tinted background; the sticky first-cell needs to
   match so it doesn't look "lighter" than the rest of the row. */
.prod-tech-table > tbody > tr.prod-city-row.is-expanded > td:first-child {
    background: var(--surface-2);
}
/* Top 10 Cities: col 1 is the chevron toggle; col 2 is the city name. Freeze
   both so the row label stays visible. */
.prod-tech-table--top-cities > thead > tr > th:nth-child(2),
.prod-tech-table--top-cities > tbody > tr > td:nth-child(2) {
    position: sticky;
    left: 1.75rem;
    z-index: 1;
    background: var(--bg-card);
}
.prod-tech-table--top-cities > thead > tr > th:nth-child(2) { z-index: 3; }
.prod-tech-table--top-cities > tbody > tr.prod-city-row.is-expanded > td:nth-child(2) {
    background: var(--surface-2);
}
/* Transposed timeseries labels keep their tinted surface (preserve the
   existing .prod-ts-row-label look after the sticky-bg override above).
   Row label can be <th> or <td>, so match by class only. */
.prod-tech-table--transposed > tbody > tr > .prod-ts-row-label {
    background: var(--surface-2);
}

.rtat-chart-wrap { position: relative; height: 420px; padding: 1rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 1rem; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06); display: flex; flex-direction: column; }
.rtat-chart-wrap > canvas { flex: 1; min-height: 0; }
.rtat-chart-toolbar { display: flex; justify-content: flex-end; align-items: center; margin-bottom: 0.5rem; }
.rtat-toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-secondary); cursor: pointer; user-select: none; }
.rtat-toggle input[type="checkbox"] { margin: 0; cursor: pointer; }

/* Reusable checkbox-dropdown (used by RTAT + Productivity for Channel / SKS /
   RSM / ASM / Tech). See web/static/js/multi-dropdown.js. */
.multi-dropdown { position: relative; display: inline-block; min-width: 180px; }
.multi-dropdown-btn {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    width: 100%; min-width: 180px; padding: 4px 8px;
    border: 1px solid var(--border); border-radius: 4px;
    background: var(--bg-input); color: var(--text-primary);
    font: inherit; font-size: 0.85em; cursor: pointer; text-align: left;
}
.multi-dropdown-btn:hover { border-color: var(--text-secondary); }
.multi-dropdown[data-open="true"] .multi-dropdown-btn {
    outline: 2px solid var(--lg-active); outline-offset: -1px;
}
.multi-dropdown-label {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.multi-dropdown-label.is-placeholder { color: var(--text-secondary); }
.multi-dropdown-caret { font-size: 0.7em; color: var(--text-secondary); }
.multi-dropdown-panel {
    position: absolute; top: calc(100% + 2px); left: 0; z-index: 50;
    min-width: 100%; max-height: 240px; overflow-y: auto;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    padding: 4px 0;
}
/* Higher specificity than `.productivity-controls label` and `.rtat-controls label`
   so the row stays a horizontal flex container rather than inheriting the
   parent's `flex-direction: column`. */
.multi-dropdown-panel .multi-dropdown-row,
label.multi-dropdown-row {
    display: flex; flex-direction: row; align-items: center; gap: 8px;
    padding: 5px 10px; margin: 0; cursor: pointer; font-size: 0.85em; color: var(--text-primary);
    user-select: none;
}
.multi-dropdown-panel .multi-dropdown-row:hover,
label.multi-dropdown-row:hover { background: var(--bg-hover); }
.multi-dropdown-panel .multi-dropdown-row input[type="checkbox"],
label.multi-dropdown-row input[type="checkbox"] {
    margin: 0; cursor: pointer; flex: 0 0 auto;
}
.multi-dropdown-empty { padding: 8px 10px; color: var(--text-secondary); font-size: 0.85em; }

/* ---- Strategic 3D pivot table ---- */
.rtat-3d-toolbar {
    display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 12px;
}
.rtat-3d-toolbar .rtat-3d-grain { margin-bottom: 0; }
.rtat-3d-range-label {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.85rem; color: var(--text-secondary);
}
.rtat-3d-range-label input[type="date"] {
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 4px 6px; font: inherit; font-size: 0.85rem;
}
.rtat-3d-range-reset {
    background: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 4px 10px; font: inherit; font-size: 0.85rem; cursor: pointer;
}
.rtat-3d-range-reset:hover { background: var(--bg-hover); }
.rtat-3d-grain,
.rtat-layout-toggle { display: inline-flex; gap: 0; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.rtat-layout-toggle { margin-top: 16px; }
.rtat-3d-grain-btn,
.rtat-layout-toggle-btn {
    background: var(--bg-card); border: none; border-right: 1px solid var(--border);
    color: var(--text-primary); font: inherit; font-size: 0.85rem;
    padding: 6px 14px; cursor: pointer;
}
.rtat-3d-grain-btn:last-child,
.rtat-layout-toggle-btn:last-child { border-right: none; }
.rtat-3d-grain-btn:hover,
.rtat-layout-toggle-btn:hover { background: var(--bg-hover); }
.rtat-3d-grain-btn.is-active,
.rtat-layout-toggle-btn.is-active { background: var(--lg-active); color: white; }
.rtat-3d-content { color: var(--text-primary); overflow-x: auto; max-height: calc(100vh - 280px); border: 1px solid var(--border); border-radius: 6px; background: var(--bg-card); }
.rtat-3d-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 0.82rem; }
.rtat-3d-table th, .rtat-3d-table td {
    padding: 4px 8px; text-align: center; border-bottom: 1px solid var(--border); white-space: nowrap;
    color: var(--text-primary);
}
.rtat-3d-table thead th {
    position: sticky; z-index: 3;
    background: var(--bg-card); font-weight: 600; text-align: center; border-bottom: 2px solid var(--border);
}
/* Year-header row (and single-row grains) stick at the top */
.rtat-3d-table thead .rtat-3d-year-header { top: 0; height: 32px; line-height: 18px; }
.rtat-3d-table thead .rtat-3d-period-col  { top: 0; height: 32px; line-height: 18px; }
.rtat-3d-table thead .rtat-3d-ytd-col     { top: 0; }
/* Month-sub row sits below the year-header row at exactly 32px */
.rtat-3d-table thead .rtat-3d-month-sub   { top: 32px; height: 26px; line-height: 16px; }
.rtat-3d-row-num {
    position: sticky; left: 0; z-index: 2;
    background: var(--bg-card); text-align: right; font-weight: 600;
    color: var(--text-secondary); white-space: nowrap;
    width: 36px; min-width: 36px; padding: 0 8px;
    border-right: 1px solid var(--border);
}
.rtat-3d-table thead .rtat-3d-row-num { top: 0; z-index: 5; text-align: center; }
.rtat-3d-row-label {
    position: sticky; left: 36px; z-index: 2;
    background: var(--bg-card); text-align: left; font-weight: 600;
    white-space: nowrap; border-right: 1px solid var(--border);
}
.rtat-3d-table thead .rtat-3d-row-label { top: 0; z-index: 5; }
.rtat-3d-metric-label {
    position: sticky; left: calc(36px + var(--rtat-3d-row-label-w, 130px)); z-index: 2;
    background: var(--bg-card); text-align: left; font-weight: 500;
    white-space: nowrap; border-right: 1px solid var(--border);
    color: var(--text-secondary);
}
.rtat-3d-table thead .rtat-3d-metric-label { top: 0; z-index: 5; }
.rtat-3d-period-col, .rtat-3d-ytd-col { min-width: 64px; }
.rtat-3d-ytd-col { background: var(--bg-elevated); font-weight: 600; border-left: 1px solid var(--border); }
.rtat-3d-table th.rtat-3d-band, .rtat-3d-table td.rtat-3d-band { background-color: var(--bg-hover); }
.rtat-3d-table tr.rtat-3d-pop td { background-color: #FFF3CD; font-weight: 600; }
[data-theme="dark"] .rtat-3d-table tr.rtat-3d-pop td { background-color: #3D3621; }

.rtat-3d-city-link {
    color: #1E40AF;
    cursor: pointer;
    text-decoration: none;
    border-radius: 2px;
}
.rtat-3d-city-link:hover,
.rtat-3d-city-link:focus {
    color: #1E3A8A;
    text-decoration: underline;
    outline: none;
}
.rtat-3d-city-link:focus-visible {
    outline: 2px solid #2563EB;
    outline-offset: 2px;
}

tr.rtat-3d-totals td {
    background: var(--bg-hover); font-weight: 600;
}
tr.rtat-3d-grand td {
    background: var(--bg-hover); font-weight: 700;
    border-top: 2px solid var(--border);
}
tr.rtat-3d-grand td.rtat-3d-row-label,
tr.rtat-3d-grand td.rtat-3d-row-num {
    background: var(--bg-hover);
}

/* FOCUS toolbar button (pill style, matches .rtat-3d-grain-btn) */
.rtat-3d-focus {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
}
.rtat-3d-focus-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.rtat-3d-focus-toggle:hover {
    color: var(--lg-active);
    border-color: var(--lg-active);
}
.rtat-3d-focus-toggle.has-focus {
    background: var(--lg-active);
    border-color: var(--lg-active);
    color: white;
}
.rtat-3d-focus-toggle:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 1px;
}
.rtat-3d-focus-toggle .rtat-3d-focus-chev {
    font-size: 10px;
    line-height: 1;
}
/* FOCUS popout — extends to the right of the toggle button */
.rtat-3d-focus-popout {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    margin-left: 2px;
}
.rtat-3d-focus-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.rtat-3d-focus-chip:hover {
    border-color: var(--lg-active);
    color: var(--lg-active);
}
.rtat-3d-focus-chip.is-active {
    background: var(--lg-active);
    border-color: var(--lg-active);
    color: white;
}
.rtat-3d-focus-chip:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 1px;
}

.rtat-3d-rollup-controls {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.rtat-3d-rollup-btn {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.rtat-3d-rollup-btn:hover {
    border-color: var(--lg-active);
    color: var(--lg-active);
}
.rtat-3d-rollup-btn:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 1px;
}

.rtat-3d-table .rtat-3d-good { color: var(--green); }
.rtat-3d-table .rtat-3d-warn { color: #8B6914; font-weight: 700; }
.rtat-3d-table .rtat-3d-bad  { color: #991B1B; font-weight: 700; }
[data-theme="dark"] .rtat-3d-table .rtat-3d-warn { color: var(--amber); }
[data-theme="dark"] .rtat-3d-table .rtat-3d-bad  { color: var(--red); }

.rtat-control.is-hidden {
    display: none !important;
}

.rtat-3d-year-header {
    cursor: pointer;
    user-select: none;
    text-align: center;
    background: var(--bg-card);
    border-bottom: 2px solid var(--border);
    padding: 6px 10px;
}

.rtat-3d-year-header.is-current {
    background: var(--lg-heritage);
    color: #fff;
}

.rtat-3d-chev {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.85em;
    opacity: 0.8;
}
.rtat-3d-rollup-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    margin-right: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    font-size: 11px;
}
.rtat-3d-rollup-chevron:hover {
    color: var(--lg-active);
}
.rtat-3d-rollup-chevron:focus-visible {
    color: var(--lg-active);
    outline: 2px solid var(--lg-active);
    outline-offset: 1px;
    border-radius: 2px;
}

/* Per-row channel chevron on RTAT / NPS / FRFT% metric rows. */
.rtat-3d-chan-chev {
    display: inline-block;
    width: 12px;
    margin-right: 4px;
    color: var(--text-muted, #475569);
    cursor: pointer;
    user-select: none;
    font-weight: 700;
}
.rtat-3d-chan-chev:hover { color: var(--text-primary, #0f172a); }
.rtat-3d-chan-chev:focus { outline: 2px solid var(--accent, #A50034); outline-offset: 1px; }

/* Channel sub-rows (DMS / DMS2 / ASD) beneath an expanded KPI row. */
tr.rtat-3d-chan-sub td { background: var(--surface-alt, #f8fafc); font-size: 11px; }
tr.rtat-3d-chan-sub td.rtat-3d-chan-label {
    padding-left: 28px;
    color: var(--text-muted, #475569);
    font-weight: 400;
}
[data-theme="dark"] tr.rtat-3d-chan-sub td { background: #1e2a3a; }

.rtat-3d-month-sub {
    font-weight: normal;
    font-size: 0.85em;
    text-align: center;
}

/* =========================================================================
   View docs library — info icon + slide-in drawer
   ========================================================================= */

.docs-info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.9rem;
    background: #DBEAFE;             /* Tailwind blue-100 — readable on parchment */
    border: 1px solid #93C5FD;       /* blue-300 */
    border-radius: 4px;
    color: #1E40AF;                  /* blue-800 — strong contrast */
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    transition: color 150ms var(--ease), border-color 150ms var(--ease), background 150ms var(--ease);
    vertical-align: middle;
}
.docs-info-btn:hover,
.docs-info-btn:focus-visible {
    background: #BFDBFE;             /* blue-200 — darker on hover */
    border-color: #2563EB;           /* blue-600 */
    color: #1E3A8A;                  /* blue-900 */
    outline: none;
}

.docs-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms var(--ease);
    z-index: 1000;
}
.docs-drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

.docs-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 40vw;
    min-width: 360px;
    max-width: 720px;
    background: var(--bg-card);
    color: var(--text-primary);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
    transform: translateX(100%);
    transition: transform 250ms var(--ease);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.docs-drawer.is-open {
    transform: translateX(0);
}

.docs-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}
.docs-drawer-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}
.docs-drawer-close {
    background: transparent;
    border: 0;
    color: var(--text-secondary);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
}
.docs-drawer-close:hover,
.docs-drawer-close:focus-visible {
    color: var(--text-primary);
    outline: none;
}

.docs-drawer-meta {
    padding: 8px 20px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.docs-drawer-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px 20px 32px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.docs-drawer-body h1,
.docs-drawer-body h2,
.docs-drawer-body h3 {
    margin-top: 1.2em;
    margin-bottom: 0.4em;
    font-weight: 600;
}
.docs-drawer-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.6em 0 1em;
    font-size: 0.85rem;
}
.docs-drawer-body th,
.docs-drawer-body td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
}
.docs-drawer-body th {
    background: var(--bg-hover);
    font-weight: 600;
}
.docs-drawer-body code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.82rem;
    background: var(--bg-hover);
    padding: 1px 4px;
    border-radius: 3px;
}
.docs-drawer-body pre {
    background: var(--bg-hover);
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.6em 0 1em;
}
.docs-drawer-body pre code {
    background: transparent;
    padding: 0;
    font-size: 0.8rem;
}
.docs-drawer-body ul {
    padding-left: 20px;
    margin: 0.4em 0 1em;
}

/* ── Reports — favorites section + mini-cards ───────────────── */

.reports-section {
    padding: 0 0.25rem;
}

.reports-section + .reports-section {
    margin-top: 0.6rem;
}

.reports-section-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    font-weight: 600;
    margin: 0 1rem 0.4rem 1rem;
}

.reports-favorites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
    padding: 0 1.25rem;
}

.reports-fav-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    min-height: 44px;
    color: inherit;
    font: inherit;
    transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}

.reports-fav-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    border-color: var(--border);
}

.reports-fav-card:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 2px;
}

.reports-fav-icon {
    color: var(--lg-heritage);
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.reports-fav-icon svg {
    width: 16px;
    height: 16px;
}

.reports-fav-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.reports-fav-crumb {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    line-height: 1.1;
}

.reports-fav-label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.reports-fav-star {
    background: none;
    border: none;
    color: var(--lg-heritage);
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.15rem 0.25rem;
    flex-shrink: 0;
}

.reports-fav-star:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 1px;
    border-radius: 4px;
}

/* Per-view star toggle (rendered next to the (i) docs icon) */

.reports-fav-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.35rem 0.9rem;
    font-size: 0.85rem;
    line-height: 1;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.reports-fav-toggle:hover {
    color: var(--lg-heritage);
    border-color: var(--lg-heritage);
}

.reports-fav-toggle:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 2px;
}

.reports-fav-toggle[aria-pressed="true"] {
    color: var(--lg-heritage);
    border-color: var(--lg-heritage);
}

/* Export menu widget */
.export-menu { position: relative; display: inline-block; }
.export-menu-btn {
    background: #1F2937;             /* slate-800 — strong neutral contrast on parchment */
    color: #FFFFFF;
    border: 1px solid #111827;       /* slate-900 */
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
    line-height: 1.4;
    font-weight: 500;
}
.export-menu-btn:hover:not(:disabled) { background: #111827; }
.export-menu-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.export-menu-caret { margin-left: 2px; font-size: 11px; }
.export-menu-pop {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--surface-1, #fff);
    border: 1px solid var(--border-1, #ddd);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    min-width: 100px;
    z-index: 50;
    overflow: hidden;
}
.export-menu-item {
    display: block;
    width: 100%;
    background: transparent;
    border: 0;
    text-align: left;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary, #222);
}
.export-menu-item:hover { background: var(--surface-3, #f0f0f0); }

/* ── MultiDropdown: Select all / Clear all header ── */
.multi-dropdown-header {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.8rem;
}
.multi-dropdown-link {
    color: var(--lg-heritage);
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
}
.multi-dropdown-link:hover {
    text-decoration: underline;
}
.multi-dropdown-sep {
    color: var(--text-muted);
}

/* ── Strategic 3D: tier totals, notice, KPI/showall labels ── */
.rtat-3d-tier-total td {
    background: var(--surface-2, var(--bg-elevated));
    font-weight: 600;
}
tr.rtat-3d-tier-total td.rtat-3d-row-label,
tr.rtat-3d-tier-total td.rtat-3d-row-num {
    background: var(--surface-2, var(--bg-elevated));
}
.rtat-3d-notice {
    margin: 0.5rem 0;
    padding: 0.5rem 0.75rem;
    background: var(--bg-elevated);
    border-left: 3px solid var(--lg-heritage);
    font-size: 0.85rem;
}
.rtat-3d-kpi-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
}
.rtat-3d-showall-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
}

/* ============================================================
   Audit Mode
   ============================================================ */

/* Toggle button (in breadcrumb header — matches Info/Favorites size; purple
   admin-tool palette so it doesn't collide with Export/Info/Favorites colors).
   No margin — parent .reports-breadcrumb-actions uses `gap: 0.4rem`. */
.breadcrumb-btn.audit-btn {
    background: #EDE9FE;             /* violet-100 */
    border: 1px solid #C4B5FD;       /* violet-300 */
    color: #6D28D9;                  /* violet-700 */
    padding: 0.35rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
    transition: color 150ms var(--ease), border-color 150ms var(--ease), background 150ms var(--ease);
    vertical-align: middle;
}
.breadcrumb-btn.audit-btn:hover,
.breadcrumb-btn.audit-btn:focus-visible {
    background: #DDD6FE;             /* violet-200 */
    border-color: #7C3AED;           /* violet-600 */
    color: #5B21B6;                  /* violet-800 */
    outline: none;
}
.breadcrumb-btn.audit-btn.audit-on {
    background: #6D28D9;             /* violet-700 — solid when on */
    color: #FFFFFF;
    border-color: #5B21B6;           /* violet-800 */
}
.breadcrumb-btn.audit-btn.audit-on:hover {
    background: #5B21B6;             /* violet-800 */
    border-color: #5B21B6;
    color: #FFFFFF;
}
.audit-glyph { font-size: 14px; }

/* Numeric cell hover state when audit mode is on */
.audit-on td.audit-cell {
    cursor: help;
}
.audit-on td.audit-cell:hover {
    outline: 1px dashed var(--lg-heritage);
    outline-offset: -1px;
    background: rgba(165, 0, 52, 0.06);
}

/* Overlay + modal */
.audit-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    animation: audit-fade-in 120ms ease-out;
}
.audit-modal {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 8px;
    width: min(720px, 92vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    animation: audit-scale-in 120ms ease-out;
}
@keyframes audit-fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes audit-scale-in  { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.audit-modal-header {
    padding: 14px 18px 10px;
    border-bottom: 1px solid var(--border);
}
.audit-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}
.audit-title {
    font-size: 15px;
    font-weight: 600;
    margin: 4px 0 2px;
    color: var(--text-primary);
}
.audit-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}
.audit-close {
    background: transparent;
    border: 0;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
}
.audit-close:hover { color: var(--text-primary); }

.audit-breadcrumb {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.audit-breadcrumb-seg {
    color: var(--lg-heritage);
    text-decoration: none;
}
.audit-breadcrumb-seg.current { color: var(--text-primary); font-weight: 500; cursor: default; }
.audit-breadcrumb-seg:hover:not(.current) { text-decoration: underline; }
.audit-breadcrumb-sep { color: var(--text-muted); }

.audit-modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    background: var(--bg-card);
}
.audit-step-title {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 12px;
    color: var(--text-primary);
}
.audit-body-md { font-size: 13px; line-height: 1.55; color: var(--text-primary); }
.audit-body-md code, .audit-formula code {
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: var(--text-primary);
}

.audit-filters, .audit-inputs, .audit-contributors {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
}
.audit-filters th, .audit-filters td,
.audit-inputs td,
.audit-contributors th, .audit-contributors td {
    border-bottom: 1px solid var(--border-light);
    padding: 6px 8px;
    text-align: left;
    color: var(--text-primary);
}
.audit-contributors th, .audit-filters th { font-weight: 600; font-size: 12px; color: var(--text-muted); }
.audit-contributors td.num, .audit-inputs td:nth-child(2) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.audit-contributors tr.audit-clickable { cursor: pointer; }
.audit-contributors tr.audit-clickable:hover { background: var(--bg-hover); }
.audit-matched-rows {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}
.audit-substep {
    margin: 10px 0;
    padding: 8px 12px;
    border-left: 3px solid var(--lg-heritage);
    background: var(--bg-elevated);
    font-size: 12px;
    color: var(--text-primary);
}
.audit-substep h4 { font-size: 12px; font-weight: 600; margin: 0 0 4px; color: var(--text-primary); }
.audit-formula {
    margin: 12px 0;
    padding: 10px 12px;
    background: var(--bg-hover);
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    text-align: center;
    color: var(--text-primary);
}

.audit-computation {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 14px;
    text-align: center;
    margin: 10px 0 4px;
    color: var(--text-primary);
}
.audit-result-value {
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    margin: 4px 0 6px;
    color: var(--lg-heritage);
}
.audit-vs-target {
    text-align: center;
    font-size: 12px;
    display: block;
    margin: 4px auto;
    width: max-content;
    padding: 2px 10px;
    border-radius: 999px;
}
.audit-vs-target.on  { background: var(--green-bg); color: var(--green); }
.audit-vs-target.off { background: var(--red-bg);   color: var(--red); }
.audit-vs-target.neutral { background: var(--surface-2); color: var(--text-muted); }

.audit-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 18px;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
}
.audit-back, .audit-next {
    background: var(--lg-heritage);
    color: var(--text-inverse);
    border: 0;
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
}
.audit-back:hover:not(:disabled), .audit-next:hover { background: var(--lg-active); }
.audit-back:disabled { background: var(--surface-2); color: var(--text-muted); cursor: default; }
.audit-step-counter { font-size: 12px; color: var(--text-muted); }
.audit-dots { letter-spacing: 2px; margin-left: 6px; color: var(--lg-heritage); }

.audit-loading, .audit-error { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.audit-error { color: var(--red); }

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

/* =========================================================================
   View docs library — info icon + slide-in drawer
   ========================================================================= */

.docs-info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.9rem;
    background: #DBEAFE;             /* Tailwind blue-100 — readable on parchment */
    border: 1px solid #93C5FD;       /* blue-300 */
    border-radius: 4px;
    color: #1E40AF;                  /* blue-800 — strong contrast */
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    transition: color 150ms var(--ease), border-color 150ms var(--ease), background 150ms var(--ease);
    vertical-align: middle;
}
.docs-info-btn:hover,
.docs-info-btn:focus-visible {
    background: #BFDBFE;             /* blue-200 — darker on hover */
    border-color: #2563EB;           /* blue-600 */
    color: #1E3A8A;                  /* blue-900 */
    outline: none;
}

.docs-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms var(--ease);
    z-index: 1000;
}
.docs-drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

.docs-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 40vw;
    min-width: 360px;
    max-width: 720px;
    background: var(--bg-card);
    color: var(--text-primary);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
    transform: translateX(100%);
    transition: transform 250ms var(--ease);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.docs-drawer.is-open {
    transform: translateX(0);
}

.docs-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}
.docs-drawer-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}
.docs-drawer-close {
    background: transparent;
    border: 0;
    color: var(--text-secondary);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
}
.docs-drawer-close:hover,
.docs-drawer-close:focus-visible {
    color: var(--text-primary);
    outline: none;
}

.docs-drawer-meta {
    padding: 8px 20px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.docs-drawer-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px 20px 32px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.docs-drawer-body h1,
.docs-drawer-body h2,
.docs-drawer-body h3 {
    margin-top: 1.2em;
    margin-bottom: 0.4em;
    font-weight: 600;
}
.docs-drawer-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.6em 0 1em;
    font-size: 0.85rem;
}
.docs-drawer-body th,
.docs-drawer-body td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
}
.docs-drawer-body th {
    background: var(--bg-hover);
    font-weight: 600;
}
.docs-drawer-body code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.82rem;
    background: var(--bg-hover);
    padding: 1px 4px;
    border-radius: 3px;
}
.docs-drawer-body pre {
    background: var(--bg-hover);
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.6em 0 1em;
}
.docs-drawer-body pre code {
    background: transparent;
    padding: 0;
    font-size: 0.8rem;
}
.docs-drawer-body ul {
    padding-left: 20px;
    margin: 0.4em 0 1em;
}

/* ── Reports — favorites section + mini-cards ───────────────── */

.reports-section {
    padding: 0 0.25rem;
}

.reports-section + .reports-section {
    margin-top: 0.6rem;
}

.reports-section-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    font-weight: 600;
    margin: 0 1rem 0.4rem 1rem;
}

.reports-favorites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
    padding: 0 1.25rem;
}

.reports-fav-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    min-height: 44px;
    color: inherit;
    font: inherit;
    transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}

.reports-fav-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    border-color: var(--border);
}

.reports-fav-card:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 2px;
}

.reports-fav-icon {
    color: var(--lg-heritage);
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.reports-fav-icon svg {
    width: 16px;
    height: 16px;
}

.reports-fav-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.reports-fav-crumb {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    line-height: 1.1;
}

.reports-fav-label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.reports-fav-star {
    background: none;
    border: none;
    color: var(--lg-heritage);
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.15rem 0.25rem;
    flex-shrink: 0;
}

.reports-fav-star:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 1px;
    border-radius: 4px;
}

/* Per-view star toggle (rendered next to the (i) docs icon) */

.reports-fav-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.35rem 0.9rem;
    font-size: 0.85rem;
    line-height: 1;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.reports-fav-toggle:hover {
    color: var(--lg-heritage);
    border-color: var(--lg-heritage);
}

.reports-fav-toggle:focus-visible {
    outline: 2px solid var(--lg-active);
    outline-offset: 2px;
}

.reports-fav-toggle[aria-pressed="true"] {
    color: var(--lg-heritage);
    border-color: var(--lg-heritage);
}

/* Export menu widget */
.export-menu { position: relative; display: inline-block; }
.export-menu-btn {
    background: #1F2937;             /* slate-800 — strong neutral contrast on parchment */
    color: #FFFFFF;
    border: 1px solid #111827;       /* slate-900 */
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
    line-height: 1.4;
    font-weight: 500;
}
.export-menu-btn:hover:not(:disabled) { background: #111827; }
.export-menu-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.export-menu-caret { margin-left: 2px; font-size: 11px; }
.export-menu-pop {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--surface-1, #fff);
    border: 1px solid var(--border-1, #ddd);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    min-width: 100px;
    z-index: 50;
    overflow: hidden;
}
.export-menu-item {
    display: block;
    width: 100%;
    background: transparent;
    border: 0;
    text-align: left;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary, #222);
}
.export-menu-item:hover { background: var(--surface-3, #f0f0f0); }

/* ── MultiDropdown: Select all / Clear all header ── */
.multi-dropdown-header {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.8rem;
}
.multi-dropdown-link {
    color: var(--lg-heritage);
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
}
.multi-dropdown-link:hover {
    text-decoration: underline;
}
.multi-dropdown-sep {
    color: var(--text-muted);
}

/* ============================================================
   KPI MODULE FRAMEWORK — shared styles for all manifest-driven
   KPI modules. Replaces per-module .frft-*/.rtat-* clones for
   modules built on web/static/js/kpi/.
   ============================================================ */
.kpi-shell { display: flex; flex-direction: column; height: 100%; gap: 12px; color: var(--text-primary); }
.kpi-shell-header { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.kpi-header { display: flex; justify-content: flex-start; align-items: center; gap: 16px; flex-wrap: wrap; }
.kpi-controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.kpi-control-view { min-width: 0; }
.kpi-view-switcher { width: auto; min-width: 140px; max-width: 220px; }
.kpi-clear-btn {
    align-self: end; padding: 0.35rem 0.9rem;
    border: 1px solid var(--lg-heritage); background: var(--lg-heritage); color: #fff;
    border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
    letter-spacing: 0.02em;
}
.kpi-clear-btn:hover { background: var(--lg-active); border-color: var(--lg-active); }
.kpi-run-btn {
    align-self: end; padding: 0.35rem 1.1rem;
    border: 1px solid var(--green); background: var(--green); color: #fff;
    border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 700;
    letter-spacing: 0.02em;
    transition: filter 0.15s var(--ease);
}
.kpi-run-btn:hover { filter: brightness(1.08); }
/* Pulses when filters are dirty (changed since last Run). */
.kpi-run-btn.is-dirty { box-shadow: 0 0 0 0 rgba(26, 135, 84, 0.6); animation: kpi-run-pulse 1.4s var(--ease) infinite; }
@keyframes kpi-run-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(26, 135, 84, 0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(26, 135, 84, 0); }
    100% { box-shadow: 0 0 0 0   rgba(26, 135, 84, 0); }
}
.kpi-control { display: flex; flex-direction: column; gap: 2px; font-size: 0.85em; color: var(--text-secondary); }
.kpi-control input, .kpi-control select { padding: 4px 6px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text-primary); border-radius: 4px; font: inherit; }
.kpi-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; margin-bottom: 16px; }
.kpi-summary-pill { padding: 4px 10px; border-radius: 12px; background: var(--bg-card); border: 1px solid var(--border); font-size: 0.9em; color: var(--text-primary); }
.kpi-kpi {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    flex: 1 1 0;
    text-align: center;
}
.kpi-kpi-label { font-size: 11px; text-transform: uppercase; color: var(--text-secondary); }
.kpi-kpi-value { font-size: 18px; font-weight: 600; color: var(--text-primary); }
.kpi-empty { padding: 24px; text-align: center; color: var(--text-secondary); }
.kpi-body { overflow: auto; color: var(--text-primary); }

.kpi-tree {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.kpi-row {
    display: grid;
    grid-template-columns: 24px minmax(180px, 2fr) minmax(60px, 1fr) minmax(60px, 1fr) minmax(60px, 1fr) minmax(80px, 1fr) minmax(80px, 1fr);
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}
.kpi-row-bucket { text-align: right; font-variant-numeric: tabular-nums; }
.kpi-row-volume, .kpi-row-rate, .kpi-row-repeats { text-align: right; font-variant-numeric: tabular-nums; }
/* Manifest opt-in (centerSupportingCols: true) — center the numeric cols
 * for modules where right-align reads awkwardly (e.g. NPS, where Surveys/
 * Promoters/Detractors are small integers next to a 1-decimal NPS value). */
.kpi-tree--center .kpi-row-volume,
.kpi-tree--center .kpi-row-repeats,
.kpi-tree--center .kpi-row-bucket,
.kpi-tree--center .kpi-row-rate { text-align: center; }
.kpi-row-header {
    background: var(--bg-hover);
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 2;
}
.kpi-row-rsm { background: var(--bg-hover); font-weight: 600; }
.kpi-row-asm { padding-left: 32px; background: var(--bg-chat); }
.kpi-row-toggle {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; font: inherit; padding: 2px 6px;
}

/* Freeze the row-label (name) column so it stays visible during horizontal
   scroll. Each row-type override sets the matching background so the sticky
   cell can occlude what scrolls past behind it. */
.kpi-row > :nth-child(2) {
    position: sticky;
    left: 0;
    z-index: 1;
}
.kpi-row-header > :nth-child(2) {
    background: var(--bg-hover);
    z-index: 3;
}
.kpi-row-rsm > :nth-child(2) { background: var(--bg-hover); }
.kpi-row-asm > :nth-child(2) { background: var(--bg-chat); }

/* Tier coloring on the rate cell. */
.kpi-tier-green   { color: var(--green); }
.kpi-tier-yellow  { color: var(--amber); }
.kpi-tier-red     { color: var(--red); }
.kpi-tier-neutral { color: var(--text-secondary); }

.kpi-ts-table { width: 100%; border-collapse: separate; border-spacing: 0; margin-bottom: 16px; color: var(--text-primary); }
.kpi-ts-table th, .kpi-ts-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.kpi-ts-table th { font-weight: 600; background: var(--bg-card); position: sticky; top: 0; color: var(--text-primary); }

/* Frozen first column on metric/KPI tables — keeps row labels visible during
   horizontal scroll. Direct-child selectors prevent nested tables from
   inheriting. `:first-child` (no element name) matches both <td> and <th> —
   transposed views use <th class="prod-ts-row-label"> as their row label. */
.kpi-ts-table > thead > tr:first-child > :first-child,
.kpi-ts-table > tbody > tr > :first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--bg-card);
}
/* Header's first cell sits at the intersection — needs to clear both axes. */
.kpi-ts-table > thead > tr:first-child > :first-child { z-index: 3; }

.kpi-chart-wrap { position: relative; height: 420px; padding: 1rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; margin-top: 16px; margin-bottom: 1rem; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06); display: flex; flex-direction: column; }
.kpi-chart-wrap > canvas { flex: 1; min-height: 0; }
.kpi-chart-toolbar { display: flex; justify-content: flex-end; align-items: center; margin-bottom: 0.5rem; }
.kpi-toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-secondary); cursor: pointer; user-select: none; }
.kpi-toggle input[type="checkbox"] { margin: 0; cursor: pointer; }

.kpi-control.is-hidden {
    display: none !important;
}

/* Horizontal scroll wrapper for transposed time-series tables. Year / Day
   grain can have 12-30+ period columns; YoY Month/Week is 12-13. The wrapper
   constrains overflow; the first-column sticky rules below freeze the row
   labels so they remain visible while scrolling. */
.kpi-ts-wrap {
    overflow-x: auto;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
}
.kpi-ts-wrap > table {
    margin: 0; /* override prod-tech-table defaults inside the wrapper */
}

/* Freeze the row-label column (first <th> / <td> of every row) so it stays
   put while the period columns scroll horizontally. The corner cell sits at
   the row-label / header intersection — needs higher z-index to occlude both
   sticky axes. Tinted bg is required so cells scrolling underneath don't
   bleed through the transparent default. */
.kpi-ts-wrap .prod-tech-table--transposed > thead > tr > .prod-ts-corner,
.kpi-ts-wrap .prod-tech-table--transposed > tbody > tr > .prod-ts-row-label {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface-2);
}
.kpi-ts-wrap .prod-tech-table--transposed > thead > tr > .prod-ts-corner {
    z-index: 4; /* clears both the sticky-top header AND the sticky-left col */
    background: var(--surface-2);
}
.kpi-ts-wrap .prod-tech-table--transposed > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-card);
    white-space: nowrap;
}
/* Keep day labels ("Apr 15") on one line in the body too — without this the
   tabular-nums cells stay one-line but the th headers wrap on the space. */
.kpi-ts-wrap .prod-tech-table--transposed th,
.kpi-ts-wrap .prod-tech-table--transposed td {
    white-space: nowrap;
}

/* Audit Log */
.audit-cat {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
}
.audit-cat-auth   { background: var(--bg-info,   #DBEAFE); color: var(--text-info,   #1E40AF); }
.audit-cat-admin  { background: var(--bg-warn,   #FEF3C7); color: var(--text-warn,   #92400E); }
.audit-cat-report { background: var(--bg-ok,     #D1FAE5); color: var(--text-ok,     #065F46); }

.audit-log-filters {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.audit-log-filters input, .audit-log-filters select { padding: 4px 8px; }
.audit-ua { color: var(--text-muted); font-size: 0.85em; }
.audit-pagination { margin-top: 1rem; display: flex; gap: 0.5rem; align-items: center; }

/* ----- Period Hierarchy: tier classes (good/warn/bad/neutral) ----------- */

.tier-good    { color: var(--chart-green-text); font-weight: 600; }
.tier-warn    { color: var(--chart-amber-text); font-weight: 600; }
.tier-bad     { color: var(--chart-red-text);   font-weight: 600; }

/* ----- Period Hierarchy Table ------------------------------------------ */

.period-hierarchy-wrap {
  overflow-x: auto;
  max-height: 70vh;
  border: 1px solid var(--border);
  border-radius: 4px;
}

table.period-hierarchy {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  width: max-content;
  min-width: 100%;
}

table.period-hierarchy thead th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 2;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-weight: 600;
}
table.period-hierarchy thead th.ph-name-h,
table.period-hierarchy thead th.ph-vol-h { text-align: left; }
table.period-hierarchy tr.ph-target-row th {
  font-weight: 400;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  background: var(--bg-card);
  top: 28px;
}

table.period-hierarchy td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border-light);
  text-align: right;
  white-space: nowrap;
}
table.period-hierarchy td.ph-name {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--bg-card);
  z-index: 1;
  cursor: default;
  min-width: 220px;
}
table.period-hierarchy td.ph-clickable { cursor: pointer; }
table.period-hierarchy td.ph-clickable:hover { background: var(--bg-hover); }

.ph-row.ph-level-0 td.ph-name { font-weight: 600; }
.ph-row.ph-level-1 td.ph-name { font-weight: 500; }
.ph-row.ph-level-2 td.ph-name { color: var(--text-primary); }
.ph-row.ph-level-org td.ph-name { font-weight: 700; text-align: right; }
.ph-row.ph-level-org td { font-weight: 600; background: var(--bg-card); }

table.period-hierarchy td.ph-ytd,
table.period-hierarchy th.ph-ytd-h {
  border-left: 2px solid var(--border, #e1e1e1);
  font-weight: 600;
  background: var(--bg-card-alt, var(--bg-card, #fafafa));
}

.ph-chevron, .ph-chevron-spacer {
  display: inline-block;
  width: 14px;
  margin-right: 4px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.ph-chevron.open { transform: rotate(90deg); }
.ph-chevron-spacer { cursor: default; }

/* ----- Period Hierarchy Drawer ----------------------------------------- */

.ph-drawer.hidden { display: none; }
.ph-drawer {
  position: fixed; inset: 0; z-index: 1000;
}
.ph-drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.25);
}
.ph-drawer-panel {
  position: absolute; right: 0; top: 0;
  width: min(900px, 90vw); height: 100vh;
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.ph-drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.ph-drawer-title { font-weight: 600; }
.ph-drawer-close {
  background: none; border: none;
  font-size: 24px; line-height: 1; cursor: pointer;
}
.ph-drawer-body { overflow: auto; padding: 12px 16px; flex: 1; }
.ph-rnm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ph-rnm-table th, .ph-rnm-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
}
.ph-truncation { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.ph-empty, .ph-loading, .ph-error { padding: 16px; color: var(--text-muted); }

/* Environment banner — visible only on non-production deployments. */
.env-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  padding: 4px 12px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #fff;
}
.env-banner[data-env="staging"] {
  display: block;
  background: #d97706; /* amber-600 */
}
.env-banner[data-env="dev"] {
  display: block;
  background: #2563eb; /* blue-600 */
}
.env-banner[data-env="local"] {
  display: block;
  background: #6b7280; /* gray-500 */
}
body:has(.env-banner[data-env="staging"]),
body:has(.env-banner[data-env="dev"]),
body:has(.env-banner[data-env="local"]) {
  padding-top: 24px;
}
