/* ============================================
   DataLink Training Portal v01 — Layout
   Top nav (PC) + bottom tabs (iPad/mobile)
   Glass morphism background on desktop
   ============================================ */

/* ---- App Shell ---- */

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* dvh excludes the mobile URL bar + on-screen keyboard so
                       the chat composer stays on-screen on phones; 100vh above
                       is the fallback for browsers without dvh support. */
    overflow: hidden;
    color: var(--text-primary);
}

/* ---- Glass Morphism Background (PC only) ---- */

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--surface-primary);
}

/* Gradient mesh — visible behind the frosted content panel */
@media (min-width: 1025px) {
    .app-body {
        background:
            radial-gradient(ellipse at 15% 10%, var(--glass-mesh-1) 0%, transparent 50%),
            radial-gradient(ellipse at 85% 80%, var(--glass-mesh-2) 0%, transparent 50%),
            radial-gradient(ellipse at 50% 50%, var(--glass-mesh-3) 0%, transparent 60%),
            var(--bg-base, #0c0c0e);
    }
}

/* ---- Header ---- */

.header {
    display: flex;
    align-items: center;
    height: 56px;
    padding: 0 24px;
    background: var(--glass-header-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--glass-header-border);
    flex-shrink: 0;
    z-index: 100;
    position: relative;
    gap: 8px;
}

/* Subtle bottom glow line */
.header::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--glass-header-glow) 30%, var(--glass-header-glow) 70%, transparent 100%);
    pointer-events: none;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.header-title {
    font-weight: 700;
    font-size: 16px;
    color: var(--accent, #00d26a);
}

.header-subtitle {
    font-size: 14px;
    color: var(--glass-user-role);
    font-weight: 500;
}

/* ---- Brand lockup (ui-v2 2026-06-10) ---- */

.brand-mark {
    flex-shrink: 0;
    transition: filter var(--duration-normal, 200ms) ease;
}

/* Soft accent halo behind the mark — dark theme only; on white it just
   blurs the edges. */
:root .brand-mark {
    filter: drop-shadow(0 0 7px var(--accent-glow, rgba(0, 210, 106, 0.35)));
}

[data-theme="light"] .brand-mark {
    filter: none;
}

.header-brand:hover .brand-mark {
    filter: drop-shadow(0 0 11px var(--accent-glow, rgba(0, 210, 106, 0.5)));
}

[data-theme="light"] .header-brand:hover .brand-mark {
    filter: drop-shadow(0 0 6px rgba(0, 165, 84, 0.3));
}

.brand-lockup {
    display: flex;
    flex-direction: column;
    line-height: 1.05;
    gap: 1px;
}

.brand-overline {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--text-muted, #888);
}

.brand-word {
    font-family: var(--font-display, 'Outfit', sans-serif);
    font-weight: 700;
    font-size: 18px;
    letter-spacing: var(--tracking-display, -0.02em);
    color: var(--text-primary);
}

.brand-word-accent {
    color: var(--accent);
}

.header-version {
    font-size: 11px;
    color: var(--text-tertiary);
    background: var(--surface-tertiary);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
}

/* ---- Header Nav (Desktop — replaces sidebar) ---- */

.header-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.header-nav .nav-item {
    padding: 6px 16px;
    border-radius: 8px;
    color: var(--glass-nav-text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
    border: 1px solid transparent;
}

.header-nav .nav-item:hover {
    color: var(--glass-nav-hover-text);
    background: var(--glass-nav-hover-bg);
}

.header-nav .nav-item.active {
    color: var(--text-primary);
    background: var(--glass-nav-active-bg);
    border-color: var(--glass-nav-active-border);
}

/* Active underline indicator */
.header-nav .nav-item.active::after {
    content: '';
    position: absolute;
    bottom: -10px; left: 16px; right: 16px;
    height: 2px;
    border-radius: 2px 2px 0 0;
    background: var(--accent, #00d26a);
    box-shadow: 0 0 8px rgba(0, 210, 106, 0.3);
}

.header-spacer {
    flex: 1;
}

/* ---- Header Nav Dropdown ---- */

.nav-dropdown {
    position: relative;
    display: inline-block;
}

.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    /* 14px clears the header's bottom border + glow line (the trigger's
       box ends ~10px above the header edge; 6px left the panel's top
       tucked under the line, which drew straight across it). */
    margin-top: 14px;
    min-width: 180px;
    background: var(--glass-nav-active-bg, rgba(20, 20, 20, 0.95));
    border: 1px solid var(--glass-nav-active-border, rgba(0, 210, 106, 0.4));
    border-radius: 8px;
    padding: 4px;
    display: none;
    flex-direction: column;
    z-index: 100;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
}

/* Dark is the default theme (no data-theme attr); use pure black so the
   menu reads as a solid panel rather than the translucent glass surface
   used elsewhere. Light theme keeps the original glass treatment. */
:root .nav-dropdown-menu {
    background: #000;
    backdrop-filter: none;
}

[data-theme="light"] .nav-dropdown-menu {
    background: #fff;
    backdrop-filter: none;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
    display: flex;
}

/* Touch devices have no :hover, and iOS Safari won't reliably focus a <div>
   trigger on tap (so :focus-within can't be trusted). The inline handler in
   base.html toggles .is-open on tap for coarse-pointer devices; this mirrors
   the open state. Desktop never gets .is-open, so hover is untouched. */
.nav-dropdown.is-open > .nav-dropdown-menu {
    display: flex;
}

/* Primary nav (.header-nav) is hidden ≤1024px with no on-screen replacement;
   these links are surfaced inside the avatar dropdown so phone/tablet users
   keep full top-level navigation. Hidden on desktop, where header-nav shows. */
.nav-mobile-only {
    display: none;
}
@media (max-width: 1024px) {
    .nav-mobile-only {
        display: block;
    }
}
.nav-dd-sep {
    height: 1px;
    margin: 4px 6px;
    background: var(--border-primary, rgba(255, 255, 255, 0.12));
}

/* Invisible hover bridge across the margin-top gap between trigger and
   panel — without it the pointer drops :hover crossing the gap and the
   menu snaps shut (visible on small triggers like the gear icon). Height
   matches the 14px panel offset. */
.nav-dropdown-menu::before {
    content: "";
    position: absolute;
    top: -16px;
    left: 0;
    right: 0;
    height: 16px;
}

.nav-dropdown-menu a {
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--glass-nav-text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.nav-dropdown-menu a:hover {
    color: var(--text-primary);
    background: var(--glass-nav-hover-bg);
}

/* ---- Grouped Admin dropdown (sections + two-line items) ---- */

.nav-dropdown-menu-grouped {
    min-width: 340px;
    padding: 6px;
}

.nav-dropdown-group-label {
    padding: 10px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted, #888);
    border-top: 1px solid var(--glass-nav-active-border, rgba(0, 210, 106, 0.15));
    margin-top: 4px;
}

/* The first group label has no top border / margin (it's at the top of the
   menu, no preceding group to separate from). */
.nav-dropdown-menu-grouped > .nav-dropdown-group-label:first-child {
    border-top: none;
    margin-top: 0;
    padding-top: 4px;
}

.nav-dropdown-menu-grouped a {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 7px 12px;
    white-space: normal;
}

.nav-dropdown-menu-grouped .nav-dd-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--glass-nav-text);
}

.nav-dropdown-menu-grouped .nav-dd-desc {
    font-size: 11px;
    font-weight: 400;
    line-height: 1.3;
    color: var(--text-muted, #888);
}

.nav-dropdown-menu-grouped a:hover .nav-dd-title,
.nav-dropdown-menu-grouped a:hover .nav-dd-desc {
    color: var(--text-primary);
}

/* ---- Subcategory flyout dropdown (Admin menu, ui-v2 2026-06-10) ----
   The top panel is a compact list of category rows; hovering/focusing a
   row opens its pages in a flyout to the right. Replaces the flat
   grouped list, which had grown to a 15-item wall. */

.nav-dropdown-menu-sub {
    min-width: 170px;
    padding: 4px;
}

.nav-subgroup {
    position: relative;
}

.nav-subgroup-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--glass-nav-text);
    cursor: default;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.nav-subgroup:hover > .nav-subgroup-label,
.nav-subgroup:focus-within > .nav-subgroup-label {
    color: var(--text-primary);
    background: var(--glass-nav-hover-bg);
}

.nav-subgroup-arrow {
    font-size: 10px;
    color: var(--text-muted, #888);
}

.nav-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: -5px;              /* visually aligns first item with the row */
    min-width: 320px;
    background: #000;
    border: 1px solid var(--glass-nav-active-border, rgba(0, 210, 106, 0.4));
    border-radius: 8px;
    padding: 5px;
    flex-direction: column;
    z-index: 101;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] .nav-submenu {
    background: #fff;
}

.nav-subgroup:hover > .nav-submenu,
.nav-subgroup:focus-within > .nav-submenu {
    display: flex;
}

/* Flyout items reuse the two-line title+desc treatment. */
.nav-submenu a {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 7px 12px;
    border-radius: 6px;
    text-decoration: none;
    white-space: normal;
    transition: all 0.15s ease;
}

.nav-submenu a:hover {
    background: var(--glass-nav-hover-bg);
}

.nav-submenu .nav-dd-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--glass-nav-text);
}

