/* Progress Dashboard | Phone-first dark theme (matches Bridge) */

:root {
    /* App-specific layout tokens */
    --header-height: 56px;
    --tab-height: 44px;
    --date-bar-height: 53px;

    /* Category accent colors (reference shared tokens) */
    --cat-passive: var(--accent);
    --cat-direct: var(--green);
    --cat-real: var(--purple);
    --cat-exercise: var(--orange);
}

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

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ─── Login ─────────────────────────────────────────────── */

.screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    z-index: 100;
}

.login-box {
    text-align: center;
    padding: 32px;
    max-width: 320px;
    width: 100%;
}

.login-box h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 3px;
    color: var(--text);
    margin-bottom: 8px;
}

.login-box input {
    width: 100%;
    padding: 14px 16px;
    margin: 16px 0 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    outline: none;
}

.login-box input:focus {
    border-color: var(--accent);
}

.error-text {
    color: var(--red);
    font-size: 13px;
    margin-top: 8px;
}

/* ─── Buttons ───────────────────────────────────────────── */

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.btn-primary:active { opacity: 0.8; }

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

/* ─── Header ────────────────────────────────────────────── */

.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: linear-gradient(180deg, var(--header-gradient-start) 0%, var(--surface) 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.header-back {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 22px;
    padding: 4px 8px 4px 0;
    line-height: 1;
}

.header-back:active { color: var(--accent); }

.header-title {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 2.5px;
    color: var(--text);
}

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

.header-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    padding: 6px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.15s;
}

.header-btn:active {
    background: var(--surface-raised);
    border-color: var(--accent);
    color: var(--accent);
}

.header-btn.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ─── Date Bar ─────────────────────────────────────────── */

.date-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: relative;
    cursor: pointer;
}

.date-display {
    flex: 1;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    transition: background 0.15s;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Timer showing: give the date its padding back so both fit on one line */
.date-bar:has(.date-timer:not(.hidden)) {
    padding-inline: 12px;
}

.date-bar:has(.date-timer:not(.hidden)) .date-display {
    padding-inline: 6px;
}

@media (max-width: 379px) {
    .date-bar:has(.date-timer:not(.hidden)) .date-display.category-won::after {
        content: "✓";
        margin-left: 6px;
    }
}

.date-bar:active .date-display {
    background: var(--surface-raised);
}

.date-display .date-today-badge {
    font-size: 11px;
    font-weight: 500;
    color: var(--green);
    margin-left: 6px;
}

/* "Day off" chip next to the Daily Habits title on rest days */
.dayoff-badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: color-mix(in srgb, var(--border) 50%, transparent);
    border-radius: var(--radius-sm);
    padding: 2px 7px;
    margin-left: 8px;
    vertical-align: middle;
}

/* Category-win state on the date bar: when the active tab is a category and
   that category booked any 1%+ improvement on the selected date, signal the
   win on the date itself so it's visible without scrolling the metrics list. */
.date-display.category-won {
    background: var(--green-glow);
    color: var(--green);
    box-shadow: inset 0 0 0 1px var(--green);
}

