/* ===========================================================================
   Habit Tracker — design system + components
   Inter font, green accent, light/dark themes, mobile-first responsive.
   =========================================================================== */
:root {
    --green: #16A34A;
    --green-600: #15803D;
    --green-100: #DCFCE7;

    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --surface-2: #F1F5F9;
    --text: #0F172A;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --primary: #16A34A;
    --primary-contrast: #FFFFFF;

    --blue: #3B82F6;
    --amber: #F59E0B;
    --red: #EF4444;
    --red-600: #DC2626;
    --teal: #0D9488;
    --indigo: #6366F1;

    --radius: 12px;
    --radius-sm: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .10);
    --ring: 0 0 0 3px rgba(22, 163, 74, .25);

    --font: 'Inter', 'Segoe UI', Roboto, Arial, system-ui, sans-serif;
    --sidebar-w: 248px;
    --topbar-h: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
    --green: #22C55E;
    --green-600: #16A34A;
    --green-100: #14532D;
    --bg: #0F172A;
    --surface: #1E293B;
    --surface-2: #334155;
    --text: #F8FAFC;
    --text-muted: #94A3B8;
    --border: #334155;
    --primary: #22C55E;
    --primary-contrast: #052e16;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
    --ring: 0 0 0 3px rgba(34, 197, 94, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: no-preference) {
    .nav-item, .btn, .card, .icon-btn, .habit-check, .switch, .switch-knob {
        transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .15s ease;
    }
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .25rem; line-height: 1.25; }
h3 { font-size: 1rem; }
.muted { color: var(--text-muted); }
.muted.sm, .sm { font-size: .85rem; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-right { text-align: right; }
.mt { margin-top: 1rem; }
.inline { display: inline; }

.skip-link { position: absolute; left: -999px; top: 0; z-index: 100; background: var(--green); color: #fff; padding: .5rem 1rem; border-radius: 0 0 8px 0; }
.skip-link:focus { left: 0; }

/* --- Layout --------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }
.layout-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 1.5rem; max-width: 1300px; width: 100%; margin: 0 auto; }

/* --- Sidebar ------------------------------------------------------------- */
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40; }
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.brand-logo { width: 32px; height: 32px; flex-shrink: 0; display: block; }
.brand-logo-lg { width: 72px; height: 72px; margin: 0 auto .25rem; }
.brand-name { font-weight: 800; font-size: .95rem; }
.sidebar-nav { padding: .75rem; display: flex; flex-direction: column; gap: .15rem; overflow-y: auto; flex: 1; }
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .65rem .8rem; border-radius: var(--radius-sm); color: var(--text); font-weight: 500; text-decoration: none; }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.is-active { background: var(--green-100); color: var(--green-600); font-weight: 600; }
[data-theme="dark"] .nav-item.is-active { color: var(--green); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); }

/* Theme row + switch */
.theme-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.theme-row svg { width: 18px; height: 18px; color: var(--text-muted); }
.theme-row-label { flex: 1; font-weight: 600; font-size: .9rem; }
.switch { width: 44px; height: 26px; border-radius: 999px; background: var(--border); border: none; cursor: pointer; padding: 0; position: relative; flex-shrink: 0; }
.switch[aria-checked="true"] { background: var(--green); }
.switch-knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(18px); }

/* --- Topbar -------------------------------------------------------------- */
.topbar { height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: 0 1.25rem; position: sticky; top: 0; z-index: 30; }
.topbar-title { font-size: 1.1rem; font-weight: 700; margin: 0; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .35rem; }
.menu-toggle { display: none; }

.icon-btn { background: none; border: none; color: var(--text); cursor: pointer; padding: .5rem; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; position: relative; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn svg { width: 20px; height: 20px; }
.badge-dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

.user-btn { display: flex; align-items: center; gap: .5rem; background: none; border: none; cursor: pointer; color: var(--text); padding: .3rem .5rem; border-radius: 8px; }
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.user-name { font-weight: 600; font-size: .9rem; }

/* --- Dropdown ------------------------------------------------------------ */
.dropdown { position: relative; }
.dropdown-menu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: .35rem; z-index: 50; display: none; }
.dropdown.is-open .dropdown-menu { display: block; }
.dropdown-menu-wide { min-width: 320px; }
.dropdown-menu-right { right: 0; }
.dropdown-item { display: block; width: 100%; text-align: left; background: none; border: none; cursor: pointer; padding: .55rem .7rem; border-radius: 8px; color: var(--text); font: inherit; }
.dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-item-danger { color: var(--red); }
.dropdown-head { padding: .5rem .7rem; display: flex; justify-content: space-between; align-items: center; }
.dropdown-sep { height: 1px; background: var(--border); margin: .35rem 0; }
.notif-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.notif-list li { padding: .6rem .7rem; border-radius: 8px; }
.notif-list li.unread { background: var(--green-100); }
[data-theme="dark"] .notif-list li.unread { background: rgba(34,197,94,.12); }
.notif-list .notif-title { font-weight: 600; font-size: .9rem; }
.notif-list .notif-body { font-size: .82rem; color: var(--text-muted); white-space: pre-line; }
.notif-empty { color: var(--text-muted); }