.nav-submenu .nav-dd-desc {
    font-size: 11px;
    font-weight: 400;
    line-height: 1.3;
    color: var(--text-muted, #888);
}

.nav-submenu a:hover .nav-dd-title,
.nav-submenu a:hover .nav-dd-desc {
    color: var(--text-primary);
}

/* Right-edge variant — used when the dropdown trigger lives in the
   header-actions cluster (far right of the header). Panel right-aligns
   under the trigger and flyouts open to the LEFT so nothing clips the
   viewport edge. */
.nav-dropdown-right .nav-dropdown-menu {
    left: auto;
    right: 0;
    transform: none;
}

.nav-dropdown-right .nav-submenu {
    left: auto;
    right: 100%;
}

/* ---- User Area (avatar + name) ---- */

.header-user-area {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 8px;
    padding: 4px 12px 4px 4px;
    border-radius: 10px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    cursor: default;
    flex-shrink: 0;
}

.header-user-area:hover {
    background: var(--glass-user-hover-bg);
    border-color: var(--glass-user-hover-border);
}

.header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--glass-avatar-bg);
    border: 1px solid var(--glass-avatar-border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.avatar-initials {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent, #00d26a);
    letter-spacing: 0.5px;
}

.avatar-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 9px;
}

.header-user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.header-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--glass-user-name);
}

