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

:root {
    --cream: #fbf6ee;
    --paper: #fffdf9;
    --ink: #3a2f28;
    --ink-soft: #6b5d51;
    --terracotta: #c1652f;
    --terracotta-dark: #a3521f;
    --sage: #7c9070;
    --line: #e8ddcc;
    --gold: #d4a24a;
    --danger: #b3452f;
    --radius: 14px;
    --shadow: 0 4px 16px rgba(58, 47, 40, 0.08);
    --shadow-lift: 0 8px 28px rgba(58, 47, 40, 0.14);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background: var(--cream);
    color: var(--ink);
    line-height: 1.5;
}

h1, h2, h3, h4, .brand {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 0.4em;
}

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

button, .btn {
    font-family: inherit;
    font-size: 0.95rem;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    cursor: pointer;
    background: var(--paper);
    color: var(--ink);
    border: 1px solid var(--line);
    transition: transform 0.08s ease, box-shadow 0.15s ease;
}
button:hover, .btn:hover { box-shadow: var(--shadow); }
button:active, .btn:active { transform: scale(0.98); }

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

.btn-ghost {
    background: transparent;
    border-color: transparent;
}

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }

input, textarea, select {
    font-family: inherit;
    font-size: 0.95rem;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--ink);
    width: 100%;
}
input:focus, textarea:focus, select:focus {
    outline: 2px solid var(--gold);
    outline-offset: -1px;
}
label {
    display: block;
    font-size: 0.82rem;
    color: var(--ink-soft);
    margin-bottom: 4px;
    font-weight: 500;
}
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }

/* ---------- Layout ---------- */
header.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { font-size: 1.4rem; display: flex; align-items: center; gap: 8px; margin: 0; }
.brand span.icon { font-size: 1.3rem; }

nav.main-nav { display: flex; gap: 4px; }
nav.main-nav a {
    padding: 8px 14px;
    border-radius: 8px;
    color: var(--ink-soft);
    font-weight: 500;
    font-size: 0.92rem;
}
nav.main-nav a:hover { background: var(--cream); text-decoration: none; }
nav.main-nav a.active { background: var(--terracotta); color: #fff; }

.search-box { display: flex; align-items: center; gap: 8px; }
.search-box input { width: 240px; }

main.content {
    max-width: 1080px;
    margin: 0 auto;
    padding: 28px 24px 80px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}
.page-header p { color: var(--ink-soft); margin: 4px 0 0; }

/* ---------- Cards ---------- */
.card {
    background: var(--paper);
    border-radius: var(--radius);
    border: 1px solid var(--line);
    padding: 20px;
    box-shadow: var(--shadow);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
}

.recipe-card {
    background: var(--paper);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    cursor: pointer;
    display: flex;
    flex-direction: column;
}
.recipe-card:hover { box-shadow: var(--shadow-lift); transform: translateY(-2px); }
.recipe-card .thumb {
    height: 150px;
    background: linear-gradient(135deg, #f1e3cf, #e6d3b6);
    display: flex; align-items: center; justify-content: center;
    color: var(--terracotta-dark); font-size: 2rem;
}
.recipe-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.recipe-card .body { padding: 14px 16px; }
.recipe-card .cat {
    display: inline-block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--sage);
    font-weight: 600;
    margin-bottom: 4px;
}
.recipe-card h3 { font-size: 1.05rem; margin-bottom: 4px; }
.recipe-card .meta { font-size: 0.8rem; color: var(--ink-soft); }
.tag-pill {
    display: inline-block;
    font-size: 0.72rem;
    background: var(--cream);
    color: var(--ink-soft);
    border-radius: 999px;
    padding: 2px 10px;
    margin: 2px 4px 0 0;
}

/* ---------- Dashboard ---------- */
.dash-section { margin-bottom: 32px; }
.dash-section h2 { font-size: 1.15rem; margin-bottom: 12px; }
.quick-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 30px; }
.quick-actions button { padding: 14px 22px; font-size: 1rem; }

.stat-strip { display: flex; gap: 16px; margin-bottom: 30px; }
.stat-box {
    flex: 1;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
    box-shadow: var(--shadow);
}
.stat-box .num { font-family: 'Fraunces', serif; font-size: 1.8rem; color: var(--terracotta); }
.stat-box .label { font-size: 0.82rem; color: var(--ink-soft); }

