/* ── Custom properties ── */
:root {
    --bg: #faf6ef;
    --text: #111;
    --muted: #555;
    --dim: #8a7d72;
    --line: #e2d8cc;
    --amber: #c8902d;
    --panel: #faf6ef;
    --font-body: 'Montserrat', system-ui, sans-serif;
    --font-display: 'Della Respira', Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }

/* Full-viewport fixed layout — body does NOT scroll */
html {
    height: 100%;
    overflow: hidden;
}

body {
    /* position:fixed;inset:0 is the only reliable way to lock scroll on iOS Safari */
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    overflow: hidden;
    overscroll-behavior: none;
    display: flex;
    flex-direction: column;
}

/* Scrollable content wrapper */
#app-scroll {
    flex: 1 1 0;          /* explicit 0 basis so Safari honours flex shrink */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* momentum scroll on iOS */
    overscroll-behavior: contain;
    padding-left: max(2rem, env(safe-area-inset-left));
    padding-right: max(2rem, env(safe-area-inset-right));
    padding-bottom: max(3rem, env(safe-area-inset-bottom));
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
}

/* ── Mosaic strip ── */
.mosaic-strip {
    position: relative;
    display: flex;
    gap: 3px;
    padding: 4px;
    background: transparent;
    flex-shrink: 0;
}
.mosaic-strip span { flex: 1; height: 7px; border-radius: 2px; }

/* ── Drawer open state (JS toggles class) ── */
#drawer.open { transform: translateX(0) !important; }
#drawerBackdrop.open { display: block !important; }

/* ── Guide backdrop open state ── */
#guideBackdrop.open { display: flex !important; }

/* ── Hide panel on new-view or dash-view ── */
body.new-view #ingPanel,
body.dash-view #ingPanel { display: none !important; }

/* ── Status error ── */
#status.error { color: #c0392b; }

/* ── Spinner ── */
.spinner {
    display: inline-block;
    width: 10px; height: 10px;
    border: 1.5px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 0.4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* ═══════════════════════════════════════════════
   Ingredient panel — shared
   ═══════════════════════════════════════════════ */
#ingPanel { background: #fff; display: flex; flex-direction: column; }

/* ── Outer tabs (replace old ing-panel-tab + panel-tab-bar) ── */
.ing-outer-tabs {
    position: absolute;
    display: flex;
}
.ing-outer-tab {
    background: var(--bg);
    border: none;
    color: var(--dim);
    font-family: var(--font-body);
    font-size: 1rem;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    line-height: 1;
}
.ing-outer-tab.active { color: var(--amber); background: #fff; }
.ing-outer-tab:not(.active):hover { color: var(--text); }

/* ── Panel sections ── */
.panel-section { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }

/* Timer + Servings: center content vertically */
#panelTimers .ing-panel-inner,
#panelServings .ing-panel-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-y: hidden;
}

/* Timer carousel nav arrows (desktop only) */
.timer-carousel-nav-wrap { display: flex; align-items: center; width: 100%; }
.timer-carousel-nav-wrap .timer-carousel { flex: 1; min-width: 0; }
.timer-nav-btn {
    flex-shrink: 0;
    width: 36px; height: 36px;
    background: rgba(0,0,0,0.06);
    border: none; border-radius: 50%;
    color: var(--dim);
    font-size: 1.5rem; line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0; transition: background 0.12s;
    font-family: inherit;
}
.timer-nav-btn:hover { background: rgba(0,0,0,0.12); color: var(--text); }
@media (max-width: 760px) { .timer-nav-btn { display: none; } }
.panel-empty-hint { font-size: 0.78rem; color: var(--dim); font-style: italic; margin: 0 0 0.75rem; line-height: 1.5; }

/* ── Timers ── */
.timer-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--line);
}
.timer-item:last-child { border-bottom: none; }
.timer-item.timer-done { opacity: 0.55; }
.timer-info { flex: 1; min-width: 0; }
.timer-label { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.timer-sublabel { font-size: 0.7rem; color: var(--dim); margin-top: 0.1rem; }
.timer-display {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    min-width: 3rem;
    text-align: right;
    flex-shrink: 0;
}
.timer-done .timer-display { color: var(--dim); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.timer-controls { display: flex; gap: 0.35rem; flex-shrink: 0; }
.timer-controls button {
    background: rgba(0,0,0,0.06);
    border: none;
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s;
    padding: 0;
    font-family: inherit;
}
.timer-controls button:hover { background: rgba(0,0,0,0.12); }

/* ── Timer carousel (mobile) ── */
.timer-carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    gap: 0;
    scrollbar-width: none;
    padding: 0.25rem 0 0.5rem;
    -webkit-overflow-scrolling: touch;
}
.timer-carousel::-webkit-scrollbar { display: none; }
.timer-card {
    flex: 0 0 100%;
    scroll-snap-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem 0.75rem;
    min-height: 0;
}
.timer-card-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.timer-card-sublabel { font-size: 0.72rem; color: var(--dim); margin-top: -0.25rem; }
.timer-card-display {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.timer-card.timer-done .timer-card-display { font-size: 1.6rem; color: var(--dim); }
.timer-card-controls { display: flex; gap: 0.5rem; margin-top: 0.25rem; }
.timer-card-controls button {
    min-width: 52px; min-height: 52px; width: 52px; height: 52px;
    background: rgba(0,0,0,0.06);
    border: none; border-radius: 50%;
    color: var(--text); font-size: 1.3rem;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.12s; padding: 0;
    font-family: inherit;
}
.timer-card-controls button:hover { background: rgba(0,0,0,0.12); }
.timer-dots {
    display: flex;
    gap: 5px;
    justify-content: center;
    margin-top: 0.25rem;
}
.timer-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--line);
    transition: background 0.2s;
}
.timer-dot.active { background: var(--text); }

