/* Glassy topbar tint per theme */
html[data-ai-theme="dark"] .ai-topbar {
    background: rgba(6, 9, 34, 0.88);
    border-bottom-color: var(--ai-line);
}

.ai-shell {
    display: grid;
    grid-template-columns: 270px 1fr;
    min-height: 100vh;
}

.ai-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--ai-navy);
    color: #fff;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    z-index: 40;
}

.ai-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 34px;
}

.ai-brand img {
    width: 38px;
    height: 38px;
    object-fit: contain;
}
.ai-brand strong {
    display: block;
    font-size: 15px;
    line-height: 1;
    letter-spacing: 0.05em;
}
.ai-brand small {
    color: var(--ai-main);
    display: block;
    font-size: 10px;
    letter-spacing: 0.18em;
    font-weight: 800;
    margin-top: 3px;
}

.ai-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 11px 12px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.82);
    font-weight: 700;
    transition:
        background 0.18s ease,
        color 0.18s ease,
        transform 0.18s ease;
}
.ai-sidebar-link i {
    font-size: 18px;
    width: 22px;
    text-align: center;
}
.ai-sidebar-link:hover,
.ai-sidebar-link.active {
    background: var(--ai-main);
    color: #fff;
    transform: translateX(2px);
}
.ai-sidebar-bottom {
    margin-top: auto;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.ai-exit-link {
    background: rgba(255, 255, 255, 0.05);
}

.ai-main {
    min-width: 0;
}
.ai-topbar {
    height: 72px;
    background: var(--ai-panel);
    border-bottom: 1px solid var(--ai-line);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 25;
    backdrop-filter: blur(16px);
}
/* Hamburger is always visible (desktop = collapses sidebar column,
   mobile = opens overlay sidebar). Old .ai-mobile-menu kept for back-compat. */
.ai-mobile-menu {
    display: none;
}
.ai-toggle-menu {
    display: inline-flex;
}

/* Desktop collapsed state: hide the sidebar column and let main content
   span the full width. Mobile uses the existing .open / .ai-scrim behaviour. */
.ai-shell--collapsed {
    grid-template-columns: 1fr;
}
.ai-shell--collapsed .ai-sidebar {
    display: none;
}

/* Breadcrumb link styling */
.ai-crumb a {
    color: inherit;
    text-decoration: none;
    opacity: 0.65;
    transition: opacity 0.15s ease;
}
.ai-crumb a:hover {
    opacity: 1;
    text-decoration: underline;
}

.ai-crumb {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ai-muted);
    font-size: 13px;
    flex: 1;
}
.ai-crumb strong {
    color: var(--ai-ink);
}
.ai-topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ai-page {
    padding: 28px;
    max-width: 1240px;
    margin: 0 auto;
}
.ai-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}
.ai-page-head h1 {
    margin: 0;
    font-size: clamp(30px, 4vw, 48px);
    line-height: 1.05;
}
.ai-page-head p {
    margin: 10px 0 0;
    color: var(--ai-muted);
    font-size: 16px;
    max-width: 680px;
}

/* ── Sidebar: section label ─────────────────────────────────────── */
.ai-sb-section {
    margin: 0 0 8px;
    padding: 0 4px;
    color: rgba(255, 255, 255, 0.38);
    font-size: 10px;
    letter-spacing: 0.18em;
    font-weight: 800;
    text-transform: uppercase;
}

