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

:root {
    --bg: #0b0b0f;
    --surface: #16161d;
    --surface-hover: #1e1e28;
    --border: #2a2a35;
    --border-subtle: #1e1e28;
    --text: #e8e8ed;
    --text-secondary: #8b8b9e;
    --text-muted: #55556a;
    --accent: #7c5cfc;
    --accent-bg: #2a1f5e;
    --green: #34d399;
    --green-bg: #134e38;
    --amber: #f0b429;
    --red: #f472b6;
    --red-bg: #3d1530;
    --blue: #818cf8;
    --heatmap-1: #1a3a4a;
    --tab-bg: rgba(16, 16, 22, 0.8);
    --overlay: rgba(0, 0, 0, 0.7);
    --cell-future-bg: #111118;
    --cell-future-border: #1e1e28;
    --radius-card: 14px;
    --radius-checkbox: 7px;
    --sidebar-width: 240px;
    --sidebar-bg: #111116;
    --habit-row-bg: #1a1a22;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f5f7;
        --surface: #fff;
        --surface-hover: #f7f7f9;
        --border: #e4e4eb;
        --border-subtle: #ececf0;
        --text: #1a1a2e;
        --text-secondary: #6b6b80;
        --text-muted: #a0a0b2;
        --accent: #7c5cfc;
        --accent-bg: #ede8ff;
        --green: #0d9668;
        --green-bg: #d1fae5;
        --amber: #d97706;
        --red: #e05288;
        --red-bg: #fce7f3;
        --blue: #6366f1;
        --heatmap-1: #a7f3d0;
        --tab-bg: rgba(255, 255, 255, 0.85);
        --overlay: rgba(0, 0, 0, 0.35);
        --cell-future-bg: #fafafe;
        --cell-future-border: #e8e8ee;
        --sidebar-bg: #fafafc;
        --habit-row-bg: #f8f8fb;
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 400;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 80px;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
}

/* ─── Sidebar ─── */
.sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 28px 16px;
    z-index: 50;
    flex-direction: column;
}

.sidebar-brand {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
    padding: 0 16px 32px;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.sidebar-link.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.sidebar-link svg { flex-shrink: 0; opacity: 0.6; }
.sidebar-link.active svg { opacity: 1; color: #fff; }

/* ─── Main content ─── */
.main-content { width: 100%; }

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top, 16px));
}

@media (min-width: 1024px) {
    .main-content {
        width: auto;
        margin-left: var(--sidebar-width);
    }
}

/* ─── Page header ─── */
.page-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 4px;
    line-height: 1.2;
}

.page-date-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.page-date-row .date-arrow {
    font-size: 18px;
    width: 28px;
    height: 28px;
}

.page-date-hint {
    font-size: 11px;
    color: var(--amber);
    margin-top: 2px;
}

.page-back-link {
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
    margin-top: 2px;
    display: inline-block;
}

/* ─── Legacy header (unused) ─── */
.header { text-align: center; margin-bottom: 16px; }
.header .date { font-size: 13px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; }
.header .hero-pct { font-size: 52px; font-weight: 700; line-height: 1; margin: 4px 0; }
.header .subtext { font-size: 13px; color: var(--text-muted); }

/* ─── Hero progress bar ─── */
.hero-bar-wrap {
    margin: 8px 0 24px;
}

.hero-bar-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}

.hero-bar-pct {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.hero-bar-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hero-bar-track {
    width: 100%;
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    overflow: hidden;
}

.hero-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 5px;
    transition: width 0.6s ease;
}

/* ─── Date navigation ─── */
.date-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 2px;
}

