/* ============================================================
   Aethyra Consulting Group — Portal Design System
   Phase 4: Responsive — Desktop web + Mobile PWA
   ============================================================ */

:root {
    --bg:           #0B1120;
    --surface:      #131B2E;
    --card:         #1A2540;
    --card-hover:   #1E2D4D;
    --accent:       #3B82F6;
    --accent-glow:  rgba(59, 130, 246, 0.25);
    --accent-light: rgba(59, 130, 246, 0.12);
    --success:      #10B981;
    --warning:      #F59E0B;
    --danger:       #EF4444;
    --purple:       #A78BFA;
    --text:         #E8ECF4;
    --text-muted:   #8896B3;
    --text-dim:     #5A6A8A;
    --border:       #1E2D4D;
    --gradient:     linear-gradient(135deg, #3B82F6 0%, #6366F1 100%);
    --radius-sm:    8px;
    --radius-md:    12px;
    --radius-lg:    16px;
    --radius-xl:    20px;
    --shadow:       0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-glow:  0 4px 20px var(--accent-glow);
    --content-max:  960px;
    --content-pad:  24px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ─── PWA SAFE AREAS ─── */
body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ─── APP SHELL ─── */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ─── HEADER ─── */
.app-header {
    padding: 16px var(--content-pad) 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

/* Desktop: center header content */
@media (min-width: 768px) {
    .app-header {
        padding: 16px 40px 12px;
    }
    .app-header-inner {
        max-width: var(--content-max);
        margin: 0 auto;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}

/* ─── CONTENT ─── */
.app-content {
    flex: 1;
    padding-bottom: 80px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Desktop: center content with max-width */
@media (min-width: 768px) {
    .app-content {
        max-width: var(--content-max);
        margin: 0 auto;
        width: 100%;
        padding-bottom: 40px;
    }
}

/* ─── BOTTOM NAV (mobile only) ─── */
.app-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    padding: 10px 0 calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
}

/* Desktop: convert to horizontal top nav or hide */
@media (min-width: 768px) {
    .app-nav {
        position: static;
        max-width: var(--content-max);
        margin: 0 auto;
        width: 100%;
        justify-content: flex-start;
        gap: 4px;
        padding: 0 var(--content-pad) 0;
        background: var(--bg);
        border-top: none;
        border-bottom: 1px solid var(--border);
    }
    .app-content {
        padding-bottom: 40px;
    }
}

.nav-item {
    text-align: center;
    cursor: pointer;
    padding: 4px 12px;
    flex: 1;
    text-decoration: none;
    transition: all 0.2s;
    border-radius: var(--radius-sm);
}

@media (min-width: 768px) {
    .nav-item {
        flex: none;
        padding: 12px 18px;
        display: flex;
        align-items: center;
        gap: 8px;
    }
}

.nav-item svg {
    width: 22px;
    height: 22px;
    display: block;
    margin: 0 auto 3px;
    stroke: var(--text-dim);
    fill: none;
    stroke-width: 2;
}

@media (min-width: 768px) {
    .nav-item svg {
        width: 18px;
        height: 18px;
        margin: 0;
    }
}

.nav-item.active svg { stroke: var(--accent); }

.nav-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
}

@media (min-width: 768px) {
    .nav-label {
        font-size: 13px;
        font-weight: 500;
    }
}

.nav-item.active .nav-label { color: var(--accent); }

@media (min-width: 768px) {
    .nav-item:hover {
        background: rgba(255,255,255,0.04);
    }
    .nav-item.active {
        background: var(--accent-light);
    }
}

/* ─── LOGO ─── */
.logo { height: 32px; width: auto; }
.logo-lg { height: 48px; }
@media (min-width: 768px) {
    .logo { height: 38px; }
}

/* ─── TYPOGRAPHY ─── */
.page-title { font-size: 20px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 12px; color: var(--text-muted); }

@media (min-width: 768px) {
    .page-title { font-size: 26px; }
    .page-subtitle { font-size: 14px; }
}

.section-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 0 20px;
}

@media (min-width: 768px) {
    .section-label { padding: 0 var(--content-pad); }
}

/* ─── CARDS ─── */
.card {
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 16px;
    margin: 0 20px 10px;
    transition: background 0.2s;
}

@media (min-width: 768px) {
    .card {
        margin: 0 var(--content-pad) 12px;
        padding: 20px 24px;
        border-radius: var(--radius-xl);
    }
    .card:hover {
        border-color: rgba(59,130,246,0.2);
    }
}

.card:active { background: var(--card-hover); }
@media (min-width: 768px) { .card:active { background: var(--card); } }

.card-featured {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
}

@media (min-width: 768px) {
    .card-featured { padding: 24px 28px; gap: 24px; }
}

/* ─── PROGRESS BAR ─── */
.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

@media (min-width: 768px) { .progress-bar { height: 6px; border-radius: 3px; } }

.progress-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--gradient);
    transition: width 0.6s ease;
}

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

