:root {
    --ios-blue: #007AFF;
    --ios-gray: #8E8E93;
    --ios-light-gray: #F2F2F7;
    --ios-bg: #F2F2F7;
    --ios-card-bg: #FFFFFF;
    --ios-text: #000000;
    --ios-secondary-text: #3C3C43;
    --ios-red: #FF3B30;
    --ios-green: #34C759;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

/* Base */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Helvetica Neue", sans-serif;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100dvh;
    background-color: var(--ios-bg);
    color: var(--ios-text);
    overflow: hidden;
    position: fixed;
    width: 100%;
    -webkit-user-select: none;
}

#app { height: 100dvh; position: relative; width: 100%; }

.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    background: var(--ios-bg);
    display: none;
    flex-direction: column;
}

.view.active { display: flex; }

/* Ultra Clean Header */
header {
    padding: 12px 20px;
    padding-top: calc(max(10px, var(--safe-top)));
    background: rgba(242, 242, 247, 0.7);
    backdrop-filter: saturate(180%) blur(25px);
    -webkit-backdrop-filter: saturate(180%) blur(25px);
    z-index: 100;
    border-bottom: 0.5px solid rgba(0,0,0,0.1);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

h1 {
    margin: 0;
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -1.2px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--ios-blue);
    padding: 8px;
    cursor: pointer;
}

/* Segmented Control */
.view-switcher {
    display: flex;
    background: rgba(118, 118, 128, 0.08);
    border-radius: 10px;
    padding: 2px;
}

.switch-btn {
    flex: 1;
    border: none;
    background: none;
    padding: 7px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    color: var(--ios-secondary-text);
}

.switch-btn.active {
    background: white;
    color: var(--ios-text);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* List Area */
main {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
    padding-bottom: calc(100px + var(--safe-bottom));
}

.list-group { margin: 24px 0; }

.list-group-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--ios-gray);
    margin: 0 0 8px 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-list {
    background: var(--ios-card-bg);
    border-radius: 12px;
    overflow: hidden;
}

.list-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: white;
    position: relative;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.list-item::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    left: 54px;
    height: 0.5px;
    background: rgba(0,0,0,0.05);
}

.list-item:last-child::after { display: none; }

/* Checkbox */
.checkbox {
    width: 24px;
    height: 24px;
    border: 1px solid #D1D1D6;
    border-radius: 50%;
    margin-right: 14px;
    flex-shrink: 0;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.list-item.done .checkbox {
    background: var(--ios-green);
    border-color: var(--ios-green);
}

.list-item.done .checkbox::after {
    content: '✓';
    color: white;
    font-size: 14px;
}

/* Item Metadata */
.item-info { flex: 1; }
.item-meta { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 8px; 
    align-items: center; 
    font-size: 12px; 
    color: var(--ios-gray); 
    margin-top: 4px; 
}
.meta-tag {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
}
.store-tag {
    padding: 2px 8px;
    border-radius: 10px;
    color: white;
    font-weight: 600;
    font-size: 11px;
}
.deadline-urgent { color: var(--ios-red); font-weight: 600; }

/* Modal Help Text */
.modal-help {
    font-size: 13px;
    color: var(--ios-gray);
    margin: -5px 0 10px 4px;
}

/* Fixes for iPhone */
@supports (padding: env(safe-area-inset-top)) {
    header {
        padding-top: calc(12px + var(--safe-top));
    }
    main {
        padding-bottom: calc(100px + var(--safe-bottom));
    }
    .modal {
        padding-bottom: calc(20px + var(--safe-bottom));
    }
}

/* Better Swipe Styling */
.list-item-wrapper {
    position: relative;
    overflow: hidden;
    background: var(--ios-red);
    margin-bottom: 1px; /* Separator color */
}

.list-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: white;
    position: relative;
    width: 100%;
    z-index: 2;
    pointer-events: auto; /* Ensure content receives clicks */
    /* Remove transition from here, handle via JS for smoothness */
}

.swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    display: flex;
    z-index: 1;
    pointer-events: auto; /* Ensure actions container doesn't block */
}

.swipe-btn {
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 15px;
    height: 100%;
    border: none;
    cursor: pointer;
    background: var(--ios-red);
    pointer-events: auto; /* Ensure button receives clicks */
}

.delete-timer {
    font-size: 10px;
    color: var(--ios-red);
    font-weight: 600;
    margin-top: 2px;
    display: block;
}

.btn-delete { background: var(--ios-red); }

/* Login */
#view-login { background: white; justify-content: center; align-items: center; }
.login-container { width: 100%; max-width: 260px; text-align: center; }
.login-container h1 { font-size: 32px; margin-bottom: 40px; }
#input-login-pin {
    width: 100%; border: none; background: var(--ios-light-gray);
    border-radius: 16px; padding: 20px; font-size: 32px;
    text-align: center; letter-spacing: 14px; font-weight: 700;
}
#input-login-pin:focus { outline: none; background: #E5E5EA; }