.date-arrow {
    font-size: 24px;
    font-weight: 300;
    color: var(--text-secondary);
    text-decoration: none;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.date-arrow:active { background: var(--surface-hover); }

.date-hint {
    font-size: 11px;
    color: var(--amber);
    margin-top: 2px;
}

.today-link {
    display: inline-block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

/* ─── Colour utility classes ─── */
.colour-green { color: var(--green); }
.colour-amber { color: var(--amber); }
.colour-red { color: var(--red); }
.colour-blue { color: var(--blue); }

/* ─── Metrics grid ─── */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 28px;
}

.metric-card {
    background: var(--surface);
    border-radius: var(--radius-card);
    border: 1px solid var(--border);
    padding: 20px 20px 18px;
    text-align: left;
}

.metric-card .label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.metric-card .value { font-size: 22px; font-weight: 700; color: var(--text); }
.metric-card.tappable { cursor: pointer; transition: background 0.15s; }
.metric-card.tappable:active { background: var(--surface-hover); }

/* Trend badges — pill style */
.metric-trend {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 6px;
    padding: 2px 8px;
    border-radius: 12px;
}

.trend-up {
    color: var(--green);
    background: rgba(74, 222, 128, 0.12);
}

.trend-down {
    color: var(--red);
    background: rgba(248, 113, 113, 0.12);
}

/* ─── Habit category containers ─── */
.habits-category {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
}

.habits-category .habit-row {
    border: none;
    background: var(--habit-row-bg);
    border-radius: 10px;
    margin-bottom: 4px;
}

.habits-category .habit-row:last-child { margin-bottom: 0; }

.habits-category .habit-row:active { background: var(--surface-hover); }

/* ─── Category headers ─── */
.category-header {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin: 0 0 12px 4px;
}

/* ─── Habit rows ─── */
.habit-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 13px 16px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.habit-row:active { background: var(--surface-hover); }

.habit-left { display: flex; align-items: center; gap: 10px; }

.checkbox {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-checkbox);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

.checkbox.done { background: var(--accent-bg); color: var(--accent); }
.checkbox.empty { background: var(--surface); border: 1px solid var(--border); }

.habit-label { font-size: 14px; }
.habit-label.done { color: var(--text); }
.habit-label.dimmed { color: var(--text-secondary); }

.habit-value { font-size: 11px; color: var(--text-secondary); margin-left: 6px; }

.habit-right { display: flex; align-items: center; gap: 8px; }

.dots { display: flex; gap: 3px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.filled { background: var(--accent); }
.dot.empty { background: var(--border); }

.week-count { font-size: 11px; color: var(--text-secondary); }
.week-count.met { color: var(--accent); }

/* ─── Week grid ─── */
.week-header { margin-bottom: 16px; }
.week-header .pct { font-size: 13px; color: var(--accent); margin-top: 4px; }

.week-grid { width: 100%; max-width: 700px; margin: 0 auto; }

.grid-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}

.grid-row .grid-cell,
.grid-row .day-header { flex: 1; }

.grid-label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 70px;
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.day-header {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    text-transform: uppercase;
    min-width: 32px;
}

.day-header.today { color: var(--accent); font-weight: 600; }

.grid-cell {
    width: 32px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell-dot {
    width: 14px;
    height: 14px;
    border-radius: 4px;
}

.cell-dot.done { background: var(--accent-bg); }
.cell-dot.done::after { content: '\2713'; font-size: 9px; color: var(--accent); display: flex; align-items: center; justify-content: center; height: 100%; }
.cell-dot.neutral { background: var(--surface); border: 1px solid var(--border); }
.cell-dot.missed { background: var(--red-bg); border: 1px solid var(--red); }
.cell-dot.future { background: var(--cell-future-bg); border: 1px solid var(--cell-future-border); }

/* ─── Stats ─── */
.score-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
    margin-bottom: 16px;
}

.progress-bar-bg {
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    overflow: hidden;
    margin: 4px 0;
}

.progress-bar-fill { height: 100%; border-radius: 3px; }

.streak-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.streak-item:last-child { border-bottom: none; }
.streak-number { font-size: 22px; font-weight: 700; color: var(--accent); min-width: 40px; }

/* ─── Heatmap ─── */
.heatmap { display: flex; gap: 2px; }
.heatmap-column { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.heatmap-cell { width: 100%; height: 14px; border-radius: 2px; }
.heatmap-cell.level-0 { background: var(--surface); }
.heatmap-cell.level-1 { background: var(--heatmap-1); }
.heatmap-cell.level-2 { background: var(--accent-bg); }
.heatmap-cell.level-3 { background: var(--accent); }
.heatmap-cell.future { background: var(--cell-future-bg); }

/* ─── Books ─── */
.books-grid { display: flex; flex-direction: column; gap: 10px; }

.book-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
}

.book-title { font-size: 16px; font-weight: 600; }
.book-author { font-size: 13px; color: var(--text-secondary); }

/* ─── Bottom tab bar (mobile) ─── */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--tab-bg);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 6px 0;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 6px));
    z-index: 100;
}

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-align: center;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    padding: 2px 0;
    flex: 1;
    -webkit-tap-highlight-color: transparent;
}

.tab svg { opacity: 0.6; }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active svg { opacity: 1; }

/* ─── Modal ─── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    width: 280px;
}

.modal h3 { font-size: 16px; margin-bottom: 12px; }

.modal input[type="number"] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    margin-bottom: 12px;
}

.modal-actions { display: flex; gap: 8px; }

.btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-secondary { background: var(--border); color: var(--text); }

/* ─── Section headers ─── */
.section-header {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 20px 0 10px;
}