/* ---------- Recipe detail ---------- */
.recipe-header { display: flex; gap: 24px; margin-bottom: 24px; flex-wrap: wrap; }
.recipe-header .cover {
    width: 260px; height: 190px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #f1e3cf, #e6d3b6);
    object-fit: cover;
    flex-shrink: 0;
}
.recipe-header .info { flex: 1; min-width: 240px; }
.recipe-facts { display: flex; gap: 22px; margin-top: 10px; flex-wrap: wrap; }
.recipe-facts .fact { font-size: 0.85rem; color: var(--ink-soft); }
.recipe-facts .fact b { color: var(--ink); display: block; font-size: 1.05rem; font-family: 'Fraunces', serif; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 22px 0 20px; }
.tab-btn {
    background: none; border: none; border-bottom: 2px solid transparent;
    border-radius: 0; padding: 10px 6px; margin-right: 18px;
    color: var(--ink-soft); font-weight: 500;
}
.tab-btn.active { color: var(--terracotta-dark); border-color: var(--terracotta); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

table.ingredients-table { width: 100%; border-collapse: collapse; }
table.ingredients-table th, table.ingredients-table td {
    text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); font-size: 0.92rem;
}
table.ingredients-table th { color: var(--ink-soft); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.cost-total-row td { font-weight: 600; border-top: 2px solid var(--line); border-bottom: none; }

.steps-list { list-style: none; padding: 0; counter-reset: step; }
.steps-list li {
    counter-increment: step;
    display: flex; gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.steps-list li::before {
    content: counter(step);
    background: var(--terracotta); color: #fff;
    width: 26px; height: 26px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.82rem; font-weight: 600; flex-shrink: 0;
}
.steps-list li.dragging { opacity: 0.4; }
.steps-list li .drag-handle { cursor: grab; color: var(--ink-soft); margin-left: auto; }

.version-list { list-style: none; padding: 0; }
.version-list li {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; border-radius: 10px; margin-bottom: 6px;
    border: 1px solid var(--line); background: var(--paper);
}
.version-list li.current { border-color: var(--terracotta); background: #fdf3ea; }
.version-list .v-tag { font-size: 0.75rem; color: var(--ink-soft); }

.baking-record {
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 16px; margin-bottom: 12px; background: var(--paper);
}
.baking-record .top { display: flex; justify-content: space-between; align-items: center; }
.stars { color: var(--gold); letter-spacing: 2px; }

.notes-box {
    background: #fdf6ea; border: 1px dashed var(--gold);
    border-radius: var(--radius); padding: 16px; font-style: italic; color: var(--ink-soft);
    white-space: pre-wrap;
}

/* ---------- Forms ---------- */
.ingredient-row, .step-row {
    display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
}
.ingredient-row .name-col { flex: 3; }
.ingredient-row .qty-col { flex: 1; }
.ingredient-row .unit-col { flex: 1; }
.step-row textarea { flex: 1; resize: vertical; }
.remove-btn { background: none; border: none; color: var(--danger); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }
.add-row-btn { margin-top: 4px; }

/* ---------- Shopping list ---------- */
.shop-item {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.shop-item.purchased { opacity: 0.45; text-decoration: line-through; }
.shop-item input[type=checkbox] { width: 20px; height: 20px; }
.shop-item .qty { color: var(--ink-soft); min-width: 90px; }
.shop-item .src { font-size: 0.78rem; color: var(--ink-soft); margin-left: auto; }

.recipe-picker { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.recipe-picker label { display: flex; align-items: center; gap: 10px; padding: 8px; font-weight: 400; color: var(--ink); }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(58,47,40,0.4);
    display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
    background: var(--paper); border-radius: var(--radius);
    padding: 26px; width: 480px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
    box-shadow: var(--shadow-lift);
}
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Toast ---------- */
#toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 999px;
    font-size: 0.88rem; opacity: 0; pointer-events: none; transition: opacity 0.25s ease;
    z-index: 100;
}
#toast.show { opacity: 1; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-soft); }
.empty-state .icon { font-size: 2.4rem; margin-bottom: 10px; }

.photo-strip { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.photo-strip .photo-thumb { position: relative; width: 90px; height: 90px; border-radius: 10px; overflow: hidden; }
.photo-strip .photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-strip .photo-thumb .cover-badge {
    position: absolute; top: 3px; left: 3px; background: var(--terracotta);
    color: #fff; font-size: 0.6rem; padding: 1px 5px; border-radius: 6px;
}
.photo-strip .photo-thumb button {
    position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,0.55);
    color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 0.7rem; padding: 0;
}

.diff-block { margin-bottom: 16px; }
.diff-block h4 { font-size: 0.9rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 8px; }
.diff-list { list-style: none; padding: 0; }
.diff-list li { padding: 6px 10px; border-radius: 8px; margin-bottom: 4px; font-size: 0.92rem; }
.diff-add { background: #eef4ea; color: #3d5c33; }
.diff-remove { background: #f7e9e4; color: var(--danger); text-decoration: line-through; }
.diff-change { background: #fdf3e0; color: #7a5a1e; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

footer.app-footer {
    text-align: center; color: var(--ink-soft); font-size: 0.8rem; padding: 30px 0 10px;
}

@media (max-width: 720px) {
    header.topbar { flex-direction: column; gap: 10px; align-items: stretch; }
    .search-box input { width: 100%; }
    nav.main-nav { justify-content: center; flex-wrap: wrap; }
    .recipe-header { flex-direction: column; }
    .recipe-header .cover { width: 100%; }
}