/* Step timing start button */
.timer-start-btn {
    background: rgba(200, 144, 45, 0.12);
    border: 1px solid rgba(200, 144, 45, 0.45);
    color: var(--amber);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0;
    margin-left: 0.4rem;
    transition: background 0.15s, border-color 0.15s;
    vertical-align: middle;
    line-height: 1;
    min-width: 28px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}
.timer-start-btn:hover { background: rgba(200, 144, 45, 0.22); border-color: var(--amber); }

/* ── Servings card (large carousel-style) ── */
.servings-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem 1rem;
    height: 100%;
}
.servings-card-label {
    font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em;
    text-transform: uppercase; color: var(--dim);
}
.servings-card-display {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    min-width: 4rem;
    text-align: center;
}
.servings-card-unit {
    font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--dim);
    margin-top: -0.25rem;
}
.servings-card-controls { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.servings-card-controls button {
    min-width: 52px; min-height: 52px; width: 52px; height: 52px;
    background: rgba(0,0,0,0.06);
    border: none; border-radius: 50%;
    color: var(--text); font-size: 1.6rem; font-weight: 300;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.12s; padding: 0;
    font-family: inherit; line-height: 1;
}
.servings-card-controls button:hover { background: rgba(0,0,0,0.12); }
.servings-card-hint {
    font-size: 0.7rem; color: var(--dim);
    font-style: italic; margin-top: 0.25rem;
}
@media (min-width: 761px) {
    #app-scroll { transition: padding-right 0.25s ease; }
    body.ing-open #app-scroll { padding-right: calc(2rem + 480px); }

    #ingPanel {
        position: fixed;
        top: 0; right: 0; bottom: 0;
        width: 400px;
        border-left: 1px solid var(--line);
        z-index: 150;
        transform: translateX(100%);
        transition: transform 0.25s ease;
    }
    #ingPanel.open {
        transform: translateX(0);
        box-shadow: -80px 0 40px -20px rgba(0,0,0,0.12), -8px 0 32px rgba(0,0,0,0.13);
    }

    /* 3 vertical side tabs on desktop */
    .ing-outer-tabs {
        left: -80px; top: 0; bottom: 0;
        width: 80px;
        flex-direction: column;
    }
    .ing-outer-tab {
        flex: 1;
        writing-mode: horizontal-tb;
        transform: none;
        border-radius: 0;
        border: 1px solid var(--line);
        border-right: none;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 0.35rem;
        padding: 0;
        font-size: 1.1rem;
    }
    .ing-outer-tab + .ing-outer-tab { border-top: none; }
    .ing-outer-tab.active { color: var(--amber); background: #fff; }

    .ing-panel-inner {
        flex: 1;
        overflow-y: auto;
        padding: 1.5rem 1.5rem 2.5rem;
        scrollbar-width: thin;
        scrollbar-color: var(--line) transparent;
    }
    .ing-panel-head {
        margin-bottom: 1.25rem;
        padding-bottom: 1rem;
        border-bottom: 1px solid rgba(255,255,255,0.25);
    }
    .ing-panel-title-row {
        display: flex; align-items: baseline;
        justify-content: space-between;
        margin-bottom: 0.75rem;
    }
    .servings-scaler {
        display: flex; align-items: center; gap: 0.5rem;
        margin-bottom: 0.75rem;
    }
    .servings-scaler button {
        background: rgba(0,0,0,0.06);
        border: 1px solid var(--line);
        border-radius: 50%;
        width: 22px; height: 22px;
        cursor: pointer; font-size: 0.9rem; line-height: 1;
        color: var(--text);
        display: flex; align-items: center; justify-content: center;
        font-family: var(--font-body);
        transition: background 0.15s; padding: 0;
    }
    .servings-scaler button:hover { background: rgba(0,0,0,0.12); }
    .servings-count { font-size: 0.85rem; font-weight: 600; min-width: 1.2rem; text-align: center; color: var(--text); }
    .servings-label { font-size: 0.62rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
}

/* ── Mobile: bottom sheet (≤760px) ── */
@media (max-width: 760px) {
    #app-scroll {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    #ingPanel {
        position: fixed;
        top: auto; left: 0; right: 0; bottom: 0;
        width: 100%; height: 40vh;
        border-left: none;
        border-top: none;
        border-radius: 0;
        z-index: 200;
        transform: translateY(100%);
        transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
        display: flex; flex-direction: column;
        filter: drop-shadow(0 -5px 16px rgba(0,0,0,0.15));
    }
    #ingPanel.open { transform: translateY(0); }

    /* 3 horizontal tabs above the panel on mobile */
    .ing-outer-tabs {
        top: -40px; left: 0; right: 0;
        flex-direction: row;
        border-radius: 0;
        overflow: hidden;
        white-space: nowrap;
        border: 1px solid var(--line);
        border-bottom: none;
    }
    .ing-outer-tab {
        flex: 1;
        padding: 0.55rem 0;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        writing-mode: horizontal-tb;
        transform: none;
        border-radius: 0;
        border: none;
    }
    .ing-outer-tab + .ing-outer-tab { border-left: 1px solid var(--line); }
    .ing-outer-tab.active { background: #fff; color: var(--amber); }

    .ing-panel-inner { flex: 1; overflow-y: auto; padding: 0.75rem 1.25rem 1.5rem; scrollbar-width: none; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
    .ing-panel-inner::-webkit-scrollbar { display: none; }
    .ing-panel-head { margin-bottom: 0.75rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--line); }
    .ing-panel-title-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 0.75rem; }
    .servings-scaler { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
    .servings-scaler button {
        background: rgba(0,0,0,0.06); border: 1px solid var(--line);
        border-radius: 50%; width: 22px; height: 22px;
        cursor: pointer; font-size: 0.9rem; line-height: 1; color: var(--text);
        display: flex; align-items: center; justify-content: center;
        font-family: var(--font-body); padding: 0;
    }
    .servings-count { font-size: 0.85rem; font-weight: 600; min-width: 1.2rem; text-align: center; color: var(--text); }
    .servings-label { font-size: 0.62rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
    .recipe-body { display: flex; flex-direction: column; }
    .recipe-steps-col { order: 1; }
}

/* ═══════════════════════════════════════════════
   Panel interior — dark on cream
   ═══════════════════════════════════════════════ */
.sidebar-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.guide-btn {
    background: none; border: none; padding: 0;
    font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--dim); cursor: pointer; font-family: var(--font-body); transition: color 0.15s;
}
.guide-btn:hover { color: var(--text); }
.unit-toggle { display: inline-flex; gap: 1.2rem; margin-bottom: 0.35rem; }
.unit-toggle-note { font-size: 0.62rem; color: var(--dim); letter-spacing: 0.02em; margin-bottom: 1rem; }
.unit-toggle button {
    background: none; border: none; padding: 0;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
    cursor: pointer; color: var(--dim); font-family: var(--font-body); transition: color 0.1s;
}
.unit-toggle button.active { color: var(--amber); }
.unit-toggle button:not(.active):hover { color: var(--text); }
.conv { color: var(--dim); font-size: 0.8rem; }

/* Ingredient list (panel) */
.ing-group + .ing-group { margin-top: 1.4rem; }
.ing-group-name { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); margin-bottom: 0.5rem; }
.ing-list { list-style: none; padding: 0; }
.ing-list li { display: flex; gap: 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); font-size: 0.95rem; line-height: 1.5; }
.ing-list li:last-child { border-bottom: none; }
.ing-qty { font-variant-numeric: tabular-nums; min-width: 5.5rem; flex-shrink: 0; color: var(--dim); font-size: 0.82rem; padding-top: 0.05rem; }
.ing-name { flex: 1; color: var(--text); }
.ing-notes { color: var(--dim); font-style: italic; font-size: 0.8rem; }
.ing-hint { display: block; font-size: 0.72rem; color: var(--dim); font-style: italic; margin-top: 0.1rem; letter-spacing: 0.01em; }

