/* ===================== LAYOUT v6.0 — Stitch Design System ===================== */
/* App Layout, Sidebar (Glass Nav), Header, Tabs, Page Transitions */

.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ---- SIDEBAR (Glass Nav) ---- */
.sidebar {
    width: 210px;
    background: rgba(9, 9, 11, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 40;
    transition: var(--transition);
}

[data-theme="light"] .sidebar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
    border-right: 1px solid rgba(0, 0, 0, 0.06);
}

.sidebar-logo {
    height: var(--header-height);
    padding: 0 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    gap: 10px;
}

[data-theme="light"] .sidebar-logo {
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

.sidebar-logo-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.15);
}

.sidebar-logo-text h1 {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.sidebar-logo-text p {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 1px;
}

.sidebar-section-label {
    font-size: 9px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 16px 20px 6px;
    font-weight: 600;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    transition: var(--transition);
    border: 1px solid transparent;
    margin-bottom: 2px;
    user-select: none;
}

.sidebar-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
    border-color: rgba(59, 130, 246, 0.2);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.15);
}

.sidebar-item .icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 10px;
    color: var(--text-dim);
}

[data-theme="light"] .sidebar-footer {
    border-top-color: rgba(0, 0, 0, 0.06);
}

/* ---- MAIN AREA ---- */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---- TOP HEADER (Glass) ---- */
.top-header {
    height: var(--header-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(9, 9, 11, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-shrink: 0;
}

[data-theme="light"] .top-header {
    border-bottom-color: rgba(0, 0, 0, 0.06);
    background: rgba(255, 255, 255, 0.8);
}

/* ---- TABS BAR ---- */
.tabs-bar {
    display: flex;
    gap: 2px;
    padding: 0 2px;
    flex: 1;
    overflow-x: auto;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    white-space: nowrap;
    transition: var(--transition);
    user-select: none;
}

.tab-item:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
}

.tab-item.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.05);
}

.tab-close {
    font-size: 14px;
    color: var(--text-dim);
    cursor: pointer;
    margin-left: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.tab-item:hover .tab-close {
    opacity: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ---- CONTENT AREA ---- */
.content-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ---- PAGE SYSTEM ---- */
.page {
    display: none;
    animation: pageFadeIn 0.2s ease;
}

.page.active {
    display: block;
}

@keyframes pageFadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Force all .page containers with ut-wrapper to stretch */
.page.active:has(.ut-wrapper) {
    display: flex !important;
    flex-direction: column;
    height: 100%;
}

/* ---- GLOBAL EMPTY STATES ---- */
.page.is-empty>*:not(.global-empty-state) {
    display: none !important;
}

.global-empty-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 500px;
    color: var(--text-muted);
    text-align: center;
    padding: 60px 20px;
    animation: fadeIn 0.4s ease forwards;
}

.page.is-empty>.global-empty-state {
    display: flex !important;
}

/* ---- THEME TOGGLE BUTTON ---- */
.theme-toggle-btn {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: var(--transition);
    flex-shrink: 0;
}

.theme-toggle-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
    transform: rotate(15deg);
}

.theme-icon-sun,
.theme-icon-moon {
    position: absolute;
    font-size: 16px;
    transition: transform 0.5s cubic-bezier(.4, 0, .2, 1), opacity 0.3s ease;
}

.theme-icon-moon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.theme-icon-sun {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

[data-theme="light"] .theme-icon-moon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

[data-theme="light"] .theme-icon-sun {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* ---- PAGE-SPECIFIC LAYOUT FIXES ---- */
#page-ai-usage {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

#page-ai {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

#page-ai.active {
    display: flex !important;
    flex-direction: column;
}

#page-costs.active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#page-costs .table-responsive {
    flex: 1;
    overflow-y: auto;
}