.date-display.category-won::after {
    content: "✓ won";
    font-size: 11px;
    font-weight: 600;
    color: var(--green);
    margin-left: 8px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.date-display.category-won .date-today-badge {
    /* "Today" badge would clash with the green glow background — drop it
       when the win indicator is shown. */
    display: none;
}

.date-arrow {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 20px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.date-arrow:active {
    background: var(--surface-raised);
    border-color: var(--accent);
    color: var(--accent);
}

/* Exercise stopwatch: sits between the date and the › arrow on the Exercise
   tab, sized to match the arrows so it reads as a third control, not a widget.
   Idle = muted, running = green, stopped with time on it = accent. */
.date-timer {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 36px;
    padding: 0 10px;
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.date-timer-icon {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 5px 0 5px 8px;
    border-color: transparent transparent transparent currentColor;
}

.date-timer.running .date-timer-icon {
    width: 8px;
    height: 10px;
    border-width: 0 3px;
    border-color: transparent currentColor;
}

.date-timer-time { min-width: 3ch; text-align: right; }

.date-timer.running {
    color: var(--green);
    border-color: var(--green);
    background: var(--green-glow);
}

.date-timer.paused {
    color: var(--accent);
    border-color: var(--accent);
    padding-right: 0;
}

.date-timer-reset {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: stretch;
    padding: 0 9px 0 7px;
    margin-left: 2px;
    border-left: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 17px;
    font-weight: 400;
}

.date-timer:active { background: var(--surface-raised); }

.date-picker-hidden {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* ─── Tab Bar ───────────────────────────────────────────── */

.tab-bar {
    display: flex;
    overflow-x: auto;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 8px;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab {
    flex-shrink: 0;
    padding: 10px 14px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab:active { opacity: 0.7; }

/* A category that booked a 1%+ win on the selected date marks its tab with
   the app's one win color (green, same as a done habit tile and a winning
   value), so the win is findable from any view. Set by markWonTabs(). */
.tab.won { color: var(--green); }

.tab.won::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 6px;
    vertical-align: 2px;
    border-radius: 50%;
    background: var(--green);
}

.tab.won.active { border-bottom-color: var(--green); }

/* ─── Content ───────────────────────────────────────────── */

.content {
    height: calc(100vh - var(--header-height) - var(--tab-height) - var(--date-bar-height));
    height: calc(100dvh - var(--header-height) - var(--tab-height) - var(--date-bar-height));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
}

/* ─── Dashboard Cards ───────────────────────────────────── */

.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.summary-card.wide {
    grid-column: 1 / -1;
}

.summary-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.summary-value {
    font-size: 24px;
    font-weight: 700;
}

.summary-value.green { color: var(--green); }
.summary-value.accent { color: var(--accent); }
.summary-value.purple { color: var(--purple); }
.summary-value.orange { color: var(--orange); }

.summary-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── Habits Section ────────────────────────────────────── */

.habits-section {
    margin-bottom: 20px;
}

.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

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

.habit-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
}

.habit-tile.done {
    background: var(--green-glow);
    border-color: var(--green);
}

.habit-tile:active { transform: scale(0.96); }

.habit-check {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border-bright);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.habit-tile.done .habit-check {
    background: var(--green);
    border-color: var(--green);
}

.habit-check svg {
    width: 14px;
    height: 14px;
    color: #fff;
    opacity: 0;
}

.habit-tile.done .habit-check svg { opacity: 1; }

.habit-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.habit-streak {
    font-size: 10px;
    color: var(--text-muted);
}

/* Derived (score-based) habits are read-only — checked only when a metric
   in that category scores a win. No pointer affordance, no press animation. */
.habit-tile.derived {
    cursor: default;
    border-style: dashed;
}
.habit-tile.derived:active { transform: none; }
.habit-auto,
.day-habit-auto {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    opacity: 0.75;
}
.day-habit-auto { margin-left: auto; }
.day-habit-row.derived { cursor: default; }
.day-habit-row.derived:active { opacity: 1; }

/* ─── Category Cards ────────────────────────────────────── */

.category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.category-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    overflow: hidden;
}

.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--cat-color);
}

.category-card:active { transform: scale(0.97); }

/* Dashboard card for a category that won on the selected date: the same
   look as a done habit tile, because it is the same fact. */
.category-card.won {
    background: var(--green-glow);
    border-color: var(--green);
}

.category-card.won::after {
    content: '\2713 won';
    position: absolute;
    top: 12px;
    right: 14px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--green);
}

.category-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
}

.category-count {
    font-size: 12px;
    color: var(--text-muted);
}

.category-empty {
    font-size: 11px;
    color: var(--yellow);
    margin-top: 4px;
}

/* ─── Metrics List ──────────────────────────────────────── */

/* ── Reorder mode ── */
.reorder-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0 2px;
}

.reorder-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font: inherit;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.reorder-btn.active {
    background: var(--surface-raised);
    border-color: var(--accent);
    color: var(--accent);
}

.reorder-hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* Handle only exists in reorder mode, so tap-to-log owns the row otherwise */
.drag-handle {
    display: none;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
    font-size: 15px;
    line-height: 1;
    color: var(--text-muted);
    cursor: grab;
    touch-action: none;   /* the drag owns the gesture; page scroll is autoscroll's job */
}

.content.reordering .drag-handle { display: block; }
.content.reordering .metric-row { cursor: default; }
.content.reordering .metric-row:active { background: none; }

.metric-row.dragging {
    position: relative;
    z-index: 10;
    background: var(--surface-raised);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    border-radius: 6px;
    cursor: grabbing;
}

.metric-row.dragging .drag-handle { color: var(--accent); }

/* Kill text selection and touch scrolling for the duration of a drag */
body.drag-active {
    user-select: none;
    -webkit-user-select: none;
}

.column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0 6px;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.col-pair {
    display: flex;
    gap: 16px;
    min-width: 160px;
    justify-content: flex-end;
}

.col-pair span {
    min-width: 72px;
    text-align: right;
}

