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

:root {
    --bg: #0a0e14;
    --bg-gradient: linear-gradient(180deg, #0d1219 0%, #0a0e14 100%);
    --surface: #131a24;
    --surface-raised: #1a2332;
    --surface-overlay: #1f2d3f;
    --border: #2a3a50;
    --border-bright: #3d5570;
    --text: #f0f4f8;
    --text-secondary: #b8c8d8;
    --text-muted: #7a8ea0;
    --accent: #4a9eff;
    --accent-glow: rgba(74, 158, 255, 0.2);
    --green: #3dd68c;
    --green-glow: rgba(61, 214, 140, 0.15);
    --yellow: #f0c030;
    --red: #ff5c5c;
    --red-glow: rgba(255, 92, 92, 0.15);
    --orange: #ff9940;
    --purple: #b388ff;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --header-height: 56px;
    --tab-height: 44px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Category accent colors */
    --cat-passive: #4a9eff;
    --cat-direct: #3dd68c;
    --cat-real: #b388ff;
    --cat-exercise: #ff9940;
}

*, *::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;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--accent), var(--green));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.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: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.header-title {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--green));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.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); }
}

/* ─── 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; }

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

.content {
    height: calc(100vh - var(--header-height) - var(--tab-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);
}

/* ─── 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); }

.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 ──────────────────────────────────────── */

.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-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;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.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;
}

.mv-latest.today-best-minor {
    color: color-mix(in srgb, var(--green) 50%, var(--text-muted));
}

.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-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;
}

.modal-body input[type="number"],
.modal-body input[type="date"] {
    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;
}

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

.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.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;
}

/* ─── 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); }
}
