@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ═══════════════ App Shell Layout ═══════════════ */
body {
    font-family: var(--font-family);
    margin: 0;
    min-height: 100vh;
}

.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: 14.5rem;
    flex-shrink: 0;
    background: var(--color-bg-surface);
    border-right: 1px solid var(--pico-muted-border-color);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 50;
    transition: transform 0.25s ease;
}
.sidebar-nav { flex: 1; min-height: 0; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .9rem 1.1rem .5rem;
    text-decoration: none;
    font-weight: 800;
    font-size: 1rem;
    color: var(--color-text);
}
.sidebar-brand .logo {
    width: 2rem; height: 2rem;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--color-brand), var(--color-brand-bright));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.05rem;
    box-shadow: 0 4px 14px rgba(139, 124, 246, 0.4);
}

.nav-group { padding: .15rem .65rem; }
.nav-group-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    padding: .55rem .5rem .2rem;
    font-family: var(--font-family);
}
.nav-group-toggle:hover { color: var(--color-text); }
.nav-group-toggle .chev {
    transition: transform .2s ease;
    font-size: .7rem;
}
.nav-group.expanded .nav-group-toggle .chev { transform: rotate(180deg); }

/* minor tabs collapse under the major tab */
.nav-group-items {
    display: none;
    flex-direction: column;
    gap: 1px;
}
.nav-group.expanded .nav-group-items { display: flex; }

.nav-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .42rem .6rem;
    border-radius: 9px;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: .88rem;
    font-weight: 500;
    transition: all .15s ease;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(139, 124, 246, 0.12); color: var(--color-text); }
.nav-item.active {
    background: linear-gradient(90deg, rgba(139,124,246,.22), rgba(139,124,246,.06));
    color: var(--color-brand-bright);
    border-left-color: var(--color-brand);
    font-weight: 600;
}
[data-theme='contrast'] .nav-item.active { background: #333; color: #ffd400; border-left-color: #ffd400; }
.nav-icon { width: 1.25rem; text-align: center; font-size: 1rem; }

.sos-btn {
    margin: .6rem .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .55rem;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--color-danger), #ff8090);
    color: #fff !important;
    font-weight: 700;
    font-size: .9rem;
    text-decoration: none;
    box-shadow: 0 4px 16px rgba(251, 91, 107, 0.35);
    transition: transform .15s ease, box-shadow .15s ease;
}
.sos-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(251, 91, 107, 0.5); }

.sidebar-footer {
    padding: .65rem;
    border-top: 1px solid var(--pico-muted-border-color);
    font-size: .74rem;
    color: var(--color-text-muted);
    text-align: center;
}
.sidebar-footer a { color: var(--color-brand-bright); text-decoration: none; }

/* keep everything visible on short screens */
@media (max-height: 700px) {
    .sidebar-brand { padding: .6rem 1rem .3rem; }
    .nav-item { padding: .32rem .6rem; }
    .nav-group-toggle { padding: .4rem .5rem .15rem; }
    .sos-btn { margin: .45rem .65rem; padding: .45rem; }
}

/* ── Main column ── */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .7rem 1.5rem;
    background: color-mix(in srgb, var(--color-bg-primary) 85%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--pico-muted-border-color);
}
.hamburger {
    display: none;
    background: transparent;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 8px;
    font-size: 1.1rem;
    padding: .25rem .6rem;
    cursor: pointer;
    color: var(--color-text);
}
.page-title { font-size: 1.05rem; font-weight: 700; margin: 0; flex: 1; }

.theme-switcher { display: flex; gap: .25rem; background: var(--color-bg-surface); border-radius: 999px; padding: .2rem; border: 1px solid var(--pico-muted-border-color); }
.theme-switcher button {
    background: transparent; border: none; cursor: pointer;
    font-size: .95rem; padding: .2rem .55rem; border-radius: 999px;
    filter: grayscale(60%); opacity: .6; transition: all .15s ease;
}
.theme-switcher button.active { background: var(--color-brand); filter: none; opacity: 1; }

.avatar-chip {
    display: flex; align-items: center; gap: .45rem;
    text-decoration: none; color: var(--color-text);
    font-size: .88rem; font-weight: 600;
}
.avatar-circle {
    width: 2rem; height: 2rem; border-radius: 50%;
    background: linear-gradient(135deg, var(--color-brand), var(--color-brand-bright));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .9rem;
}

.content { padding: 1.5rem; max-width: 68rem; width: 100%; margin: 0 auto; }