/* ─── BADGES ─── */
.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    letter-spacing: 0.3px;
}

@media (min-width: 768px) { .badge { font-size: 12px; padding: 3px 10px; } }

.badge-accent  { background: var(--accent-light); color: var(--accent); }
.badge-success { background: rgba(16,185,129,0.13); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.13); color: var(--warning); }
.badge-danger  { background: rgba(239,68,68,0.13); color: var(--danger); }
.badge-purple  { background: rgba(167,139,250,0.13); color: var(--purple); }
.badge-dim     { background: rgba(90,106,138,0.13); color: var(--text-dim); }

/* ─── BUTTONS ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient);
    color: #fff;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.97); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn-success { background: rgba(16,185,129,0.13); color: var(--success); }
.btn-success:hover { background: rgba(16,185,129,0.22); }
.btn-danger { background: rgba(239,68,68,0.13); color: var(--danger); }
.btn-danger:hover { background: rgba(239,68,68,0.22); }
.btn-block { display: flex; width: 100%; text-align: center; }

/* ─── FORMS ─── */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-input-wrap {
    background: var(--card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: border-color 0.2s;
}

.form-input-wrap:focus-within { border-color: var(--accent); }

.form-input-wrap svg {
    width: 18px; height: 18px;
    stroke: var(--text-dim); fill: none; stroke-width: 2; flex-shrink: 0;
}

.form-input {
    background: none; border: none; outline: none;
    color: var(--text); font-size: 14px; font-family: inherit; flex: 1; width: 100%;
}

.form-input::placeholder { color: var(--text-dim); }
textarea.form-input { resize: vertical; min-height: 80px; line-height: 1.5; }
select.form-input { appearance: none; -webkit-appearance: none; }
.form-error { color: var(--danger); font-size: 13px; text-align: center; margin-bottom: 12px; }

/* ─── QUICK ACTION GRID ─── */
.action-grid {
    display: grid;
    gap: 10px;
    padding: 0 20px;
    margin-bottom: 16px;
}

@media (min-width: 768px) {
    .action-grid { padding: 0 var(--content-pad); gap: 12px; }
}

.action-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.action-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.action-tile {
    background: var(--card);
    border-radius: var(--radius-md);
    padding: 18px 10px;
    text-align: center;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all 0.2s;
    text-decoration: none;
}

.action-tile:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.action-tile:active { transform: scale(0.97); }

.action-tile svg {
    width: 24px; height: 24px; display: block; margin: 0 auto 8px;
    stroke: var(--accent); fill: none; stroke-width: 2;
}

.action-tile-label { font-size: 12px; font-weight: 600; color: var(--text); }

@media (min-width: 768px) {
    .action-tile { padding: 24px 16px; border-radius: var(--radius-lg); }
    .action-tile svg { width: 28px; height: 28px; margin-bottom: 10px; }
    .action-tile-label { font-size: 14px; }
}

/* ─── STAT CARDS ─── */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 0 20px;
    margin-bottom: 16px;
}

@media (min-width: 768px) {
    .stat-grid {
        grid-template-columns: 1fr 1fr 1fr 1fr;
        padding: 0 var(--content-pad);
        gap: 12px;
    }
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 16px;
}

@media (min-width: 768px) {
    .stat-card { padding: 20px; }
}

