/* ============================================================
   Kaufliste – Design System
   ============================================================ */
:root {
    --bg-top: #eef2f7;
    --bg-bottom: #e4e9f0;
    --surface: #ffffff;
    --surface-2: #f5f7fa;
    --surface-3: #eef1f5;
    --border: #e4e9f0;
    --border-strong: #cbd5e1;
    --text: #1a2433;
    --text-muted: #64748b;
    --text-faint: #94a3b8;
    /* CI: Navy primär, Schweizer Rot als Kreuz/Akzent (Swisscom-Stil) */
    --primary: #122347;
    --primary-strong: #0b1730;
    --primary-soft: #eaeef6;
    --red: #e1261c;
    --red-strong: #be1f16;
    --danger: #e1261c;
    --danger-strong: #be1f16;
    --danger-soft: #fdecea;
    --radius-lg: 18px;
    --radius: 12px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.06);
    --shadow-md: 0 4px 16px rgba(15,23,42,0.08);
    --shadow-lg: 0 12px 40px rgba(15,23,42,0.12);
    --ring: 0 0 0 3px rgba(18,35,71,0.22);
}

* { box-sizing: border-box; }

body, html {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    color: var(--text);
    background: transparent;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
body {
    /* KEIN height:100% – sonst wird der body auf Viewport-Höhe gedeckelt und das
       padding-bottom reserviert keinen Platz unter überlaufendem Inhalt.
       min-height sorgt nur dafür, dass der Hintergrund bei wenig Inhalt voll ist. */
    min-height: 100vh;
    /* Platz für die fixe Bottom-Nav reservieren; --nav-h wird per JS auf die
       echte Navbar-Höhe (inkl. Safe-Area) gesetzt, Fallback für vor dem JS. */
    padding-bottom: var(--nav-h, calc(88px + env(safe-area-inset-bottom, 0px)));
}

.bg-gradient {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

/* Start-Ladeanzeige (wird nach der Initialisierung per JS ausgeblendet) */
.app-loading {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.2em;
    background: var(--bg-top);
}
.app-loading .brand-mark { width: 46px; height: 46px; border-radius: 11px; }
.app-loading .brand-mark svg { width: 27px; height: 27px; }
.spinner {
    width: 26px;
    height: 26px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: kl-spin 0.7s linear infinite;
}
@keyframes kl-spin { to { transform: rotate(360deg); } }

/* ---------- App shell ---------- */
.main-card {
    position: relative;
    z-index: 1;
    max-width: 460px;
    margin: 2.2em auto 2em auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.9em 1.6em;
    display: flex;
    flex-direction: column;
}

.app-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55em;
    margin: 0 0 0.7em 0;
}
.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--red);
    display: grid;
    place-content: center;
    box-shadow: 0 1px 3px rgba(225,38,28,0.35);
}
.brand-mark svg { width: 18px; height: 18px; color: #fff; }
.brand-word {
    font-size: 1.55em;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}
/* feine rote Keyline als Brand-Device */
.brand-rule {
    height: 3px;
    width: 38px;
    background: var(--red);
    border-radius: 3px;
    margin: 0 auto 1.3em auto;
}

/* ---------- Forms / inputs ---------- */
.input,
.add-form input[type="text"] {
    width: 100%;
    font-size: 1em;
    font-family: inherit;
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.72em 0.85em;
    background: var(--surface);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder,
.add-form input::placeholder { color: var(--text-faint); }
.input:focus,
.add-form input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: var(--ring);
}

.add-form {
    display: flex;
    flex-direction: column;
    gap: 0.65em;
    margin-bottom: 1.6em;
}

.field { margin-bottom: 0.4em; }
.field .input { margin-bottom: 0.6em; }

/* ---------- Buttons ---------- */
.btn,
.add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    font-family: inherit;
    font-size: 1em;
    font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.78em 1.15em;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}
.btn:focus-visible,
.add-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.btn-primary,
.add-btn {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover,
.add-btn:hover { background: var(--primary-strong); }

.btn-ghost {
    background: var(--surface);
    color: var(--text-muted);
    border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: rgba(225,29,72,0.25);
}
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn-block { width: 100%; }
.add-btn { width: 100%; margin-top: 0.1em; }

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    align-items: center;
}

