/* ============================================================
   chrome.css — CCI CRM app chrome (dark left-rail sidebar)
   Ported from gridops-ft-aps/frontend/css/styles.css. Owns ONLY the
   shell: design tokens, sidebar, main-content, mobile topbar, page
   header, and the ft-aps Drawer module. Loaded BEFORE main.css so the
   --color-* token namespace is available to app-dialog.js / drawer.js.

   Deliberately EXCLUDES the ft-aps collision set (.card*, .status-badge,
   .stat-card*, .stats-row, .datatable-*, .table-scroll-area,
   .drawer-wide, and every page-specific ft-aps section) — those belong
   to the libre-crm engine (main.css / datatable.css).
   ============================================================ */

/* Design tokens — accent overridden to indigo for CCI CRM. Dark slate
   sidebar tokens kept as-is from the donor. These --color-* names are a
   separate namespace from main.css's --bg-primary/--text-primary set and
   are consumed by the chrome, drawer.js, and app-dialog.js. */
:root {
    --color-primary: #4f46e5;
    --color-primary-dark: #4338ca;
    --color-primary-rgb: 79,70,229;
    --color-success: #059669;
    --color-warning: #d97706;
    --color-danger: #dc2626;
    --color-text: #111827;
    --color-text-secondary: #6b7280;
    --color-border: #e5e7eb;
    --color-bg: #ffffff;
    --color-bg-surface: #f9fafb;
    --color-bg-secondary: #f3f4f6;
    --touch-target-min: 44px;
    --color-solar: #f59e0b;
    /* Sidebar dark tokens */
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-text-bright: #f1f5f9;
    --sidebar-border: rgba(255,255,255,0.06);
    --sidebar-hover: rgba(255,255,255,0.08);
    --sidebar-section: #94a3b8;
}

/* ============================================================
   App layout (sidebar + main content)
   Adapted for the libre-crm SPA: body is height:100vh/overflow:hidden
   with inner scrolling in .route-view, so .app-layout is height-locked
   (not min-height:100vh like the multi-page donor) and .main-content is
   a flex column that lets #app-content own the scroll.
   ============================================================ */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 210px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    /* Must sit above Leaflet's tile/popup panes (~400-700) so the
       dashboard map doesn't paint over the slide-in sidebar on mobile. */
    z-index: 1000;
    transform: translateX(-210px);
    transition: transform 0.25s ease, width 0.25s ease;
    overflow: visible;
}
.sidebar-nav {
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    /* One below .sidebar so tapping the overlay still closes the sidebar,
       but above Leaflet's panes. */
    z-index: 999;
}
.sidebar-overlay.visible { display: block; }

