/* =====================================================================
 * Dashboard layout & components
 * ===================================================================== */

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    background: var(--ink);
    color: var(--paper);
    padding: 28px 20px;
    border-right: 1.5px solid var(--ink);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.sidebar .brand { color: var(--paper); }
.sidebar .brand__mark { background: var(--lime); color: var(--ink); }

.sidebar__group {
    display: flex; flex-direction: column; gap: 4px;
}
.sidebar__heading {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: rgba(244,241,234,0.45);
    padding: 0 14px 6px;
}

.sidebar__link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px;
    color: rgba(244,241,234,0.8);
    text-decoration: none;
    border-radius: var(--r-md);
    font-size: 0.94rem;
    transition: background .18s, color .18s, transform .18s;
    cursor: pointer;
    border: 1.5px solid transparent;
}
.sidebar__link:hover {
    background: rgba(216,255,62,0.08);
    color: var(--paper);
}
.sidebar__link.active {
    background: var(--lime);
    color: var(--ink);
    font-weight: 500;
    border-color: var(--lime);
    box-shadow: 3px 3px 0 rgba(216,255,62,0.25);
}
.sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar__user {
    margin-top: auto;
    padding: 14px;
    border: 1px solid rgba(244,241,234,0.15);
    border-radius: var(--r-md);
    display: flex; align-items: center; gap: 12px;
}
.sidebar__avatar {
    width: 36px; height: 36px;
    border-radius: 999px;
    background: var(--lime);
    color: var(--ink);
    display: grid; place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar__user-info { flex: 1; min-width: 0; }
.sidebar__user-name { font-size: 0.88rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-mail { font-size: 0.74rem; color: rgba(244,241,234,0.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar__logout {
    background: transparent;
    border: 1px solid rgba(244,241,234,0.2);
    color: var(--paper);
    border-radius: var(--r-sm);
    width: 32px; height: 32px;
    cursor: pointer;
    display: grid; place-items: center;
    transition: background .18s;
}
.sidebar__logout:hover { background: var(--clay); border-color: var(--clay); }

.sidebar__admin-badge {
    background: var(--clay);
    color: var(--bone);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: auto;
}

/* Main area */
.main {
    background: var(--bg);
    padding: 36px 44px 80px;
    min-width: 0;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1.5px solid var(--line);
}
.page-head h1 {
    font-size: clamp(2rem, 4vw, 3.2rem);
    font-weight: 800;
}
.page-head__sub {
    color: var(--fg-mute);
    margin-top: 6px;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 1.1rem;
}

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.stat-card {
    background: var(--bg-card);
    border: 1.5px solid var(--line);
    border-radius: var(--r-lg);
    padding: 22px;
    position: relative;
    overflow: hidden;
}
.stat-card__label {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--fg-mute);
}
.stat-card__value {
    font-family: var(--font-display);
    font-size: clamp(2rem, 3vw, 2.8rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-top: 4px;
    line-height: 1;
}
.stat-card__hint {
    font-size: 0.85rem;
    color: var(--fg-mute);
    margin-top: 8px;
}
.stat-card--accent {
    background: var(--lime);
    border-color: var(--ink);
    box-shadow: var(--shadow-hard);
    color: var(--ink);                 /* force ink in both themes */
}
.stat-card--accent .stat-card__label,
.stat-card--accent .stat-card__value,
.stat-card--accent .stat-card__hint { color: var(--ink) !important; }
.stat-card--accent .stat-card__hint  { color: rgba(11,11,10,0.65) !important; }

.stat-card--ink { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.stat-card--ink .stat-card__label, .stat-card--ink .stat-card__hint { color: rgba(244,241,234,0.65); }
.stat-card--clay { background: var(--clay); color: var(--bone); border-color: var(--clay); }
.stat-card--clay .stat-card__label, .stat-card--clay .stat-card__hint { color: rgba(255,254,249,0.75); }

/* Content grid */
.content-grid {
    display: grid;
    gap: 24px;
    grid-template-columns: 1fr;
}
@media (min-width: 1100px) {
    .content-grid--two { grid-template-columns: 2fr 1fr; }
    .content-grid--two-eq { grid-template-columns: 1fr 1fr; }
}

.section-card {
    background: var(--bg-card);
    border: 1.5px solid var(--line);
    border-radius: var(--r-lg);
    padding: 26px;
}
.section-card__head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}
.section-card__head h3 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
}

/* Subscription list */
.sub-list { display: flex; flex-direction: column; gap: 12px; }
.sub-item {
    display: grid;
    grid-template-columns: 48px 1fr auto auto;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1.5px solid var(--line-soft);
    border-radius: var(--r-md);
    transition: border-color .15s, transform .15s;
}
.sub-item:hover { border-color: var(--line); transform: translateX(2px); }
.sub-item__icon {
    width: 48px; height: 48px;
    border-radius: var(--r-md);
    display: grid; place-items: center;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--bone);
    flex-shrink: 0;
}
.sub-item__name { font-weight: 500; font-size: 1rem; }
.sub-item__meta { font-size: 0.82rem; color: var(--fg-mute); margin-top: 2px; }
.sub-item__price {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.2rem;
    text-align: right;
}
.sub-item__cycle { font-size: 0.75rem; color: var(--fg-mute); font-family: var(--font-mono); }
.sub-item__actions { display: flex; gap: 4px; }
.sub-item__action {
    background: transparent;
    border: 1px solid var(--line-soft);
    width: 32px; height: 32px;
    border-radius: var(--r-sm);
    cursor: pointer;
    display: grid; place-items: center;
    color: var(--fg);
    transition: background .15s, color .15s;
}
.sub-item__action:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.sub-item__action--danger:hover { background: var(--danger); border-color: var(--danger); }

/* Empty states */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--fg-mute);
}
.empty__title {
    font-family: var(--font-display);
    font-size: 1.4rem;
    color: var(--fg);
    margin-bottom: 8px;
    font-weight: 600;
}
.empty__sub { margin-bottom: 20px; max-width: 40ch; margin-inline: auto; }