/* ─── Dashboard grid (Stats page) ─── */
.dash-grid { display: flex; flex-direction: column; gap: 10px; }

.dash-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
}

.dash-card-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.dash-card-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 10px; }

.dash-hero-pct { font-size: 44px; font-weight: 700; line-height: 1.1; }
.dash-delta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* Category sparklines */
.cat-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.cat-info { min-width: 100px; display: flex; justify-content: space-between; align-items: baseline; }
.cat-name { font-size: 12px; color: var(--text-secondary); }
.cat-pct { font-size: 13px; font-weight: 600; }
.cat-spark { flex: 1; height: 28px; position: relative; }
.cat-spark canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

/* Reading goals */
.goal-row { margin-bottom: 10px; }
.goal-row:last-child { margin-bottom: 0; }
.goal-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.goal-label { font-size: 12px; color: var(--text-secondary); }
.goal-nums { display: flex; align-items: baseline; gap: 3px; }
.goal-val { font-size: 16px; font-weight: 700; }
.goal-target { font-size: 11px; color: var(--text-muted); }

/* Streak chips */
.streaks-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.streak-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border-radius: 20px;
    padding: 4px 12px 4px 8px;
}
.streak-chip-num { font-size: 15px; font-weight: 700; color: var(--accent); }
.streak-chip-label { font-size: 11px; color: var(--text-secondary); }

/* ─── Food tracking ─── */
.food-totals {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
}
.food-total-col { flex: 1; text-align: center; }
.food-total-val { font-size: 18px; font-weight: 700; line-height: 1.2; }
.food-total-label { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.food-total-name { font-size: 10px; color: var(--text-secondary); margin-top: 4px; }

.meal-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    margin-bottom: 10px;
    overflow: hidden;
}
.meal-header {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    gap: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.meal-chevron {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s;
    display: inline-block;
    flex: none;
}
.meal-section.open .meal-chevron {
    transform: rotate(90deg);
}
.meal-body {
    display: none;
}
.meal-section.open .meal-body {
    display: block;
}
.meal-label { font-size: 13px; font-weight: 600; color: var(--text); }
.meal-cals { font-size: 12px; color: var(--text-secondary); margin-left: auto; }
.meal-header-macros {
    display: flex;
    gap: 2px;
    margin-left: auto;
    font-size: 11px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}
.meal-header-macros span { width: 40px; text-align: right; }
.meal-header-macros .fem-cal { width: 36px; color: var(--text); font-weight: 600; }
.meal-copy-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: none;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.meal-add-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: none;
    color: var(--accent);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.food-entry {
    display: flex;
    align-items: center;
    padding: 8px 14px;
    border-top: 1px solid var(--border-subtle);
    gap: 8px;
}
.food-entry-editable { cursor: pointer; }
.food-entry-editable:active { background: var(--bg); }
.food-entry-name { flex: 1; min-width: 0; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.food-entry-qty { font-size: 11px; color: var(--text-muted); margin-left: 4px; }
.food-entry-macros {
    display: flex;
    gap: 2px;
    flex: none;
    font-size: 11px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}
.food-entry-macros span {
    width: 40px;
    text-align: right;
}
.food-entry-macros .fem-cal { width: 36px; color: var(--text); font-weight: 600; }
.food-entry-del {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
    flex: none;
}

.food-week-table { overflow-x: auto; }
.food-week-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
.food-week-table th { padding: 4px 6px; color: var(--text-secondary); font-weight: 500; text-align: center; }
.food-week-table .food-week-today { color: var(--accent); font-weight: 700; }
.food-week-label { color: var(--text-secondary); font-weight: 500; padding: 4px 6px; white-space: nowrap; }
.food-week-cell { text-align: center; padding: 4px 6px; font-variant-numeric: tabular-nums; }
.food-week-cell.future { color: var(--text-muted); }

.radio-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: border-color 0.15s, color 0.15s;
}
.radio-pill input { display: none; }
.radio-pill:has(input:checked) {
    border-color: var(--accent);
    color: var(--accent);
}

.macro-input-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-top: 8px;
}
.macro-input-cell label {
    display: block;
    font-size: 10px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}
.macro-input-cell input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 6px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
}

.food-search-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.1s;
}
.food-search-item:hover { background: var(--bg); }
.food-search-item-name { font-size: 13px; color: var(--text); }
.food-search-item-macros { font-size: 11px; color: var(--text-secondary); margin-top: 1px; }

