:root {
    --primary: #e07b7b;
    --primary-light: #fce4e4;
    --primary-dark: #c45c5c;
    --gold: #d4a853;
    --gold-light: #fef6e4;
    --bg: #fef9f4;
    --card-bg: #ffffff;
    --text: #3d2c2c;
    --text-secondary: #6b5b5b;
    --border: #f0e0d6;
    --danger: #d9534f;
    --success: #6aab73;
    --purple: #9b7bb8;
    --blue: #5b9bd5;
    --blue-light: #eef4fb;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    --radius: 18px;
    --radius-sm: 12px;
}

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

body {
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    padding: 16px;
    -webkit-font-smoothing: antialiased;
}

.container { max-width: 720px; margin: 0 auto; }

/* ── Navigation ─────────────────── */

.nav-bar {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 10px 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.nav-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-brand {
    font-weight: 800;
    color: var(--primary-dark);
    text-decoration: none;
    font-size: 1.05rem;
    margin-right: auto;
}

.nav-links {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 14px;
    transition: background 0.15s;
}

.nav-links a:hover { background: var(--primary-light); color: var(--primary-dark); }

.nav-logout { color: var(--danger) !important; }
.nav-user {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--primary-light);
    padding: 2px 10px;
    border-radius: 12px;
    white-space: nowrap;
}

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

.header {
    text-align: center;
    padding: 28px 20px 20px;
    background: linear-gradient(135deg, #fce4e4 0%, #fdf2f2 40%, #fff5f0 100%);
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.header .icon { font-size: 3rem; margin-bottom: 6px; }

.header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.header .subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
    background: rgba(255, 255, 255, 0.7);
    display: inline-block;
    padding: 4px 14px;
    border-radius: 20px;
    margin-top: 6px;
}

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

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px 18px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 2px dashed var(--primary-light);
    padding-bottom: 10px;
}

.card h2 .emoji { font-size: 1.4rem; }