/* ── Scrape queue ── */
#scrapeQueue { margin: 0; padding: 0; list-style: none; }
.queue-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--line);
    font-size: 0.78rem;
    color: var(--muted);
}
.queue-item:last-child { border-bottom: none; }
.queue-item-url {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.queue-item-state {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.queue-item[data-state="pending"] .queue-item-state { color: var(--dim); }
.queue-item[data-state="processing"] .queue-item-state { color: var(--amber); }
.queue-item[data-state="done"] .queue-item-state { color: #2a9d8f; }
.queue-item[data-state="error"] .queue-item-state { color: #c0392b; }

/* ═══════════════════════════════════════════════
   Dashboard
   ═══════════════════════════════════════════════ */
.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.dash-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1.1rem 1.25rem 1rem;
    cursor: pointer;
    text-align: left;
    font-family: var(--font-body);
    transition: box-shadow 0.15s, transform 0.15s;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.dash-card:hover {
    box-shadow: 0 4px 18px rgba(0,0,0,0.09);
    transform: translateY(-2px);
}
.dash-card-title {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.dash-card-meta {
    font-size: 0.68rem;
    color: var(--dim);
    letter-spacing: 0.02em;
    margin-top: auto;
    padding-top: 0.5rem;
}

/* ═══════════════════════════════════════════════
   JS-rendered recipe components (main area)
   ═══════════════════════════════════════════════ */
.recipe-title { font-family: var(--font-display); font-size: 3rem; font-weight: 400; letter-spacing: 0.01em; line-height: 1.15; margin-bottom: 0.4rem; }
@media (min-width: 900px) { .recipe-title { font-size: 4.5rem; line-height: 1.1; } }

.recipe-source-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.recipe-source { font-size: 0.72rem; color: var(--dim); text-decoration: none; }
.recipe-source:hover { color: var(--muted); }
.refetch-btn { font-size: 0.68rem; font-family: var(--font-body); color: var(--dim); background: none; border: 1px solid var(--dim); border-radius: 3px; padding: 0.15em 0.55em; cursor: pointer; opacity: 0.6; }
.refetch-btn:hover { opacity: 1; }
.recipe-description { color: var(--muted); font-size: 1rem; line-height: 1.7; max-width: 560px; margin-bottom: 1.5rem; }

.meta-row { display: flex; flex-wrap: wrap; gap: 2rem; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.meta-pill { display: flex; flex-direction: column; gap: 0.1rem; }
.meta-pill .label { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.meta-pill .value { font-size: 1rem; font-weight: 600; }
@media (min-width: 900px) { .meta-pill .value { font-size: 1.1rem; } }

.recipe-body { display: grid; grid-template-columns: 1fr; gap: 2rem; align-items: start; }

.section-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); margin-bottom: 1rem; }
.steps-list { list-style: none; padding: 0; }
.step { display: grid; grid-template-columns: 1.6rem 1fr; gap: 0.75rem; padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: none; }
.step-num { font-size: 0.72rem; font-weight: 700; color: var(--amber); padding-top: 0.2rem; letter-spacing: 0.02em; }
.step-body { display: flex; flex-direction: column; gap: 0.3rem; }
.step-instruction { font-size: 1rem; line-height: 1.7; }
@media (min-width: 900px) { .step-instruction { font-size: 1.1rem; line-height: 1.75; } }
.step-bullets { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.35rem; font-size: 1rem; line-height: 1.6; }
.step-timing {
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
    color: var(--amber); align-self: flex-start;
    display: inline-flex; align-items: center;
}

/* History list (drawer) */
.history-list { list-style: none; padding: 0; }
.history-list li { margin-bottom: 0.15rem; }
.history-list button { width: 100%; text-align: left; background: none; border: none; padding: 0.25rem 0; font-size: 0.82rem; cursor: pointer; color: var(--muted); line-height: 1.35; font-family: var(--font-body); transition: color 0.1s; }
.history-list button:hover { color: var(--text); }
.history-list button.active { color: var(--text); font-weight: 600; }
.hist-date { display: block; font-size: 0.68rem; color: var(--dim); }

/* Guide modal rows */
.guide-group + .guide-group { margin-top: 1.25rem; }
.guide-group-name { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--amber); margin-bottom: 0.4rem; }
.guide-row { display: grid; grid-template-columns: 5rem 1fr auto; gap: 0.5rem 0.75rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); align-items: baseline; font-size: 1rem; }
.guide-row:last-child { border-bottom: none; }
.guide-qty { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.92rem; white-space: nowrap; }
.guide-name { color: var(--text); line-height: 1.4; }
.guide-notes { color: var(--dim); font-style: italic; font-size: 0.88rem; }
.guide-hint-cell { color: var(--dim); font-style: italic; font-size: 0.92rem; white-space: nowrap; text-align: right; }

/* ── Desktop scale-up ── */
@media (min-width: 900px) {
    body { font-size: 19px; }
    .ing-list li { font-size: 1.05rem; }
    .ing-qty { font-size: 0.92rem; }
    .ing-notes { font-size: 0.88rem; }
    .history-list button { font-size: 0.9rem; }
    .hist-date { font-size: 0.72rem; }
}
