@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,500;0,9..144,600;0,9..144,700;1,9..144,500&family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #2f9e6e;
    --primary-dark: #237d55;
    --primary-light: #e7f6ef;
    --bg: #f7f4ee;
    --card-bg: #ffffff;
    --text: #211f1c;
    --muted: #8a8579;
    --border: #ebe6dd;
    --danger: #d1483a;
    --radius: 20px;
    --radius-sm: 12px;
    --shadow: 0 1px 2px rgba(30, 25, 15, 0.03), 0 10px 30px -12px rgba(30, 25, 15, 0.12);
    --shadow-lg: 0 4px 8px rgba(30, 25, 15, 0.04), 0 24px 48px -20px rgba(30, 25, 15, 0.18);
    --font-display: "Fraunces", Georgia, "Times New Roman", serif;
    --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    margin: 0;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 28px 20px 72px;
}

.container-narrow { max-width: 480px; }

.header-actions { display: flex; gap: 10px; align-items: center; }

/* Top navigation */
.topnav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 24px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    flex-wrap: wrap;
    box-shadow: 0 1px 3px rgba(30, 25, 15, 0.03);
}
.topnav-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 1.15rem;
    text-decoration: none;
    color: var(--text);
    letter-spacing: -0.01em;
}
.topnav-brand { font-family: var(--font-display); font-weight: 600; }
.topnav-brand .app-logo { font-size: 1.4rem; }

.topnav-links { display: flex; align-items: center; gap: 6px; }

.navlink {
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.92rem;
    padding: 8px 14px;
    border-radius: 999px;
    transition: background 0.15s ease, color 0.15s ease;
}
.navlink:hover { color: var(--text); background: var(--bg); }
.navlink-active { color: var(--primary-dark); background: var(--primary-light); }

.topnav-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
    padding-left: 14px;
    border-left: 1px solid var(--border);
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
}
.btn-sm { padding: 7px 16px; font-size: 0.82rem; }

@media (max-width: 560px) {
    .topnav { padding: 10px 16px; gap: 10px; }
    .topnav-user-name { display: none; }
    .topnav-user { margin-left: 4px; padding-left: 10px; }
    .navlink { padding: 7px 10px; }
}

/* Auth cards */
.auth-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 26px;
    box-shadow: var(--shadow);
    margin-top: 32px;
}
.auth-card h1 { margin: 0 0 18px; }
.auth-switch { margin-top: 18px; text-align: center; color: var(--muted); font-size: 0.9rem; }
.auth-switch a { color: var(--primary-dark); font-weight: 600; }

/* Tracker */
.tracker-head { margin: 24px 0 20px; }
.tracker-head h1 { margin: 0 0 4px; }

.tracker-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 16px; font-size: 1.05rem; }
.tracker-food, .tracker-week { grid-column: 1 / -1; }

.btn-block { width: 100%; }

.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* Daily ring */
.ring-wrap { position: relative; width: 180px; height: 180px; margin: 0 auto 20px; }
.ring { width: 100%; height: 100%; }
.ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.ring-value { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; }
.ring-target { font-size: 0.85rem; color: var(--muted); }

