/* Keine Webfonts von Dritten (Datenschutz, strenge CSP): Inter nur, wenn lokal installiert, sonst Systemschrift. */

:root {
    --color-bg: #f4f1ea;
    --color-surface: #ffffff;
    --color-primary: #2f7d5b;
    --color-primary-dark: #235f45;
    --color-primary-light: #e4f0e9;
    --color-accent: #d97b3f;
    --color-text: #21261f;
    --color-muted: #7a8177;
    --color-border: #e6e1d5;
    --color-danger: #c0492e;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(33, 38, 31, 0.06);
    --shadow-md: 0 8px 24px rgba(33, 38, 31, 0.08);
    --shadow-lg: 0 16px 40px rgba(33, 38, 31, 0.12);
    color-scheme: light;
}

* { box-sizing: border-box; }

/* Muss vor den ID-Regeln mit expliziten display-Werten stehen bzw. diese per Spezifität
   schlagen, sonst gewinnt z. B. "#login-screen { display: flex }" gegen das UA-[hidden]. */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    background-image: radial-gradient(circle at 15% 0%, rgba(47, 125, 91, 0.06), transparent 40%),
                       radial-gradient(circle at 100% 20%, rgba(217, 123, 63, 0.05), transparent 35%);
    background-attachment: fixed;
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}

button {
    font: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
button:active { transform: scale(0.97); }

input, select {
    font: inherit;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.6em 0.75em;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

h1 {
    font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    margin: 0;
    letter-spacing: -0.02em;
}

/* App-Icon (icons/icon.svg) vor dem Titel - als Flex-Item, damit es nie in eine eigene Zeile umbricht. */
.login-card h1, .app-header h1 { display: flex; align-items: center; gap: 0.4em; }
.login-card h1::before, .app-header h1::before {
    content: '';
    flex: none;
    width: 1.3em;
    height: 1.3em;
    background: url('/icons/icon.svg') center / contain no-repeat;
}
h3 { margin: 0 0 0.55em; font-size: 0.78rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }

.empty-hint, .empty-hint-small {
    color: var(--color-muted);
    padding: 2.5em 1em;
    text-align: center;
    font-size: 0.95rem;
}
.empty-hint-small { padding: 0.6em 1em; font-size: 0.85rem; text-align: left; }
.empty-hint::before { content: '🛒'; display: block; font-size: 2rem; margin-bottom: 0.4em; opacity: 0.6; }

/* --- Login --- */

#login-screen, #password-change-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    background: var(--color-surface);
    border-radius: 20px;
    padding: 2.4rem 2.2rem;
    max-width: 380px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}
.login-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 5px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
}

.login-card .subtitle { color: var(--color-muted); margin-top: 0.35em; font-size: 0.95rem; }

.login-card form { display: flex; flex-direction: column; gap: 1.1em; margin-top: 1.5em; }
.login-card label { display: flex; flex-direction: column; gap: 0.4em; font-size: 0.85rem; font-weight: 600; color: var(--color-muted); }
.login-card button[type="submit"] {
    background: var(--color-primary);
    color: white;
    padding: 0.75em;
    border-radius: var(--radius-sm);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.login-card button[type="submit"]:hover { background: var(--color-primary-dark); box-shadow: var(--shadow-md); }
.login-card .link-button { align-self: center; color: var(--color-muted); font-size: 0.82rem; text-decoration: underline; padding: 0.2em; }
.login-card .link-button:hover { color: var(--color-danger); }
.login-card input[type="text"], .login-card input[type="password"] { width: 100%; }
.login-card .hint { color: var(--color-muted); font-size: 0.78rem; margin-top: 1.4em; text-align: center; line-height: 1.4; }
.error-text { color: var(--color-danger); font-size: 0.85rem; margin: 0; min-height: 1.1em; font-weight: 500; }

/* --- App shell --- */

#app { display: flex; flex-direction: column; min-height: 100vh; }

.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 1.2rem;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.8em; }
.header-user { display: flex; align-items: center; gap: 0.6em; font-size: 0.85rem; color: var(--color-muted); font-weight: 500; }
#logout-button {
    font-size: 1rem;
    padding: 0.4em 0.5em;
    border-radius: 999px;
    color: var(--color-muted);
}
#logout-button:hover { background: var(--color-bg); color: var(--color-danger); }

.add-form { display: flex; gap: 0.6em; }
.add-input-wrap { position: relative; flex: 1; }
.add-input-wrap input { width: 100%; }
.add-quantity-input { width: 5.5em; flex: 0 0 auto; }
.add-form button[type="submit"] {
    background: var(--color-primary);
    color: white;
    width: 2.8em;
    border-radius: var(--radius-sm);
    font-size: 1.3rem;
    line-height: 1;
    box-shadow: var(--shadow-sm);
}
.add-form button[type="submit"]:hover { background: var(--color-primary-dark); }

