/* ==========================================================
   bTool – Global Dashboard Layout
   Sidebar + Header + Main Content
   ========================================================== */

@import url('btool-text-overflow.css');
@import url('btool-tooltip.css');

/* Brand (logo: blue “b”, dark “Tool”) – use for text & accents app-wide */
:root {
    /* Sidebar width (desktop expanded) — used for margin/offset alignment */
    --app-sidebar-width: 240px;
    --app-font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --color-primary-blue: #1d6ff2;
    --color-primary-blue-hover: #1558d0;
    --color-primary-dark: #1e293b;
    --color-primary-dark-strong: #0f172a;
    --color-text-secondary: #64748b;
    --color-text-medium: #475569;
    --color-text-emphasis: #334155;
    --color-text-muted: #94a3b8;
    --color-neutral-border: #e2e8f0;
    --color-surface-subtle: #f8fafc;
    --color-accent-soft-bg: #eff6ff;
    /* Empty state — circular icon (Team, BOQ/Site project gate, shared) */
    --empty-icon-bg: #f1f3f5;
    --empty-icon-color: #6b7280;
}

/* ══ Workspace back link (Dashboard / project context) — shared with project workspace header ══ */
a.workspace-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted, #94a3b8);
    text-decoration: none;
    flex-shrink: 0;
    letter-spacing: 0.01em;
    line-height: 1.35;
    font-family: inherit;
    transition: color 140ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

a.workspace-back:hover {
    color: var(--color-primary-dark, #1e293b);
    text-decoration: none;
}

a.workspace-back:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.35);
    outline-offset: 3px;
    border-radius: 4px;
}

/* Viewport chain: body → #layout-root (when present) → .app-shell fills height; scroll lives in .page-content */
html {
    height: 100%;
    font-family: var(--app-font-family);
}

body {
    font-family: var(--app-font-family);
}

/* ══ Empty state icon — circular, shared across tools (use with .empty-icon and .sp-no-project__icon) ══ */
.empty-icon,
.sp-no-project__icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--empty-icon-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-sizing: border-box;
}

.empty-icon {
    margin-bottom: 16px;
}

.sp-no-project__icon {
    margin-bottom: 4px;
    font-size: 0;
}

.empty-icon i,
.empty-icon svg,
.sp-no-project__icon i,
.sp-no-project__icon svg {
    width: 22px;
    height: 22px;
    color: var(--empty-icon-color);
    stroke: var(--empty-icon-color);
    flex-shrink: 0;
}

/* Font Awesome (glyph); SVG icons use width/height above */
.empty-icon i,
.sp-no-project__icon i {
    font-size: 22px;
    line-height: 1;
    display: block;
    width: auto;
    min-width: 0.8em;
    height: auto;
    stroke: none;
}

#layout-root {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- App Shell (outer only — do not use .app-layout here: BOQ has an inner .app-layout) --- */
.app-shell {
    display: flex;
    flex: 1;
    height: 100vh;
    min-height: 0;
    align-self: stretch;
    background: var(--color-surface-subtle);
    font-family: var(--app-font-family);
    overflow: hidden;
}

/* --- Sidebar (Desktop) --- */
.app-sidebar {
    width: var(--app-sidebar-width);
    min-width: var(--app-sidebar-width);
    background: var(--color-surface-subtle);
    border-right: 1px solid var(--color-neutral-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 1000;
    transition: width 0.25s ease, min-width 0.25s ease, transform 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
    font-family: var(--app-font-family);
}

.app-sidebar__logo {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-neutral-border);
    font-weight: 700;
    font-size: 18px;
    color: var(--color-primary-dark);
    overflow: hidden;
    flex-shrink: 0;
    transition: padding 0.25s ease;
}

.app-sidebar__logo .brand-mark {
    color: var(--color-primary-blue);
    flex-shrink: 0;
}

/* "Tool" part of the logo — fades out when collapsed */
.app-sidebar__logo-text {
    overflow: hidden;
    white-space: nowrap;
    max-width: 120px;
    transition: max-width 0.25s ease, opacity 0.2s ease;
}