/* Add Button / Footer */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-bottom));
    background: linear-gradient(to top, var(--ios-bg) 80%, transparent);
    z-index: 999; /* Very high to be above everything */
    display: flex;
    justify-content: center;
    pointer-events: none; /* Let clicks pass through the footer container... */
}

.add-btn {
    background: var(--ios-blue);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 28px;
    font-size: 17px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 20px rgba(0, 122, 255, 0.3);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    pointer-events: auto; /* ...but the button itself MUST catch clicks */
}

.add-btn:active {
    transform: scale(0.96);
    box-shadow: 0 4px 10px rgba(0, 122, 255, 0.2);
}

.plus-icon {
    font-size: 22px;
    font-weight: 400;
    line-height: 1;
}

.add-btn-secondary {
    width: 100%;
    padding: 14px 16px;
    background: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    color: var(--ios-blue);
    cursor: pointer;
    text-align: left;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.add-btn-secondary:active { background: #E5E5EA; }

.user-row, .store-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-bottom: 0.5px solid rgba(0,0,0,0.05);
}

.user-row:last-child, .store-row:last-child { border-bottom: none; }

/* FAB */
.fab {
    display: none; /* Removed in favor of nice footer button */
}

/* Sheets */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); display: none; z-index: 1000;
}
.modal-overlay.active { display: block; }
.modal {
    position: fixed; bottom: 0; left: 0; right: 0; background: white;
    border-radius: 12px 12px 0 0; padding: 20px;
    padding-bottom: calc(20px + var(--safe-bottom));
    transform: translateY(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal input, .modal select {
    width: 100%; background: var(--ios-light-gray); border: none;
    border-radius: 10px; padding: 14px; font-size: 17px; margin-bottom: 10px;
}
.modal-actions { display: flex; gap: 10px; }
.modal-actions button {
    flex: 1; padding: 14px; border-radius: 10px; border: none;
    font-size: 17px; font-weight: 600;
}
.primary { background: var(--ios-blue); color: white; }

/* PWA Prompt */
.pwa-prompt {
    position: fixed; bottom: 20px; left: 20px; right: 20px;
    background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); border-radius: 18px;
    padding: 16px; display: none; z-index: 2000;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15); border: 0.5px solid rgba(0,0,0,0.1);
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes slideUp { from { transform: translateY(120%); } to { transform: translateY(0); } }
.pwa-prompt-content { display: flex; align-items: center; gap: 16px; }
.pwa-prompt-icon { font-size: 32px; }
.pwa-prompt-text { flex: 1; }
.pwa-prompt-text strong { display: block; font-size: 16px; margin-bottom: 2px; }
.pwa-prompt-text p { margin: 0; font-size: 13px; color: var(--ios-secondary-text); }
.ios-share-icon {
    display: inline-block; width: 20px; height: 20px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%23007AFF' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M12 5V19M12 5L7 10M12 5L17 10M5 12V21H19V12'/%3E%3C/svg%3E") no-repeat center;
    vertical-align: middle;
}
.pwa-prompt button { background: none; border: none; font-size: 20px; color: var(--ios-gray); }

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.select-with-add {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.select-with-add select {
    margin-bottom: 0 !important;
    flex: 1;
}

.icon-btn-small {
    background: var(--ios-light-gray);
    border: none;
    border-radius: 10px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--ios-blue);
    cursor: pointer;
}

/* Print Styles */
@media print {
    @page { size: A4; margin: 2cm; }
    
    body { 
        position: static; 
        overflow: visible; 
        background: white;
        height: auto;
    }
    
    #app { height: auto; }
    
    header, footer, .fab, .modal-overlay, .pwa-prompt, .header-actions, .view-switcher, .swipe-actions, .checkbox {
        display: none !important;
    }
    
    .view { position: static; display: block; height: auto; background: white; }
    
    main { 
        padding: 0; 
        overflow: visible; 
        height: auto;
    }
    
    .list-group { margin: 20px 0; break-inside: avoid; }
    
    .list-group-title { 
        color: black; 
        font-size: 18px; 
        border-bottom: 2px solid black;
        margin-bottom: 10px;
        padding-bottom: 5px;
    }
    
    .card-list { border: none; border-radius: 0; }
    
    .list-item { 
        padding: 8px 0; 
        border-bottom: 0.5px solid #ccc;
        background: white !important;
    }
    
    .list-item.done { display: none !important; } /* Only print open items */
    
    .item-name { font-size: 16px; font-weight: 600; color: black !important; }
    
    .item-meta { margin-top: 2px; }
    
    .meta-tag, .store-tag { 
        background: none !important; 
        color: #555 !important; 
        padding: 0; 
        border: none;
        font-size: 12px;
    }
    
    .store-tag { font-weight: bold; margin-right: 10px; }
    
    /* Print Header */
    main::before {
        content: "Einkaufsliste - Stand: " attr(data-date);
        display: block;
        font-size: 24px;
        font-weight: bold;
        margin-bottom: 30px;
        text-align: center;
    }
}

/* Error Msg */