.stat-value { font-size: 22px; font-weight: 700; color: var(--text); margin-top: 10px; }
.stat-label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

@media (min-width: 768px) {
    .stat-value { font-size: 28px; }
    .stat-label { font-size: 13px; }
}

/* ─── LIST ITEMS ─── */
.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 14px 16px;
    margin: 0 20px 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: var(--text);
}

@media (min-width: 768px) {
    .list-item {
        margin: 0 var(--content-pad) 8px;
        padding: 16px 20px;
    }
    .list-item:hover {
        border-color: rgba(59,130,246,0.2);
        transform: translateX(4px);
    }
}

.list-item-title { font-size: 14px; font-weight: 500; color: var(--text); }
.list-item-sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.list-item-meta { font-size: 12px; color: var(--text-dim); white-space: nowrap; margin-left: 12px; text-align: right; }

/* ─── PAGE HEADER ─── */
.page-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

@media (min-width: 768px) {
    .page-header { padding: 20px var(--content-pad); }
}

.page-header-split { justify-content: space-between; }
.page-header-left { display: flex; align-items: center; gap: 12px; }

.back-btn { cursor: pointer; padding: 4px; display: flex; }
.back-btn svg { width: 20px; height: 20px; stroke: var(--text); fill: none; stroke-width: 2; }

/* ─── NOTIFICATION DOT ─── */
.notif-dot {
    position: absolute; top: -2px; right: -2px; width: 8px; height: 8px;
    border-radius: 4px; background: var(--danger); border: 2px solid var(--surface);
}

/* ─── TIMELINE ─── */
.timeline-step { display: flex; align-items: center; gap: 12px; margin: 0 20px 8px; }
@media (min-width: 768px) { .timeline-step { margin: 0 var(--content-pad) 8px; } }

.timeline-dot {
    width: 24px; height: 24px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.timeline-dot.done    { background: var(--success); }
.timeline-dot.active  { background: rgba(59,130,246,0.2); border: 2px solid var(--accent); }
.timeline-dot.upcoming { background: var(--border); }
.timeline-dot svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 2.5; }

.timeline-card {
    flex: 1; background: var(--card); border-radius: 10px;
    padding: 12px 14px; border: 1px solid var(--border);
}
.timeline-card.active { border-color: rgba(59,130,246,0.27); }
.timeline-card-title { font-size: 14px; font-weight: 500; color: var(--text); }
.timeline-card.upcoming .timeline-card-title { color: var(--text-dim); }

/* ─── AVATAR ─── */
.avatar {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--gradient); display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; color: #fff; flex-shrink: 0; cursor: pointer;
}

@media (min-width: 768px) {
    .avatar { width: 40px; height: 40px; font-size: 16px; }
}

/* ─── SPINNER ─── */
.spinner {
    width: 24px; height: 24px; border: 3px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── TOAST ─── */
.toast {
    position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%;
    transform: translateX(-50%) translateY(-120%);
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 20px;
    font-size: 14px; font-weight: 500; color: var(--text);
    z-index: 1000; box-shadow: var(--shadow);
    transition: transform 0.3s ease; max-width: calc(100vw - 40px);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ─── UTILITIES ─── */
.px-20 { padding-left: 20px; padding-right: 20px; }
@media (min-width: 768px) { .px-20 { padding-left: var(--content-pad); padding-right: var(--content-pad); } }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.hidden { display: none !important; }

/* ─── DESKTOP LAYOUT REFLOW ─── */
@media (min-width: 768px) {
    /* Use top nav instead of bottom nav — reorder DOM visually */
    .app-shell {
        display: flex;
        flex-direction: column;
    }

    /* Two-column layout for dashboard grids */
    .dashboard-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        padding: 0 var(--content-pad);
    }

    .dashboard-grid > .card { margin: 0; }
}

/* ─── DESKTOP FOOTER ─── */
@media (min-width: 768px) {
    .app-footer {
        text-align: center;
        padding: 24px;
        color: var(--text-dim);
        font-size: 12px;
        border-top: 1px solid var(--border);
        margin-top: auto;
    }
}