.app-sidebar__nav {
    flex: 1;
    padding: 10px 10px 12px;
    overflow-y: auto;
    overflow-x: hidden;
}

.app-sidebar__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    margin-bottom: 2px;
    transition: background 0.15s, color 0.15s, padding 0.25s ease, gap 0.25s ease;
    white-space: nowrap;
    overflow: hidden;
}

.app-sidebar__link i {
    width: 20px;
    min-width: 20px;
    text-align: center;
    font-size: 15px;
    flex-shrink: 0;
}

.app-sidebar__link.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.app-sidebar__badge {
    font-size: 10px;
    color: var(--color-text-muted);
    margin-left: auto;
    transition: opacity 0.2s ease;
}

/* Text label span inside each nav link */
.app-sidebar__label {
    overflow: hidden;
    white-space: nowrap;
    max-width: 160px;
    transition: max-width 0.25s ease, opacity 0.2s ease;
}

/* Sidebar groups (project-centric nav) */
.app-sidebar__section {
    margin-bottom: 4px;
}

.app-sidebar__section--primary {
    margin-bottom: 2px;
}

.app-sidebar__section-title {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    padding: 10px 12px 6px 12px;
    line-height: 1.2;
}

.app-sidebar__section-divider {
    height: 1px;
    background: var(--color-neutral-border);
    margin: 8px 8px;
    opacity: 0.85;
}

.app-sidebar__link:hover:not(.active):not(.disabled) {
    background: #f1f5f9;
    color: var(--color-primary-dark);
}

/* Active: light blue surface, bold label (Notion-style) */
.app-sidebar__link.active {
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 700;
    border-radius: 8px;
}

.app-sidebar__link.active:hover {
    background: #e0e7ff;
    color: #1d4ed8;
}

.app-sidebar__link.active i {
    color: #1d4ed8;
}

/* ── Desktop collapsible sidebar ───────────────────────── */
@media (min-width: 769px) {

    /* Show the hamburger on desktop to serve as collapse toggle */
    .app-topbar__hamburger {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Smooth push of topbar + main content */
    .main-content {
        transition: margin-left 0.25s ease;
    }

    .app-topbar {
        transition: left 0.25s ease, width 0.25s ease;
    }

    /* ── Collapsed state ── */
    .app-sidebar.collapsed {
        width: 64px;
        min-width: 64px;
    }

    .app-sidebar.collapsed .app-sidebar__logo {
        padding: 16px 0;
        justify-content: center;
    }

    .app-sidebar.collapsed .app-sidebar__logo-text {
        max-width: 0;
        opacity: 0;
    }

    .app-sidebar.collapsed .app-sidebar__nav {
        padding: 12px 8px;
    }

    .app-sidebar.collapsed .app-sidebar__link {
        justify-content: center;
        padding: 10px 0;
        gap: 0;
    }

    .app-sidebar.collapsed .app-sidebar__label {
        max-width: 0;
        opacity: 0;
    }

    .app-sidebar.collapsed .app-sidebar__badge {
        display: none;
    }

    .app-sidebar.collapsed .app-sidebar__section-title {
        display: none;
    }

    .app-sidebar.collapsed .app-sidebar__section-divider {
        margin: 8px 6px;
    }

    /* Tooltip on collapsed nav items */
    .app-sidebar.collapsed .app-sidebar__link[data-tooltip] {
        position: relative;
        overflow: visible;
    }

    .app-sidebar.collapsed .app-sidebar__link[data-tooltip]::after {
        content: attr(data-tooltip);
        position: absolute;
        left: calc(100% + 10px);
        top: 50%;
        transform: translateY(-50%);
        background: var(--color-primary-dark);
        color: #fff;
        padding: 5px 10px;
        border-radius: 6px;
        font-size: 12px;
        font-weight: 500;
        white-space: nowrap;
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.15s ease;
        z-index: 9999;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }

    .app-sidebar.collapsed .app-sidebar__link[data-tooltip]:hover::after {
        opacity: 1;
    }

    /* ── Body-level collapsed: push topbar + content ── */
    body.sidebar-collapsed .main-content {
        margin-left: 64px;
    }

    body.sidebar-collapsed .app-topbar {
        left: 64px;
        width: calc(100% - 64px);
    }
}

/* --- Main Content (column: fixed topbar in flow gap + scrollable .page-content below) --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--app-sidebar-width);
    height: 100vh;
    min-height: 0;
    overflow: hidden;
    padding-top: 56px;
}

/* --- Topbar (fixed for reliable stickiness) --- */
.app-topbar {
    position: fixed;
    top: 0;
    left: var(--app-sidebar-width); /* Align with main content (sidebar width) */
    width: calc(100% - var(--app-sidebar-width));
    height: 56px;
    min-height: 56px;
    background: #fff;
    border-bottom: 1px solid var(--color-neutral-border);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    box-shadow: none; /* Desktop: no shadow */
}

@media (min-width: 769px) {
    .app-topbar {
        box-shadow: none;
        border-bottom: 1px solid #eee;
    }
}

@media (max-width: 768px) {
    .app-topbar {
        left: 0;
        width: 100%;
        box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    }
}

.app-topbar__left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-topbar__hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 6px;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}