/* --- Cards --------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; gap: .5rem; }
.section-link { font-size: .85rem; font-weight: 600; color: var(--green); }

/* --- Buttons ------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; cursor: pointer; background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: .55rem .9rem; border-radius: var(--radius-sm); font: inherit; font-weight: 600; min-height: 40px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primary { background: var(--primary); color: var(--primary-contrast); border-color: transparent; }
.btn-primary:hover { background: var(--green-600); }
.btn-danger { background: var(--red); color: #fff; border-color: transparent; }
.btn-danger:hover { background: var(--red-600); }
.btn-block { width: 100%; }
.btn-sm { padding: .35rem .65rem; min-height: 32px; font-size: .85rem; }
.link-btn { background: none; border: none; color: var(--green); cursor: pointer; font: inherit; font-weight: 600; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* --- Forms --------------------------------------------------------------- */
.form .field { margin-bottom: .9rem; }
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }
input, select, textarea { width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; min-height: 40px; }
textarea { min-height: auto; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: var(--ring); }
.hint { color: var(--text-muted); font-size: .78rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: auto; min-height: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid .field { margin-bottom: .9rem; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; align-items: center; margin-top: .5rem; }

/* --- Page head ----------------------------------------------------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head-actions { display: flex; gap: .5rem; }

/* --- Grids --------------------------------------------------------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .15rem; }
.stat-label { color: var(--text-muted); font-size: .82rem; font-weight: 500; }
.stat-value { font-size: 1.9rem; font-weight: 800; }
.stat-sub { font-size: .72rem; font-weight: 600; }

/* --- Wellness card ------------------------------------------------------- */
.wellness { border-left: 5px solid var(--green); margin-bottom: 1.25rem; }
.wellness-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.wellness-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: .25rem; }
.wellness-score-row { display: flex; align-items: baseline; gap: .25rem; }
.wellness-score { font-size: 3rem; font-weight: 900; letter-spacing: -.04em; line-height: 1; }
.wellness-max { font-size: 1rem; font-weight: 600; color: var(--text-muted); }
.wellness-top .badge { margin-top: .5rem; }
.wellness-emoji { font-size: 2.6rem; line-height: 1; }
.wellness-bars { display: flex; flex-direction: column; gap: .55rem; margin-bottom: 1rem; }
.ws-bar-row { display: flex; align-items: center; gap: .6rem; }
.ws-bar-label { font-size: .8rem; font-weight: 600; color: var(--text-muted); width: 66px; flex-shrink: 0; }
.ws-bar-track { flex: 1; height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.ws-bar-fill { height: 100%; border-radius: 99px; transition: width .8s ease; }
.ws-bar-pct { font-size: .8rem; font-weight: 700; width: 36px; text-align: right; flex-shrink: 0; }
.wellness-foot { display: flex; border-top: 1px solid var(--border); background: var(--surface-2); margin: 0 -1.1rem -1.1rem; border-radius: 0 0 var(--radius) var(--radius); }
.ws-stat { flex: 1; text-align: center; padding: .8rem 0; }
.ws-stat + .ws-stat { border-left: 1px solid var(--border); }
.ws-stat-val { font-size: 1.2rem; font-weight: 800; }
.ws-stat-label { font-size: .68rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* --- Streak cards -------------------------------------------------------- */
.streak-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: 1.25rem; }
.streak-card { border-radius: var(--radius); padding: 1rem .75rem; text-align: center; box-shadow: var(--shadow); }
.streak-emoji { font-size: 1.5rem; display: block; margin-bottom: .4rem; }
.streak-num { font-size: 1.8rem; font-weight: 900; line-height: 1; }
.streak-unit { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; opacity: .7; }
.streak-name { font-size: .78rem; font-weight: 600; margin-top: .25rem; opacity: .85; }
.streak-orange { background: #FFF7ED; color: #C2410C; }
.streak-purple { background: #F5F3FF; color: #6D28D9; }
.streak-blue { background: #EFF6FF; color: #1D4ED8; }
[data-theme="dark"] .streak-orange { background: rgba(245,158,11,.12); color: #fdba74; }
[data-theme="dark"] .streak-purple { background: rgba(124,58,237,.15); color: #c4b5fd; }
[data-theme="dark"] .streak-blue { background: rgba(59,130,246,.15); color: #93c5fd; }

/* --- Habit rows ---------------------------------------------------------- */
.habit-list { display: flex; flex-direction: column; }
.habit-row { display: flex; align-items: center; gap: .8rem; padding: .75rem .25rem; border-bottom: 1px solid var(--border); }
.habit-row:last-child { border-bottom: none; }
.habit-check-form { display: flex; }
.habit-check { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); background: transparent; cursor: pointer; flex-shrink: 0; display: grid; place-items: center; padding: 0; color: #fff; }
.habit-check svg { width: 14px; height: 14px; opacity: 0; }
.habit-check.is-checked { background: var(--green); border-color: var(--green); }
.habit-check.is-checked svg { opacity: 1; }
.habit-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 1.2rem; flex-shrink: 0; }
.habit-main { flex: 1; min-width: 0; }
.habit-title { font-weight: 600; }
.habit-row.is-done .habit-title { color: var(--text-muted); }
.habit-meta { display: flex; align-items: center; gap: .5rem; margin-top: .15rem; flex-wrap: wrap; }
.habit-streak { font-size: .78rem; font-weight: 700; color: var(--text-muted); }
.habit-count { font-size: .78rem; font-weight: 700; color: var(--text-muted); background: var(--surface-2); padding: .05rem .45rem; border-radius: 99px; }
.habit-progress { height: 3px; background: var(--surface-2); border-radius: 99px; margin-top: .4rem; overflow: hidden; }
.habit-progress span { display: block; height: 100%; border-radius: 99px; transition: width .6s ease; }
.habit-row-actions { display: flex; gap: .1rem; }
.habit-row-actions form { display: flex; }
.habit-add svg, .habit-undo svg { width: 17px; height: 17px; }

/* --- Today head ---------------------------------------------------------- */
.today-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.today-date { text-align: center; flex-shrink: 0; }
.today-day { font-size: 1.8rem; font-weight: 900; color: var(--green); line-height: 1; }
.today-mon { font-size: .75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.today-progress-wrap { flex: 1; }
.today-sub { font-weight: 600; font-size: .9rem; }
.today-bar { height: 7px; background: var(--surface-2); border-radius: 99px; margin-top: .5rem; overflow: hidden; }
.today-bar-fill { height: 100%; background: var(--green); border-radius: 99px; transition: width .6s ease; }
.today-pct { font-size: 1.4rem; font-weight: 900; color: var(--green); }
.cat-section { margin-bottom: 1.25rem; }
.cat-section-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; }
.cat-section-title { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }
.cat-section-pct { margin-left: auto; font-size: .8rem; font-weight: 700; }

/* --- Filter tabs --------------------------------------------------------- */
.filter-tabs { display: flex; gap: .35rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .35rem; margin-bottom: 1.25rem; }
.filter-tab { flex: 1; padding: .45rem .6rem; border-radius: var(--radius-sm); font-weight: 600; font-size: .85rem; color: var(--text-muted); background: none; border: none; cursor: pointer; }
.filter-tab:hover { color: var(--text); }
.filter-tab.is-active { background: var(--green); color: #fff; }

/* --- Challenge cards (habits page) --------------------------------------- */
.habit-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.challenge-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.challenge-top { display: flex; align-items: flex-start; gap: .8rem; margin-bottom: .8rem; }
.challenge-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem; flex-shrink: 0; }
.challenge-info { flex: 1; min-width: 0; }
.challenge-name { font-weight: 800; }
.challenge-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.challenge-pct { font-size: 1.2rem; font-weight: 900; }
.challenge-bar-track { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: .8rem; }
.challenge-bar-fill { height: 100%; border-radius: 99px; }
.challenge-footer { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.challenge-stats { display: flex; gap: .8rem; }
.row-actions { display: flex; gap: .4rem; align-items: center; }

/* --- Badges -------------------------------------------------------------- */
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.badge-green { background: var(--green-100); color: var(--green-600); }
[data-theme="dark"] .badge-green { color: #bbf7d0; }
.badge-blue { background: rgba(59,130,246,.15); color: #2563eb; }
[data-theme="dark"] .badge-blue { color: #93c5fd; }
.badge-amber { background: rgba(245,158,11,.18); color: #b45309; }
[data-theme="dark"] .badge-amber { color: #fcd34d; }
.badge-red { background: rgba(239,68,68,.15); color: #dc2626; }
[data-theme="dark"] .badge-red { color: #fca5a5; }
.badge-gray { background: var(--surface-2); color: var(--text-muted); }

/* --- Activity feed ------------------------------------------------------- */
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-row { display: flex; align-items: center; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.activity-row:last-child { border-bottom: none; }
.act-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.act-text { flex: 1; min-width: 0; }
.act-time { white-space: nowrap; font-size: .78rem; }

/* --- Lists --------------------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.empty-inline { padding: 1rem 0; }
.report-side { display: flex; flex-direction: column; }

/* --- Category bars ------------------------------------------------------- */
.cat-bar-row { display: flex; align-items: center; gap: .6rem; padding: .35rem 0; }
.cat-bar-label { font-size: .8rem; font-weight: 600; color: var(--text-muted); width: 64px; flex-shrink: 0; }
.cat-bar-track { flex: 1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 99px; transition: width .8s ease; }
.cat-bar-pct { font-size: .8rem; font-weight: 700; width: 36px; text-align: right; flex-shrink: 0; }

/* --- Charts -------------------------------------------------------------- */
.chart-box { width: 100%; }
.chart-box canvas { width: 100% !important; display: block; }

/* --- Tables -------------------------------------------------------------- */
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .7rem .9rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--surface-2); }
.table tbody tr:hover { background: var(--surface-2); }
.cell-strong { font-weight: 600; }
.rank-bar-wrap { width: 90px; }
.rank-bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.rank-bar-fill { height: 100%; border-radius: 99px; }

/* comp table (weekly grid) */
.comp-table { width: 100%; border-collapse: collapse; }
.comp-table th, .comp-table td { padding: .5rem .4rem; text-align: center; border-bottom: 1px solid var(--border); }
.comp-table th { font-size: .68rem; text-transform: uppercase; color: var(--text-muted); }
.comp-table .comp-name { text-align: left; white-space: nowrap; font-size: .85rem; }
.comp-day.is-today { color: var(--green); font-weight: 800; }
.comp-mark { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--surface-2); color: var(--text-muted); font-size: .75rem; font-weight: 700; }
.comp-mark.done { background: var(--green); color: #fff; }

/* --- Heatmap ------------------------------------------------------------- */
.heatmap-dow, .heatmap-cells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.heatmap-dow { margin-bottom: 6px; }
.heatmap-dow span { text-align: center; font-size: .68rem; font-weight: 700; color: var(--text-muted); }
.hm-cell { aspect-ratio: 1; border-radius: 5px; background: var(--surface-2); }
.heatmap-legend .hm-cell, .heatmap-dow + .heatmap-cells .hm-cell { aspect-ratio: auto; }
.hm-empty { background: transparent; }
.hm-0 { background: var(--surface-2); }
.hm-1 { background: var(--green-100); }
.hm-2 { background: rgba(22,163,74,.45); }
.hm-3 { background: rgba(22,163,74,.7); }
.hm-4 { background: var(--green); }
.hm-today { outline: 2px solid var(--green); outline-offset: 1px; }
.heatmap-legend { display: flex; align-items: center; gap: 4px; margin-top: .75rem; }
.heatmap-legend .hm-cell { width: 14px; height: 14px; border-radius: 4px; }

/* --- Insights ------------------------------------------------------------ */
.insights-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.insight-card { }
.insight-emoji { font-size: 1.8rem; margin-bottom: .5rem; }
.insight-title { font-weight: 800; margin-bottom: .25rem; }
.insight-hl { font-size: 1.4rem; font-weight: 900; color: var(--green); margin: .35rem 0; }
.insight-body { font-size: .88rem; color: var(--text-muted); }
.risk-list { margin-top: .75rem; display: flex; flex-direction: column; gap: .4rem; }
.risk-item { display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem; background: var(--surface-2); border-radius: var(--radius-sm); }
.risk-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.risk-name { flex: 1; font-size: .85rem; font-weight: 600; }
.risk-streak { font-size: .82rem; font-weight: 700; }
.rec-item { display: flex; gap: .6rem; padding: .55rem; background: var(--surface-2); border-radius: var(--radius-sm); margin-top: .5rem; }
.rec-icon { flex-shrink: 0; }
.rec-text { font-size: .85rem; color: var(--text-muted); }

/* --- Settings ------------------------------------------------------------ */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.settings-row { display: flex; align-items: center; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: none; }
.settings-row-info { flex: 1; min-width: 0; }
.settings-row-title { font-weight: 600; font-size: .9rem; }
.settings-row-sub { font-size: .78rem; color: var(--text-muted); }

/* --- Modal --------------------------------------------------------------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 80; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-card { width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.icon-grid { display: flex; flex-wrap: wrap; gap: .4rem; }
.icon-opt { width: 40px; height: 40px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--surface-2); font-size: 1.2rem; cursor: pointer; display: grid; place-items: center; }
.icon-opt.is-selected { border-color: var(--green); box-shadow: var(--ring); }

/* --- Alerts -------------------------------------------------------------- */
.alert { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--green-100); color: var(--green-600); border-color: rgba(22,163,74,.3); }
.alert-error { background: rgba(239,68,68,.12); color: var(--red-600); border-color: rgba(239,68,68,.3); }
.alert-info { background: rgba(59,130,246,.12); color: #2563eb; border-color: rgba(59,130,246,.3); }
[data-theme="dark"] .alert-success { color: #bbf7d0; }
.alert-close { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: inherit; line-height: 1; }

/* --- Empty state --------------------------------------------------------- */
.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-illustration { font-size: 3rem; font-weight: 800; color: var(--text-muted); margin-bottom: .5rem; }

/* --- Auth ---------------------------------------------------------------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; background: var(--bg); }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand h1 { font-size: 1.4rem; margin-top: .75rem; }
.auth-card { padding: 1.5rem; }
.auth-title { margin-bottom: 1rem; }
.auth-links { text-align: center; margin-top: 1rem; }

/* --- Offline banner ------------------------------------------------------ */
.offline-banner { background: var(--amber); color: #1f2937; padding: .6rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-weight: 600; }

/* --- Sidebar collapse ---------------------------------------------------- */
.sidebar-collapse { margin-left: auto; }
.layout.is-collapsed .sidebar { width: 64px; }
.layout.is-collapsed .brand-name, .layout.is-collapsed .nav-item span,
.layout.is-collapsed .sidebar-footer .theme-row-label, .layout.is-collapsed .sidebar-footer .muted { display: none; }
.layout.is-collapsed .sidebar-brand { justify-content: center; padding: 1rem .5rem; }
.layout.is-collapsed .sidebar-collapse { margin-left: 0; }
.layout.is-collapsed .nav-item { justify-content: center; padding: .65rem; }
.layout.is-collapsed .sidebar-collapse svg { transform: rotate(180deg); }
.sidebar-collapse svg { width: 16px; height: 16px; }
@media (max-width: 767px) { .sidebar-collapse { display: none; } }

/* --- Scrim --------------------------------------------------------------- */
.scrim { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 35; }

/* --- Bottom nav (mobile) ------------------------------------------------- */
.bottom-nav { display: none; }

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 980px) {
    .form-grid { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); box-shadow: var(--shadow-md); }
    .sidebar.is-open { transform: translateX(0); }
    .menu-toggle { display: inline-flex; }
    .content { padding: 1rem; padding-bottom: calc(80px + var(--safe-bottom)); }
    .user-name { display: none; }
    .topbar-title { font-size: 1rem; }
    .streak-num { font-size: 1.4rem; }
    .wellness-score { font-size: 2.4rem; }

    .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: calc(64px + var(--safe-bottom)); padding: 0 .5rem var(--safe-bottom); background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -2px 12px rgba(15,23,42,.08); z-index: 36; align-items: center; justify-content: space-around; }
    .bn-item { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-muted); font-size: .65rem; font-weight: 600; padding: .35rem .5rem; min-width: 48px; }
    .bn-item.is-active { color: var(--green); }
    .bn-item svg { width: 22px; height: 22px; }
    .bn-fab { width: 52px; height: 52px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 18px rgba(22,163,74,.4); margin-top: -22px; flex-shrink: 0; }
    .bn-fab svg { width: 24px; height: 24px; }
}
@media (min-width: 769px) { .scrim { display: none !important; } }