.header-user-role {
    font-size: 10px;
    color: var(--glass-user-role);
    font-weight: 500;
}

.header-actions {
    display: flex;
    gap: 4px;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid transparent;
    background: none;
    color: var(--glass-icon-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* ---- Bottom Tab Bar (hidden on desktop) ---- */

.bottom-tabs {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--surface-secondary);
    border-top: 1px solid var(--border-primary);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 2px;
    color: var(--text-tertiary);
    text-decoration: none;
    font-size: 11px;
    min-height: 44px;
    transition: color var(--duration-fast);
}

.tab-item.active {
    color: var(--accent-primary);
}

.tab-icon {
    width: 22px;
    height: 22px;
}

.tab-label {
    font-weight: 500;
}

/* ---- Main Content ---- */

.main {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.main-inner {
    padding: 28px 32px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Frosted glass content panel on desktop */
@media (min-width: 1025px) {
    .main-inner {
        background: var(--glass-panel-bg);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid var(--glass-panel-border);
        border-radius: 16px;
        margin: 24px auto;
        box-shadow: var(--glass-panel-shadow);
    }
}

/* ---- View Common ---- */

.view-header {
    margin-bottom: 24px;
}

.view-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.view-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

.view-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 16px;
    color: var(--text-tertiary);
    text-align: center;
}

.view-empty-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

/* ---- Card Grid ---- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.card {
    background: var(--surface-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: 16px;
    transition: border-color var(--duration-fast);
}

.card:hover {
    border-color: var(--border-secondary);
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 4px;
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ---- Stats Row ---- */

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 12px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

/* ---- Tables ---- */

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-primary);
}

.data-table th {
    background: var(--surface-tertiary);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.data-table th:hover {
    color: var(--text-primary);
}

.data-table tbody tr:hover {
    background: var(--surface-tertiary);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ---- Progress Bar ---- */

.progress-bar {
    height: 8px;
    background: var(--surface-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
    background: var(--accent-primary);
}

.progress-fill.complete {
    background: var(--status-success);
}

/* ---- Buttons ---- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-fast);
    min-height: 36px;
}

.btn-primary {
    background: var(--accent-primary);
    color: #fff;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--surface-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-primary);
}

/* ---- Badge ---- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success { background: rgba(72, 187, 120, 0.15); color: #48bb78; }
.badge-warning { background: rgba(237, 137, 54, 0.15); color: #ed8936; }
.badge-info    { background: rgba(66, 153, 225, 0.15); color: #4299e1; }
.badge-danger  { background: rgba(245, 101, 101, 0.15); color: #f56565; }

/* ---- Loading ---- */

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--text-tertiary);
}

/* ============================================
   Responsive: iPad/Tablet (max-width: 1024px)
   Show bottom tabs, hide header nav
   ============================================ */

@media (max-width: 1024px) {
    .header-nav {
        display: none;
    }

    .bottom-tabs {
        display: flex;
    }

    .header-user-info {
        display: none;
    }

    .header-user-area {
        margin-right: 4px;
        padding: 0;
    }

    .main-inner {
        padding: 16px;
        padding-bottom: 80px; /* space for bottom tabs */
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .view-title {
        font-size: 20px;
    }

    /* Larger touch targets for buttons */
    .btn {
        min-height: 44px;
        padding: 10px 20px;
    }
}

/* ============================================
   Responsive: Mobile (max-width: 640px)
   ============================================ */

@media (max-width: 640px) {
    .header-subtitle,
    .brand-overline,
    .header-version {
        display: none;
    }

    .main-inner {
        padding: 12px;
        padding-bottom: 80px;
    }

    .stats-row {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-value {
        font-size: 22px;
    }

    .data-table {
        font-size: 13px;
    }

    .data-table th,
    .data-table td {
        padding: 8px 10px;
    }
}