.app-topbar__hamburger:hover {
    background: #f1f5f9;
    color: var(--color-primary-dark);
}

.app-topbar__logo-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}

/* Project name lives next to "Back to Project" in tool content; keep topbar minimal. */
body.page-boq #projectContextLabel,
body.page-site-planner #projectContextLabel {
    display: none !important;
}

.app-topbar__project-context {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    padding: 4px 10px;
    border-radius: 6px;
    background: #f1f5f9;
    white-space: nowrap;
    max-width: min(240px, 40vw);
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
    line-height: 1.3;
}

.app-topbar__project-select-btn {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-primary-blue);
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1.3;
}

.app-topbar__project-select-btn:hover {
    background: #dbeafe;
    border-color: #93c5fd;
}

.app-topbar__logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1.5px dashed #cbd5e1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: var(--color-surface-subtle);
}

.app-topbar__logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.app-topbar__logo .logo-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--color-text-muted);
    width: 100%;
    height: 100%;
}

/* Company initial shown when no logo is uploaded */
.app-topbar__logo .logo-initial {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: #2563eb;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0;
    user-select: none;
    border-radius: 50%;
}

.app-topbar__company {
    font-weight: 600;
    font-size: 15px;
    color: var(--color-primary-dark);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-topbar__company:hover {
    background: #f1f5f9;
}

.app-topbar__right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-topbar__support {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    background: #22c55e;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    transition: background 0.15s;
    white-space: nowrap;
}

.app-topbar__support:hover { background: #16a34a; }

.app-topbar__btn-login {
    padding: 7px 14px;
    background: var(--color-primary-blue);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.app-topbar__btn-login:hover { background: var(--color-primary-blue-hover); }

.app-topbar__btn-login:disabled {
    opacity: 0.75;
    cursor: not-allowed;
}

.btn-loader {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    display: inline-block;
    animation: btoolBtnSpin 0.7s linear infinite;
}

.btn-loader[hidden] {
    display: none !important;
}

@keyframes btoolBtnSpin {
    to { transform: rotate(360deg); }
}

/* ── Profile dropdown ── */
.app-topbar__profile {
    position: relative;
    align-items: center; /* used when auth JS sets display:flex */
}

.app-topbar__avatar-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    border-radius: 8px;
    padding: 4px 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.app-topbar__avatar-btn:hover {
    background: #f1f5f9;
}

.app-topbar__avatar-img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid var(--color-neutral-border);
    display: block;
}

.app-topbar__avatar-chevron {
    font-size: 10px;
    color: var(--color-text-muted);
    transition: transform 0.2s ease;
}

.app-topbar__avatar-btn[aria-expanded="true"] .app-topbar__avatar-chevron {
    transform: rotate(180deg);
}

.app-topbar__profile-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 176px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10);
    padding: 4px 0;
    z-index: 9999;
}

