/* ===========================================
   TOKENS
   =========================================== */
:root {
    --bg:               #f5f0eb;
    --surface:          #fffdf9;
    --border:           #e8e0d5;
    --text-primary:     #2c2416;
    --text-primary-dark: #3d3024;
    --text-secondary:   #7a6350;
    --text-muted:       #b0a090;
    --accent:           #c8b89a;
    --done-bg:          #f0ebe4;
    --error:            #a05030;
}

/* ===========================================
   RESET & BASE
   =========================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
    background: var(--bg);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
}

body.is-sorting {
    user-select: none;
    cursor: grabbing;
}

button, input { font: inherit; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===========================================
   APP LAYOUT (full-height, fixed bottom nav)
   =========================================== */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    max-width: 640px;
    margin: 0 auto;
    padding-top: env(safe-area-inset-top, 0px);
    overflow: hidden;
}

/* ===========================================
   HEADERS
   =========================================== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 16px 10px;
    flex-shrink: 0;
}

.app-title {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.progress {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ===========================================
   INPUT AREA (Liste-Modus only)
   =========================================== */
.input-area {
    padding: 0 16px 12px;
    flex-shrink: 0;
}

.input-area form {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-area input {
    min-height: 48px;
    padding: 0 14px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-area input:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(200, 184, 154, 0.2);
}

.input-area input::placeholder { color: var(--text-muted); }

.input-area input[name="quantity"] { flex: 0 0 100px; }

.btn-add {
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    background: var(--text-primary);
    color: var(--surface);
    border: none;
    border-radius: 12px;
    font-size: 1.6rem;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease;
}

.btn-add:hover  { background: var(--text-primary-dark); }
.btn-add:active { transform: scale(0.94); }

/* ===========================================
   LIST AREA
   =========================================== */
.list-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 16px 16px;
}

#list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ===========================================
   ITEM CARDS
   =========================================== */
.item-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    animation: cardIn 0.22s ease both;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.item-card.is-dragging {
    opacity: 0.98;
    border-color: var(--accent);
    box-shadow: 0 18px 36px rgba(44, 36, 22, 0.22);
    animation: none;
    transform: scale(1.01) rotate(-0.4deg);
}

.item-card.is-editing {
    align-items: flex-start;
    background: #fffaf2;
    border-color: var(--accent);
    box-shadow: 0 10px 22px rgba(44, 36, 22, 0.08);
    opacity: 1;
}

.item-card.done {
    background: var(--done-bg);
    border-color: transparent;
    opacity: 0.55;
}