.group-header {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.group-header:active { opacity: 0.7; }

.group-arrow {
    font-size: 10px;
    width: 12px;
    flex-shrink: 0;
}

.group-count {
    font-weight: 400;
    font-size: 11px;
}

/* Group with a 1%+ win inside it on the selected date. */
.group-header.won {
    color: var(--green);
    background: var(--green-glow);
    box-shadow: inset 3px 0 0 var(--green);
    padding-left: 8px;
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.group-won {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    color: var(--green);
    letter-spacing: 0.5px;
}

.group-body.collapsed {
    display: none;
}

.metric-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
    cursor: pointer;
    transition: background 0.1s;
}

.metric-row:active { background: var(--surface-raised); }

.metric-row.no-data {
    opacity: 0.5;
}

.metric-info {
    flex: 1;
    min-width: 0;
}

.metric-name {
    font-size: 14px;
    font-weight: 500;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.3;
}

.metric-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.metric-value {
    font-size: 16px;
    font-weight: 700;
    text-align: right;
    flex-shrink: 0;
}

.mv-pair {
    display: flex;
    gap: 16px;
    flex-shrink: 0;
    min-width: 160px;
    justify-content: flex-end;
}

.mv-latest {
    min-width: 72px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    text-align: right;
}

.mv-latest.today-best {
    color: var(--green);
    font-weight: 700;
    background: var(--green-glow);
    padding: 1px 6px;
    border-radius: var(--radius-xs);
}

.mv-latest.today-best-minor {
    color: var(--gold);
    font-weight: 600;
}

.mv-best {
    min-width: 72px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: right;
}

.metric-sparkline {
    flex-shrink: 0;
    width: 60px;
    height: 24px;
}

.metric-sparkline svg {
    width: 100%;
    height: 100%;
}

.best-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    color: var(--green);
    background: var(--green-glow);
    padding: 1px 5px;
    border-radius: 4px;
    margin-left: 4px;
    vertical-align: middle;
}

/* ─── Wins View ─────────────────────────────────────────── */

.wins-empty {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-muted);
}

.win-card {
    background: var(--surface);
    border: 1px solid var(--green);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
    overflow: hidden;
}

.win-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--green), var(--accent));
}

.win-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
}

.win-values {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.win-current {
    font-size: 22px;
    font-weight: 700;
    color: var(--green);
}

.win-pct {
    font-size: 14px;
    font-weight: 700;
    color: var(--green);
    background: var(--green-glow);
    padding: 2px 8px;
    border-radius: var(--radius-xs);
}

.win-prev {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}


/* ─── Search Overlay ────────────────────────────────────── */

.overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.search-bar input {
    flex: 1;
    padding: 10px 14px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    outline: none;
}

.search-bar input:focus { border-color: var(--accent); }

.search-results {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
}

/* ─── Entry Modal ───────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: flex-end;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-sheet {
    position: relative;
    width: 100%;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px 16px calc(20px + var(--safe-bottom));
    max-height: 70vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.entry-settings {
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.entry-settings > summary {
    cursor: pointer;
    padding: 4px 0;
    color: var(--text-secondary);
    user-select: none;
    list-style: none;
}

.entry-settings > summary::-webkit-details-marker { display: none; }

.entry-settings > summary::before {
    content: '⚙ ';
    opacity: 0.7;
}

.entry-settings-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px 10px;
    margin-top: 10px;
}

.entry-settings-grid label {
    flex-shrink: 0;
}

.entry-settings-grid select,
.entry-settings-grid input,
.entry-settings-grid textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

.entry-settings-grid input,
.entry-settings-grid textarea {
    cursor: text;
}

.entry-settings-grid textarea {
    grid-column: 1 / -1;
    resize: vertical;
    font-family: inherit;
    line-height: 1.4;
}

.entry-settings-grid select:focus,
.entry-settings-grid input:focus,
.entry-settings-grid textarea:focus {
    border-color: var(--accent);
}

.entry-context {
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.entry-context .best-line {
    color: var(--green);
    font-weight: 600;
}

.entry-context .howto {
    margin-bottom: 12px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.entry-context .howto > summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--accent);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.entry-context .howto > summary::-webkit-details-marker { display: none; }

.entry-context .howto > summary::before {
    content: "📋";
    font-size: 14px;
}

.entry-context .howto-source {
    margin-left: auto;
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
}

.entry-context .howto-body {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.entry-context .howto-step {
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.modal-body input[type="number"],
.modal-body input[type="date"],
.modal-body input[type="text"],
.modal-body select {
    width: 100%;
    padding: 14px 16px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 18px;
    outline: none;
    margin-bottom: 12px;
    box-sizing: border-box;
}

.modal-body input:focus,
.modal-body select:focus { border-color: var(--accent); }

.nm-label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin: 4px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nm-optional {
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-muted);
    opacity: 0.7;
}

.entry-feedback {
    margin-top: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    font-weight: 600;
}

.entry-feedback.success {
    background: var(--green-glow);
    color: var(--green);
    border: 1px solid var(--green);
}

.entry-feedback.best {
    background: linear-gradient(135deg, var(--green-glow), var(--accent-glow));
    color: var(--green);
    border: 1px solid var(--green);
    font-size: 18px;
}

/* ─── History List (Entry Modal) ────────────────────────── */

.history-section {
    margin-top: 12px;
}

.history-title {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
}

.history-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 13px;
    border-bottom: 1px solid color-mix(in srgb, var(--border) 40%, transparent);
}