.app-topbar__profile-info {
    padding: 10px 14px 8px;
}

.app-topbar__profile-name {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 148px;
}

.app-topbar__profile-divider {
    height: 1px;
    background: #f1f5f9;
    margin: 2px 0;
}

.app-topbar__dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-emphasis);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.app-topbar__dropdown-item:hover {
    background: #f8fafc;
}

.app-topbar__dropdown-logout {
    color: #ef4444;
}

.app-topbar__dropdown-logout:hover {
    background: #fef2f2;
}

/* ── Auth flicker prevention ─────────────────────────────────────────────
   While auth state is unresolved (.auth-pending on body), suppress the
   entire right-side auth area so neither "Login" nor the avatar flash
   prematurely. The class is added synchronously by app.js on load and
   removed once onAuthStateChanged fires.
   ───────────────────────────────────────────────────────────────────── */
body.auth-pending #loginBtn,
body.auth-pending #userInfo {
    visibility: hidden !important;
    pointer-events: none !important;
}
body.auth-pending #sidebarLoginMobileWrap,
body.auth-pending .sidebar-logout-wrap {
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Smooth reveal when auth resolves */
#loginBtn,
#userInfo {
    transition: opacity 0.15s ease;
}

/* --- Export actions: desktop default --- */
.export-actions {
    display: flex;
    gap: 10px;
}

/* --- More menu (3-dot): hidden on desktop/tablet (CSS ONLY - never override via JS) --- */
.more-menu,
.more-menu--mobile-only {
    display: none !important;
}



@media (max-width: 768px) {
    .app-topbar__support,
    .app-topbar__support.support-btn,
    a.support-btn,
    a.app-topbar__support {
        display: inline-flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        animation: none !important;
        transition: none !important;
    }
}




/* --- Tablet & Desktop: show buttons, hide 3-dot --- */
@media (min-width: 481px) {
    .export-actions {
        display: flex;
    }
    .more-menu,
    .more-menu--mobile-only {
        display: none !important;
    }
}

/* --- Mobile accordion: 768px (when Data Library hidden) --- */
@media (max-width: 768px) {
    .boq-settings-accordion {
        display: block;
        flex: 1;
        min-width: 0;
    }
    .boq-settings-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 6px 10px;
        font-size: 12px;
        font-weight: 600;
        color: var(--color-text-medium);
        background: transparent;
        border: none;
        border-radius: 6px;
        cursor: pointer;
        transition: background 0.15s, color 0.15s;
        -webkit-tap-highlight-color: transparent;
    }
    .boq-settings-header:hover {
        background: rgba(0,0,0,0.04);
    }
    .boq-settings-chevron {
        font-size: 10px;
        color: var(--color-text-muted);
        transition: transform 0.25s ease;
    }
    .boq-settings-accordion.is-expanded .boq-settings-chevron {
        transform: rotate(180deg);
    }
    .boq-settings-content {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 8px 0 0 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.25s ease;
    }
    .boq-settings-accordion.is-expanded .boq-settings-content {
        max-height: 150px;
    }
    .boq-settings-accordion .nav-selector-group {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        margin: 0;
    }
    .boq-settings-accordion .nav-selector-group label {
        display: block !important;
        font-size: 10px;
        margin-bottom: 0;
    }
    .boq-settings-accordion #boqTemplate,
    .boq-settings-accordion #startPhrase {
        width: 100% !important;
        max-width: none !important;
        height: 32px !important;
    }
}

