/* =========================================================
   Einkaufsliste – Modern Mobile-First Styles
   ========================================================= */

:root {
    --bg:            #f6f7f9;
    --surface:       #ffffff;
    --surface-2:     #f1f3f5;
    --text:          #1a1d20;
    --text-muted:    #6b7280;
    --border:        #e5e7eb;
    --primary:       #10b981;
    --primary-600:   #059669;
    --primary-50:    #ecfdf5;
    --danger:        #ef4444;
    --warning:       #f59e0b;
    --shadow-sm:     0 1px 2px rgba(0,0,0,.04);
    --shadow-md:     0 4px 16px rgba(0,0,0,.08);
    --shadow-lg:     0 10px 32px rgba(0,0,0,.18);
    --radius:        14px;
    --radius-lg:     20px;
    --radius-sm:     8px;
    --tap:           44px;

    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:         #0f1115;
        --surface:    #1a1d23;
        --surface-2:  #23272f;
        --text:       #e5e7eb;
        --text-muted: #9ca3af;
        --border:     #2c313a;
        --primary:    #10b981;
        --primary-50: #052e23;
        --shadow-sm:  0 1px 2px rgba(0,0,0,.3);
        --shadow-md:  0 4px 16px rgba(0,0,0,.4);
        --shadow-lg:  0 10px 32px rgba(0,0,0,.6);
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
    font-size: 16px;
    line-height: 1.4;
}

button, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* =========================================================
   Login
   ========================================================= */
#login-screen {
    background: linear-gradient(160deg, var(--primary) 0%, var(--primary-600) 100%);
    align-items: center;
    justify-content: center;
    padding: 1rem;
    padding-top: calc(2rem + var(--safe-top));
    padding-bottom: calc(2rem + var(--safe-bottom));
}
.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2rem 1.5rem 1.75rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.login-logo {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--primary-50);
    color: var(--primary-600);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1rem;
}
.login-card h1 { margin: 0 0 .25rem; font-size: 1.5rem; }
.login-sub { color: var(--text-muted); margin: 0 0 1.5rem; font-size: .95rem; }

/* =========================================================
   App-Header
   ========================================================= */
.app-header {
    position: sticky; top: 0; z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: calc(.75rem + var(--safe-top)) 1rem .75rem;
    display: flex; align-items: center; gap: .5rem;
}
.app-title {
    margin: 0; font-size: 1.15rem; font-weight: 600;
    flex: 1;
}
.header-actions { display: flex; align-items: center; gap: .5rem; }

.icon-btn {
    width: var(--tap); height: var(--tap);
    border: 0; background: transparent;
    color: var(--text);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.95); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn-sm {
    width: 28px; height: 28px;
    border: 0; background: transparent;
    color: var(--text-muted);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}

.install-btn {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: var(--primary);
    color: #fff;
    border: 0;
    padding: .45rem .75rem;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transition: background .15s, transform .1s;
}
.install-btn:hover { background: var(--primary-600); }
.install-btn:active { transform: scale(.96); }
.install-btn span { white-space: nowrap; }

.user-badge {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 0;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: .95rem;
    box-shadow: var(--shadow-sm);
}

/* =========================================================
   Tabs
   ========================================================= */
.tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 .5rem;
    position: sticky;
    top: calc(var(--safe-top) + 56px);
    z-index: 9;
}
.tab {
    flex: 1;
    border: 0; background: transparent;
    padding: .85rem .5rem;
    color: var(--text-muted);
    font-weight: 500;
    display: flex; align-items: center; justify-content: center;
    gap: .4rem;
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
}
.tab.active { color: var(--primary-600); border-bottom-color: var(--primary); }
@media (prefers-color-scheme: dark) {
    .tab.active { color: var(--primary); }
}
.tab .badge {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .75rem;
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: 600;
    min-width: 22px;
    text-align: center;
}
.tab.active .badge { background: var(--primary); color: #fff; }

/* =========================================================
   Suchleiste
   ========================================================= */
.searchbar {
    background: var(--surface);
    padding: .75rem 1rem;
    display: flex; align-items: center; gap: .5rem;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.searchbar .search-icon {
    position: absolute; left: 1.6rem; color: var(--text-muted); pointer-events: none;
}
#search-input {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 999px;
    padding: .65rem .8rem .65rem 2.3rem;
    outline: none;
    transition: border-color .15s, background .15s;
}
#search-input:focus { border-color: var(--primary); background: var(--surface); }

/* =========================================================
   Content / Listen
   ========================================================= */
.content {
    flex: 1;
    padding: 1rem 1rem calc(6rem + var(--safe-bottom));
    overflow-y: auto;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

.empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-emoji { font-size: 3rem; margin-bottom: .5rem; }
.empty .sub { font-size: .9rem; margin-top: .25rem; }

/* Vorschläge (Autocomplete) */
.suggestions {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    margin-bottom: 1rem;
    overflow: hidden;
    border: 1px solid var(--border);
}
.suggestion {
    padding: .75rem 1rem;
    display: flex; align-items: center; gap: .75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}
.suggestion:last-child { border-bottom: 0; }
.suggestion:hover { background: var(--surface-2); }
.suggestion .icon {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary-50);
    color: var(--primary-600);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.suggestion .name { flex: 1; font-weight: 500; }
.suggestion .meta { color: var(--text-muted); font-size: .8rem; }
.suggestion.new .icon { background: var(--primary); color: #fff; }
.suggestion.new .name::before { content: "Neu: "; color: var(--text-muted); font-weight: 400; }

/* Listen-Items */
.items {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex; flex-direction: column;
    gap: .5rem;
}
.item {
    background: var(--surface);
    border-radius: var(--radius);
    padding: .75rem .9rem;
    display: flex; align-items: center; gap: .8rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: background .15s, transform .1s;
    animation: slideIn .25s ease;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.item:active { transform: scale(.99); }

.check {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    padding: 0;
}
.check svg { opacity: 0; color: #fff; transition: opacity .15s; }
.item.checked .check {
    background: var(--primary);
    border-color: var(--primary);
}
.item.checked .check svg { opacity: 1; }

.item-body { flex: 1; min-width: 0; }
.item-name {
    font-weight: 500;
    color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-meta {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: .8rem;
    display: flex; gap: .5rem; align-items: center;
    flex-wrap: wrap;
}
.qty {
    background: var(--surface-2);
    padding: 1px 7px;
    border-radius: 8px;
    color: var(--text);
    font-weight: 500;
    font-size: .8rem;
}
.user-dot {
    display: inline-flex; align-items: center; gap: .3rem;
}
.user-dot::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--user-color, var(--primary));
}

.item.checked .item-name {
    text-decoration: line-through;
    color: var(--text-muted);
}

.item-delete {
    border: 0; background: transparent;
    color: var(--text-muted);
    padding: 6px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    opacity: .6;
    transition: opacity .15s, background .15s, color .15s;
}
.item-delete:hover { opacity: 1; color: var(--danger); background: var(--surface-2); }

.done-wrap { margin-top: 1.25rem; }
.done-wrap summary {
    list-style: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: .85rem;
    padding: .5rem .25rem;
    display: flex; justify-content: space-between; align-items: center;
}
.done-wrap summary::-webkit-details-marker { display: none; }
.items-done .item { background: var(--surface-2); }
.link-btn {
    border: 0; background: transparent;
    color: var(--primary-600);
    font-size: .85rem;
    padding: .25rem .5rem;
    border-radius: var(--radius-sm);
}
@media (prefers-color-scheme: dark) { .link-btn { color: var(--primary); } }
.link-btn:hover { background: var(--surface); }

/* Sortier-Pills */
.sort-pills {
    display: flex;
    gap: .35rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    padding-bottom: .25rem;
    scrollbar-width: none;
}
.sort-pills::-webkit-scrollbar { display: none; }
.pill {
    padding: .45rem .9rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: .85rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s, transform .1s;
}
.pill:active { transform: scale(.96); }
.pill.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Kategorie-Header in der Liste */
.category-header {
    list-style: none;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .85rem .25rem .35rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
    margin-top: .25rem;
    animation: slideIn .2s ease;
}
.category-header:first-child { margin-top: 0; }
.category-header .cat-icon { font-size: 1.1rem; }
.category-header .cat-count {
    margin-left: auto;
    background: var(--surface-2);
    padding: 1px 8px;
    border-radius: 8px;
    font-size: .7rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}

/* Kategorie-Header im Katalog-Grid (volle Breite) */
.cat-header-grid {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .85rem .25rem .35rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
    margin-top: .25rem;
}
.cat-header-grid:first-child { margin-top: 0; }
.cat-header-grid .cat-icon { font-size: 1.1rem; }

/* =========================================================
   Katalog (Vorrat)
   ========================================================= */
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .75rem;
}
.catalog-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem .75rem;
    display: flex; flex-direction: column; gap: .25rem;
    cursor: pointer;
    transition: border-color .15s, transform .1s, box-shadow .15s;
    position: relative;
    text-align: left;
}
.catalog-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.catalog-item:active { transform: scale(.97); }
.catalog-item .ci-name {
    font-weight: 600;
    color: var(--text);
    overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
    line-height: 1.25;
}
.catalog-item .ci-meta {
    color: var(--text-muted);
    font-size: .75rem;
}
.catalog-item .ci-add {
    position: absolute; top: 6px; right: 6px;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--primary-50);
    color: var(--primary-600);
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity .15s;
    pointer-events: none;
}
.catalog-item:hover .ci-add { opacity: 1; }
.catalog-item.on-list {
    border-color: var(--primary);
    background: var(--primary-50);
}
@media (prefers-color-scheme: dark) {
    .catalog-item.on-list { background: var(--primary-50); color: var(--text); }
}
.catalog-item.on-list::after {
    content: "auf der Liste";
    position: absolute; top: 6px; right: 6px;
    font-size: .7rem;
    background: var(--primary);
    color: #fff;
    padding: 2px 6px;
    border-radius: 8px;
}

/* =========================================================
   FAB
   ========================================================= */
.fab {
    position: fixed;
    right: 1.25rem;
    bottom: calc(1.25rem + var(--safe-bottom));
    width: 58px; height: 58px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: 0;
    box-shadow: var(--shadow-lg);
    display: flex; align-items: center; justify-content: center;
    transition: transform .15s, background .15s;
    z-index: 8;
}
.fab:hover { background: var(--primary-600); }
.fab:active { transform: scale(.92); }

/* =========================================================
   Bottom-Sheet
   ========================================================= */
.sheet {
    position: fixed; inset: 0;
    z-index: 100;
    display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,.45);
    animation: fadeIn .2s ease;
}
.sheet-panel {
    position: relative;
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: .5rem 1.25rem calc(1.25rem + var(--safe-bottom));
    box-shadow: var(--shadow-lg);
    animation: slideUp .25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
.sheet-handle {
    width: 40px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: .5rem auto 1rem;
    cursor: pointer;
}
.sheet-panel h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.sheet-actions {
    display: flex; gap: .5rem; justify-content: flex-end;
    margin-top: 1rem;
}

/* Sheet-Varianten */
.sheet-panel-sm { max-width: 420px; }
.sheet-panel-lg { max-width: 600px; max-height: 85vh; display: flex; flex-direction: column; }
.sheet-header {
    display: flex; align-items: center; gap: .5rem;
    padding: .25rem 0 .75rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}
.sheet-header h2 { flex: 1; margin: 0; font-size: 1.1rem; text-align: center; }

/* Menü-Items */
.menu-user {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem .25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: .5rem;
}
.menu-user-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    background: var(--primary);
}
.menu-user-name { font-weight: 600; }
.menu-user-role {
    font-size: .8rem;
    color: var(--text-muted);
}
.menu-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    padding: .85rem .5rem;
    display: flex; align-items: center; gap: .75rem;
    border-radius: var(--radius-sm);
    text-align: left;
    font-size: .95rem;
    transition: background .1s;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item-danger { color: var(--danger); }