.history-row:last-child { border-bottom: none; }

.history-row.editable {
    cursor: pointer;
    align-items: center;
}

.history-row.editable:active {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.history-edit-hint {
    color: var(--text-muted);
    font-size: 12px;
    opacity: 0.5;
    margin-left: 6px;
    flex-shrink: 0;
}

.history-row.editable:hover .history-edit-hint,
.history-row.editable:active .history-edit-hint {
    opacity: 1;
    color: var(--accent);
}

.history-row.best {
    background: var(--green-glow);
}

.history-row.best .history-val {
    color: var(--green);
    font-weight: 700;
}

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

.history-val {
    color: var(--text);
}

/* ─── Wins inline ──────────────────────────────────────── */

.wins-empty-inline {
    padding: 20px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

.week-day-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 12px 0 6px;
}

.week-day-empty {
    font-weight: 400;
    color: var(--text-muted);
    opacity: 0.7;
}

/* ─── History Calendar ──────────────────────────────────── */

.history-summary {
    display: flex;
    justify-content: space-around;
    padding: 12px;
    margin-bottom: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-secondary);
}

.cal-month {
    margin-bottom: 20px;
}

.cal-month-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.cal-month-stats {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
}

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

.cal-dow {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    padding-bottom: 4px;
}

.cal-cell {
    aspect-ratio: 1;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.cal-day-num {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.7;
}

.cal-empty {
    background: transparent;
}

.cal-future {
    background: transparent;
    border: 1px dashed color-mix(in srgb, var(--border) 50%, transparent);
}

.cal-future .cal-day-num { opacity: 0.3; }

/* Habit states */
.cal-habit-done {
    background: color-mix(in srgb, var(--green) 40%, var(--surface));
    border: 1px solid var(--green);
}

.cal-habit-done .cal-day-num {
    color: var(--green);
    opacity: 1;
}

.cal-habit-partial {
    background: color-mix(in srgb, var(--yellow) 20%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--yellow) 50%, var(--border));
}

.cal-habit-partial .cal-day-num {
    color: var(--yellow);
    opacity: 0.9;
}

.cal-habit-miss {
    background: color-mix(in srgb, var(--red) 10%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--red) 30%, var(--border));
}

.cal-habit-miss .cal-day-num {
    color: var(--red);
    opacity: 0.6;
}

/* Rest day — neutral, never reads as a miss */
.cal-day-off {
    background: repeating-linear-gradient(
        135deg,
        var(--surface),
        var(--surface) 4px,
        color-mix(in srgb, var(--border) 60%, transparent) 4px,
        color-mix(in srgb, var(--border) 60%, transparent) 6px
    );
    border: 1px dashed var(--border-bright);
}

.cal-day-off .cal-day-num {
    color: var(--text-muted);
    opacity: 0.7;
}

.cal-habit-count {
    position: absolute;
    bottom: 1px;
    right: 2px;
    font-size: 8px;
    font-weight: 700;
    color: var(--yellow);
    line-height: 1;
}

.cal-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 8px;
    padding: 12px;
}

.cal-legend-label {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 4px;
}

.cal-legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

/* ─── Day Edit Modal ────────────────────────────────────── */

.cal-cell.cal-clickable { cursor: pointer; }
.cal-cell.cal-clickable:active { opacity: 0.7; }

.day-habit-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.day-habit-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    cursor: pointer;
    transition: background 0.15s;
}

.day-habit-row:active { opacity: 0.7; }

.day-habit-check {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.day-habit-row.done .day-habit-check {
    background: var(--green);
    border-color: var(--green);
}

.day-habit-check svg {
    width: 14px;
    height: 14px;
    opacity: 0;
}

.day-habit-row.done .day-habit-check svg {
    opacity: 1;
    stroke: var(--bg);
}

.day-habit-label {
    font-size: 15px;
    font-weight: 500;
}

.day-habit-row.done .day-habit-label {
    color: var(--green);
}

/* ─── Toast ─────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: calc(24px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    font-size: 13px;
    color: var(--text);
    z-index: 70;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Sparkline SVG ─────────────────────────────────────── */

.sparkline-path {
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sparkline-area {
    opacity: 0.1;
}

/* ─── Responsive ────────────────────────────────────────── */

@media (min-width: 600px) {
    .summary-grid { grid-template-columns: repeat(4, 1fr); }
    .habits-grid { grid-template-columns: repeat(6, 1fr); }
    .category-grid { grid-template-columns: repeat(4, 1fr); }
    .metric-name { font-size: 15px; }
}

@media (min-width: 1024px) {
    .content { max-width: 720px; margin: 0 auto; }
}