/* Macro bars */
.macro { margin-bottom: 14px; }
.macro:last-child { margin-bottom: 0; }
.macro-top { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: 600; margin-bottom: 5px; }
.macro-bar { height: 9px; background: var(--border); border-radius: 999px; overflow: hidden; }
.macro-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.macro-protein { background: #2f9e6e; }
.macro-carbs { background: #e0a53b; }
.macro-fat { background: #6c8ee3; }

/* Food log */
.food-log { list-style: none; padding: 0; margin: 0; }
.food-log li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.food-log li:last-child { border-bottom: none; }
.food-log-main { display: flex; flex-direction: column; gap: 2px; }
.food-log-name { font-weight: 600; }
.food-log-meta { font-size: 0.82rem; color: var(--muted); }
.food-log-del {
    color: var(--danger);
    font-size: 1.4rem;
    text-decoration: none;
    line-height: 1;
    padding: 0 6px;
}

/* Week table + graph */
.week-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.week-table th, .week-table td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.week-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.week-table th:not(:first-child), .week-table td:not(:first-child) { text-align: right; }
.week-today { background: var(--primary-light); font-weight: 700; }
.week-today td:first-child { border-radius: 8px 0 0 8px; }
.week-today td:last-child { border-radius: 0 8px 8px 0; }

.week-graph { background: var(--bg); border-radius: var(--radius-sm); padding: 14px 16px; }
.week-graph-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.graph-svg { width: 100%; height: 160px; display: block; }

@media (max-width: 700px) {
    .tracker-grid { grid-template-columns: 1fr; }
    .tracker-food, .tracker-week { grid-column: auto; }
    .form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
}

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

.app-brand { display: flex; align-items: center; gap: 10px; }
.app-logo { font-size: 1.8rem; }
.app-header h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

h1 { margin: 0; font-size: 2rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
h2 { font-size: 1.25rem; }
h3 { margin-top: 32px; margin-bottom: 12px; font-size: 1.1rem; }

.muted { color: var(--muted); font-size: 0.92rem; }
.error { color: var(--danger); font-weight: 600; background: #fbeae7; padding: 10px 14px; border-radius: var(--radius-sm); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 22px;
    border-radius: 999px;
    text-decoration: none;
    font-family: var(--font-body);
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-size: 0.92rem;
    line-height: 1;
    transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: white; box-shadow: 0 6px 16px -6px rgba(47, 158, 110, 0.6); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 8px 20px -6px rgba(47, 158, 110, 0.7); }
.btn-lg { padding: 14px 30px; font-size: 1rem; }

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

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

/* Speed filter (soort maaltijd — hoger niveau dan categorie) */
.speed-filter {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.speed-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 22px;
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    border: 1.5px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.98rem;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.speed-tab:hover { border-color: var(--muted); }
.speed-tab-icon { font-size: 1.15rem; }
.speed-tab-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 6px 16px -6px rgba(47, 158, 110, 0.55);
}

/* Speed choice in het formulier */
.speed-choice { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.speed-option { margin: 0 !important; cursor: pointer; flex: 1; min-width: 180px; }
.speed-option input { position: absolute; opacity: 0; width: 0; height: 0; }
.speed-option > span {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: #fdfcfa;
    font-weight: 600;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.speed-option-icon { font-size: 1.3rem; }
.speed-option:hover > span { border-color: var(--muted); }
.speed-option input:checked + span {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary-dark);
    box-shadow: 0 0 0 3px rgba(47, 158, 110, 0.12);
}
.speed-option input:focus-visible + span { outline: 2px solid var(--primary-dark); outline-offset: 2px; }

/* Category pills */
.category-pills {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 14px;
    margin-bottom: 16px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.category-pills::-webkit-scrollbar { height: 7px; }
.category-pills::-webkit-scrollbar-track { background: transparent; }
.category-pills::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}
.category-pills::-webkit-scrollbar-thumb:hover { background: #d6ccbc; }

.pill {
    flex: 0 0 auto;
    scroll-snap-align: start;
    padding: 9px 18px;
    border-radius: 999px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.pill:hover { background: var(--bg); border-color: var(--muted); }
.pill-active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.category-tag {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 10px;
    border-radius: 999px;
}

.category-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.speed-badge {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 999px;
}

.view-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

/* Category chips (multi-select in het formulier) */
.category-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}
.chip {
    display: inline-flex;
    align-items: center;
    margin: 0 !important;
    cursor: pointer;
}
.chip input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.chip span {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 600;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.chip:hover span { border-color: var(--muted); }
.chip input:checked + span {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.chip input:focus-visible + span {
    outline: 2px solid var(--primary-dark);
    outline-offset: 2px;
}

/* Recipe grid + cards */
.recipe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

.recipe-card {
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.recipe-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.card-link-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.recipe-thumb-wrap { position: relative; }

.recipe-thumb {
    width: 100%;
    height: 150px;
    object-fit: cover;
    display: block;
}

.recipe-thumb-placeholder {
    background: linear-gradient(135deg, var(--primary-light), #f3ede0);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.8rem;
}

.kcal-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(35, 35, 33, 0.75);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    backdrop-filter: blur(2px);
}

.recipe-card-body { padding: 14px 16px 6px; position: relative; z-index: 2; pointer-events: none; }
.recipe-card-body h2 { margin: 0 0 4px; }

.card-actions {
    display: flex;
    gap: 14px;
    font-size: 0.85rem;
    padding: 10px 16px 14px;
    position: relative;
    z-index: 2;
}
.card-actions a { color: var(--primary-dark); text-decoration: none; font-weight: 600; }
.card-actions a.danger { color: var(--danger); }
.card-actions a:hover { text-decoration: underline; }

.empty-state {
    text-align: center;
    padding: 64px 20px;
    color: var(--muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { margin-bottom: 20px; }

/* Forms */
.form-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

form label { display: block; margin-bottom: 16px; font-weight: 600; font-size: 0.9rem; }
form label:last-child { margin-bottom: 0; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

form input[type="text"], form input[type="number"], form input[type="password"], form input[type="file"], form select, form textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    margin-top: 6px;
    font-weight: 500;
    background: #fdfcfa;
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
form input::placeholder, form textarea::placeholder { color: #b3ab9d; }
form input:focus, form select:focus, form textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(47, 158, 110, 0.12);
}

.ingredient-row-header {
    display: grid;
    grid-template-columns: 2fr 0.8fr 0.6fr 0.8fr 0.8fr 0.8fr 0.8fr auto;
    gap: 8px;
    margin-bottom: 8px;
    padding: 0 9px;
}
.ingredient-row-header span {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}

.ingredient-row {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.ingredient-row:last-child { border-bottom: none; }

.ingredient-row-fields {
    display: grid;
    grid-template-columns: 2fr 0.8fr 0.6fr 0.8fr 0.8fr 0.8fr 0.8fr auto;
    gap: 8px;
    align-items: center;
    position: relative;
}

.ingredient-row-fields input { margin: 0; padding: 9px; font-size: 0.85rem; }

.ing-row-total {
    margin: 6px 0 0;
    font-size: 0.82rem;
    color: var(--primary-dark);
    font-weight: 600;
    min-height: 1.2em;
}

.nutrition-totals-box {
    margin-top: 20px;
    padding: 16px 18px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
}
.nutrition-totals-box h4 {
    margin: 0 0 10px;
    font-size: 0.9rem;
    color: var(--primary-dark);
}
.nutrition-totals-box .nutrition-table th,
.nutrition-totals-box .nutrition-table td {
    border-bottom: 1px solid rgba(47, 158, 110, 0.15);
}

.ing-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    width: 260px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    z-index: 10;
    display: none;
    max-height: 240px;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.ing-suggestions.open { display: block; }

.suggestion-item {
    padding: 9px 12px;
    cursor: pointer;
    font-size: 0.83rem;
    border-bottom: 1px solid var(--border);
}
.suggestion-item:hover { background: var(--primary-light); }
.suggestion-item:last-child { border-bottom: none; }

.btn-remove-row {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1.3rem;
    cursor: pointer;
    line-height: 1;
}

.form-actions { margin-top: 24px; text-align: right; }

/* Nutrition */
.nutrition-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

.nutrition-table { width: 100%; border-collapse: collapse; }
.nutrition-table th, .nutrition-table td {
    text-align: left;
    padding: 9px 6px;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}
.nutrition-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.nutrition-table tr:last-child td { border-bottom: none; }

.ingredient-list { padding-left: 4px; list-style: none; }
.ingredient-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.ingredient-list li:last-child { border-bottom: none; }

.instructions { white-space: pre-wrap; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }

.recipe-photo {
    width: 100%;
    max-height: 380px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.field-label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.dropzone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover, .dropzone.dropzone-active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.dropzone-empty { padding: 24px; color: var(--muted); }
.dropzone-icon { font-size: 2.2rem; display: block; margin-bottom: 8px; }
.dropzone-empty p { margin: 2px 0; }
.dropzone-empty strong { color: var(--text); }

.dropzone-preview {
    width: 100%;
    max-height: 280px;
    object-fit: cover;
    display: block;
}

.dropzone-overlay {
    position: absolute;
    inset: 0;
    background: rgba(35, 35, 33, 0.55);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}
.dropzone:has(.dropzone-preview:not([style*="display: none"])):hover .dropzone-overlay {
    opacity: 1;
}

.dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

@media (max-width: 700px) {
    .form-row { grid-template-columns: 1fr; }
    .ingredient-row-header { display: none; }
    .ingredient-row-fields {
        grid-template-columns: 1fr 1fr;
    }
    .ing-suggestions { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