/* --- Mobile: 3-dot menu, export actions hidden --- */
@media (max-width: 480px) {
    .export-actions {
        display: none !important;
    }
    /* BOQ only: allow more-menu dropdown to escape scroll clipping */
    body.page-boq .app-shell,
    body.page-boq .main-content {
        overflow: visible !important;
    }
    .app-topbar,
    .app-topbar__right {
        overflow: visible !important;
    }
    .more-menu,
    .more-menu--mobile-only {
        display: flex !important;
        visibility: visible !important;
        align-items: center;
        position: relative;
        overflow: visible;
    }
    .more-menu button {
        font-size: 20px;
        background: none;
        border: none;
        cursor: pointer;
        color: var(--color-text-secondary);
        padding: 6px;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .more-menu button:hover { color: var(--color-primary-dark); }
    .more-dropdown {
        position: absolute;
        top: calc(100% + 4px);
        right: 0;
        left: auto;
        background: #fff;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        box-shadow: 0 8px 20px rgba(0,0,0,0.1);
        padding: 6px 0;
        width: 160px;
        min-width: 160px;
        z-index: 9999;
    }
    .more-dropdown.hidden { display: none !important; }
    .more-dropdown:not(.hidden) { display: block; }
    .more-dropdown button {
        width: 100%;
        padding: 10px 12px;
        text-align: left;
        background: none;
        border: none;
        font-size: 14px;
        cursor: pointer;
        color: var(--color-text-emphasis);
        transition: background 0.15s;
    }
    .more-dropdown button:hover { background: #f3f4f6; }
}

/* --- Page Content (single vertical scroll region below fixed topbar) --- */
.page-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    padding: 24px;
}

/* --- Sidebar Overlay (Mobile) --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* --- Body: prevent scroll when menu open --- */
body.menu-open {
    overflow: hidden !important;
}

/* --- Dashboard Module Cards --- */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    max-width: 1200px;
}

.dashboard-card {
    background: #fff;
    border: 1px solid var(--color-neutral-border);
    border-radius: 12px;
    padding: 24px;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.dashboard-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    border-color: #cbd5e1;
}

.dashboard-card__icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 16px;
}

.dashboard-card__icon--blue { background: var(--color-accent-soft-bg); color: var(--color-primary-blue); }
.dashboard-card__icon--violet { background: #f5f3ff; color: #7c3aed; }
.dashboard-card__icon--gray { background: #f1f5f9; color: var(--color-text-secondary); }

.dashboard-card__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-primary-dark);
    margin-bottom: 8px;
}

.dashboard-card__desc {
    font-size: 14px;
    color: var(--color-text-secondary);
    line-height: 1.5;
    margin-bottom: 16px;
}

.dashboard-card__footer {
    display: flex;
    gap: 8px;
}

.dashboard-card__btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: var(--color-primary-blue);
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.dashboard-card__btn:hover { background: var(--color-primary-blue-hover); }