/* Bar chart (CSS-only) */
.cat-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 0;
    border-bottom: 1px dashed var(--line-soft);
}
.cat-bar:last-child { border-bottom: 0; }
.cat-bar__name { width: 130px; font-size: 0.9rem; flex-shrink: 0; }
.cat-bar__track {
    flex: 1; height: 22px;
    background: var(--bg-alt);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    overflow: hidden;
}
.cat-bar__fill {
    height: 100%;
    transition: width .6s cubic-bezier(.2,.8,.2,1);
    border-right: 1.5px solid var(--ink);
}
.cat-bar__value {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.86rem;
    width: 90px;
    text-align: right;
    flex-shrink: 0;
}

/* Donut chart */
.donut-wrap { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.donut { width: 180px; height: 180px; flex-shrink: 0; }
.donut-legend { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 8px; }
.donut-legend__item { display: flex; align-items: center; gap: 10px; font-size: 0.88rem; }
.donut-legend__swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--ink); flex-shrink: 0; }

/* Mobile sidebar */
.mobile-bar {
    display: none;
    position: sticky; top: 0; z-index: 40;
    background: var(--bg);
    border-bottom: 1.5px solid var(--line);
    padding: 12px 18px;
    align-items: center; justify-content: space-between;
    gap: 12px;
}
.mobile-bar__menu {
    background: transparent; border: 1.5px solid var(--line);
    width: 40px; height: 40px; border-radius: var(--r-md);
    cursor: pointer; display: grid; place-items: center; color: var(--fg);
}

@media (max-width: 1000px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; left: -280px; top: 0; bottom: 0; width: 260px;
        z-index: 80; transition: left .25s;
    }
    .sidebar.open { left: 0; box-shadow: 6px 0 24px rgba(0,0,0,0.25); }
    .sidebar-backdrop {
        position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 70;
        display: none;
    }
    .sidebar-backdrop.show { display: block; }
    .mobile-bar { display: flex; }
    .main { padding: 24px 20px 60px; }
    .page-head { flex-direction: column; align-items: stretch; }
    .sub-item { grid-template-columns: 40px 1fr auto; }
    .sub-item__actions { grid-column: 1 / -1; justify-self: end; }
}

/* Forms (modal) */
.form-grid {
    display: grid; gap: 14px;
    grid-template-columns: 1fr 1fr;
}
.form-grid--full { grid-template-columns: 1fr; }
.form-grid > .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* Tabs */
.tabs {
    display: flex; gap: 4px;
    border-bottom: 1.5px solid var(--line);
    margin-bottom: 24px;
    overflow-x: auto;
}
.tab {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 12px 20px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--fg-mute);
    margin-bottom: -1.5px;
    white-space: nowrap;
}
.tab.active {
    color: var(--fg);
    border-bottom-color: var(--ink);
    font-weight: 500;
}
[data-theme="dark"] .tab.active { border-bottom-color: var(--paper); }