.item-card.is-removing {
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.drag-placeholder {
    position: relative;
    background: rgba(200, 184, 154, 0.08);
    border: 1.5px dashed rgba(200, 184, 154, 0.7);
    animation: none;
}

.drag-placeholder::after {
    content: "";
    position: absolute;
    left: 16px;
    right: 16px;
    top: 50%;
    height: 4px;
    border-radius: 999px;
    background: var(--accent);
    transform: translateY(-50%);
    box-shadow: 0 0 0 4px rgba(200, 184, 154, 0.16);
}

.item-card.is-drop-target-before,
.item-card.is-drop-target-after {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(200, 184, 154, 0.16);
}

.item-card.is-drop-target-before {
    box-shadow:
        0 0 0 3px rgba(200, 184, 154, 0.16),
        inset 0 4px 0 0 var(--accent);
}

.item-card.is-drop-target-after {
    box-shadow:
        0 0 0 3px rgba(200, 184, 154, 0.16),
        inset 0 -4px 0 0 var(--accent);
}

/* Shopping mode: larger tap targets */
[data-mode="einkaufen"] .item-card { padding: 14px 16px; gap: 14px; }

/* ===========================================
   CHECKBOX TOGGLE
   =========================================== */
.toggle {
    appearance: none;
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    min-width: 24px;
    border: 1.5px solid var(--accent);
    border-radius: 7px;
    background: transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle:checked { background: var(--accent); border-color: var(--accent); }

.toggle:checked::after {
    content: "✓";
    font-size: 13px;
    color: var(--surface);
    line-height: 1;
}

.toggle:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

[data-mode="einkaufen"] .toggle {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 8px;
}

[data-mode="einkaufen"] .toggle:checked::after { font-size: 15px; }

/* ===========================================
   ITEM CONTENT
   =========================================== */
.item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.item-edit-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.item-edit-quantity-row {
    display: flex;
    gap: 8px;
}

.item-edit-input {
    min-height: 42px;
    width: 100%;
    padding: 0 12px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
}

.item-edit-input:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(200, 184, 154, 0.18);
}

.item-name {
    font-size: 0.95rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

[data-mode="einkaufen"] .item-name { font-size: 1rem; font-weight: 500; }

.quantity-badge {
    padding: 2px 8px;
    background: var(--border);
    color: var(--text-secondary);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}

.item-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
}

.item-card.is-editing .item-actions {
    align-self: flex-start;
}

.btn-item-action,
.btn-delete {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    font-size: 1.1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.btn-item-action:hover,
.btn-delete:hover {
    transform: translateY(-1px);
}

.btn-edit:hover {
    color: var(--text-secondary);
    background: rgba(200, 184, 154, 0.12);
}

.btn-save {
    color: #5d7b4c;
}

.btn-save:hover {
    background: rgba(93, 123, 76, 0.1);
}

.btn-cancel:hover {
    color: var(--text-secondary);
    background: rgba(200, 184, 154, 0.12);
}

.btn-drag-handle {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: grab;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    touch-action: none;
    transition: color 0.15s ease, background 0.15s ease;
}

.btn-drag-handle::before {
    content: "";
    width: 12px;
    height: 20px;
    background:
        radial-gradient(circle at 2px 2px, currentColor 0 2px, transparent 2.2px),
        radial-gradient(circle at 10px 2px, currentColor 0 2px, transparent 2.2px),
        radial-gradient(circle at 2px 10px, currentColor 0 2px, transparent 2.2px),
        radial-gradient(circle at 10px 10px, currentColor 0 2px, transparent 2.2px),
        radial-gradient(circle at 2px 18px, currentColor 0 2px, transparent 2.2px),
        radial-gradient(circle at 10px 18px, currentColor 0 2px, transparent 2.2px);
}

.btn-drag-handle:hover {
    color: var(--text-secondary);
    background: rgba(200, 184, 154, 0.12);
}

.btn-drag-handle:active { cursor: grabbing; }

.btn-drag-handle:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ===========================================
   DELETE BUTTON
   =========================================== */
.btn-delete { font-size: 1.25rem; }

.btn-delete:hover { color: var(--error); background: rgba(160, 80, 48, 0.08); /* --error at 8% opacity */ }
.btn-item-action:disabled,
.btn-delete:disabled { opacity: 0.35; cursor: not-allowed; }

/* Hidden in shopping mode */
[data-mode="einkaufen"] .btn-edit { display: none; }
[data-mode="einkaufen"] .btn-drag-handle { display: none; }
[data-mode="einkaufen"] .btn-delete { display: none; }

/* ===========================================
   EMPTY STATE
   =========================================== */
.empty-state {
    list-style: none;
    padding: 40px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
    animation: cardIn 0.22s ease both;
}

/* ===========================================
   CLEAR DONE BUTTON
   =========================================== */
.btn-clear {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    background: none;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-clear:hover   { border-color: var(--accent); color: var(--text-secondary); }
.btn-clear:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===========================================
   STATUS MESSAGE (toast)
   =========================================== */
.message {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 8px) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--text-primary);
    color: var(--surface);
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 0.85rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
    max-width: calc(100vw - 32px);
    text-align: center;
}

.message.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.message.is-error   { background: var(--error); }

/* ===========================================
   MODE TOGGLE BUTTON (oben rechts im Header)
   =========================================== */
.btn-mode-toggle {
    min-width: 40px;
    min-height: 40px;
    padding: 0 10px;
    background: var(--border);
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-mode-toggle:hover  { background: var(--accent); }
.btn-mode-toggle:active { transform: scale(0.92); }

/* ===========================================
   MODE VISIBILITY (CSS-driven)
   =========================================== */
[data-mode="einkaufen"] .liste-only { display: none; }
[data-mode="liste"]     .shopping-only { display: none; }

/* ===========================================
   ANIMATIONS
   =========================================== */
@keyframes cardIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0);   }
}

/* ===========================================
   PWA INSTALL BANNER
   =========================================== */
.install-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1.5px solid var(--border);
    flex-shrink: 0;
}

.install-banner[hidden] { display: none; }

.status-banner,
.update-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1.5px solid var(--border);
    flex-shrink: 0;
}

.status-banner {
    background: #efe7dc;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.status-banner[hidden],
.update-banner[hidden] {
    display: none;
}

.update-banner {
    background: var(--surface);
}

.update-text {
    flex: 1;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.btn-update-reload {
    padding: 6px 14px;
    background: var(--text-primary);
    color: var(--surface);
    border: none;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.btn-update-reload:hover { background: var(--text-primary-dark); }

.install-text {
    flex: 1;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.btn-install {
    padding: 6px 14px;
    background: var(--text-primary);
    color: var(--surface);
    border: none;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.btn-install:hover { background: var(--text-primary-dark); }

.btn-install-dismiss {
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s ease;
}

.btn-install-dismiss:hover { color: var(--text-primary); }

/* ===========================================
   REDUCED MOTION
   =========================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===========================================
   SECTION TABS (Bereichs-Navigation oben)
   =========================================== */
.section-tabs {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    border-bottom: 1.5px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.section-tabs::-webkit-scrollbar { display: none; }

.section-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 14px;
    background: none;
    border: none;
    border-bottom: 2.5px solid transparent;
    cursor: pointer;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 52px;
    transition: color 0.15s ease, border-color 0.15s ease;
    margin-bottom: -1.5px; /* overlap border-bottom */
}

.section-tab[aria-current="page"] {
    color: var(--text-primary);
    border-bottom-color: var(--text-primary);
    font-weight: 700;
}

.section-tab:hover:not([aria-current="page"]) {
    color: var(--text-secondary);
}

.section-icon { font-size: 1.1rem; line-height: 1; }
.section-label { font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