.autocomplete-list {
    list-style: none;
    margin: 0;
    padding: 0.3em;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-top: 0.35em;
    max-height: 220px;
    overflow-y: auto;
    z-index: 20;
    box-shadow: var(--shadow-md);
}
.autocomplete-list:empty { display: none; border: none; margin: 0; }
.autocomplete-list li { padding: 0.6em 0.7em; border-radius: 8px; cursor: pointer; }
.autocomplete-list li:hover { background: var(--color-primary-light); }

.sync-indicator {
    font-size: 0.75rem;
    color: var(--color-muted);
    margin-top: 0.6em;
    display: flex;
    align-items: center;
    gap: 0.4em;
}
.sync-indicator::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--color-muted);
    flex-shrink: 0;
}
.sync-indicator.idle::before, .sync-indicator:not(.syncing):not(.error):not(.offline)::before { background: var(--color-primary); }
.sync-indicator.syncing { color: var(--color-primary); }
.sync-indicator.syncing::before { background: var(--color-primary); animation: pulse 1s ease-in-out infinite; }
.sync-indicator.error { color: var(--color-danger); }
.sync-indicator.error::before { background: var(--color-danger); }
.sync-indicator.offline::before { background: var(--color-accent); }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.3); }
}

.quick-select {
    display: flex;
    gap: 0.6em;
    overflow-x: auto;
    padding: 0.8rem 1.2rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    scrollbar-width: thin;
}
.chip {
    flex: 0 0 auto;
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.55em 1.1em;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}
.chip:hover { background: var(--color-primary); color: white; transform: translateY(-1px); box-shadow: var(--shadow-md); }

.content { flex: 1; padding: 1.2rem; padding-bottom: 5.5rem; }
.panel { max-width: 720px; margin: 0 auto; }

.category-group { margin-bottom: 1.6em; }
.category-group.uncategorized h3 { color: var(--color-accent); }

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5em; }
.item {
    display: flex;
    align-items: center;
    gap: 0.7em;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.75em 0.9em;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s ease, opacity 0.15s ease;
}
.item:hover { box-shadow: var(--shadow-md); }
.item.done { opacity: 0.6; }
.item.done .item-name { text-decoration: line-through; color: var(--color-muted); }
.item input[type="checkbox"] {
    width: 1.3em; height: 1.3em;
    accent-color: var(--color-primary);
    cursor: pointer;
    flex-shrink: 0;
}
.item-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.item-meta { display: contents; }

/* Smartphone: Name + ✕ in der ersten Zeile, Menge + Kategorie darunter - sonst läuft das ✕ aus der Karte. */
@media (max-width: 480px) {
    .item { flex-wrap: wrap; row-gap: 0.5em; }
    .item .delete-button { order: 2; }
    .item-meta {
        order: 3;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5em;
        flex: 1 0 100%;
        padding-left: 2em; /* unter dem Namen einrücken (Checkbox + Abstand) */
    }
}
.item-quantity {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--color-primary-dark);
    background: var(--color-primary-light);
    border-radius: 999px;
    padding: 0.2em 0.7em;
    white-space: nowrap;
}
.item-quantity:hover { background: var(--color-primary); color: white; }
.item-quantity.empty {
    color: var(--color-muted);
    background: transparent;
    border: 1px dashed var(--color-border);
}
.item-quantity.empty:hover { border-color: var(--color-primary); color: var(--color-primary); }
.item-quantity-input {
    width: 6em;
    font: inherit;
    font-size: 0.85rem;
    padding: 0.2em 0.6em;
    border: 1px solid var(--color-primary);
    border-radius: 999px;
    outline: none;
}
.tag-button {
    font-size: 0.72rem;
    color: var(--color-accent);
    border: 1px dashed var(--color-accent);
    border-radius: 999px;
    padding: 0.3em 0.7em;
    font-weight: 500;
    white-space: nowrap;
}
.tag-button:hover { background: var(--color-accent); color: white; border-style: solid; }
.delete-button {
    color: var(--color-muted);
    font-size: 0.9rem;
    padding: 0.3em 0.5em;
    border-radius: 999px;
    line-height: 1;
}
.delete-button:hover { color: var(--color-danger); background: rgba(192, 73, 46, 0.1); }

.list-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.6em; margin-bottom: 0.8em; }
.clear-done-button { margin-left: auto; }
.market-select { display: flex; align-items: center; gap: 0.5em; font-size: 0.85rem; font-weight: 500; color: var(--color-muted); }
.market-select select {
    font: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 0.35em 0.9em;
}
.clear-done-button {
    font-size: 0.85rem;
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
    border-radius: 999px;
    padding: 0.4em 1em;
    font-weight: 500;
    background: transparent;
}
.clear-done-button:hover { background: var(--color-danger); color: white; }

