:root {
    --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
                   "Helvetica Neue", Arial, sans-serif;

    --accent: #007AFF;
    --accent-tint-bg: rgba(0, 122, 255, 0.12);

    --bg-primary: #F2F2F7;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F2F2F7;

    --label-primary: rgba(0, 0, 0, 1);
    --label-secondary: rgba(60, 60, 67, 0.6);
    --label-tertiary: rgba(60, 60, 67, 0.3);

    --fill-primary: rgba(120, 120, 128, 0.2);
    --fill-secondary: rgba(120, 120, 128, 0.16);
    --fill-tertiary: rgba(118, 118, 128, 0.12);
    --fill-quaternary: rgba(116, 116, 128, 0.08);

    --separator: rgba(60, 60, 67, 0.29);

    --green: #34C759; --green-text: #248a3d; --green-bg: rgba(52, 199, 89, 0.14);
    --orange: #FF9500; --orange-text: #9a5a00; --orange-bg: rgba(255, 149, 0, 0.14);
    --red: #FF3B30; --red-text: #b8291f; --red-bg: rgba(255, 59, 48, 0.14);

    --glass-tint: rgba(255, 255, 255, 0.55);
    --glass-tint-strong: rgba(255, 255, 255, 0.78);
    --glass-border: rgba(255, 255, 255, 0.65);

    --r-sm: 8px; --r-md: 14px; --r-lg: 20px; --r-xl: 28px;

    --shadow-card: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
    --shadow-modal: 0 20px 60px rgba(0,0,0,0.22);
    --shadow-glass: inset 0 1px 0 rgba(255,255,255,0.5), 0 8px 30px rgba(31,38,90,0.10);

    --ease-standard: cubic-bezier(0.2, 0.8, 0.2, 1);
    --ease-out-soft: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #000000;
        --bg-secondary: #1C1C1E;
        --bg-tertiary: #2C2C2E;

        --label-primary: rgba(255, 255, 255, 1);
        --label-secondary: rgba(235, 235, 245, 0.6);
        --label-tertiary: rgba(235, 235, 245, 0.3);

        --separator: rgba(84, 84, 88, 0.6);

        --accent: #0A84FF;
        --accent-tint-bg: rgba(10, 132, 255, 0.18);

        --green: #30D158; --green-text: #30D158; --green-bg: rgba(48, 209, 88, 0.16);
        --orange: #FF9F0A; --orange-text: #FF9F0A; --orange-bg: rgba(255, 159, 10, 0.16);
        --red: #FF453A; --red-text: #FF453A; --red-bg: rgba(255, 69, 58, 0.16);

        --glass-tint: rgba(30, 30, 34, 0.55);
        --glass-tint-strong: rgba(30, 30, 34, 0.78);
        --glass-border: rgba(255, 255, 255, 0.12);

        --shadow-glass: inset 0 1px 0 rgba(255,255,255,0.06), 0 8px 30px rgba(0,0,0,0.45);
    }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font-system);
    background: var(--bg-primary);
    color: var(--label-primary);
    -webkit-font-smoothing: antialiased;
}

/* Ambient wash behind everything -- gives the glass sidebar something to refract */
.ambient-mesh {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(circle at 8% 8%, rgba(120,170,255,0.35), transparent 55%),
        radial-gradient(circle at 92% 12%, rgba(255,150,190,0.28), transparent 55%),
        radial-gradient(circle at 25% 95%, rgba(140,230,200,0.24), transparent 55%);
    filter: blur(80px) saturate(150%);
}

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

::selection { background: var(--accent); color: #fff; }

/* Layout */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    flex-shrink: 0;
    padding: 28px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--glass-tint-strong);
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
}

.sidebar h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 4px 0 28px;
    color: var(--label-primary);
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar nav a {
    display: block;
    padding: 10px 14px;
    border-radius: var(--r-md);
    color: var(--label-secondary);
    font-size: 15px;
    font-weight: 500;
    transition: background-color 0.15s var(--ease-standard), color 0.15s var(--ease-standard);
}

.sidebar nav a:hover { background: var(--fill-tertiary); text-decoration: none; color: var(--label-primary); }

