/* Engel Coaching Admin – Shell (index.html) */
:root {
    color-scheme: only light;
    --shell-primary: #0f2d4a;
    --shell-primary-mid: #1a4d7a;
    --shell-primary-light: #2a6ba0;
    --shell-accent: #38bdf8;
    --shell-bg: #f1f5f9;
    --shell-surface: #ffffff;
    --shell-border: #e2e8f0;
    --shell-text: #1e293b;
    --shell-text-muted: #64748b;
    --shell-danger: #dc2626;
    --shell-sidebar-width: 280px;
    --shell-sidebar-collapsed: 76px;
    --shell-header-height: 64px;
    --shell-font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --shell-radius: 10px;
    --shell-shadow: 0 1px 3px rgba(15, 45, 74, 0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--shell-font);
    background: var(--shell-bg);
    display: flex;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#appShell {
    display: none;
    width: 100%;
    height: 100%;
}

#appShell.is-visible {
    display: flex;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--shell-sidebar-width);
    min-width: var(--shell-sidebar-width);
    background: linear-gradient(180deg, var(--shell-primary) 0%, #0a1f33 100%);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    z-index: 20;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand:has(.portal-logo) {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

.portal-logo {
    display: block;
    width: 44px;
    max-width: 44px;
    height: auto;
    box-sizing: border-box;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
    color: inherit;
}

.brand-logo-wrap {
    width: 52px;
    height: 52px;
    background: #fff;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.brand-text h1 {
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.brand-text span {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px 12px 24px;
}

.nav-section[data-account-nav] {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-menu::-webkit-scrollbar { width: 4px; }
.nav-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.nav-section {
    margin-bottom: 8px;
}

.nav-section + .nav-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.nav-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255, 255, 255, 0.35);
    padding: 0 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    margin-bottom: 2px;
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    border-radius: var(--shell-radius);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border: 1px solid transparent;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.nav-item.is-active {
    background: rgba(56, 189, 248, 0.15);
    color: #fff;
    border-color: rgba(56, 189, 248, 0.25);
}

.nav-item.is-active .nav-icon {
    background: rgba(56, 189, 248, 0.2);
    color: var(--shell-accent);
}

.nav-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    font-size: 1rem;
    flex-shrink: 0;
}

.nav-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.3);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
}

/* ── Desktop: icon rail, expand on hover (width only) ── */
@media (min-width: 901px) {
    .sidebar {
        width: var(--shell-sidebar-collapsed);
        min-width: var(--shell-sidebar-collapsed);
        flex-shrink: 0;
        overflow-x: hidden;
        transition: width 0.22s ease, min-width 0.22s ease;
    }

    html:not(.touch-nav) .sidebar:hover,
    .sidebar:focus-within,
    .sidebar.is-open {
        width: var(--shell-sidebar-width);
        min-width: var(--shell-sidebar-width);
    }

    .sidebar .nav-label {
        opacity: 0;
        max-width: 0;
        flex: 0 0 0;
        overflow: hidden;
        white-space: nowrap;
        pointer-events: none;
        transition: opacity 0.16s ease, max-width 0.22s ease;
    }

    html:not(.touch-nav) .sidebar:hover .nav-label,
    .sidebar:focus-within .nav-label,
    .sidebar.is-open .nav-label {
        opacity: 1;
        max-width: 220px;
        flex: 1 1 auto;
        pointer-events: auto;
    }

    .sidebar .nav-item {
        justify-content: center;
        align-items: center;
        gap: 0;
        min-height: 44px;
        padding: 6px 8px;
    }

    html:not(.touch-nav) .sidebar:hover .nav-item,
    .sidebar:focus-within .nav-item,
    .sidebar.is-open .nav-item {
        justify-content: flex-start;
        gap: 12px;
        padding-left: 12px;
        padding-right: 12px;
    }

    .sidebar .nav-menu {
        padding: 10px 8px 12px;
    }

    .sidebar .nav-title {
        height: 0;
        padding: 0;
        margin: 0;
        overflow: hidden;
        opacity: 0;
    }

    .sidebar .nav-section + .nav-section {
        margin-top: 6px;
        padding-top: 6px;
    }

    .sidebar .sidebar-brand {
        padding: 14px 10px 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 56px;
        box-sizing: border-box;
    }

    html:not(.touch-nav) .sidebar:hover .sidebar-brand,
    .sidebar:focus-within .sidebar-brand,
    .sidebar.is-open .sidebar-brand {
        justify-content: flex-start;
        padding-left: 12px;
        padding-right: 12px;
    }

    .sidebar .brand-link {
        flex-direction: row;
        align-items: center;
        gap: 10px;
        min-height: 40px;
    }

    .sidebar .brand-logo-wrap {
        width: 40px;
        height: 40px;
        max-width: 40px;
        object-fit: contain;
        flex-shrink: 0;
    }

    .sidebar .portal-logo {
        width: 36px;
        height: 36px;
        max-width: 36px;
        object-fit: contain;
        flex-shrink: 0;
    }

    html:not(.touch-nav) .sidebar:hover .portal-logo,
    .sidebar:focus-within .portal-logo,
    .sidebar.is-open .portal-logo {
        width: 44px;
        height: 44px;
        max-width: 44px;
    }

    .sidebar .brand-text,
    .sidebar .sidebar-footer {
        display: none;
    }

    .sidebar .brand-role {
        display: none;
        white-space: nowrap;
        font-size: 0.7rem;
        color: rgba(255, 255, 255, 0.78);
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.08em;
    }

    html:not(.touch-nav) .sidebar:hover .brand-role,
    .sidebar:focus-within .brand-role,
    .sidebar.is-open .brand-role {
        display: inline;
    }
}

