:root {
    --bg: #f6f7fb;
    --card: #ffffff;
    --text: #1e2130;
    --muted: #8a8fa3;
    --border: #e9eaf2;
    --primary: #6c5ce7;
    --primary-dark: #5849c2;

    --gray: #e3e5ee;
    --gray-text: #9aa0b4;
    --red: #ff6b6b;
    --red-bg: #ffecec;
    --orange: #ffa94d;
    --orange-bg: #fff3e6;
    --yellow: #ffd43b;
    --yellow-bg: #fffbe6;
    --green: #2ecc71;
    --green-bg: #e8f9ef;
    --future-bg: #f0f1f6;

    --radius: 16px;
    --shadow: 0 4px 20px rgba(30, 33, 48, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

.wrap.narrow {
    max-width: 640px;
}

/* ---------- Header ---------- */
.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 12px;
    flex-wrap: wrap;
}

.top-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 400;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 12px;
    font-family: inherit;
    font-weight: 500;
    font-size: 14px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all .15s ease;
}

.btn-ghost {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: #fafafd; border-color: #d8daea; }

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

.btn-block { width: 100%; justify-content: center; }

/* ---------- Stat cards ---------- */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-num {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.stat-total { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat-green { color: #27ae60; }
.stat-orange { color: #e67e22; }

.stat-label {
    font-size: 12.5px;
    color: var(--muted);
    font-weight: 500;
}

/* ---------- Legend ---------- */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 18px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.dot.gray { background: var(--gray); }
.dot.red { background: var(--red); }
.dot.orange { background: var(--orange); }
.dot.yellow { background: var(--yellow); }
.dot.green { background: var(--green); }
.dot.future { background: var(--future-bg); border: 1px dashed #c7c9d9; }

/* ---------- Grid ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 8px;
}

.day-box {
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    background: var(--gray);
    transition: transform .12s ease, box-shadow .12s ease;
    position: relative;
}

.day-box:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(30,33,48,0.12); }

.day-box.future {
    background: var(--future-bg);
    color: #c3c6d6;
    cursor: default;
    pointer-events: none;
    border: 1px dashed #dcdee9;
}

.day-box.red     { background: var(--red-bg);    color: #d63031; }
.day-box.orange  { background: var(--orange-bg); color: #d1780b; }
.day-box.yellow  { background: var(--yellow-bg); color: #b8960c; }
.day-box.green   { background: var(--green-bg);  color: #1f9e56; }

.day-box.is-today {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---------- Day hero ---------- */
.day-hero {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px 20px;
    text-align: center;
    margin-bottom: 18px;
    border-top: 5px solid var(--gray);
}

.day-hero.status-red     { border-top-color: var(--red); }
.day-hero.status-orange  { border-top-color: var(--orange); }
.day-hero.status-yellow  { border-top-color: var(--yellow); }
.day-hero.status-green   { border-top-color: var(--green); }

.day-hero-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.nav-arrow {
    text-decoration: none;
    color: var(--muted);
    font-size: 22px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}
.nav-arrow:hover { background: var(--bg); }
.nav-arrow.disabled { pointer-events: none; opacity: 0.25; }

.day-hero-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.day-hero-num { font-size: 13px; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; }
.day-hero-date { font-size: 18px; font-weight: 600; }

.day-hero-status {
    font-size: 15px;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 14px;
}

.progress-dots {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.pdot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gray);
    transition: background .15s ease;
}
.pdot.on { background: var(--green); }

/* ---------- Checklist card ---------- */
.checklist-card, .calorie-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 20px;
    margin-bottom: 18px;
}

.checklist-card h2, .calorie-card h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 16px;
}

.check-row {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.check-row:last-child { border-bottom: none; padding-bottom: 0; }
.check-row-auto { cursor: default; }

.check-row input[type="checkbox"] {
    display: none;
}

.check-box {
    width: 26px;
    height: 26px;
    min-width: 26px;
    border-radius: 8px;
    border: 2px solid var(--border);
    background: var(--bg);
    position: relative;
    transition: all .15s ease;
    margin-top: 2px;
}

.check-row input:checked + .check-box {
    background: var(--green);
    border-color: var(--green);
}
.check-row input:checked + .check-box::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
}

.check-box.auto.on {
    background: var(--green);
    border-color: var(--green);
}
.check-box.auto.on::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
}

.check-text { display: flex; flex-direction: column; gap: 2px; }
.check-text strong { font-size: 14.5px; font-weight: 500; }
.check-text small { color: var(--muted); font-size: 12.5px; }

/* ---------- Calorie card ---------- */
.calorie-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.calorie-head h2 { margin: 0; }

.calorie-total {
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
}
#calorieTotal { color: var(--text); font-size: 16px; }

.calorie-bar-track {
    width: 100%;
    height: 10px;
    background: var(--bg);
    border-radius: 20px;
    overflow: hidden;
    margin: 12px 0 18px;
}
.calorie-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #a29bfe);
    border-radius: 20px;
    transition: width .3s ease;
}
.calorie-bar-fill.over {
    background: linear-gradient(90deg, #ff6b6b, #ff8787);
}

.food-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.food-form input[type="text"] {
    flex: 2;
    min-width: 140px;
}
.food-form input[type="number"] {
    flex: 1;
    min-width: 80px;
}
.food-form input {
    font-family: inherit;
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 14px;
    outline: none;
}
.food-form input:focus { border-color: var(--primary); }

.food-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.food-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 10px;
    font-size: 14px;
}
.food-name { flex: 1; font-weight: 500; }
.food-cal { color: var(--muted); font-weight: 500; font-size: 13px; }
.food-del {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
}
.food-del:hover { background: var(--red-bg); color: var(--red); }

.food-empty {
    text-align: center;
    color: var(--muted);
    font-size: 13.5px;
    padding: 10px 0;
    list-style: none;
}

/* ---------- Settings form ---------- */
.settings-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 500; color: var(--muted); }
.field input {
    font-family: inherit;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 15px;
    color: var(--text);
    outline: none;
}
.field input:focus { border-color: var(--primary); }

.alert {
    background: var(--green-bg);
    color: #1f9e56;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 500;
    margin-bottom: 16px;
}

.info-text {
    font-size: 13.5px;
    color: var(--muted);
    line-height: 1.6;
    margin: 0 0 10px;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .top-header h1 { font-size: 20px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; }
    .day-box { font-size: 10.5px; border-radius: 8px; }
    .food-form { flex-direction: column; }
    .food-form input { width: 100%; }
}

@media (max-width: 400px) {
    .stats-row { grid-template-columns: 1fr 1fr; }
}