.sidebar nav a.active {
    background: var(--accent);
    color: #fff;
}

.sidebar .logout {
    margin-top: auto;
    padding-top: 16px;
    font-size: 13px;
    color: var(--red-text);
    opacity: 0.85;
}
.sidebar .logout:hover { opacity: 1; text-decoration: none; }

.main {
    flex: 1;
    padding: 40px 48px;
    max-width: 1040px;
    background: var(--bg-primary);
}

.main.main-full {
    max-width: none;
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Typography scale */

.main h2 {
    font-size: 28px;
    line-height: 34px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 20px;
    color: var(--label-primary);
}

.main h3 {
    font-size: 20px;
    line-height: 25px;
    font-weight: 600;
    margin: 0 0 14px;
    color: var(--label-primary);
}

p { line-height: 1.5; }

.muted { color: var(--label-secondary); font-size: 15px; }

/* Cards */

.card {
    background: var(--bg-secondary);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-card);
    padding: 24px;
    margin-bottom: 20px;
}

/* Stats */

.stats { display: flex; gap: 16px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 180px; }
.stat .value {
    font-size: 34px;
    line-height: 41px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--label-primary);
}
.stat .label {
    font-size: 13px;
    color: var(--label-secondary);
    font-weight: 500;
}

/* Tables -- styled as an inset-grouped list */

table { width: 100%; border-collapse: collapse; }

th {
    text-align: left;
    padding: 0 8px 10px;
    color: var(--label-secondary);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-bottom: 1px solid var(--separator);
}

td {
    text-align: left;
    padding: 13px 8px;
    font-size: 15px;
    border-bottom: 1px solid var(--separator);
}

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

tbody tr:hover td { background: var(--fill-quaternary); }

/* Badges */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 700;
}
.badge.active { background: var(--green-bg); color: var(--green-text); }
.badge.paused { background: var(--orange-bg); color: var(--orange-text); }
.badge.finished { background: var(--fill-secondary); color: var(--label-secondary); }

/* Forms */

form.stacked label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--label-secondary);
    margin: 16px 0 6px;
}

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=time], textarea, select {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid transparent;
    background: var(--fill-tertiary);
    border-radius: var(--r-sm);
    font-size: 15px;
    font-family: inherit;
    color: var(--label-primary);
    transition: background-color 0.15s var(--ease-standard), box-shadow 0.15s var(--ease-standard);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    background: var(--bg-secondary);
    box-shadow: 0 0 0 3px var(--accent-tint-bg), inset 0 0 0 1px var(--accent);
}

textarea { min-height: 110px; resize: vertical; line-height: 1.45; }

label input[type=checkbox] { width: auto; margin-right: 6px; vertical-align: middle; }

/* Buttons -- filled / tinted / gray / danger */

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    padding: 0 22px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 9999px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    margin-top: 18px;
    transition: transform 0.15s var(--ease-standard), opacity 0.15s var(--ease-standard);
}
button:hover, .btn:hover { opacity: 0.88; text-decoration: none; }
button:active, .btn:active { transform: scale(0.97); }

.btn-secondary {
    background: var(--fill-secondary);
    color: var(--label-primary);
    height: 36px;
    padding: 0 16px;
    font-size: 13px;
    margin-top: 0;
}

.btn-danger {
    background: var(--red-bg);
    color: var(--red-text);
    height: 36px;
    padding: 0 16px;
    font-size: 13px;
    margin-top: 0;
}

.error { color: var(--red-text); font-size: 14px; margin: 8px 0; }

.notice {
    background: var(--green-bg);
    color: var(--green-text);
    padding: 12px 16px;
    border-radius: var(--r-md);
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
}

/* Login (glass sheet floating over the ambient wash) */

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.login-box {
    width: 340px;
    padding: 32px;
    background: var(--glass-tint-strong);
    backdrop-filter: blur(34px) saturate(190%);
    -webkit-backdrop-filter: blur(34px) saturate(190%);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-glass), var(--shadow-modal);
}

.login-box h2 { text-align: center; }

/* Chart */

.weight-chart { width: 100%; height: auto; }

@media (prefers-reduced-motion: reduce) {
    * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