/* ─── Alcohol tracking ─── */
.alcohol-trigger {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s;
}
.alcohol-trigger:active { color: var(--text-secondary); }

.alcohol-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.alcohol-presets .btn { flex: none; padding: 8px 14px; font-size: 13px; }

/* ─── BM tracking ─── */
.bm-pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.bm-pill-col { display: flex; flex-direction: column; gap: 4px; }
.radio-pill.sm { padding: 5px 8px; font-size: 11px; }
.toggle-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.toggle-pill input { display: none; }
.toggle-pill:has(input:checked) {
    border-color: var(--red, #e74c3c);
    color: var(--red, #e74c3c);
}

.bm-entry {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    gap: 10px;
}
.bm-entry:last-child { border-bottom: none; }
.bm-entry-time { font-size: 12px; color: var(--text-muted); width: 40px; flex: none; }
.bm-entry-detail { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bm-consistency { font-size: 13px; font-weight: 500; color: var(--text); }
.bm-flag { font-size: 11px; color: var(--text-secondary); background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 2px 8px; }
.bm-flag-blood { color: var(--red, #e74c3c); border-color: var(--red, #e74c3c); }
.bm-flag-pain { color: var(--amber); border-color: var(--amber); }
.bm-flag-urgency { color: var(--amber); border-color: var(--amber); }
.bm-entry-score { font-size: 13px; font-weight: 600; width: 24px; text-align: center; flex: none; }

.bm-history-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 20px;
}
.bm-day {
    background: var(--card-bg);
    border-radius: 6px;
    padding: 6px 4px;
    text-align: center;
    min-height: 56px;
}
.bm-day-label { font-size: 11px; color: var(--text-muted); }
.bm-day-score { font-size: 16px; font-weight: 700; color: var(--text); margin-top: 2px; }
.bm-day-count { font-size: 9px; color: var(--text-muted); margin-top: 1px; }
.bm-day-clear { background: var(--accent-bg); }
.bm-day-clear .bm-day-score { color: var(--accent); }
.bm-day-mild { background: rgba(240, 180, 41, 0.15); }
.bm-day-moderate { background: rgba(240, 180, 41, 0.25); }
.bm-day-bad { background: var(--red-bg); }
.bm-day-bad .bm-day-score { color: var(--red); }
.bm-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
}
.bm-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
}
.bm-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

/* ─── Responsive: Tablet (768px+) ─── */
@media (min-width: 768px) {
    .container { max-width: 720px; padding: 24px; }

    .hero-ring-wrap { width: 160px; height: 160px; }
    .hero-ring-pct { font-size: 40px; }

    .header .hero-pct { font-size: 64px; }
    .header .date { font-size: 14px; }

    .metrics-grid { gap: 12px; margin-bottom: 24px; }
    .metric-card { padding: 14px 12px; }
    .metric-card .label { font-size: 11px; }
    .metric-card .value { font-size: 24px; }

    .habits-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }

    .habit-row { padding: 13px 16px; margin-bottom: 6px; }
    .habit-label { font-size: 15px; }

    .grid-label { min-width: 100px; max-width: 100px; font-size: 13px; }
    .cell-dot { width: 18px; height: 18px; border-radius: 5px; }
    .day-header { font-size: 11px; }

    .score-card { padding: 20px; }

    .modal { width: 340px; }

    .book-card { padding: 20px; }
}

/* ─── Responsive: Desktop (1024px+) — sidebar visible ─── */
@media (min-width: 1024px) {
    .sidebar { display: flex; }
    .tab-bar { display: none; }

    body { padding-bottom: 0; }

    .container { max-width: 100%; padding: 32px 48px; }

    .metrics-grid { grid-template-columns: repeat(6, 1fr); gap: 16px; }
    .metric-card { padding: 24px 24px 20px; }
    .metric-card .value { font-size: 26px; }
    .metric-trend { font-size: 11px; }

    .habits-grid {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 20px;
    }

    .habits-category { padding: 24px; }

    .habit-row { padding: 14px 16px; margin-bottom: 6px; }

    .week-grid { max-width: 900px; }
    .grid-label { min-width: 140px; max-width: 140px; font-size: 14px; }
    .grid-row { gap: 6px; padding: 3px 0; }
    .cell-dot { width: 24px; height: 24px; border-radius: 5px; }
    .cell-dot.done::after { font-size: 12px; }
    .day-header { font-size: 13px; }

    .week-header .range { font-size: 24px; }
    .week-header .pct { font-size: 14px; }

    .books-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

    .section-header { margin: 12px 0 8px; }

    .dash-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: auto auto auto auto;
        gap: 10px;
    }
    .dash-hero { grid-column: 1; }
    .dash-month { grid-column: 2; }
    .dash-perfect { grid-column: 3; }
    .dash-best { grid-column: 4; }
    .dash-categories { grid-column: 1 / 3; }
    .dash-trend { grid-column: 3 / 5; }
    .dash-heatmap { grid-column: 1 / 3; }
    .dash-reading { grid-column: 3 / 5; }
    .dash-weight { grid-column: 1 / 3; }
    .dash-nutrition { grid-column: 3 / 5; }
    .dash-gut { grid-column: 1 / 3; }
    .dash-streaks { grid-column: 1 / 5; }

    .dash-card { padding: 14px 18px; }
    .dash-hero-pct { font-size: 40px; }
    .dash-hero .dash-hero-pct { font-size: 48px; }

    .modal { width: 400px; }
}