.dashboard-card__btn--disabled {
    background: #e2e8f0;
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.dashboard-card__badge {
    font-size: 11px;
    color: var(--color-text-muted);
}

/* --- Sidebar: mobile-only items hidden on desktop --- */
.app-sidebar__link--mobile-only,
.app-sidebar__auth--mobile-only { display: none !important; }

/* --- Responsive --- */
@media (max-width: 768px) {
    /* Mobile sidebar: proper slide-in drawer */
    .app-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 280px;
        height: 100vh;
        background: #fff;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.08);
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .app-sidebar.open {
        left: 0;
    }

    .app-sidebar__nav {
        flex: 1;
        overflow-y: auto;
    }

    .app-sidebar__link--mobile-only,
    .app-sidebar__auth--mobile-only { display: block !important; }

    .app-sidebar .sidebar-footer {
        padding: 16px;
        border-top: 1px solid #eee;
        flex-shrink: 0;
    }

    .app-sidebar__auth--mobile-only .app-sidebar__btn-login,
    .app-sidebar__auth--mobile-only .app-sidebar__btn-logout {
        width: 100%;
    }

    .main-content {
        margin-left: 0;
    }

    /* Prevent horizontal overflow on all mobile pages */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw;
    }
    .app-shell {
        overflow-x: hidden !important;
        max-width: 100vw;
    }
    .main-content {
        overflow-x: hidden !important;
        max-width: 100%;
        min-width: 0;
    }

    .app-topbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 12px;
        overflow-x: hidden;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .app-topbar__left {
        display: flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
        flex: 1;
    }

    .app-topbar__logo-wrap {
        min-width: 0;
        flex: 1;
    }

    .app-topbar__company {
        font-size: 14px;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 160px;
    }

    /* Ensure Support icon stays within viewport - reserve space */
    .app-topbar__support,
    .app-topbar__support.support-btn,
    a.app-topbar__support {
        flex-shrink: 0;
        box-sizing: border-box;
    }

    .app-topbar__right {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
        min-width: 0;
        overflow: visible;
    }

    .app-topbar__hamburger {
        display: block;
    }




.app-topbar__support,
    .support-btn {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        animation: none !important;
        transition: none !important;
        padding: 6px !important;
        min-width: 32px;
        min-height: 32px;
    }

    .app-topbar__support span {
        display: none !important;
        width: 0 !important;
        overflow: hidden !important;
    }

    .app-topbar__support i {
        display: inline-flex;
        align-items: center;
        line-height: 1;
    }






    .header-auth--desktop {
        display: none !important;
    }

    /* Hide topbar login/logout on mobile to prevent overflow; sidebar has mobile auth */
    .app-topbar__right .app-topbar__btn-login,
    .app-topbar__right .app-topbar__btn-logout,
    .app-topbar__right #userInfo {
        display: none !important;
    }

    .page-content {
        padding: 16px 12px;
    }

    .dashboard-cards {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .dashboard-card {
        padding: 20px;
    }
}

/* Extra narrow (360px): tighten topbar to prevent icon overflow */
@media (max-width: 400px) {
    .app-topbar {
        padding: 6px 10px !important;
    }
    .app-topbar__company {
        max-width: 120px !important;
    }
}

/* --- BOQ page: split layout – fixed left form, scrollable right table --- */
/* Prevent body scroll on BOQ page */
html.page-boq,
body.page-boq {
    overflow: hidden;
    height: 100%;
}

body.page-boq .app-shell {
    height: 100%;
    min-height: 0;
    flex: 1;
    overflow: hidden;
}

body.page-boq .main-content {
    min-height: 0;
    flex: 1;
}

/* page-content has class boq-page on BOQ page */
.page-content.boq-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0; /* inner panels own their padding */
}

.page-content.boq-page .nav-selector-strip {
    flex-shrink: 0;
    padding-left: 24px;
    padding-right: 24px;
}

/*
 * BOQ main area: capped at 1400px and centred so the two-panel layout
 * does not stretch edge-to-edge on ultra-wide monitors.
 */
.page-content.boq-page #boq-main:not([hidden]) {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    align-self: stretch; /* still claims full available height */
}

/* Container: topbar 56px + nav strip ~52px = ~108px subtracted from viewport */
.page-content.boq-page .app-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
    padding: 0 24px 0 24px;
    gap: 0; /* gap is handled by the resizer + panel padding */
}

/* Left panel: flex column, scrollable content + sticky footer */
.page-content.boq-page .left-panel {
    width: 380px;
    min-width: 280px;
    max-width: 560px;
    flex-shrink: 0;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    margin: 16px 0 20px;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: calc(100% - 36px);
    box-shadow: 0 1px 4px rgba(0,0,0,.04);
}

/* Scrollable form area – chips can expand, content scrolls */
.page-content.boq-page .left-panel-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 16px 12px 20px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.page-content.boq-page .form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    flex: none;
}

.page-content.boq-page .form-grid > .row,
.page-content.boq-page .form-grid > .calculation-row {
    grid-column: 1 / -1;
}

.page-content.boq-page .form-grid .row,
.page-content.boq-page .form-grid .calculation-row {
    margin-bottom: 0;
}

.page-content.boq-page .form-grid > * {
    margin-bottom: 14px;
}

.page-content.boq-page .form-grid > *:last-of-type {
    margin-bottom: 0;
}