.main-content {
    flex: 1;
    margin-left: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@media (min-width: 768px) {
    .sidebar { transform: translateX(0); }
    .main-content { margin-left: 210px; }
    .sidebar-overlay { display: none !important; }

    /* Collapsed sidebar (desktop only) */
    .app-layout.sidebar-collapsed .sidebar {
        width: 56px;
        overflow: visible;
    }
    .app-layout.sidebar-collapsed .main-content {
        margin-left: 56px;
    }
    .app-layout.sidebar-collapsed .sidebar-header {
        padding: 0;
        height: 56px;
        justify-content: center;
    }
    .app-layout.sidebar-collapsed .sidebar-app-name,
    .app-layout.sidebar-collapsed .sidebar-app-subtitle,
    .app-layout.sidebar-collapsed .sidebar-header > div:last-child {
        display: none;
    }
    .app-layout.sidebar-collapsed .sidebar-logo {
        width: 32px;
        height: 32px;
        border-radius: 6px;
    }
    .app-layout.sidebar-collapsed .sidebar-nav a {
        justify-content: center;
        padding: 0.625rem 0;
        border-left: none;
        position: relative;
    }
    .app-layout.sidebar-collapsed .sidebar-nav a span,
    .app-layout.sidebar-collapsed .sidebar-nav a:not(.active)::after {
        display: none;
    }
    /* Hide text labels — nav items are text nodes after the svg */
    .app-layout.sidebar-collapsed .sidebar-nav a {
        font-size: 0;
        gap: 0;
    }
    .app-layout.sidebar-collapsed .sidebar-nav a svg {
        width: 20px;
        height: 20px;
    }
    .app-layout.sidebar-collapsed .sidebar-nav a.active {
        border-left: none;
        border-radius: 0;
    }
    .app-layout.sidebar-collapsed .nav-section-label {
        display: none;
    }
    .app-layout.sidebar-collapsed .sidebar-footer {
        padding: 0.5rem;
    }
    .app-layout.sidebar-collapsed .sidebar-profile {
        justify-content: center;
    }
    .app-layout.sidebar-collapsed .sidebar-profile > div:last-child {
        display: none;
    }
    .app-layout.sidebar-collapsed .ai-chat-toggle-btn {
        font-size: 0;
        gap: 0;
        justify-content: center;
        padding: 0.5rem;
    }
    .app-layout.sidebar-collapsed .btn-signout {
        font-size: 0;
        padding: 0.5rem;
        display: flex;
        justify-content: center;
    }
    .app-layout.sidebar-collapsed .btn-signout::before {
        content: '';
        display: block;
        width: 16px;
        height: 16px;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23cbd5e1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 21H5a2 2 0 01-2-2V5a2 2 0 012-2h4'/%3E%3Cpolyline points='16 17 21 12 16 7'/%3E%3Cline x1='21' y1='12' x2='9' y2='12'/%3E%3C/svg%3E") no-repeat center;
    }

    /* Tooltip on hover for collapsed items */
    .app-layout.sidebar-collapsed .sidebar-nav a:hover::after {
        content: attr(data-label);
        position: absolute;
        left: 56px;
        top: 50%;
        transform: translateY(-50%);
        background: var(--color-text);
        color: #fff;
        padding: 4px 10px;
        border-radius: 4px;
        font-size: 0.75rem;
        font-weight: 500;
        white-space: nowrap;
        z-index: 200;
        pointer-events: none;
        display: block;
    }
}

/* Collapse toggle button */
.sidebar-collapse-btn {
    position: absolute;
    top: 42px;
    right: -14px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    /* Sits just above its parent sidebar so the tab pokes out cleanly */
    z-index: 1001;
    padding: 0;
    transition: all 0.15s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.sidebar-collapse-btn:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.sidebar-collapse-btn svg {
    width: 14px;
    height: 14px;
}
@media (min-width: 768px) {
    .sidebar-collapse-btn { display: flex; }
    .app-layout.sidebar-collapsed .sidebar-collapse-btn svg {
        transform: rotate(180deg);
    }
}

/* ============================================================
   Sidebar header (logo + app name)
   ============================================================ */
.sidebar-header {
    padding: 0 0.875rem;
    height: 56px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-shrink: 0;
    background: #fff;
}
.sidebar-logo {
    width: 36px; height: 36px;
    background: var(--color-primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
    overflow: hidden;
}
.sidebar-logo img {
    width: 36px; height: 36px;
    border-radius: 8px;
    object-fit: contain;
}
.sidebar-app-name {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}
.sidebar-app-subtitle {
    font-size: 0.6875rem;
    color: var(--color-text-secondary);
}

/* Company logo takes over the whole brand block: the uploaded wordmark replaces
   the small square icon AND hides the "CCI CRM" text (which would be redundant
   next to a wordmark). Toggled by NavModule.applyCompanyLogo() adding
   .has-company-logo to .sidebar-header. Removing the logo drops the class and
   restores the default icon + text. */
.sidebar-header.has-company-logo {
    justify-content: flex-start;
}
.sidebar-header.has-company-logo .sidebar-logo {
    width: auto;
    height: auto;
    background: transparent;
    border-radius: 0;
    overflow: visible;
}
.sidebar-header.has-company-logo img {
    max-width: 176px;
    max-height: 40px;
    width: auto;
    height: auto;
    object-fit: contain;
    background: #fff;
    border-radius: 8px;
    padding: 2px 6px;
}
.sidebar-header.has-company-logo .sidebar-app-name,
.sidebar-header.has-company-logo > div:last-child {
    display: none;
}
/* Collapsed rail: keep a company wordmark from overflowing the 56px column. */
.app-layout.sidebar-collapsed .sidebar-header.has-company-logo img {
    max-width: 44px;
    max-height: 32px;
    padding: 2px;
}

/* ============================================================
   Sidebar nav
   ============================================================ */
.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    list-style: none;
    margin: 0;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.875rem;
    color: var(--sidebar-text);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0;
    transition: background 0.15s, color 0.15s;
    min-height: var(--touch-target-min);
    text-decoration: none;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-bright);
    text-decoration: none;
}
.sidebar-nav a.active {
    background: rgba(var(--color-primary-rgb), 0.15);
    color: #fff;
    border-left-color: var(--color-primary);
    border-right: none;
}
.sidebar-nav svg {
    width: 18px; height: 18px;
    flex-shrink: 0;
}
.nav-section-label {
    padding: 0.75rem 0.875rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sidebar-section);
}

/* ============================================================
   Sidebar footer (AI chat toggle + profile + signout)
   ============================================================ */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
/* AI chat toggle relocated here from the old top header — full-width
   above the profile block. Base look comes from ai-chat.css; the
   translucent-white treatment already reads well on the dark rail. */