/* ── Main area ── */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--shell-bg);
}

.top-header {
    height: var(--shell-header-height);
    min-height: var(--shell-header-height);
    background: var(--shell-surface);
    border-bottom: 1px solid var(--shell-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    box-shadow: var(--shell-shadow);
    gap: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.page-title-wrap h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--shell-text);
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-title-wrap p {
    font-size: 0.75rem;
    color: var(--shell-text-muted);
    margin-top: 1px;
}

.header-badges {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.chat-badge {
    display: none;
    align-items: center;
    gap: 6px;
    background: #fef2f2;
    color: var(--shell-danger);
    border: 1px solid #fecaca;
    padding: 6px 14px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.75rem;
    white-space: nowrap;
    animation: badge-pulse 2.5s ease-in-out infinite;
    cursor: pointer;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
}

.chat-badge:hover {
    background: #fee2e2;
    border-color: #fca5a5;
}

.chat-badge.approval-badge {
    background: #fff7ed;
    color: #c2410c;
    border-color: #fed7aa;
}

.chat-badge.approval-badge::before {
    background: #ea580c;
}

.chat-badge::before {
    content: '';
    width: 7px;
    height: 7px;
    background: var(--shell-danger);
    border-radius: 50%;
    flex-shrink: 0;
}

@keyframes badge-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.user-chip {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 6px 14px 6px 8px;
    background: #f8fafc;
    border: 1px solid var(--shell-border);
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--shell-text-muted);
}

.user-chip.is-visible { display: flex; }

.role-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1e3a8a;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.role-badge.is-trainer {
    background: #d1fae5;
    color: #047857;
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--shell-primary-mid), var(--shell-primary-light));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
}

.logout-btn {
    background: transparent;
    color: var(--shell-danger);
    border: 1px solid #fecaca;
    padding: 8px 18px;
    border-radius: var(--shell-radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.logout-btn:hover {
    background: var(--shell-danger);
    color: white;
    border-color: var(--shell-danger);
}

.content-area {
    flex: 1;
    min-height: 0;
    position: relative;
    background: var(--shell-bg);
}

.content-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: var(--shell-bg);
}

/* Loading overlay while auth + first module boot */
#authLoading {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(ellipse 80% 60% at 50% 0%, rgba(42, 107, 160, 0.18), transparent 58%),
        linear-gradient(180deg, #0a1f33 0%, #0f2d4a 55%, #10263a 100%);
    z-index: 200;
    transition: opacity 0.32s ease, visibility 0.32s ease;
}

#authLoading.is-leaving {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#authLoading.hidden { display: none; }

.boot-card {
    width: min(420px, 100%);
    color: #e8eef4;
}

.boot-logo {
    display: block;
    width: 112px;
    height: auto;
    margin-bottom: 18px;
    border-radius: 14px;
}

.boot-kicker {
    margin: 0 0 6px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #7dd3fc;
}

.boot-title {
    margin: 0 0 18px;
    font-size: 1.45rem;
    letter-spacing: -0.03em;
    color: #fff;
}

.boot-mods {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
    display: grid;
    gap: 8px;
}

.boot-mods li {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 28px;
    font-size: 0.92rem;
    font-weight: 600;
    color: rgba(226, 232, 240, 0.42);
    transition: color 0.25s ease;
}

.boot-mods li.is-on { color: #fff; }
.boot-mods li.is-done { color: #9fd4c8; }

.boot-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(226, 232, 240, 0.28);
    flex-shrink: 0;
    position: relative;
}

.boot-mods li.is-on .boot-dot {
    border-color: #38bdf8;
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.16);
}

.boot-mods li.is-on .boot-dot::after {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: #38bdf8;
    animation: boot-pulse 0.9s ease-in-out infinite;
}

.boot-mods li.is-done .boot-dot {
    border-color: #34d399;
    background: #34d399;
}

.boot-mods li.is-done .boot-dot::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 2px;
    width: 5px;
    height: 8px;
    border: solid #0f2d4a;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    animation: none;
    inset: auto;
    background: none;
    border-radius: 0;
}

