/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --border: #2e3345;
    --text: #e4e6ef;
    --text-muted: #8b8fa3;
    --primary: #4f8cff;
    --primary-dim: rgba(79, 140, 255, 0.15);
    --green: #34d399;
    --green-dim: rgba(52, 211, 153, 0.15);
    --yellow: #fbbf24;
    --yellow-dim: rgba(251, 191, 36, 0.15);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.15);
    --radius: 10px;
    --radius-sm: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Nav === */
.nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}
.nav-brand:hover { text-decoration: none; }

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

.nav-links a {
    color: var(--text-muted);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
}
.nav-links a:hover { color: var(--text); text-decoration: none; background: var(--surface2); }
.nav-links a.active { color: var(--primary); background: var(--primary-dim); }

/* === Totals Bar === */
#totals-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    position: sticky;
    top: 48px;
    z-index: 99;
}

.totals-row {
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    gap: 20px;
}

.total-item { flex: 1; }
.total-label { font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.05em; margin-bottom: 3px; }
.total-numbers { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; }

.progress-bar {
    height: 8px;
    background: var(--surface2);
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar.small { height: 5px; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.progress-fill.good { background: var(--green); }
.progress-fill.warn { background: var(--yellow); }
.progress-fill.over { background: var(--red); }

/* === Container === */
.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 16px;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* === Auth Pages === */
.auth-page {
    padding: 60px 0 40px;
    text-align: center;
}
.auth-page h1 { font-size: 1.8rem; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 32px; }

.auth-form {
    max-width: 320px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: left;
}

.auth-link { margin-top: 20px; color: var(--text-muted); font-size: 0.9rem; }

/* === Forms === */
label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

input, select, textarea {
    padding: 10px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-dim);
}

button {
    padding: 10px 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.error {
    background: var(--red-dim);
    color: var(--red);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

/* === Profile === */
.profile-page {
    padding: 24px 0;
}
.profile-page h1 { margin-bottom: 8px; }
.profile-page > p { color: var(--text-muted); margin-bottom: 24px; }

.profile-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 400px;
}

.height-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}
.height-inputs input { width: 70px; }
.height-inputs span { color: var(--text-muted); font-size: 0.9rem; }

.targets-display {
    background: var(--green-dim);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.override-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.override-section legend {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0 4px;
}

.form-row.inline {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}
.form-row.inline label { flex: 1; }

/* === Chat === */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-bottom: 16px;
    min-height: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-messages.readonly { max-height: 600px; }

.chat-welcome {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }

.msg-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.chat-msg.user .msg-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant .msg-bubble {
    background: var(--surface2);
    border-bottom-left-radius: 4px;
}

.food-cards {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.food-card {
    background: var(--green-dim);
    border: 1px solid rgba(52, 211, 153, 0.2);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    position: relative;
}

.food-name { font-weight: 600; font-size: 0.9rem; }
.food-meal {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--primary);
    background: var(--primary-dim);
    padding: 1px 6px;
    border-radius: 3px;
    margin-right: 4px;
    letter-spacing: 0.03em;
}
.food-qty { font-weight: 400; color: var(--text-muted); }
.food-macros { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.food-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 2px 6px;
    cursor: pointer;
    opacity: 0.5;
}
.food-delete:hover { opacity: 1; color: var(--red); filter: none; }

.chat-input {
    display: flex;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.chat-input input {
    flex: 1;
    padding: 12px 16px;
    border-radius: 24px;
}

.chat-input button {
    border-radius: 24px;
    padding: 12px 24px;
}

/* === History === */
.history-page { padding: 24px 0; }
.history-page h1 { margin-bottom: 16px; }

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

.history-day-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
}
.history-day-card:hover { background: var(--surface2); text-decoration: none; }
.history-day-card.today { border-color: var(--primary); }

.history-date { font-weight: 600; min-width: 100px; font-size: 0.9rem; }
.badge {
    background: var(--primary-dim);
    color: var(--primary);
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    font-weight: 600;
}

.history-stats { font-size: 0.85rem; color: var(--text-muted); min-width: 130px; }
.history-progress { flex: 1; max-width: 120px; }

/* === History Day === */
.history-day-page { padding: 24px 0; }
.back-link { font-size: 0.85rem; }
.day-header h1 { margin-top: 4px; font-size: 1.3rem; }

.day-summary {
    display: flex;
    gap: 24px;
    margin: 20px 0;
}

.summary-stat { text-align: center; }
.summary-value { font-size: 2rem; font-weight: 700; }
.summary-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; }
.summary-target { font-size: 0.85rem; color: var(--text-muted); }

.food-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 24px;
}

.history-day-page h2 { font-size: 1rem; margin-bottom: 12px; color: var(--text-muted); }

/* === Weight === */
.weight-page { padding: 24px 0; }
.weight-page h1 { margin-bottom: 16px; }
.weight-page h2 { font-size: 1rem; margin: 24px 0 12px; color: var(--text-muted); }

.weigh-in-form { margin-bottom: 24px; }

.weight-chart {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 8px;
}

.weighin-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.weighin-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface);
    border-radius: var(--radius-sm);
}
.weighin-date { color: var(--text-muted); font-size: 0.85rem; min-width: 60px; }
.weighin-weight { font-weight: 600; flex: 1; }
.weighin-delta { font-size: 0.85rem; }
.weighin-delta.down { color: var(--green); }
.weighin-delta.up { color: var(--red); }

/* === Empty State === */
.empty-state { color: var(--text-muted); padding: 40px 0; text-align: center; }

/* === Responsive === */
@media (max-width: 480px) {
    .nav-links a { padding: 6px 6px; font-size: 0.8rem; }
    .totals-row { gap: 12px; }
    .day-summary { gap: 16px; }
    .summary-value { font-size: 1.5rem; }
    .form-row.inline { flex-direction: column; }
    .form-row.inline button { width: 100%; }
}