/* ── Page transitions ── */
@keyframes pageEnter {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.page-enter { animation: pageEnter .35s ease both; }
@media (prefers-reduced-motion: reduce) {
    .page-enter { animation: none; }
    * { transition-duration: 0s !important; }
}

/* staggered card entrance */
.page-enter > * { animation: pageEnter .4s ease both; }
.page-enter > *:nth-child(2) { animation-delay: .05s; }
.page-enter > *:nth-child(3) { animation-delay: .1s; }
.page-enter > *:nth-child(4) { animation-delay: .15s; }
.page-enter > *:nth-child(5) { animation-delay: .2s; }

main.container { max-width: 68rem !important; width: auto !important; }

/* ── Cards & polish ── */
.card {
    background: var(--color-bg-surface);
    border-radius: var(--radius-card);
    padding: var(--space-card);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--pico-muted-border-color);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    margin-bottom: 1rem;
}
.card:hover { box-shadow: var(--shadow-card-hover); transform: translateY(-2px); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; }

/* ── Subtabs (Trackers: major → Mood / Sleep minor tabs) ── */
.subtabs {
    display: inline-flex;
    gap: .35rem;
    background: var(--color-bg-surface);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 999px;
    padding: .25rem;
    margin-bottom: 1.25rem;
}
.subtab {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: .45rem 1rem;
    border-radius: 999px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--color-text-muted);
    transition: all .15s ease;
}
.subtab:hover { color: var(--color-text); }
.subtab.active {
    background: var(--color-brand);
    color: #fff;
    box-shadow: 0 2px 10px rgba(139,124,246,.35);
}

.hero-welcome {
    background: linear-gradient(120deg, var(--color-brand) 0%, #b39dfc 100%);
    border-radius: 16px;
    color: #fff;
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 8px 28px rgba(139, 124, 246, 0.35);
}
.hero-welcome h1 { color: #fff; margin: 0 0 .25rem; font-size: 1.5rem; }
.hero-welcome p { color: rgba(255,255,255,.9); margin: 0; }

.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--color-brand-bright); }

/* accent-tinted cards — each stat gets its own hue */
.accent-card { border-top: 3px solid var(--accent, var(--color-brand)); }
.accent-card .stat-value { color: var(--accent, var(--color-brand)); }
.accent-violet { --accent: var(--color-brand); }
.accent-teal   { --accent: var(--color-accent-teal); }
.accent-coral  { --accent: var(--color-accent-coral); }
.accent-amber  { --accent: var(--color-warning); }
.accent-mint   { --accent: var(--color-success); }

.card h3 { display: flex; align-items: center; gap: .45rem; }

/* ── badges / mood grid / alerts (unchanged semantics) ── */
.badge {
    display: inline-flex; align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-badge);
    font-weight: 700; font-size: 0.8rem; color: #fff;
}
.badge.high { background: var(--color-danger); }
.badge.moderate { background: var(--color-warning); color: #1a1a2e; }
.badge.low { background: #ffd166; color: #1a1a2e; }
.badge.none { background: var(--color-success); color: #1a1a2e; }

.mood-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: 0.5rem; }
.mood-btn {
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--radius-card);
    background: transparent; color: var(--color-text);
    padding: 0.6rem 0.4rem; cursor: pointer; font-size: 0.85rem;
    transition: all 0.15s ease;
}
.mood-btn:hover { border-color: var(--color-brand); transform: translateY(-1px); }
.mood-btn.selected { background: var(--color-brand); border-color: var(--color-brand); color: #fff; font-weight: 600; }

.crisis-alert {
    background: rgba(251, 91, 107, 0.12);
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-card);
    padding: 1rem;
    margin-bottom: 1rem;
}

.text-muted { color: var(--color-text-muted); }

footer.page-footer { text-align: center; padding: 2rem 1rem; font-size: 0.85rem; }
footer.page-footer a { color: var(--color-text-muted); }

/* ── Mobile ── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.5); }
    .hamburger { display: block; }
    .sidebar-backdrop {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 45;
    }
    .sidebar-backdrop.show { display: block; }
    .content { padding: 1rem; }
}

/* ── UX polish ── */
body {
    transition: background-color .3s ease, color .3s ease;
}

:focus-visible {
    outline: 2px solid var(--color-brand-bright);
    outline-offset: 2px;
    border-radius: 6px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--color-brand) 45%, transparent);
    border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--color-brand); }

button, [role='button'], a[role='button'] {
    transition: transform .12s ease, box-shadow .12s ease, background-color .2s ease !important;
}
button:hover, a[role='button']:hover { transform: translateY(-1px); }
button:active, a[role='button']:active { transform: translateY(0); }

input, select, textarea {
    transition: border-color .2s ease, box-shadow .2s ease;
}
input:focus, select:focus, textarea:focus {
    box-shadow: 0 0 0 3px rgba(139, 124, 246, 0.18) !important;
}

details.card > summary {
    cursor: pointer;
    font-weight: 600;
    list-style-position: outside;
}
details.card[open] > summary { margin-bottom: .5rem; }

@media print {
    .sidebar, .topbar, footer.page-footer { display: none !important; }
}
