/* ============================================================
   layout.css: App shell, sidebar (all states), topbar, mobile hamburger, scrim
   ============================================================ */

/* ── App Shell ──────────────────────────────────────────────── */
.shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    background: var(--sb-bg);
    width: var(--sb-w);
    flex-shrink: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 300;
    border-right: 1px solid var(--sb-border);
    transition: width var(--ease-md);
    position: relative;
}

/* Desktop collapsed (icon-only) */
.shell[data-sidebar="collapsed"] .sidebar {
    width: var(--sb-collapsed-w);
}

/* ── Sidebar: Logo ──────────────────────────────────────────── */
.sidebar__logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 64px;
    border-bottom: 1px solid var(--sb-border);
    flex-shrink: 0;
    overflow: hidden;
    white-space: nowrap;
    text-decoration: none;
    min-width: 0;
}

.sidebar__logo-mark {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
}

.sidebar__logo-text {
    font-family: var(--font-display);
    font-size: 0.98rem;
    color: #e8f0fe;
    letter-spacing: -0.2px;
    line-height: 1.25;
    min-width: 0;
    overflow: hidden;
    transition: opacity var(--ease-md), max-width var(--ease-md);
    max-width: 180px;
}

.sidebar__logo-text em {
    display: block;
    font-style: normal;
    font-size: 0.58rem;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    color: var(--sb-icon);
    font-family: var(--font-body);
    font-weight: 500;
    margin-top: 2px;
}

/* ── Sidebar: Nav Body ──────────────────────────────────────── */
.sidebar__nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 10px 4px;
    scrollbar-width: none;
}

.sidebar__nav::-webkit-scrollbar { display: none; }

.sidebar__section {
    margin-bottom: 4px;
}

.sidebar__section-label {
    display: block;
    font-size: 0.6rem;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    color: var(--sb-icon);
    font-weight: 600;
    padding: 0 10px;
    margin-bottom: 3px;
    margin-top: 16px;
    white-space: nowrap;
    overflow: hidden;
    opacity: 1;
    transition: opacity var(--ease-md);
}

.sidebar__section:first-child .sidebar__section-label {
    margin-top: 4px;
}

/* ── Sidebar: Nav Links ─────────────────────────────────────── */
.sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-md);
    color: var(--sb-text);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background var(--ease), color var(--ease);
    position: relative;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-decoration: none;
    width: 100%;
    text-align: left;
}

.sidebar__link-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar__link-icon svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.6;
    transition: opacity var(--ease);
}

.sidebar__link-label {
    overflow: hidden;
    transition: opacity var(--ease-md), max-width var(--ease-md);
    max-width: 180px;
}

.sidebar__badge {
    margin-left: auto;
    background: rgba(45, 212, 191, 0.15);
    color: var(--teal-light);
    font-size: 0.58rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--r-full);
    letter-spacing: 0.3px;
    flex-shrink: 0;
    transition: opacity var(--ease-md), max-width var(--ease-md);
    max-width: 60px;
    overflow: hidden;
}

.sidebar__link:hover {
    background: var(--sb-hover-bg);
    color: rgba(255, 255, 255, 0.85);
}

.sidebar__link:hover .sidebar__link-icon svg { opacity: 0.9; }

.sidebar__link.active {
    background: var(--sb-active-bg);
    color: var(--sb-active-text);
}

.sidebar__link.active .sidebar__link-icon svg { opacity: 1; }

.sidebar__link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    background: var(--teal-light);
    border-radius: 0 3px 3px 0;
}

/* ── Sidebar: Theme Toggle ──────────────────────────────────── */
.sidebar__link.theme-btn .theme-icon-sun  { display: block; }
.sidebar__link.theme-btn .theme-icon-moon { display: none; }
[data-theme="dark"] .sidebar__link.theme-btn .theme-icon-sun  { display: none; }
[data-theme="dark"] .sidebar__link.theme-btn .theme-icon-moon { display: block; }
.sidebar__link.theme-btn .theme-label-light { display: none; }
.sidebar__link.theme-btn .theme-label-dark  { display: block; }
[data-theme="dark"] .sidebar__link.theme-btn .theme-label-light { display: block; }
[data-theme="dark"] .sidebar__link.theme-btn .theme-label-dark  { display: none; }

/* ── Sidebar: Footer ────────────────────────────────────────── */
.sidebar__footer {
    padding: 10px;
    border-top: 1px solid var(--sb-border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar__signout-form {
    display: contents;
}

.sidebar__signout {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-md);
    color: var(--sb-text);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background var(--ease), color var(--ease);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    width: 100%;
}

.sidebar__signout svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.5;
    transition: opacity var(--ease);
}