.category-list { list-style: none; margin: 0 0 1.2em; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5em; }
.category-list li {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 0.45em 1em;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}
.category-form { display: flex; gap: 0.6em; }
.category-form input { flex: 1; }
.category-form button {
    background: var(--color-primary);
    color: white;
    border-radius: var(--radius-sm);
    padding: 0.6em 1.2em;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.category-form button:hover { background: var(--color-primary-dark); }

.panel-heading { margin-top: 1.8em; }
.panel-heading:first-child { margin-top: 0; }
.panel-hint { margin: 0 0 0.8em; font-size: 0.85rem; color: var(--color-muted); }

.market-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    margin-bottom: 0.6em;
    padding: 0 0.9em;
}
.market-card summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6em;
    padding: 0.75em 0;
    cursor: pointer;
    font-weight: 500;
}
.delete-button.confirm { color: white; background: var(--color-danger); font-size: 0.8rem; padding: 0.35em 0.8em; }

.user-list { list-style: none; margin: 0 0 0.8em; padding: 0; display: flex; flex-direction: column; gap: 0.5em; }
.user-row {
    display: flex;
    align-items: center;
    gap: 0.6em;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    padding: 0.6em 0.9em;
    min-height: 2.9em;
}
.user-name { flex: 1; font-weight: 500; }
.user-badge.admin { color: var(--color-accent); background: rgba(217, 123, 63, 0.12); }
.user-badge {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-primary-dark);
    background: var(--color-primary-light);
    border-radius: 999px;
    padding: 0.2em 0.7em;
}
.user-form { flex-wrap: wrap; }
.user-form input[type="text"], .user-form input[type="password"] { min-width: 8em; }
.user-form .check { display: flex; align-items: center; gap: 0.4em; font-size: 0.85rem; color: var(--color-muted); white-space: nowrap; }
.user-form .check input { flex: none; width: 1.1em; height: 1.1em; accent-color: var(--color-primary); }
.success-text { color: var(--color-primary-dark); font-size: 0.85rem; margin: 0; font-weight: 500; }
.market-order { list-style: none; margin: 0 0 0.8em; padding: 0; counter-reset: pos; }
.market-order li {
    display: flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.4em 0;
    border-top: 1px solid var(--color-border);
    counter-increment: pos;
}
.market-order li::before { content: counter(pos) '.'; width: 1.8em; color: var(--color-muted); font-size: 0.8rem; }
.market-order li span { flex: 1; }
.market-order li.unsorted span { color: var(--color-muted); }
.move-button {
    color: var(--color-primary-dark);
    background: var(--color-primary-light);
    border-radius: var(--radius-sm);
    padding: 0.35em 0.7em;
    font-size: 0.8rem;
    line-height: 1;
}
.move-button:hover:not(:disabled) { background: var(--color-primary); color: white; }
.move-button:disabled { opacity: 0.3; cursor: default; }

.assign-category-dialog {
    border: none;
    border-radius: var(--radius);
    padding: 1.6em;
    max-width: 320px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}
.assign-category-dialog::backdrop { background: rgba(33, 38, 31, 0.45); backdrop-filter: blur(2px); }
.assign-category-dialog h3 { text-transform: none; letter-spacing: normal; color: var(--color-text); font-size: 1.05rem; font-weight: 600; }
.assign-category-dialog select { width: 100%; margin: 1em 0; }
.assign-category-dialog menu { display: flex; justify-content: flex-end; gap: 0.6em; margin: 0; padding: 0; }
.assign-category-dialog button { padding: 0.5em 1em; border-radius: var(--radius-sm); font-weight: 500; }
.assign-category-dialog button.primary { background: var(--color-primary); color: white; }
.assign-category-dialog button.primary:hover { background: var(--color-primary-dark); }

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 16px rgba(33, 38, 31, 0.05);
}
.nav-button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2em;
    padding: 0.7em 0;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--color-muted);
}
.nav-button.active { color: var(--color-primary); font-weight: 700; }

/* --- Tablet/Desktop: Schnellauswahl als feste linke Sidebar --- */
@media (min-width: 900px) {
    /* align-content: flex-start verhindert, dass die Flex-Zeile des Headers (er allein auf
       seiner Zeile durch width:100%) sich über die übrige Höhe von #app (min-height:100vh)
       aufbläht - sonst würde .app-header per align-items:stretch riesig hoch werden. */
    #app { flex-direction: row; flex-wrap: wrap; align-content: flex-start; }
    .app-header { width: 100%; }
    .quick-select {
        flex-direction: column;
        width: 240px;
        overflow-x: visible;
        border-right: 1px solid var(--color-border);
        border-bottom: none;
        align-self: flex-start;
        position: sticky;
        top: 4.9rem;
    }
    .chip { width: 100%; text-align: left; }
    .content { flex: 1; min-width: 0; }
    .bottom-nav { position: sticky; bottom: 0; flex-basis: 100%; }
}

/* Umschalter "Gemeinsam | Meine" über der Liste */
.list-scope {
    display: flex;
    gap: 0.3em;
    padding: 0.25em;
    margin-bottom: 0.9em;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
}
.list-scope-button {
    flex: 1;
    padding: 0.5em 0.8em;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-muted);
    background: transparent;
}
.list-scope-button:hover:not(.active) { color: var(--color-primary-dark); background: var(--color-primary-light); }
.list-scope-button.active { background: var(--color-primary); color: white; }