.boot-hint {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.45;
    color: rgba(226, 232, 240, 0.55);
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--shell-border);
    border-top-color: var(--shell-primary-mid);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes boot-pulse {
    0%, 100% { transform: scale(0.72); opacity: 0.45; }
    50% { transform: scale(1); opacity: 1; }
}

.loading-text {
    font-size: 0.875rem;
    color: var(--shell-text-muted);
    font-weight: 500;
}

/* ── Mobile controls (hidden on desktop) ── */
.menu-toggle,
.sidebar-close-btn,
.sidebar-backdrop {
    display: none;
}

.menu-toggle {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    background: #f8fafc;
    border: 1px solid var(--shell-border);
    border-radius: 10px;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
}

.menu-toggle-bar {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--shell-primary);
    border-radius: 2px;
}

.sidebar-close-btn {
    position: absolute;
    top: 16px;
    right: 12px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    border-radius: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 45, 74, 0.45);
    z-index: 40;
    border: none;
    padding: 0;
    cursor: pointer;
}

/* ── Mobile layout (desktop unchanged above 900px) ── */
@media (max-width: 900px) {
    body {
        height: 100dvh;
        height: 100vh;
    }

    body.nav-open {
        overflow: hidden;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .sidebar-close-btn {
        display: inline-flex;
    }

    .sidebar-backdrop {
        display: none;
    }

    body.nav-open .sidebar-backdrop {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(300px, 86vw);
        min-width: 0;
        z-index: 50;
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        box-shadow: none;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    body.nav-open .sidebar {
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.28);
    }

    .sidebar-brand {
        position: relative;
        padding-right: 52px;
    }

    .main-wrapper {
        width: 100%;
    }

    .top-header {
        height: auto;
        min-height: var(--shell-header-height);
        padding: 10px 14px;
        padding-top: max(10px, env(safe-area-inset-top));
        gap: 10px;
        flex-wrap: wrap;
    }

    .header-left {
        flex: 1;
        min-width: 0;
        gap: 10px;
    }

    .page-title-wrap h2 {
        font-size: 0.95rem;
    }

    .page-title-wrap p {
        display: none;
    }

    .chat-badge {
        padding: 5px 10px;
        font-size: 0.7rem;
        max-width: 100%;
    }

    .header-right {
        gap: 8px;
    }

    .user-chip span {
        display: none;
    }

    .user-chip {
        padding: 4px;
        border-radius: 50%;
    }

    .logout-btn {
        padding: 8px 12px;
        font-size: 0.75rem;
    }

    .content-area {
        /* leave room for iOS home indicator in standalone PWA */
        padding-bottom: env(safe-area-inset-bottom);
    }
}

@media (max-width: 480px) {
    .top-header {
        padding-left: 12px;
        padding-right: 12px;
    }

    .logout-btn {
        padding: 8px 10px;
    }
}

html.is-pwa body {
    height: 100dvh;
}

html.is-pwa .sidebar {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

html.is-pwa .top-header {
    padding-top: max(10px, env(safe-area-inset-top));
}

html.is-pwa .content-area {
    padding-bottom: env(safe-area-inset-bottom);
}
