/* ═══════════════════════════════════════════════════════
   Layout — Shell, chrome, and navigation rhythm
   ═══════════════════════════════════════════════════════ */

.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
    padding: var(--shell-gutter);
    gap: 18px;
}

.sidebar {
    width: var(--sidebar-width-collapsed);
    height: calc(100vh - (var(--shell-gutter) * 2));
    background: var(--glass);
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    transition: width 350ms cubic-bezier(0.22, 1, 0.36, 1);
    flex-shrink: 0;
    z-index: 100;
    overflow: hidden;
    border-radius: var(--radius-3xl);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(22px) saturate(160%);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
}

.sidebar:hover,
.sidebar.pinned {
    width: var(--sidebar-width-expanded);
}

/* When pinned (clicked open) the labels stay visible just like on hover. */
.sidebar.pinned .sidebar-logo-text,
.sidebar.pinned .nav-item-label {
    opacity: 1;
}

/* Pin toggle button inside the logo row */
.sidebar-pin-btn {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-slow), background-color var(--transition-fast), color var(--transition-fast);
    flex-shrink: 0;
}

.sidebar:hover .sidebar-pin-btn,
.sidebar.pinned .sidebar-pin-btn {
    opacity: 1;
}

.sidebar-pin-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-pin-btn svg {
    width: 16px;
    height: 16px;
}

.sidebar.pinned .sidebar-pin-btn {
    color: var(--accent-text);
    background: var(--accent-light);
}

.sidebar-logo {
    min-height: 88px;
    display: flex;
    align-items: center;
    padding: 0 var(--space-5);
    gap: var(--space-3);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.sidebar-logo-icon {
    width: 42px;
    height: 42px;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.24), transparent 42%), linear-gradient(145deg, var(--accent), var(--accent-strong));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.24), 0 12px 24px rgba(0, 122, 255, 0.24);
    /* Acts as the pin toggle */
    border: none;
    padding: 0;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.sidebar-logo-icon:hover {
    transform: translateY(-1px);
}

/* Pinned state — a ring around the logo signals the panel is locked open */
.sidebar.pinned .sidebar-logo-icon {
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.24), 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--accent), 0 12px 24px rgba(0, 122, 255, 0.24);
}

.sidebar-logo-icon svg {
    width: 20px;
    height: 20px;
    color: white;
}

.sidebar-logo-text {
    font-size: 1.125rem;
    font-weight: var(--font-weight-extrabold);
    color: var(--text-primary);
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--transition-slow);
    letter-spacing: -0.04em;
}

.sidebar:hover .sidebar-logo-text {
    opacity: 1;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 14px 16px;
    border-radius: var(--radius-field);
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
    border: none;
    background: none;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    width: 100%;
    text-align: left;
}

.nav-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
    transform: translateX(1px);
}

.nav-item.active {
    background: linear-gradient(180deg, color-mix(in srgb, var(--accent-light) 60%, transparent), rgba(255,255,255,0.02));
    color: var(--accent-text);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 14%, transparent);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-item-label {
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.sidebar:hover .nav-item-label {
    opacity: 1;
}

.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--border-light);
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    gap: 14px;
}

.header {
    min-height: var(--header-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    flex-shrink: 0;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(22px) saturate(160%);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
}

.header-left {
    gap: var(--space-4);
}

.header-right {
    gap: var(--space-3);
}

.header-title {
    font-size: 1.25rem;
    font-weight: var(--font-weight-extrabold);
    letter-spacing: -0.04em;
}

.theme-toggle {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.theme-toggle:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

.lang-selector {
    display: flex;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    overflow: hidden;
    padding: 3px;
    background: var(--bg-elevated);
}

.lang-btn {
    padding: 0 var(--space-3);
    font-size: 0.72rem;
    font-weight: var(--font-weight-bold);
    font-family: var(--font-family);
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    height: 34px;
    border-radius: var(--radius-full);
}

.lang-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.lang-btn.active {
    background-color: var(--accent);
    color: white;
}

.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) 16px var(--space-1) var(--space-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), transform var(--transition-fast);
    height: 42px;
    box-shadow: var(--shadow-xs);
}

.user-menu-btn:hover {
    border-color: color-mix(in srgb, var(--accent) 36%, var(--border-light));
    transform: translateY(-1px);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--accent), var(--accent-strong));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: var(--font-weight-extrabold);
    flex-shrink: 0;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: var(--space-2);
    min-width: 180px;
    z-index: 200;
    animation: fadeInUp 150ms ease;
    display: none;
    box-shadow: var(--shadow-md);
}

.user-dropdown.open {
    display: block;
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    font-family: var(--font-family);
    transition: background-color var(--transition-fast);
}

.user-dropdown-item:hover {
    background-color: var(--bg-hover);
}

.user-dropdown-item.danger {
    color: var(--error);
}

.user-dropdown-item svg {
    width: 16px;
    height: 16px;
}

.content {
    flex: 1;
    overflow-y: auto;
    /* Breathing room at the bottom so rounded panels' soft shadows fade out
       instead of being hard-clipped into a rectangular band by this scroll box. */
    padding: 0 2px 18px;
}

.view {
    display: none;
    height: 100%;
}

.view.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 200ms ease;
    width: min(100%, var(--content-max-width));
    margin: 0 auto;
    min-height: 100%;
}

.mobile-toggle-btn {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.mobile-toggle-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.mobile-overlay {
    position: fixed;
    inset: 0;
    background-color: var(--overlay);
    z-index: 90;
    display: none;
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.mobile-overlay.show {
    display: block;
    opacity: 1;
}

@media (max-width: 768px) {
    .app-layout {
        padding: var(--shell-gutter-mobile);
        gap: 12px;
    }

    .sidebar {
        position: fixed;
        top: var(--shell-gutter-mobile);
        bottom: var(--shell-gutter-mobile);
        left: calc(-1 * min(86vw, 320px));
        width: min(86vw, 320px);
        height: auto;
        z-index: 100;
        transition: left var(--transition-slow);
    }

    .sidebar:hover {
        width: min(86vw, 320px);
    }

    .sidebar .sidebar-logo-text,
    .sidebar .nav-item-label {
        opacity: 1 !important;
    }

    .sidebar.open {
        left: var(--shell-gutter-mobile);
    }

    .mobile-toggle-btn {
        display: flex;
    }

    .header {
        padding: 0 16px;
    }
}