.sidebar-footer .ai-chat-toggle-btn {
    width: 100%;
    justify-content: center;
    margin: 0 0 0.75rem;
}
.sidebar-profile {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.75rem;
}
.sidebar-avatar {
    width: 32px; height: 32px;
    background: var(--color-primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-user-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--sidebar-text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: 0.6875rem;
    color: var(--sidebar-section);
    text-transform: capitalize;
}
.btn-signout {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    font-size: 0.8125rem;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-signout:hover { background: var(--sidebar-hover); color: var(--sidebar-text-bright); }

/* ============================================================
   Mobile hamburger (top bar visible only on mobile)
   ============================================================ */
.mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    /* Must sit above Leaflet's tile panes so the hamburger stays
       clickable on pages with a map. */
    z-index: 800;
}
.mobile-topbar-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}
.btn-hamburger {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text);
    border-radius: 6px;
    flex-shrink: 0;
}
.btn-hamburger:hover { background: var(--color-bg-secondary); }
@media (min-width: 768px) { .mobile-topbar { display: none; } }

/* ============================================================
   Page title chrome (for views that opt in)
   ============================================================ */
.page-header {
    margin-bottom: 0.85rem;
}
.page-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0 0 0.25rem;
}
.page-subtitle {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin: 0;
}

/* ============================================================
   Drawer module (ft-aps Drawer.open/close — js/drawer.js).
   Distinct from the libre-crm engine's native <dialog class="drawer">;
   no class overlap (this uses .drawer-panel/.drawer-overlay).
   ============================================================ */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.drawer-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 420px;
    background: var(--color-bg);
    z-index: 201;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
}
.drawer-panel.open {
    transform: translateX(0);
}
.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.drawer-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}
.drawer-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-secondary);
    border-radius: 6px;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.drawer-close:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text);
}
.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}
.drawer-footer {
    flex-shrink: 0;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
}
.drawer-footer .drawer-form-actions {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

/* ============================================================
   GLOBAL SEARCH — Cmd/Ctrl+K command palette (js/global-search.js)
   Appended section; does not modify any rule above. Sidebar trigger
   is styled to match .sidebar-nav links; the palette is a centered
   overlay above all app chrome (below the loading bar at z-index 9999).
   ============================================================ */

/* ── Sidebar trigger button (injected above .sidebar-nav) ── */
.gs-trigger {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: calc(100% - 1.5rem);
    margin: 0.75rem 0.75rem 0.25rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    min-height: var(--touch-target-min);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.gs-trigger:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-bright);
    border-color: rgba(255, 255, 255, 0.12);
}
.gs-trigger-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}
.gs-trigger-label {
    flex: 1;
    text-align: left;
}
.gs-kbd {
    display: inline-flex;
    align-items: center;
    padding: 0.0625rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--sidebar-section);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--sidebar-border);
    border-radius: 5px;
    flex-shrink: 0;
}

/* Collapsed desktop rail: show icon only (mirrors .sidebar-nav a behavior). */
@media (min-width: 768px) {
    .app-layout.sidebar-collapsed .gs-trigger {
        width: auto;
        margin: 0.75rem auto 0.5rem;
        padding: 0.5rem;
        justify-content: center;
    }
    .app-layout.sidebar-collapsed .gs-trigger-label,
    .app-layout.sidebar-collapsed .gs-kbd {
        display: none;
    }
}

/* ── Overlay + palette ── */
.gs-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(15, 23, 42, 0.55);
    padding: 20vh 1rem 1rem;
    justify-content: center;
    align-items: flex-start;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.gs-overlay.open {
    display: flex;
}
.gs-palette {
    width: 100%;
    max-width: 560px;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

/* ── Input row ── */
.gs-input-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.gs-input-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--color-text-secondary);
}
.gs-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1rem;
    font-family: inherit;
    color: var(--color-text);
    padding: 0.25rem 0;
}
.gs-input::placeholder {
    color: var(--color-text-secondary);
}

/* ── Results list ── */
.gs-results {
    overflow-y: auto;
    padding: 0.375rem 0;
}
.gs-message {
    padding: 1.25rem 1rem;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    text-align: center;
}
.gs-group {
    padding: 0.5rem 1rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
}
.gs-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
}
.gs-row[aria-selected="true"] {
    background: rgba(var(--color-primary-rgb), 0.10);
}
.gs-row-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 7px;
    background: var(--color-bg-secondary);
    color: var(--color-primary);
}
.gs-row-icon svg {
    width: 16px;
    height: 16px;
}
.gs-row-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}
.gs-row-primary {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gs-row-secondary {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gs-row-type {
    flex-shrink: 0;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    opacity: 0.7;
}
.gs-hl {
    background: rgba(var(--color-primary-rgb), 0.22);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

