/*
 * sidebar.css — shared layout and sidebar styles
 * Referenced by every page that uses the app shell (sidebar + main content).
 */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* App palette */
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #e0e4ea;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-text: #ffffff;
    --text: #1a1d23;
    --text-muted: #6b7280;
    --error: #dc2626;
    --success: #16a34a;
    --input-bg: #f9fafb;
    --input-focus: #4f46e5;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);

    /* Sidebar */
    --sidebar-w: 64px;
    --sidebar-w-expanded: 220px;
    --sidebar-bg: #111827;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(79, 70, 229, 0.25);
    --sidebar-active-indicator: #4f46e5;
    --sidebar-text: #9ca3af;
    --sidebar-text-active: #ffffff;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    min-height: 100vh;
    color: var(--text);
}

/* ── Skip link ───────────────────────────────────────────────────────────────── */
.skip-link {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.skip-link:focus {
    position: fixed;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    overflow: visible;
    padding: 12px 20px;
    background: var(--primary);
    color: #fff;
    font-size: 0.9375rem;
    font-weight: 600;
    z-index: 9999;
    text-decoration: none;
    border-radius: 0 0 var(--radius-sm) 0;
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* ── App shell ───────────────────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex: 1;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    transition:
        width var(--sidebar-transition),
        min-width var(--sidebar-transition);
    flex-shrink: 0;
    z-index: 100;
}

.sidebar.sidebar--expanded {
    width: var(--sidebar-w-expanded);
    min-width: var(--sidebar-w-expanded);
}

/* ── Sidebar header (brand icon only) ────────────────────────────────────────── */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar--expanded .sidebar-header {
    justify-content: flex-start;
    padding: 0 16px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--sidebar-text-active);
    border-radius: var(--radius-sm);
    padding: 4px;
    flex-shrink: 0;
}

.sidebar-brand:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.sidebar-logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

/* ── Sidebar toggle (standalone row between nav and footer) ──────────────────── */
/*
 * In collapsed state: only the chevron is visible, centered in the 64 px rail.
 * In expanded state: chevron + "Collapse" label, flush left like a nav link.
 * The chevron rotates 180° when expanded so it always points in the right direction.
 */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center; /* center chevron in collapsed rail */
    width: 100%;
    height: 44px;
    padding: 0;
    background: none;
    border: none;
    border-top: 1px solid var(--sidebar-border);
    cursor: pointer;
    color: var(--sidebar-text);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    transition:
        color 0.15s,
        background 0.15s;
}

.sidebar--expanded .sidebar-toggle {
    justify-content: flex-start;
    gap: 12px;
    padding: 0 20px;
}

.sidebar-toggle:hover {
    color: var(--sidebar-text-active);
    background: var(--sidebar-hover);
}

.sidebar-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    border-radius: 4px;
}

.sidebar-toggle .sidebar-icon {
    transition: transform var(--sidebar-transition);
}

.sidebar--expanded .sidebar-toggle .sidebar-icon {
    transform: rotate(180deg);
}

/* ── Sidebar nav list ────────────────────────────────────────────────────────── */
.sidebar-nav {
    list-style: none;
    padding: 8px 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
    display: none;
}

/* ── Sidebar link / button (shared base) ─────────────────────────────────────── */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 44px;
    padding: 0 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    transition:
        color 0.15s,
        background 0.15s;
    position: relative;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}

.sidebar-link[aria-current="page"] {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
}

.sidebar-link[aria-current="page"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--sidebar-active-indicator);
}

.sidebar-link:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    border-radius: 4px;
}

/* ── Sidebar icon ────────────────────────────────────────────────────────────── */
.sidebar-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
    flex-shrink: 0;
}

/* ── Sidebar label ───────────────────────────────────────────────────────────── */
/*
 * Uses the sr-only clip technique so labels remain in the DOM and are announced
 * by screen readers even when the sidebar is collapsed (icon-only). The clip is
 * reversed in .sidebar--expanded to make labels visible to sighted users.
 */
.sidebar-label {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    width: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--sidebar-transition);
}

.sidebar--expanded .sidebar-label {
    clip: auto;
    clip-path: none;
    height: auto;
    width: auto;
    overflow: visible;
    position: static;
    opacity: 1;
    pointer-events: auto;
}

/* ── Sidebar settings (language, theme) ──────────────────────────────────────── */
.sidebar-settings {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 0;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-settings-btn {
    height: 40px;
    padding: 0 20px;
}

.sidebar-lang-symbol {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 600;
}

.sidebar-settings-btn .sidebar-theme-icon {
    width: 20px;
    height: 20px;
}

.sidebar-settings .sidebar-theme-icon.sidebar-icon-moon {
    display: none;
}

.theme-dark .sidebar-settings .sidebar-theme-icon.sidebar-icon-sun {
    display: none;
}

.theme-dark .sidebar-settings .sidebar-theme-icon.sidebar-icon-moon {
    display: block;
}

/* ── Sidebar footer ──────────────────────────────────────────────────────────── */
.sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    padding: 8px 0;
    flex-shrink: 0;
}

.sidebar-user {
    gap: 12px;
    min-height: 48px;
    display: flex;
    flex-flow: column;
    justify-content: center;
    align-items: center;
}

.sidebar-user-email {
    font-size: 0.8125rem;
    color: var(--sidebar-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}

.sidebar-logout:hover {
    background: rgba(220, 38, 38, 0.12);
    color: #fca5a5;
}

/* ── Avatar ──────────────────────────────────────────────────────────────────── */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    flex-shrink: 0;
    user-select: none;
}

/* ── Page main ───────────────────────────────────────────────────────────────── */
.page-main {
    flex: 1;
    min-width: 0;
    padding: 32px 24px 48px;
    outline: none;
}

.content-area {
    max-width: 800px;
    margin: 0 auto;
}

/* ── Dark theme ─────────────────────────────────────────────────────────────── */
.theme-dark {
    --bg: #0f172a;
    --surface: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --input-bg: #1e293b;
    --input-focus: #6366f1;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.theme-dark .section-card {
    background: var(--surface);
}

.theme-dark .confirm-modal-dialog {
    background: var(--surface);
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .sidebar {
        position: fixed;
        height: 100%;
    }

    .page-main {
        padding: 20px 16px 40px;
        margin-left: var(--sidebar-w);
    }

    .app-shell:has(.sidebar--expanded) .page-main {
        pointer-events: none;
        opacity: 0.4;
    }
}