/* ─── Check-in ─── */
.checkin-toggle {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin: 10px 0 16px;
    background: var(--surface);
    border-radius: 10px;
    padding: 3px;
}
.checkin-tab {
    flex: 1;
    text-align: center;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
}
.checkin-tab.active {
    background: var(--bg);
    color: var(--accent);
    font-weight: 600;
}

.checkin-whoop {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}
.whoop-card {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.whoop-icon { font-size: 20px; flex: none; }
.whoop-detail { flex: 1; }
.whoop-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.whoop-value { font-size: 22px; font-weight: 700; line-height: 1.2; }
.whoop-sub { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

.checkin-gaps {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 12px 14px;
    margin-bottom: 16px;
}
.gaps-title { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.gap-item { font-size: 13px; color: var(--text); padding: 3px 0; }

.checkin-prompts {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 10px 14px;
    margin-bottom: 16px;
}
.prompt-item {
    padding: 7px 0;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
    line-height: 1.4;
}
.prompt-item:last-child { border-bottom: none; }
.prompt-item strong { color: var(--text); }
.prompt-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    margin-right: 6px;
    flex: none;
    vertical-align: middle;
}

.checkin-input-area { margin-bottom: 16px; }
.checkin-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.checkin-textarea {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 44px;
    line-height: 1.4;
}
.checkin-textarea:focus { outline: none; border-color: var(--accent); }
.checkin-textarea::placeholder { color: var(--text-muted); }

.record-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    transition: border-color 0.15s, color 0.15s;
}
.record-btn:active { background: var(--surface-hover); }
.record-btn.recording {
    border-color: var(--red);
    color: var(--red);
    animation: pulse-record 1.5s ease-in-out infinite;
}
@keyframes pulse-record {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.recording-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    font-size: 13px;
    color: var(--red);
}
.recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
    animation: pulse-record 1s ease-in-out infinite;
}
.stop-record-btn {
    background: var(--red);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    margin-left: auto;
}

.transcript-preview {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 6px 0;
    font-style: italic;
}

.checkin-submit {
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    font-size: 15px;
}
.checkin-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.hidden { display: none !important; }

.checkin-feedback { margin-bottom: 16px; }
.feedback-logged, .feedback-answer {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.5;
}
.feedback-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.feedback-cat {
    display: inline-block;
    background: var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-right: 4px;
}
.feedback-error {
    background: var(--red-bg);
    border-radius: var(--radius-card);
    padding: 12px 14px;
    font-size: 13px;
    color: var(--red);
}

.checkin-logged { margin-bottom: 16px; }
.logged-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.logged-item {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 10px 14px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.logged-cat {
    background: var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    flex: none;
}
.logged-summary { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logged-time { font-size: 11px; color: var(--text-muted); flex: none; }

/* ─── Responsive: Wide desktop (1280px+) ─── */
@media (min-width: 1280px) {
    .container { max-width: 100%; padding: 32px 48px; }
    .dash-grid { gap: 12px; }
    .dash-card { padding: 16px 20px; }
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    width: 100%;
    max-width: 340px;
    padding: 40px 32px;
    background: var(--surface);
    border-radius: var(--radius-card);
    border: 1px solid var(--border);
}
.login-brand {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    margin-bottom: 32px;
}
.login-card input {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    box-sizing: border-box;
}
.login-card input:focus {
    outline: none;
    border-color: var(--accent);
}
.login-card .btn {
    width: 100%;
    margin-top: 4px;
}
.login-error {
    color: var(--red);
    font-size: 14px;
    text-align: center;
    margin-bottom: 14px;
}