/* Table */
.tbl-wrap { overflow-x: auto; border: 1.5px solid var(--line); border-radius: var(--r-lg); }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tbl th {
    text-align: left;
    padding: 14px 16px;
    background: var(--bg-alt);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--fg-mute);
    border-bottom: 1.5px solid var(--line);
    white-space: nowrap;
}
.tbl td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--bg-alt); }

/* Alternative card */
.alt-card {
    border: 1.5px solid var(--line);
    border-radius: var(--r-lg);
    padding: 20px;
    background: var(--bg-card);
    display: flex; flex-direction: column; gap: 12px;
    transition: transform .2s, box-shadow .2s;
}
.alt-card:hover { transform: translate(-2px,-2px); box-shadow: var(--shadow-hard); }
.alt-card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.alt-card__savings {
    background: var(--lime);
    color: var(--ink);
    border: 1.5px solid var(--ink);
    border-radius: 999px;
    padding: 4px 12px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
}
.alt-card__title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.alt-card__pros, .alt-card__cons {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 0.86rem;
}
.alt-card__pros li::before { content: '✓'; margin-right: 6px; color: var(--success); font-weight: 700; }
.alt-card__cons li::before { content: '–'; margin-right: 6px; color: var(--clay); font-weight: 700; }
.alt-card ul { list-style: none; padding: 0; margin: 0; }

/* =====================================================================
 * DARK THEME — readability fixes for elements with fixed-color backgrounds
 * Lime, accent and "always light" surfaces must keep INK text in both themes.
 * ===================================================================== */

/* Lime / accent backgrounds always need ink text */
[data-theme="dark"] .btn--accent,
[data-theme="dark"] .pill--accent,
[data-theme="dark"] .stat-card--accent,
[data-theme="dark"] .alt-card__savings,
[data-theme="dark"] .sidebar__link.active {
    color: var(--ink) !important;
}
[data-theme="dark"] .stat-card--accent .stat-card__label,
[data-theme="dark"] .stat-card--accent .stat-card__value,
[data-theme="dark"] .stat-card--accent .stat-card__hint {
    color: var(--ink) !important;
}
[data-theme="dark"] .stat-card--accent .stat-card__hint {
    color: rgba(11,11,10,0.65) !important;
}

/* Highlight span on landing hero */
[data-theme="dark"] .hero h1 .highlight { color: var(--ink) !important; }

/* "Final CTA" lime section on landing — keep dark text */
[data-theme="dark"] .cta-final,
[data-theme="dark"] .cta-final h2,
[data-theme="dark"] .cta-final p,
[data-theme="dark"] .cta-final .eyebrow {
    color: var(--ink) !important;
}

/* Compare card "good" variant has lime bg — force ink text */
[data-theme="dark"] .compare__card--good,
[data-theme="dark"] .compare__card--good h3,
[data-theme="dark"] .compare__card--good li {
    color: var(--ink) !important;
}
[data-theme="dark"] .compare__card--good li::before { color: var(--ink) !important; }

/* Avatar (lime bg with initials) */
[data-theme="dark"] .sidebar__avatar { color: var(--ink) !important; }

/* Hint pills inside lime context */
[data-theme="dark"] .pwd-hint.ok { color: var(--ink) !important; }

/* Form inputs: in dark, color-pickers & date inputs need readable text */
[data-theme="dark"] input[type="color"] {
    background: var(--bg-card);
}
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

/* Tables — better contrast in dark */
[data-theme="dark"] .tbl tr:hover td { background: rgba(255,255,255,0.04); }

/* Sub-items border softens too much in dark; bump it */
[data-theme="dark"] .sub-item { border-color: rgba(255,255,255,0.08); }
[data-theme="dark"] .sub-item:hover { border-color: rgba(255,255,255,0.25); }

/* Modal: reduce harsh white border in dark */
[data-theme="dark"] .modal { border-color: var(--paper); }

/* Service cards in "Add subscription" — lime hover effect needs ink text */
[data-theme="dark"] .feature:hover { color: var(--ink); }
[data-theme="dark"] .feature:hover h3,
[data-theme="dark"] .feature:hover p,
[data-theme="dark"] .feature:hover .feature__num { color: var(--ink) !important; }
[data-theme="dark"] .feature:hover .feature__num { color: rgba(11,11,10,0.6) !important; }

