/* Mobile-first design */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.container {
    max-width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    padding: 0.75rem 1rem 1rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

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

.header-top h1 {
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.list-selector-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.header-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.header-btn:hover {
    background: rgba(255,255,255,0.3);
}

.header-select {
    flex: 1;
    padding: 0.65rem 0.75rem;
    border: none;
    border-radius: 20px;
    background: white;
    color: #333;
    font-size: 0.95rem;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Input container - NOW AT THE TOP */
.input-container {
    position: relative;
    margin-bottom: 0.5rem;
}

#item-input {
    width: 100%;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 28px;
    background: rgba(255,255,255,0.15);
    color: white;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}

#item-input::placeholder {
    color: rgba(255,255,255,0.7);
}

#item-input:focus {
    border-color: white;
    background: rgba(255,255,255,0.25);
}

.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 100;
    margin-top: 0.25rem;
    color: #333;
}

.suggestion-item {
    padding: 0.75rem 1rem;
    background: white;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover, .suggestion-item.selected {
    background-color: #f0f7f4;
}

/* Main content */
main {
    flex: 1;
    padding: 0 1rem 1rem;
    overflow-y: auto;
    background-color: #f5f5f5;
}

#lists {
    margin-top: 0;
}

/* List items with swipe support */
.list-section {
    margin-bottom: 1rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    overflow: hidden;
}

.list-section h3 {
    padding: 0.75rem 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    font-size: 1.1rem;
    color: #333;
}

.item-row {
    position: relative;
    overflow: hidden;
    border-bottom: 1px solid #e9ecef;
    touch-action: pan-y;
    user-select: none;
}

.item-row:last-child {
    border-bottom: none;
}

.item-content {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: white;
    transition: transform 0.2s, background 0.2s;
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-name {
    font-size: 1rem;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-name.completed {
    text-decoration: line-through;
    color: #888;
}

.item-quantity {
    font-size: 0.9rem;
    color: #666;
    margin-left: 0.5rem;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.item-actions button {
    background: none;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.item-actions button:hover {
    background: #f0f0f0;
}

.item-actions button:active {
    background: #e0e0e0;
}

.item-actions button.disabled {
    cursor: not-allowed;
    color: #ccc;
}

/* Swipe background (shown during swipe) */
.swipe-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
}

.swipe-background.left {
    background: linear-gradient(90deg, #e8f5e9, #c8e6c9);
}

.swipe-background.right {
    background: linear-gradient(90deg, #ffebee, #ef9a9a);
}

.swipe-icon {
    position: absolute;
    font-size: 1.5rem;
}

.swipe-icon.left {
    left: 1rem;
    color: #4CAF50;
}

.swipe-icon.right {
    right: 1rem;
    color: #f44336;
}

/* FAB */
.fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 1000;
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.5);
}

.fab:active {
    transform: scale(0.95);
}

/* Undo Toast */
.undo-toast {
    position: fixed;
    bottom: 4rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 28px;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 2000;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.undo-toast.hiding {
    animation: fadeOut 0.3s ease-out forwards;
}

#undo-message {
    font-size: 0.9rem;
    white-space: nowrap;
}

.undo-button {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.undo-button:hover {
    background: #45a049;
}

.undo-button:active {
    background: #3d8b40;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0, 0, 0);
    background-color: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: white;
    margin: 2rem auto;
    padding: 1.5rem;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: slideUpModal 0.3s ease-out;
}

@keyframes slideUpModal {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.close {
    color: #888;
    float: right;
    font-size: 1.8rem;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.close:hover,
.close:focus {
    color: #333;
    background: #f0f0f0;
    text-decoration: none;
}

.modal-input {
    width: 100%;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.modal-input:focus {
    border-color: #4CAF50;
}

.modal-textarea {
    width: 100%;
    min-height: 200px;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
}

.modal-textarea:focus {
    border-color: #4CAF50;
}

.modal-btn {
    display: block;
    width: 100%;
    padding: 0.75rem;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.5rem;
}

.modal-btn:hover {
    background: #45a049;
}

.modal-btn:active {
    background: #3d8b40;
}

#list-management {
    list-style: none;
    margin-top: 1rem;
}

#list-management li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e9ecef;
}

#list-management li:last-child {
    border-bottom: none;
}

#list-management button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    margin-left: 0.5rem;
}

#list-management button:first-of-type {
    background: #e3f2fd;
    color: #1976d2;
}

#list-management button:last-of-type {
    background: #ffebee;
    color: #f44336;
}

#list-management button:hover {
    opacity: 0.8;
}

/* Sort options */
.sort-option {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.sort-option:hover {
    border-color: #4CAF50;
    background: #f8f9fa;
}

.sort-option:active {
    background: #f0f7f4;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    .header-top h1 {
        font-size: 1.8rem;
    }
    
    .container {
        max-width: 600px;
        margin: 0 auto;
        border-left: 1px solid #e0e0e0;
        border-right: 1px solid #e0e0e0;
    }
    
    main {
        padding: 0 1.5rem 1.5rem;
    }
    
    .header-btn {
        width: 44px;
        height: 44px;
        font-size: 1.3rem;
    }
}