.card.cash-card {
    border: 2px solid #f0d78c;
    background: linear-gradient(135deg, #fffdf7, #fff9f0);
}

.card.cash-card h2 { color: #8b6914; border-bottom-color: #f0d78c; }

/* ── Auth ─────────────────── */

.auth-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px 24px;
    margin: 40px auto;
    max-width: 400px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

/* ── Flash Messages ─────────────────── */

.flash-container { margin-bottom: 16px; }

.flash {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.flash-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.flash-danger { background: #fde8e8; color: #a83232; border: 1px solid #f5c6cb; }
.flash-warning { background: #fef6e4; color: #8b6914; border: 1px solid #f0d78c; }
.flash-info { background: var(--blue-light); color: #3a6fa0; border: 1px solid #b8d4f0; }

/* ── Forms ─────────────────── */

.form { display: flex; flex-direction: column; gap: 16px; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

input, select, .input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: #fefcf9;
    transition: border-color 0.15s;
    outline: none;
}

input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.form-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.form-inline {
    display: flex;
    gap: 10px;
    align-items: center;
}

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

.btn {
    display: inline-block;
    padding: 8px 18px;
    border-radius: 14px;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    line-height: 1.4;
}

.btn:hover { background: #f5f0eb; }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-gold {
    background: var(--gold);
    color: #fff;
    border-color: var(--gold);
    font-size: 1rem;
    padding: 12px 24px;
}

.btn-gold:hover { background: #c49a3a; }
.btn-gold:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-full { width: 100%; text-align: center; }

/* ── Stats Row ─────────────────── */

.stats-row {
    display: flex;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 100px;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.stat-label { font-size: 0.8rem; color: var(--text-secondary); font-weight: 600; }
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--primary-dark); }
.stat-sub { font-size: 0.8rem; color: var(--text-secondary); }

.stat-points .stat-value { color: #c4912a; }
.stat-streak .stat-value { color: var(--primary); }
.stat-week .stat-value { color: #2e7d32; }

/* ── Progress Bar ─────────────────── */

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.progress-bar {
    height: 12px;
    background: var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--gold));
    border-radius: 10px;
    transition: width 0.3s;
}

/* ── Mini Calendar ─────────────────── */

.mini-calendar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.mini-day {
    width: 52px;
    text-align: center;
    padding: 8px 4px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    border: 1px solid var(--border);
}

.mini-day.valid { background: #e8f5e9; border-color: #a5d6a7; }
.mini-day.invalid { background: #fde8e8; border-color: #f5c6cb; }
.mini-date { font-weight: 600; }
.mini-kcal { font-size: 0.7rem; color: var(--text-secondary); }

/* ── Transactions ─────────────────── */

.txn-list { display: flex; flex-direction: column; }

.txn-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border);
    gap: 12px;
}

.txn-item:last-child { border-bottom: none; }

.txn-desc { flex: 1; font-size: 0.9rem; }
.txn-date { font-size: 0.75rem; color: var(--text-secondary); margin-left: 8px; }
.txn-pts { font-weight: 800; font-size: 1rem; white-space: nowrap; }
.txn-item.positive .txn-pts { color: #2e7d32; }
.txn-item.negative .txn-pts { color: var(--danger); }

/* ── Food Grid ─────────────────── */

.food-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.food-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    background: #fefcf9;
}

.food-item:hover { border-color: var(--primary); background: var(--primary-light); }
.food-item.selected { border-color: var(--danger); background: #fde8e8; }

.food-pts { color: var(--danger); font-weight: 700; font-size: 0.8rem; }

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

.month-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.calendar {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.cal-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: var(--primary-light);
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--primary-dark);
}

.cal-header span { padding: 8px 4px; text-align: center; }

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

.cal-day {
    min-height: 70px;
    padding: 6px 4px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-align: center;
    font-size: 0.8rem;
}

.cal-day:nth-child(7) { border-right: none; }
.cal-week:last-child .cal-day { border-bottom: none; }
.cal-day.empty { background: #faf8f5; }

.cal-date { font-weight: 700; margin-bottom: 2px; font-size: 0.8rem; }
.cal-status { font-size: 1.1rem; }
.cal-info { font-size: 0.7rem; color: var(--text-secondary); }
.cal-info.weigh { color: var(--blue); }

/* ── Shop Vouchers ─────────────────── */

.voucher-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.voucher-card {
    background: #fffbf5;
    border: 1px solid #f5e1c4;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 120px;
    flex: 1;
}

.voucher-name { font-weight: 700; color: #5e3a1c; font-size: 0.95rem; }
.voucher-cost { color: var(--text-secondary); font-size: 0.85rem; }

/* ── Milestones ─────────────────── */

.milestone-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
}

.milestone-item {
    flex: 1 1 140px;
    background: linear-gradient(135deg, #fff9f0, #fef6e4);
    border: 1px solid #f0d78c;
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
    font-weight: 600;
    color: #5c3d0e;
}

.milestone-item.claimed { opacity: 0.65; background: #f0f0f0; border-color: #ddd; }

.milestone-icon { font-size: 1.3rem; margin-bottom: 4px; }
.milestone-lbs { font-size: 0.9rem; }
.milestone-pts { font-size: 1.2rem; font-weight: 800; color: #c4912a; }
.milestone-bonus { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 4px; }
.milestone-badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; background: #e8f5e9; color: #2e7d32; display: inline-block; }

/* ── Alert ─────────────────── */

.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 0.9rem; margin-bottom: 14px; }
.alert-info { background: var(--blue-light); border: 1px solid #b8d4f0; color: #3a6fa0; }

/* ── Tables ─────────────────── */

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 700;
    padding: 10px;
    text-align: left;
    white-space: nowrap;
    font-size: 0.85rem;
}

td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    color: var(--text);
}

tr:last-child td { border-bottom: none; }

.tag {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 14px;
    font-size: 0.8rem;
    margin: 2px 2px;
    white-space: nowrap;
}

.tag.gold { background: var(--gold-light); color: #8b6914; }
.tag.purple { background: #f3eef8; color: #6a4f8a; }
.tag.danger { background: #fde8e8; color: #a83232; }

.footer-note {
    text-align: center;
    font-size: 0.8rem;
    color: #a09090;
    padding: 16px;
    margin-top: 6px;
}

/* ── Leaderboard ─────────────────── */

.leaderboard {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.leaderboard th {
    text-align: left;
    padding: 8px 6px;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    font-weight: 600;
}
.leaderboard td {
    padding: 6px;
    border-bottom: 1px solid var(--border);
}
.leaderboard tr.me {
    background: #fef9e7;
    font-weight: 600;
}
.leaderboard tr.me td:first-child::after {
    content: " 👈";
}

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

@media (max-width: 500px) {
    body { padding: 10px; }
    .header h1 { font-size: 1.5rem; }
    .card { padding: 16px 12px; }
    .nav-links a { font-size: 0.78rem; padding: 3px 8px; }
    .stat-card { min-width: 80px; }
    .stat-value { font-size: 1.4rem; }
    .cal-day { min-height: 56px; padding: 4px 2px; font-size: 0.7rem; }
    .milestone-item { flex: 1 1 120px; padding: 10px 6px; }
}

@media print {
    body { background: #fff; padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    .nav-bar { display: none; }
}
