/* =====================================================================
   Vorratskammer – Stylesheet (mobile-first, iOS/iPad/Laptop)
   ===================================================================== */
:root {
    --bg:        #f2f2f7;
    --card:      #ffffff;
    --text:      #1c1c1e;
    --muted:     #8e8e93;
    --border:    #e2e2e7;
    --primary:   #16a34a;
    --primary-d: #15803d;
    --danger:    #dc2626;
    --warn:      #d97706;
    --accent:    #2563eb;
    --radius:    14px;
    --shadow:    0 1px 3px rgba(0,0,0,.08);
    --header-h:  52px;
    --tab-h:     58px;
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    font-size: 16px;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg:     #000000;
        --card:   #1c1c1e;
        --text:   #f2f2f7;
        --muted:  #98989f;
        --border: #38383a;
        --shadow: none;
    }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* hidden-Attribut muss immer gewinnen (überschreibt display:flex etc.) */
[hidden] { display: none !important; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg); color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overscroll-behavior-y: none;
}
h1, h2, h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
    font-family: inherit; font-size: 1rem;
    background: var(--card); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 11px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.muted { color: var(--muted); }

/* ---------- Header ---------- */
.app-header {
    position: sticky; top: 0; z-index: 20;
    height: calc(var(--header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    display: flex; align-items: center; justify-content: space-between;
    padding-left: 16px; padding-right: 12px;
    background: color-mix(in srgb, var(--card) 88%, transparent);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-bottom: 1px solid var(--border);
}
.app-header h1 { font-size: 1.15rem; font-weight: 700; }
.icon-btn {
    background: none; border: none; font-size: 1.3rem; color: var(--text);
    padding: 6px 8px; border-radius: 8px; line-height: 1;
}

/* ---------- Layout ---------- */
#app {
    max-width: 820px; margin: 0 auto;
    padding: 14px 14px calc(var(--tab-h) + var(--safe-bottom) + 20px);
}
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.section-intro { color: var(--muted); font-size: .9rem; margin: 4px 2px 12px; }
.list-heading { font-size: 1rem; margin: 22px 2px 10px; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--tab-h) + var(--safe-bottom));
    /* Symbole in die Home-Indikator-Zone hineinrücken -> einheitliche Leiste */
    padding-bottom: calc(var(--safe-bottom) * 0.3);
    display: flex;
    background: color-mix(in srgb, var(--card) 96%, transparent);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid var(--border);
}
.tab {
    flex: 1; background: none; border: none; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: .68rem; padding: 6px 0;
}
.tab .ic { font-size: 1.35rem; line-height: 1; }
.tab.active { color: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
    background: var(--card); color: var(--text);
    border: 1px solid var(--border); border-radius: 11px;
    padding: 12px 16px; font-size: 1rem; font-weight: 600;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:active { background: var(--primary-d); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.block { display: block; width: 100%; }
.btn.small { padding: 8px 12px; font-size: .85rem; border-radius: 9px; }

/* ---------- Cards / list ---------- */
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 14px; margin-bottom: 12px;
}
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.item .thumb {
    width: 44px; height: 44px; border-radius: 9px; object-fit: cover;
    background: var(--bg); flex-shrink: 0; display: flex; align-items: center;
    justify-content: center; font-size: 1.4rem;
}
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; font-size: .98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.item .qty { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 999px;
    font-size: .72rem; font-weight: 600;
}
.badge.warn   { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.ok     { background: #dcfce7; color: #166534; }
@media (prefers-color-scheme: dark) {
    .badge.warn   { background: #422006; color: #fbbf24; }
    .badge.danger { background: #450a0a; color: #fca5a5; }
    .badge.ok     { background: #052e16; color: #86efac; }
}
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .big { font-size: 2.4rem; display: block; margin-bottom: 8px; }

/* ---------- Filters ---------- */
.filters { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 12px; }
@media (min-width: 520px) { .filters { grid-template-columns: 1fr 1fr 1fr; } }

/* ---------- Segmented control ---------- */
.segmented {
    display: flex; background: var(--bg); border: 1px solid var(--border);
    border-radius: 12px; padding: 3px; margin-bottom: 14px;
}
.seg {
    flex: 1; border: none; background: none; color: var(--muted);
    padding: 9px; border-radius: 9px; font-weight: 600; font-size: .95rem;
}
.seg.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Scanner ---------- */
.qr-reader {
    width: 100%; max-width: 420px; margin: 0 auto 12px;
    border-radius: var(--radius); overflow: hidden; background: #000;
}
.qr-reader:empty { display: none; }
/* iOS: Video zuverlässig sichtbar machen (sonst teils Höhe 0) */
.qr-reader video {
    width: 100% !important; height: auto !important;
    display: block; object-fit: cover;
}
.qr-reader:not(:empty) { min-height: 240px; }
.scan-controls { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.manual-barcode { display: flex; gap: 8px; margin-bottom: 8px; }
.manual-barcode input { flex: 1; }
.scan-hint { text-align: center; color: var(--muted); font-size: .85rem; }
.scan-log { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.scan-log .logline {
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    padding: 9px 12px; font-size: .88rem; display: flex; gap: 8px; align-items: center;
    animation: fade .2s ease;
}
.scan-log .logline .lic { font-size: 1.15rem; line-height: 1; }
.scan-log .logline.ok  { border-left: 5px solid var(--primary); }
.scan-log .logline.in,
.scan-log .logline.new {
    border-left: 5px solid var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, var(--card));
}
.scan-log .logline.out {
    border-left: 5px solid var(--warn);
    background: color-mix(in srgb, var(--warn) 15%, var(--card));
}
.scan-log .logline.err {
    border-left: 5px solid var(--danger);
    background: color-mix(in srgb, var(--danger) 12%, var(--card));
}

/* ---------- Recipes ---------- */
.recipe-controls .row { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.recipe-controls label { font-size: .9rem; display: flex; gap: 6px; align-items: center; }
.recipe-controls label.check { color: var(--text); }
.recipe-controls select { width: auto; }
.recipe-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.recipe-card h3 { font-size: 1.05rem; margin-bottom: 4px; }
.recipe-meta { color: var(--muted); font-size: .82rem; margin-bottom: 8px; }
.recipe-card ul, .recipe-card ol { margin: 6px 0; padding-left: 20px; }
.recipe-card li { margin: 3px 0; font-size: .9rem; }
.ing-have  { color: var(--primary); }
.ing-miss  { color: var(--warn); }
.recipe-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45);
    display: flex; align-items: flex-end; justify-content: center;
    padding: 0; animation: fade .15s ease;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; padding: 20px; } }
.modal {
    background: var(--card); width: 100%; max-width: 560px;
    max-height: 92vh; overflow-y: auto;
    border-radius: 18px 18px 0 0;
    padding-bottom: calc(var(--safe-bottom) + 12px);
    animation: slideup .22s ease;
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
    position: sticky; top: 0; background: var(--card);
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 16px 10px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1.1rem; }
.modal-body { padding: 16px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card {
    background: var(--card); border: 1px solid var(--border); border-radius: 20px;
    box-shadow: var(--shadow); padding: 28px 24px; width: 100%; max-width: 380px; text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: 6px; }
.login-card h1 { font-size: 1.5rem; margin-bottom: 16px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.login-or { color: var(--muted); font-size: .8rem; margin: 14px 0 10px; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: .9rem; margin-bottom: 12px; }
.alert.error { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) { .alert.error { background: #450a0a; color: #fca5a5; } }

/* ---------- Toast ---------- */
.toast {
    position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
    transform: translateX(-50%); z-index: 60;
    background: #1c1c1e; color: #fff; padding: 11px 18px; border-radius: 12px;
    font-size: .9rem; box-shadow: 0 4px 20px rgba(0,0,0,.3); max-width: 90%;
    animation: fade .2s ease;
}
.toast.err { background: var(--danger); }
/* Große Scan-Rückmeldung */
.toast.scan-in, .toast.scan-out, .toast.scan-err {
    font-size: 1.1rem; font-weight: 700; padding: 15px 24px; color: #fff;
}
.toast.scan-in  { background: var(--primary); }
.toast.scan-out { background: var(--warn); }
.toast.scan-err { background: var(--danger); }

/* ---------- Weekly plan ---------- */
.week-day { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.week-day .day-head { background: var(--bg); padding: 8px 12px; font-weight: 600; font-size: .9rem;
    display: flex; justify-content: space-between; align-items: center; }
.week-day .day-body { padding: 8px 12px; }
.plan-entry { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-size: .9rem; }

/* ---------- Spinner ---------- */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { text-align: center; padding: 30px; color: var(--muted); }

/* rows / chips */
.row { display: flex; gap: 10px; align-items: center; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
    padding: 6px 12px; font-size: .85rem; display: inline-flex; gap: 6px; align-items: center; }
.chip button { background: none; border: none; color: var(--danger); font-size: 1rem; padding: 0; }