/* hCaptcha iframe in dark — let's at least add the data-theme attr usage hint
   (the captcha re-renders with dark theme via JS; here only fallback styling) */
[data-theme="dark"] .captcha-fallback {
    background: var(--bg-alt);
    color: var(--fg-mute);
    border-color: rgba(255,255,255,0.15);
}

/* Cookie consent banner — already uses tokens, just slight dark tweak */
[data-theme="dark"] .stc-banner {
    background: var(--bg-card);
    border-color: var(--paper);
    box-shadow: 6px 6px 0 var(--paper), 0 18px 48px -12px rgba(0,0,0,.5);
}
[data-theme="dark"] .stc-banner__btn {
    border-color: var(--paper);
}
[data-theme="dark"] .stc-banner__btn:hover {
    box-shadow: 3px 3px 0 var(--paper);
}
[data-theme="dark"] .stc-banner__btn--primary {
    color: var(--ink);
}

/* Pills should remain readable */
[data-theme="dark"] .pill--success { background: #1f3d22; color: #b8e0bd; border-color: #2f5a35; }
[data-theme="dark"] .pill--danger  { background: #3d1c1c; color: #e0b8b8; border-color: #5a2f2f; }
[data-theme="dark"] .pill--warn    { background: #3d2e18; color: #e0d2b8; border-color: #5a4528; }

/* sub-item__action contrast in dark */
[data-theme="dark"] .sub-item__action {
    border-color: rgba(255,255,255,0.18);
}
[data-theme="dark"] .sub-item__action:hover {
    background: var(--paper);
    color: var(--ink);
    border-color: var(--paper);
}

/* CSS-bar charts: track is too dark in dark mode */
[data-theme="dark"] .cat-bar__track {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.12);
}
[data-theme="dark"] .cat-bar__fill {
    border-right-color: var(--paper);
}

/* Donut chart center text */
[data-theme="dark"] .donut text { fill: var(--paper); }

/* Donut legend swatches: keep visible border in dark */
[data-theme="dark"] .donut-legend__swatch { border-color: var(--paper); }

/* "Quote" cards on landing keep paper bg + hard shadow — they need explicit
   ink-on-paper styling in dark to stay readable */
[data-theme="dark"] .quote {
    background: var(--bg-card);
    border-color: var(--paper);
    box-shadow: 4px 4px 0 var(--paper);
    color: var(--fg);
}
[data-theme="dark"] .quote:hover { box-shadow: 6px 6px 0 var(--paper); }

/* Marquee remains dark always — keep it */
.marquee { color: var(--paper); }

/* Stats banner already dark — keep */

/* feature cards on landing */
[data-theme="dark"] .features { border-color: var(--paper); }
[data-theme="dark"] .feature { border-color: var(--paper); background: var(--bg-card); }
[data-theme="dark"] .feature:hover { background: var(--lime); }
/* On hover, force the icon box to be readable on the lime background */
[data-theme="dark"] .feature__icon {
    background: var(--bg-card);
    border-color: var(--paper);
    color: var(--paper);
}
[data-theme="dark"] .feature:hover .feature__icon {
    background: var(--bone);
    border-color: var(--ink);
    color: var(--ink);
}

/* how-step counters use lime stroke — keep visible */
[data-theme="dark"] .how-step { background: var(--bg-card); border-color: var(--paper); }
[data-theme="dark"] .how-step::before { -webkit-text-stroke: 2px var(--paper); }

/* Landing CTA button — light on dark */
[data-theme="dark"] .hero__cta .btn[style*="ink"] {
    background: var(--paper) !important;
    color: var(--ink) !important;
}

/* hero__total banner */
[data-theme="dark"] .hero__total { background: var(--paper); color: var(--ink); border-color: var(--paper); }
[data-theme="dark"] .hero__total span { color: inherit !important; }

/* Float cards on hero */
[data-theme="dark"] .float-card { border-color: var(--paper); box-shadow: var(--shadow-hard-lg); }

/* App header in dark for landing */
[data-theme="dark"] .app-header { border-bottom-color: rgba(255,255,255,0.15); }

/* Theme toggle visibility in dark */
[data-theme="dark"] .theme-toggle { border-color: rgba(255,255,255,0.25); }

/* Landing hero CTA button — uses inline ink bg → invert in dark */
[data-theme="dark"] .hero__cta a[style*="ink"],
[data-theme="dark"] .cta-final a[style*="ink"] {
    background: var(--paper) !important;
    color: var(--ink) !important;
    border-color: var(--paper) !important;
}