/* Footer always visible at bottom of left panel */
.page-content.boq-page .form-footer {
    flex-shrink: 0;
    border-top: 1px solid #e5e7eb;
    padding: 12px 20px;
    background: #fff;
}

.page-content.boq-page .form-footer .footer-actions {
    margin-top: 0;
}

/* Rate basis input-group spans full width */
.page-content.boq-page .form-grid > .input-group {
    grid-column: 1 / -1;
}

/* Chip containers expand properly, no clipping */
.page-content.boq-page .tag-display-area {
    min-height: 40px;
    max-height: none;
    overflow: visible;
}

/* Resizer between panels — acts as the gap divider */
.boq-resizer {
    width: 16px;
    flex-shrink: 0;
    cursor: col-resize;
    background: transparent;
    position: relative;
    user-select: none;
    align-self: stretch;
}

.boq-resizer::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 24px;
    bottom: 24px;
    width: 1px;
    background: #e5e7eb;
    transform: translateX(-50%);
    transition: background 0.15s;
}

.boq-resizer:hover::after {
    background: #94a3b8;
}

/* Short viewport: left-panel-content scrolls (no change needed) */

/* Right panel: SCROLLABLE independently */
.page-content.boq-page .right-panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    padding: 20px 4px 40px 20px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.page-content .nav-selector-strip {
    flex-shrink: 0;
}

/* BOQ page padding is fully controlled by the rule above */

.page-content .app-layout {
    flex: 1;
    min-height: 0;
}

/*
 * #boq-main is the wrapper that houses the nav-selector-strip + .app-layout.
 * :not([hidden]) ensures we never override the HTML hidden attribute with
 * display:flex, which would make the editor visible on the entry/list screen.
 * max-width + margin:auto centre the two-panel layout on wide viewports.
 */
.page-content.boq-page #boq-main:not([hidden]) {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    /* centred container already set above; repeat here for specificity safety */
    max-width: 1400px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 768px) {
    /* Mobile: re-enable body scroll, stack layout */
    html.page-boq,
    body.page-boq {
        overflow: auto;
        height: auto;
    }

    body.page-boq .app-shell {
        height: auto;
        overflow: visible;
    }

    .page-content .app-layout {
        flex-direction: column;
    }

    .boq-resizer {
        display: none;
    }

    .page-content.boq-page .left-panel {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        overflow-y: visible;
        border-radius: 0;
        border-left: none;
        border-right: none;
        margin: 0;
        height: auto;
        box-shadow: none;
    }

    .page-content.boq-page .left-panel-content {
        padding: 12px 16px;
        height: auto;
        overflow: visible;
        overflow-x: hidden;
        flex: none;
        max-width: 100%;
    }

    .page-content.boq-page .form-footer {
        position: relative;
    }

    /* Form grid 2-col handled in features.css for mobile */
    .page-content.boq-page .form-grid {
        gap: 14px;
        flex: none;
    }

    .page-content.boq-page .form-footer {
        margin-top: 0;
    }

    .page-content.boq-page .app-layout {
        padding: 0 12px;
    }

    .page-content.boq-page .right-panel {
        overflow-y: visible;
        flex: none;
        padding: 12px 0 40px;
    }

    .page-content .left-panel,
    .page-content .right-panel {
        max-width: 100%;
    }

    .page-content .right-panel .output-container {
        overflow-x: auto;
    }
}