/* ── Sidebar: credits mini-widget ───────────────────────────────── */
.ai-sb-credits {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
}
.ai-sb-credits-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.ai-sb-credits-plan {
    font-size: 10px;
    letter-spacing: 0.14em;
    font-weight: 800;
    color: var(--ai-main);
}
.ai-sb-credits-topup {
    font-size: 11px;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.55);
    transition: color 0.15s;
}
.ai-sb-credits-topup:hover {
    color: #fff;
}
.ai-sb-credits-val {
    display: flex;
    align-items: baseline;
    gap: 5px;
}
.ai-sb-credits-val strong {
    color: #fff;
    font-size: 20px;
}
.ai-sb-credits-val small {
    color: rgba(255, 255, 255, 0.45);
    font-size: 12px;
}
.ai-sb-credits-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 99px;
    margin-top: 8px;
    overflow: hidden;
}
.ai-sb-credits-bar i {
    display: block;
    height: 100%;
    width: 0%; /* JS or server can set inline width later */
    background: var(--ai-main);
    border-radius: 99px;
}
/* New layout: ring + text side by side. Replaces the linear bar. */
.ai-sb-credits-stack {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}
.ai-sb-credits-ring {
    width: 50px;
    height: 50px;
    flex-shrink: 0;
}
.ai-sb-credits-ring .ring-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 4;
}
.ai-sb-credits-ring .ring-fg {
    fill: none;
    stroke: var(--ai-main);
    stroke-width: 4;
    stroke-linecap: round;
}
.ai-sb-credits-ring .ring-label {
    fill: #fff;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--ai-font, inherit);
}
.ai-sb-credits-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}
.ai-sb-credits-text strong {
    color: #fff;
    font-size: 16px;
    font-weight: 700;
}
.ai-sb-credits-text small {
    color: rgba(255, 255, 255, 0.55);
    font-size: 10px;
    letter-spacing: 0.04em;
}
.ai-sb-credits-of {
    color: rgba(255, 255, 255, 0.4);
    font-size: 10px;
    margin-top: 2px;
}

@media (max-width: 1020px) {
    .ai-shell {
        grid-template-columns: 1fr;
    }
    .ai-sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        width: min(82vw, 300px);
    }
    .ai-sidebar.open {
        transform: translateX(0);
    }
    .ai-scrim {
        position: fixed;
        inset: 0;
        background: rgba(5, 10, 35, 0.45);
        opacity: 0;
        pointer-events: none;
        z-index: 30;
        transition: opacity 0.2s ease;
    }
    .ai-scrim.open {
        opacity: 1;
        pointer-events: auto;
    }
    .ai-mobile-menu {
        display: inline-flex;
    }
    .ai-grid-2,
    .ai-grid-vault,
    .ai-kpis,
    .ai-plan-grid {
        grid-template-columns: 1fr;
    }
    .ai-action-grid,
    .ai-saved-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .ai-topbar {
        gap: 8px;
        padding: 0 10px;
        min-width: 0;
        overflow: visible;
    }
    .ai-crumb {
        min-width: 0;
        overflow: hidden;
        gap: 5px;
        font-size: 12px;
    }
    .ai-crumb a,
    .ai-crumb strong {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .ai-topbar-actions {
        flex: 0 0 auto;
        gap: 6px;
        min-width: 0;
    }
    .ai-credit-pill {
        display: none;
    }
    .ai-page {
        padding: 18px 14px;
    }
    .ai-page-head,
    .ai-public-head,
    .ai-plan-hero {
        flex-direction: column;
        align-items: stretch;
    }
    .ai-page-head {
        gap: 14px;
    }
    .ai-page-head h1 {
        font-size: 30px;
        overflow-wrap: anywhere;
    }
    .ai-page-head p {
        font-size: 14px;
    }
    .ai-page-head .ai-btn {
        width: 100%;
    }
    .ai-form-grid,
    .ai-public-grid {
        grid-template-columns: 1fr;
    }
    .ai-table > div {
        grid-template-columns: 1fr;
    }
    .ai-composer-footer {
        flex-direction: column;
    }
    .ai-pages-bubble {
        max-width: none;
        margin: 0;
    }
    .ai-pages-bubble::after {
        display: none;
    }
    .ai-pages-stepper {
        justify-content: center;
    }
}

@media (max-width: 420px) {
    .ai-topbar {
        padding-inline: 8px;
    }
    .ai-topbar-actions {
        gap: 4px;
    }
    .ai-crumb a,
    .ai-crumb .bi {
        display: none;
    }
}

/* Approved mobile Help placement and Android navigation safe height. */
@media (max-width: 1024px) {
    .ai-sidebar {
        box-sizing: border-box;
        height: 100vh;
        height: 100dvh;
        max-height: 100dvh;
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
        overscroll-behavior-y: contain;
    }
    .ai-sidebar > * {
        flex-shrink: 0;
    }
    .ai-sidebar-bottom {
        padding-top: 12px;
        flex-shrink: 0;
        margin-top: auto;
    }
    .ai-sidebar-bottom > .ws-help-trigger.ws-help-trigger {
        width: 100%;
        margin: 0 0 14px;
        justify-content: flex-start;
    }
}