.icon-btn {
    display: inline-grid;
    place-content: center;
    width: 2.2em;
    height: 2.2em;
    flex: 0 0 auto;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--text-faint);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
@media (hover: hover) {
    .icon-btn:hover { background: var(--surface-3); color: var(--text); }
    .delete-btn:hover { background: var(--danger-soft); color: var(--danger); }
}
.save-btn { background: var(--primary); color: #fff; }
.save-btn:hover { background: var(--primary-strong); color: #fff; }

.ic { width: 1.2em; height: 1.2em; display: block; }

/* ---------- Mode switch: Vorrat | Extra ---------- */
.mode-switch {
    display: inline-flex;
    align-self: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    gap: 4px;
    margin: 0 auto 1.5em auto;
}
.mode-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95em;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.5em 1.4em;
    border-radius: 999px;
    transition: background 0.15s, color 0.15s;
}
.mode-btn.active { background: var(--primary); color: #fff; }
.mode-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.mode-badge {
    display: inline-grid;
    place-content: center;
    min-width: 1.45em;
    height: 1.45em;
    padding: 0 0.35em;
    margin-left: 0.5em;
    border-radius: 999px;
    background: var(--red);
    color: #fff;
    font-size: 0.7em;
    font-weight: 700;
    line-height: 1;
}

/* View-Titel: zeigt jederzeit, in welchem Menü man ist */
.view-title {
    text-align: center;
    font-size: 1.08em;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    margin: 0 0 1em 0;
}

.extra-intro {
    font-size: 0.92em;
    color: var(--text-muted);
    line-height: 1.55;
    margin: 0 0 1.1em 0;
    text-align: center;
}

/* Onboarding (Erstnutzer, leerer Haushalt) */
.onboarding {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2em 1.25em;
    margin-bottom: 1.4em;
}
.onboarding-steps {
    margin: 0 0 1.1em 0;
    padding-left: 1.3em;
    color: var(--text-muted);
    font-size: 0.95em;
    line-height: 1.7;
}
.onboarding-steps strong { color: var(--text); }
.onboarding-lead {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0 0 0.7em 0;
}
.onboarding-note {
    font-size: 0.9em;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0 0 0.7em 0;
}
.onboarding-or {
    font-size: 0.85em;
    color: var(--text-faint);
    text-align: center;
    margin: 0.9em 0 0.6em 0;
}
.starter-chips { display: flex; flex-wrap: wrap; gap: 0.5em; }
.chip {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    border-radius: 999px;
    padding: 0.45em 0.9em;
    font-size: 0.92em;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.added {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
    cursor: default;
}

/* "Zugang sichern"-Hinweis */
.secure-hint {
    display: flex;
    align-items: center;
    gap: 0.6em;
    flex-wrap: wrap;
    background: var(--primary-soft);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 0.7em 0.9em;
    margin-bottom: 1.1em;
    font-size: 0.9em;
    line-height: 1.45;
}
.secure-hint span { flex: 1 1 12em; }
.secure-hint-link {
    border: none;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 0.45em 0.85em;
    font-size: 0.85em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}
.secure-hint-link:hover { background: var(--primary-strong); }
.secure-hint-close {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95em;
    cursor: pointer;
    padding: 0.2em 0.4em;
    line-height: 1;
}

/* ---------- Item lists ---------- */
.item-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.55em;
}
.item-list li {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.7em 0.7em 0.7em 1em;
    font-size: 1.02em;
    flex-wrap: wrap;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.item-list li:hover { box-shadow: var(--shadow-md); }
.item-text {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    overflow-wrap: anywhere;
    font-weight: 500;
    color: var(--text);
}

/* Drag-Griff für die manuelle Heimweg-Sortierung im Vorrat */
.drag-handle {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    margin-left: -0.15em;
    color: var(--text-faint);
    cursor: grab;
    touch-action: none; /* am Griff ziehen statt scrollen */
}
.drag-handle:active { cursor: grabbing; }
.item-list li.sortable-chosen { box-shadow: var(--shadow-md); }
.item-list li.sortable-ghost { opacity: 0.4; }
.item-list li.sortable-drag { box-shadow: var(--shadow-lg); }

.item-list li .edit-name,
.item-list li .edit-note {
    flex: 1 1 7em;
    min-width: 0;
    padding: 0.5em 0.65em;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.95em;
    font-family: inherit;
    outline: none;
}
.item-list li .edit-name:focus,
.item-list li .edit-note:focus { border-color: var(--primary); box-shadow: var(--ring); }

/* Empty-State-Hinweis als Listeneintrag (ohne Karten-Look) */
.item-list li.empty-hint {
    background: transparent;
    border: none;
    box-shadow: none;
    justify-content: center;
    text-align: center;
    color: var(--text-faint);
    font-weight: 400;
    padding: 1.5em 0.6em;
    line-height: 1.55;
}
.item-list li.empty-hint:hover { box-shadow: none; }

/* "Gekauft" round check button */
.bought-btn {
    width: 2.5em;
    height: 2.5em;
    flex: 0 0 auto;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: var(--surface);
    color: var(--primary);
    display: inline-grid;
    place-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}
.bought-btn:active { transform: scale(0.92); }
/* Hover-Füllung nur auf echten Hover-Geräten – verhindert den "klebenden" Haken
   auf Touch, wenn nach dem Abhaken der nächste Artikel unter den Finger nachrutscht. */
@media (hover: hover) {
    .bought-btn:hover { background: var(--primary); color: #fff; }
}

/* Custom checkbox (Markieren-Tab) */
.to-buy-checkbox {
    appearance: none;
    -webkit-appearance: none;
    flex: 0 0 auto;
    width: 1.6em;
    height: 1.6em;
    margin: 0;
    border: 2px solid var(--border-strong);
    border-radius: 0.5em;
    background: var(--surface);
    cursor: pointer;
    display: grid;
    place-content: center;
    transition: background 0.15s, border-color 0.15s;
}
.to-buy-checkbox::after {
    content: "";
    width: 0.62em;
    height: 0.62em;
    transform: scale(0);
    transition: transform 0.15s ease;
    background: #fff;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.to-buy-checkbox:checked {
    background: var(--primary);
    border-color: var(--primary);
}
.to-buy-checkbox:checked::after { transform: scale(1); }
.to-buy-checkbox:focus-visible { outline: none; box-shadow: var(--ring); }

/* Erledigte Einträge (Extra-Liste) durchgestrichen */
.item-list li.done .item-text { text-decoration: line-through; color: var(--text-faint); }

/* Hinweis: Reihenfolge/Weg (Vorrat-Check bzw. gelernter Einkaufsweg) */
.route-hint {
    display: flex;
    align-items: center;
    gap: 0.45em;
    font-size: 0.85em;
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
    padding: 0.55em 0.8em;
    margin: 0 0 0.9em 0;
    line-height: 1.4;
}
.route-hint svg { width: 15px; height: 15px; flex: 0 0 auto; }

/* ---------- Buy tab: note + qr ---------- */
.buy-note-box { margin: 1.4em 0 0.5em 0; }
.buy-note-input {
    width: 100%;
    padding: 0.75em 0.9em;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 1em;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    outline: none;
    resize: vertical;
    min-height: 3em;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.buy-note-input:focus { border-color: var(--primary); box-shadow: var(--ring); }
.save-buy-note-btn {
    margin-top: 0.6em;
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.6em 1.1em;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.95em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.save-buy-note-btn:hover { background: var(--surface-2); color: var(--text); }

.buy-qrcodes-box {
    margin-top: 1.6em;
    padding: 1.1em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.buy-qrcodes-label {
    font-weight: 600;
    font-size: 0.95em;
    display: block;
    margin-bottom: 0.8em;
    color: var(--text);
}
.buy-qrcodes-list { display: flex; gap: 0.8em; margin-bottom: 0.8em; flex-wrap: wrap; }
.buy-qrcode-img-box {
    position: relative;
    width: 84px;
    height: 84px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}
.buy-qrcode-img { max-width: 80px; max-height: 80px; display: block; cursor: zoom-in; }
.buy-qrcode-delete {
    position: absolute;
    top: 3px;
    right: 3px;
    background: rgba(255,255,255,0.92);
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: grid;
    place-content: center;
    cursor: pointer;
    color: var(--danger);
    box-shadow: var(--shadow-sm);
    transition: background 0.15s;
}
.buy-qrcode-delete:hover { background: var(--danger-soft); }
.buy-qrcode-delete .ic { width: 0.95em; height: 0.95em; }
.buy-qrcode-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    padding: 0.6em 1.05em;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--primary);
    font-size: 0.95em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.buy-qrcode-upload-btn:hover { background: var(--primary-soft); border-color: var(--primary); }
.buy-qrcodes-hint { font-size: 0.88em; color: var(--text-faint); margin-top: 0.7em; }

/* ---------- Info / settings panel ---------- */
.panel-info { display: flex; flex-direction: column; gap: 1em; animation: fadeInInfo 0.25s ease; }
@keyframes fadeInInfo {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}
.settings-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2em 1.15em;
}
.settings-card-danger { background: var(--danger-soft); border-color: rgba(225,29,72,0.18); }
.settings-title {
    font-size: 1.02em;
    font-weight: 700;
    margin: 0 0 0.3em 0;
    color: var(--text);
}
.settings-subtitle {
    font-size: 0.92em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin: 1em 0 0.4em 0;
}
.settings-desc { font-size: 0.92em; color: var(--text-muted); margin: 0 0 0.9em 0; line-height: 1.55; }
.settings-card-danger .btn-danger { margin-bottom: 0.8em; }
.settings-list { font-size: 0.92em; color: var(--text-muted); margin: 0; padding-left: 1.2em; line-height: 1.6; }
.settings-list li { margin-bottom: 0.3em; }
.settings-desc a { color: var(--primary); text-decoration: none; }
.settings-desc a:hover { text-decoration: underline; }

.status { font-size: 0.88em; color: var(--text-muted); margin: 0.2em 0 0 0; min-height: 1.1em; line-height: 1.45; }
.status-ok { color: var(--primary); }

/* Share */
.share-block { display: flex; flex-direction: column; align-items: center; gap: 0.8em; }
.share-qr {
    width: 160px;
    height: 160px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #fff;
    padding: 6px;
}
.share-link {
    font-size: 0.85em;
    color: var(--text-faint);
    word-break: break-all;
    text-align: center;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

/* ---------- Bottom navigation ---------- */
.tabs { display: none; }
.bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    background: rgba(255,255,255,0.92);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 16px rgba(15,23,42,0.06);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    /* Mehr Luft nach unten, damit die Icons nicht am iPhone-Rand (Home-Indikator) kleben. */
    padding: 0.5em 0.3em calc(0.9em + env(safe-area-inset-bottom, 0px)) 0.3em;
}
.nav-btn {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25em;
    background: none;
    border: none;
    color: var(--text-faint);
    font-family: inherit;
    font-size: 0.72em;
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: 0.5em 0.2em;
    min-width: 0;
    cursor: pointer;
    transition: color 0.15s;
}
.nav-btn .nav-svg { width: 23px; height: 23px; stroke: currentColor; }
.nav-icon { display: inline-grid; place-content: center; }
.nav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.nav-btn:hover { color: var(--text-muted); }
.nav-btn.active { color: var(--primary); }

/* ---------- QR modal ---------- */
.qrcode-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qrcode-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,0.6);
    backdrop-filter: blur(2px);
}
.qrcode-modal-content {
    position: relative;
    z-index: 2;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 1.3em;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 96vw;
    max-height: 90vh;
}
#qrcode-modal-img {
    max-width: 82vw;
    max-height: 60vh;
    border-radius: var(--radius-sm);
    margin-bottom: 1.1em;
}
.qrcode-modal-close {
    padding: 0.65em 1.4em;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 1em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}
.qrcode-modal-close:hover { background: var(--primary-strong); }

/* ---------- Offline banner ---------- */
#offline-banner { transition: opacity 0.5s; font-family: inherit; }

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
    .main-card {
        margin: 0.8em 0.6em 1em 0.6em;
        max-width: none;
        border-radius: var(--radius-lg);
        padding: 1.4em 1.1em;
    }
}