/* Benutzerliste */
.users-list {
    list-style: none; padding: 0; margin: 0;
    display: flex; flex-direction: column; gap: .5rem;
    overflow-y: auto;
    flex: 1;
}
.user-row {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem;
    background: var(--surface-2);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.user-row .avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}
.user-row .who { flex: 1; min-width: 0; }
.user-row .name { font-weight: 600; }
.user-row .login { color: var(--text-muted); font-size: .8rem; }
.role-badge {
    display: inline-block;
    font-size: .7rem;
    padding: 1px 7px;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-muted);
    margin-left: .35rem;
    border: 1px solid var(--border);
    vertical-align: middle;
}
.role-badge.admin {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.user-actions {
    display: flex; gap: .25rem;
    flex-shrink: 0;
}

.field .hint { color: var(--text-muted); font-weight: 400; font-size: .8rem; }
.field select {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: .65rem .8rem;
    outline: none;
}
.field input[type=color] {
    width: 56px; height: 40px;
    padding: 2px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
}

/* =========================================================
   Forms / Buttons
   ========================================================= */
.field {
    display: block;
    margin-bottom: .75rem;
}
.field > span {
    display: block;
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: .35rem;
    font-weight: 500;
}
.field input {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: .65rem .8rem;
    outline: none;
    transition: border-color .15s;
}
.field input:focus { border-color: var(--primary); }
.row { display: flex; gap: .5rem; }
.row .field { flex: 1; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border: 0;
    padding: .75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: background .15s, transform .1s;
    width: 100%;
}
.btn-primary:hover { background: var(--primary-600); }
.btn-primary:active { transform: scale(.98); }
.sheet-actions .btn-primary { width: auto; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: .75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
}
.btn-ghost:hover { background: var(--surface-2); }

.error {
    color: var(--danger);
    background: rgba(239, 68, 68, .1);
    border-radius: var(--radius-sm);
    padding: .5rem .75rem;
    margin-top: .75rem;
    text-align: left;
    font-size: .9rem;
}

/* =========================================================
   Toast
   ========================================================= */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(6rem + var(--safe-bottom));
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: .65rem 1rem;
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    font-size: .9rem;
    z-index: 200;
    max-width: calc(100% - 2rem);
    animation: toastIn .2s ease, toastOut .25s ease 2.5s forwards;
}
@keyframes toastIn  { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes toastOut { to   { opacity: 0; transform: translate(-50%, 8px); } }

/* =========================================================
   Pull-to-refresh Indikator
   ========================================================= */
.ptr-indicator {
    position: fixed;
    top: calc(var(--safe-top) + 56px);
    left: 50%;
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: var(--shadow-md);
    display: flex; align-items: center; justify-content: center;
    color: var(--primary);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -80px);
    transition: transform .15s ease, opacity .15s ease;
}
.ptr-indicator.visible {
    opacity: 1;
    transform: translate(-50%, 12px);
}
.ptr-indicator.loading svg { animation: spin .8s linear infinite; }

/* =========================================================
   Größere Screens
   ========================================================= */
@media (min-width: 768px) {
    .content { max-width: 720px; margin: 0 auto; width: 100%; }
    .app-header, .tabs, .searchbar { padding-left: max(1rem, calc((100vw - 720px) / 2)); padding-right: max(1rem, calc((100vw - 720px) / 2)); }
    .fab { right: calc((100vw - 720px) / 2 + 1.25rem); }
}