.sidebar__signout-label {
    overflow: hidden;
    transition: opacity var(--ease-md), max-width var(--ease-md);
    max-width: 180px;
}

.sidebar__signout:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
}

.sidebar__signout:hover svg { opacity: 0.8; }

/* ── Sidebar: Collapse Button ───────────────────────────────── */
.sidebar__collapse-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-md);
    color: var(--sb-text);
    font-size: 0.875rem;
    font-weight: 500;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    transition: background var(--ease), color var(--ease);
    text-align: left;
}

.sidebar__collapse-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.5;
    transition: transform var(--ease-md), opacity var(--ease);
}

.sidebar__collapse-btn:hover {
    background: var(--sb-hover-bg);
    color: rgba(255, 255, 255, 0.85);
}

.sidebar__collapse-btn:hover svg { opacity: 0.9; }

.sidebar__collapse-btn-label {
    overflow: hidden;
    transition: opacity var(--ease-md), max-width var(--ease-md);
    max-width: 180px;
}

/* Arrow flips when collapsed */
.shell[data-sidebar="collapsed"] .sidebar__collapse-btn svg {
    transform: rotate(180deg);
}

/* ── Hide text labels when sidebar is collapsed (desktop) ───── */
.shell[data-sidebar="collapsed"] .sidebar__logo-text,
.shell[data-sidebar="collapsed"] .sidebar__section-label,
.shell[data-sidebar="collapsed"] .sidebar__link-label,
.shell[data-sidebar="collapsed"] .sidebar__badge,
.shell[data-sidebar="collapsed"] .sidebar__signout-label,
.shell[data-sidebar="collapsed"] .sidebar__collapse-btn-label {
    opacity: 0;
    max-width: 0;
    pointer-events: none;
}

/* Center icons when collapsed */
.shell[data-sidebar="collapsed"] .sidebar__link,
.shell[data-sidebar="collapsed"] .sidebar__signout,
.shell[data-sidebar="collapsed"] .sidebar__collapse-btn {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.shell[data-sidebar="collapsed"] .sidebar__link.active::before {
    display: none;
}

/* ── Content Column ─────────────────────────────────────────── */
.content-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: none;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.75rem;
    gap: 0.75rem;
    flex-shrink: 0;
    z-index: 200;
    transition: background var(--ease), border-color var(--ease);
}

.topbar__title {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--text-1);
    letter-spacing: -0.2px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Topbar mobile theme toggle */
.topbar-theme-btn {
    display: none;
    width: 32px;
    height: 32px;
    border-radius: var(--r-md);
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--ease);
}

.topbar-theme-btn:hover {
    border-color: var(--teal);
    color: var(--teal);
}

.topbar-theme-btn svg { width: 15px; height: 15px; }

.topbar-theme-btn .theme-icon-sun  { display: block; }
.topbar-theme-btn .theme-icon-moon { display: none; }
[data-theme="dark"] .topbar-theme-btn .theme-icon-sun  { display: none; }
[data-theme="dark"] .topbar-theme-btn .theme-icon-moon { display: block; }

/* ── Mobile Hamburger ───────────────────────────────────────── */
.hamburger {
    display: none;
    width: 34px;
    height: 34px;
    border-radius: var(--r-md);
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all var(--ease);
    flex-shrink: 0;
}

.hamburger:hover { border-color: var(--teal); color: var(--teal); }

.hamburger__line {
    display: block;
    width: 15px;
    height: 1.5px;
    background: currentColor;
    border-radius: 2px;
    transition: transform var(--ease), opacity var(--ease);
}

.hamburger.is-open .hamburger__line:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
.hamburger.is-open .hamburger__line:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger.is-open .hamburger__line:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

/* ── Sidebar Scrim (mobile overlay) ─────────────────────────── */
.sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    z-index: 390;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.sidebar-scrim.is-visible { display: block; }

/* ── Mobile overrides ───────────────────────────────────────── */
@media (max-width: 768px) {
    .shell {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .content-col {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .page-content {
        overflow: visible;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: var(--sb-w) !important;
        transform: translateX(-100%);
        transition: transform var(--ease-md);
        z-index: 400;
    }

    .sidebar.is-open {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }

    .sidebar__collapse-btn { display: none; }
    .hamburger             { display: flex; }
    .topbar-theme-btn      { display: flex; }
}