@media (max-width: 768px) {
    .app-topbar__support,
    .app-topbar__support.support-btn,
    a.app-topbar__support {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        visibility: visible !important;
        opacity: 1 !important;
        min-width: 32px;
        min-height: 32px;
        padding: 6px !important;
    }

    .app-topbar__support span {
        display: none !important; /* hide text, keep icon */
    }

    .app-topbar__support i {
        display: inline-flex !important;
        align-items: center !important;
        line-height: 1 !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════════════
   Project Context Header  (project-header.js component)
   Appears at the top of tool pages when a ?projectId= is present.
   ══════════════════════════════════════════════════════════════════════════════ */

.project-header {
    margin-bottom: 20px;
}

/* Top row: back-btn  |  project-badge  |  [extra slot right] */
.ph-top-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

/* "← Back to Project" button */
.ph-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: #6b7280;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    line-height: 1.4;
    text-decoration: none;
    transition: color 0.15s;
}
.ph-back-btn:hover {
    color: #111827;
    text-decoration: none;
}

/* "📁 Project Name" pill */
.ph-project-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #f3f4f6;
    color: #374151;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.15s;
}
.ph-project-badge:hover {
    background: #e5e7eb;
}

/* Extra slot (e.g. "+ New Plan" button) pushed to the right */
.ph-extra {
    margin-left: auto;
    display: flex;
    align-items: center;
}

/* Optional page-title line rendered below the top row */
.ph-page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-primary-dark, #1e293b);
    margin: 4px 0 0;
    line-height: 1.3;
}

/* —— Auth overlay — hidden while Firebase/session is still restoring (see auth-guard.js) — */
html.auth-resolving #auth-overlay {
    display: none !important;
}

/* —— Auth overlay — default hidden (FOUC): shown via .show or html.need-auth — */
#auth-overlay.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;

    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);

    background: rgba(246, 248, 250, 0.36);

    align-items: center;
    justify-content: center;

    box-sizing: border-box;
}

#auth-overlay {
    display: none;
}

#auth-overlay.show,
html.need-auth #auth-overlay {
    display: flex;
}

.auth-modal {
    background: #ffffff;
    border-radius: 12px;
    padding: 24px;
    width: 320px;
    max-width: calc(100vw - 40px);
    text-align: center;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.08),
        0 2px 8px rgba(0, 0, 0, 0.05);
}

.auth-modal h2 {
    margin: 0 0 8px 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e293b;
}

.auth-modal p {
    margin: 0 0 20px 0;
    font-size: 14px;
    line-height: 1.5;
    color: #64748b;
}

.auth-overlay #login-btn,
.auth-overlay .auth-btn {
    width: 100%;
    padding: 12px 16px;

    background: #2563eb;
    color: #ffffff;

    border: none;
    border-radius: 8px;

    font-size: 14px;
    font-weight: 600;

    cursor: pointer;
    transition: all 0.2s ease;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

/* Premium touch — soft lift */
.auth-overlay #login-btn {
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.auth-overlay #login-btn:hover,
.auth-overlay .auth-btn:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
}

.auth-overlay #login-btn:active,
.auth-overlay .auth-btn:active {
    transform: translateY(0);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.auth-overlay #login-btn.primary-btn .btn-loader {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
}

.auth-overlay #login-btn.primary-btn.loading,
.app-topbar__btn-login.loading,
.app-sidebar__btn-login.loading {
    opacity: 0.9;
    pointer-events: none;
}

html.auth-overlay-open,
body.auth-overlay-open {
    overflow: hidden;
}

/* Guest gate: avoid stacked blur — veil blur lives only on .auth-overlay */
body.auth-overlay-open #layout-root,
body.auth-overlay-open #app-content,
body.auth-overlay-open .app-shell,
body.auth-overlay-open .main-content {
    filter: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* Access denied (module / permission) — Notion-style modal */
.access-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 15, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    box-sizing: border-box;
    padding: 16px;
}

.access-modal.hidden {
    display: none;
}

.access-modal-card {
    background: #ffffff;
    border-radius: 10px;
    padding: 24px 20px;
    width: 100%;
    max-width: 320px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    text-align: center;
    font-family: system-ui, -apple-system, Segoe UI, sans-serif;
    box-sizing: border-box;
}

.access-modal-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #111;
}

.access-modal-message {
    font-size: 13px;
    color: #666;
    margin-bottom: 16px;
    line-height: 1.45;
}

.access-modal-btn {
    background: #111;
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}

.access-modal-btn:hover {
    background: #333;
}

.access-modal-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #111;
}