:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --border: #2d3244;
    --text: #e4e6eb;
    --text-dim: #8b8fa3;
    --blue: #3b82f6;
    --green: #22c55e;
    --red: #ef4444;
    --orange: #f59e0b;
    --purple: #a855f7;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Nav */
nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 24px;
}
nav .logo { font-weight: 700; font-size: 18px; color: var(--blue); }
nav a { color: var(--text-dim); text-decoration: none; font-size: 14px; padding: 6px 12px; border-radius: 6px; }
nav a:hover, nav a.active { color: var(--text); background: var(--surface2); }
nav .spacer { flex: 1; }
nav .logout { color: var(--red); cursor: pointer; font-size: 13px; }

/* Layout */
.container { max-width: 900px; margin: 0 auto; padding: 24px; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}
.card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); margin-bottom: 12px; }

/* Stat grid */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.stat {
    background: var(--surface2);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
}
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); margin-bottom: 6px; }
.stat .value { font-size: 24px; font-weight: 700; }
.stat .sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* Colors */
.green { color: var(--green); }
.red { color: var(--red); }
.blue { color: var(--blue); }
.orange { color: var(--orange); }
.purple { color: var(--purple); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); border-bottom: 2px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--surface2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Chart container */
.chart-container { position: relative; margin: 16px 0; }
.chart-bar-row {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 140px;
    padding: 0 4px;
}
.chart-bar {
    flex: 1;
    min-width: 20px;
    border-radius: 4px 4px 0 0;
    position: relative;
    transition: opacity 0.2s;
}
.chart-bar:hover { opacity: 0.8; }
.chart-bar .tip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 10;
}
.chart-bar:hover .tip { display: block; }
.chart-labels {
    display: flex;
    gap: 4px;
    padding: 4px 4px 0;
}
.chart-labels span {
    flex: 1;
    text-align: center;
    font-size: 10px;
    color: var(--text-dim);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--blue); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }

/* Forms */
input, select {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--blue); }
label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; display: block; }
.form-row { display: flex; gap: 12px; margin-bottom: 12px; }
.form-row > * { flex: 1; }

/* Macro bar */
.macro-bar {
    display: flex;
    height: 24px;
    border-radius: 12px;
    overflow: hidden;
    font-size: 11px;
    font-weight: 600;
    color: white;
    margin: 8px 0;
}
.macro-bar > div { display: flex; align-items: center; justify-content: center; }

/* Progress bar */
.progress { height: 12px; background: var(--surface2); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 6px; transition: width 0.3s; }

/* Login page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}
.login-card h1 { font-size: 24px; margin-bottom: 8px; }
.login-card p { color: var(--text-dim); margin-bottom: 24px; }
.login-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: 16px; }
.login-card .btn + .btn { margin-top: 12px; }
.login-card .error { color: var(--red); font-size: 13px; margin-top: 12px; }
.login-card .icon { font-size: 48px; margin-bottom: 16px; }

/* Responsive */
@media (max-width: 600px) {
    .container { padding: 12px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { flex-direction: column; }
    nav { padding: 10px 16px; gap: 12px; }
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-dim);
}

/* Drag and drop */
.meal-row { cursor: grab; }
.meal-row:active { cursor: grabbing; }
.day-total-row { background: var(--surface2); transition: background 0.15s, outline 0.15s; }
.drop-target { outline: 2px dashed var(--blue); outline-offset: -2px; }
.drop-hover { background: rgba(59, 130, 246, 0.15) !important; outline-color: var(--green); }
