* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #4F46E5; --primary-dark: #4338CA;
    --success: #10B981; --danger: #EF4444; --warning: #F59E0B; --urgent: #DC2626;
    --bg: #F3F4F6; --card-bg: #FFFFFF; --text: #1F2937; --text-muted: #6B7280; --border: #E5E7EB;
    --shadow: 0 1px 3px rgba(0,0,0,0.1); --shadow-lg: 0 4px 6px rgba(0,0,0,0.1);
    --radius: 12px; --radius-sm: 8px;
}
body.dark-mode { --bg: #1F2937; --card-bg: #374151; --text: #F9FAFB; --text-muted: #9CA3AF; --border: #4B5563; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
.screen { min-height: 100vh; }

/* Auth */
.auth-container { max-width: 400px; margin: 0 auto; padding: 60px 24px; text-align: center; }
.auth-container h1 { font-size: 2.5rem; margin-bottom: 8px; }
.auth-container .subtitle, .subtitle { color: var(--text-muted); margin-bottom: 16px; font-size: 0.9rem; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form input { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; background: var(--card-bg); color: var(--text); }
.auth-divider { margin: 24px 0; display: flex; align-items: center; gap: 16px; color: var(--text-muted); }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Buttons */
.btn { padding: 12px 20px; border: none; border-radius: var(--radius-sm); font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-text { background: none; color: var(--primary); padding: 8px; }
.btn-success { background: var(--success); color: white; }
.btn-small { padding: 8px 12px; font-size: 13px; }
.icon-btn { background: none; border: none; font-size: 1.4rem; cursor: pointer; padding: 6px; border-radius: 50%; }
.fab { position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: white; border: none; font-size: 1.8rem; cursor: pointer; box-shadow: var(--shadow-lg); z-index: 50; }

/* Header */
.app-header { background: var(--primary); color: white; padding: 8px 12px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 100; gap: 8px; }
.app-header h1 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; margin: 0; }
.header-actions { display: flex; gap: 2px; }
.header-actions .icon-btn { color: white; font-size: 1.1rem; }

/* Mode Toggle */
.mode-toggle { display: flex; background: rgba(255,255,255,0.2); border-radius: 20px; padding: 2px; position: relative; z-index: 101; }
.mode-btn { background: none; border: none; color: rgba(255,255,255,0.8); padding: 5px 10px; border-radius: 18px; font-size: 0.8rem; cursor: pointer; transition: all 0.2s; white-space: nowrap; position: relative; z-index: 102; }
.mode-btn.active { background: white; color: var(--primary); font-weight: 600; }
.mode-btn:hover:not(.active) { background: rgba(255,255,255,0.1); }

/* Views */
.view { padding: 12px; padding-bottom: 320px; overflow-y: auto; }
.view h2 { margin-bottom: 4px; }
.back-btn { background: none; border: none; color: var(--primary); font-size: 0.95rem; font-weight: 500; cursor: pointer; padding: 8px 0; }

/* Items container scroll */
.items-container { max-height: calc(100vh - 400px); overflow-y: auto; padding-bottom: 20px; }

/* Items Header */
.items-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

/* Search & Filter */
.search-bar { display: flex; gap: 8px; margin-bottom: 8px; }
.search-bar input { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: var(--card-bg); color: var(--text); }
.store-filter-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.store-filter-btn { padding: 6px 12px; background: white; border: 2px solid #CBD5E1; border-radius: 16px; font-size: 13px; cursor: pointer; transition: all 0.2s; white-space: nowrap; }
.store-filter-btn:hover { border-color: var(--primary); background: #EEF2FF; }
.store-filter-btn.selected { background: var(--primary); color: white; border-color: var(--primary); }

/* List Summary */
.list-summary { display: flex; justify-content: space-between; background: var(--card-bg); padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 10px; font-weight: 600; font-size: 0.9rem; }
.list-summary span:first-child { color: var(--success); }

/* Lists */
.lists-container, .items-container, .favorites-container, .history-container, .recipes-container, .recurring-container { display: flex; flex-direction: column; gap: 10px; }
.list-card { background: var(--card-bg); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: center; }
.list-card .list-info { cursor: pointer; flex: 1; }
.list-card .list-info:hover h3 { color: var(--primary); }
.list-info h3 { font-size: 1rem; margin-bottom: 2px; }
.list-info p { color: var(--text-muted); font-size: 0.8rem; }
.list-actions { display: flex; align-items: center; gap: 8px; }
.list-count { background: var(--primary); color: white; padding: 4px 10px; border-radius: 16px; font-weight: 600; font-size: 0.85rem; }
.list-edit-btn, .list-delete-btn { background: none; border: none; cursor: pointer; font-size: 1rem; opacity: 0.5; padding: 4px; }
.list-edit-btn:hover, .list-delete-btn:hover { opacity: 1; }

/* Items */
.item-card { background: var(--card-bg); border-radius: var(--radius-sm); padding: 10px 12px; box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 10px; }
.item-card.in-cart { background: #ECFDF5; border-left: 3px solid var(--success); }
.item-card.urgent { border-left: 3px solid var(--urgent); }
body.dark-mode .item-card.in-cart { background: #064E3B; }
.item-checkbox { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.85rem; }
.item-checkbox.checked { background: var(--success); border-color: var(--success); color: white; }
.item-content { flex: 1; min-width: 0; }
.item-row-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.item-name { font-weight: 600; font-size: 1rem; flex-shrink: 0; max-width: 50%; }
.item-name .urgent-badge { color: var(--urgent); }
.item-note-text { color: var(--text-muted); font-size: 0.85rem; font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-row-bottom { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); }
.item-details { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.item-meta { font-size: 0.75rem; color: var(--text-muted); }
.item-actions { display: flex; gap: 2px; flex-shrink: 0; }
.item-actions button { background: none; border: none; font-size: 1rem; cursor: pointer; padding: 2px; opacity: 0.5; }
.item-actions button:hover { opacity: 1; }
.item-category { font-size: 0.7rem; padding: 1px 5px; background: var(--bg); border-radius: 8px; }
.item-qty { font-size: 0.8rem; }
.item-qty-controls { display: inline-flex; align-items: center; gap: 4px; margin-left: 4px; }
.item-qty-controls .qty-btn { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border); background: white; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.item-qty-controls .qty-btn:hover { background: var(--bg); }
.item-qty-controls .qty-val { font-size: 0.85rem; min-width: 20px; text-align: center; }
.purchase-qty-controls { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; background: rgba(16,185,129,0.15); padding: 2px 8px; border-radius: 12px; }
.purchase-qty-controls .cart-icon { font-size: 0.8rem; }
.purchase-qty-controls .qty-btn { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--success); background: white; color: var(--success); cursor: pointer; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.purchase-qty-controls .qty-btn:hover { background: #D1FAE5; }
.purchase-qty-controls .purchase-val { font-size: 0.85rem; min-width: 18px; text-align: center; font-weight: 600; color: var(--success); }
.item-price { color: var(--success); font-weight: 600; }
.item-store { font-size: 0.65rem; background: var(--primary); color: white; padding: 1px 5px; border-radius: 8px; }

/* Add Item Form */
.add-item-form { position: fixed; bottom: 0; left: 4px; right: 4px; background: #DBEAFE; padding: 14px 12px 20px; box-shadow: 0 -4px 20px rgba(0,0,0,0.15); z-index: 50; border-top: 2px solid #93C5FD; border-radius: 12px 12px 0 0; transition: transform 0.3s ease; }
.add-item-form.minimized { transform: translateY(calc(100% - 50px)); }
.add-item-form.minimized .add-item-content { display: none; }
body.dark-mode .add-item-form { background: #1E3A5F; border-top-color: #2563EB; }
.add-item-toggle { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.add-item-toggle span { font-weight: 600; color: var(--primary); font-size: 1.1rem; }
.minimize-btn { background: var(--primary); color: white; border: none; border-radius: 20px; padding: 8px 16px; font-size: 14px; cursor: pointer; }
.add-item-content {}
.add-item-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.add-item-row-inputs { display: flex; gap: 10px; margin-bottom: 10px; position: relative; }
.add-input-half { flex: 1; padding: 12px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 18px; background: white; color: var(--text); height: 46px; }
.autocomplete-list { position: absolute; top: 100%; left: 0; right: 50%; background: white; border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); max-height: 200px; overflow-y: auto; z-index: 200; margin-top: 2px; }
.autocomplete-item { padding: 10px 14px; cursor: pointer; font-size: 16px; border-bottom: 1px solid var(--border); }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.selected { background: var(--bg); }
.autocomplete-item .match { font-weight: 700; }
.add-item-name { flex: 1; padding: 12px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 18px; background: white; color: var(--text); height: 46px; }
.add-item-details { display: flex; gap: 8px; margin-bottom: 10px; }
.add-item-qty { width: 80px; text-align: center; padding: 10px 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; background: white; color: var(--text); height: 40px; }
.add-item-unit { flex: 1; padding: 10px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 15px; background: white; color: var(--text); height: 40px; }
.add-item-row2 { display: flex; gap: 8px; margin-bottom: 0; align-items: center; }
.add-item-row-note { margin-bottom: 10px; }
.add-item-row-note .add-item-note { width: 100%; }
.add-item-row-bottom { display: flex; gap: 10px; align-items: center; }
.btn-add { padding: 12px 20px; font-size: 16px; margin-left: auto; }
.add-item-note { flex: 1; padding: 12px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 18px; background: white; color: var(--text); height: 46px; min-width: 0; }
.voice-btn { font-size: 1.4rem !important; padding: 8px !important; flex-shrink: 0; }
.voice-btn.listening { background: var(--danger); border-radius: 50%; color: white; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }

/* Category & Store suggestions */
.category-suggestions, .store-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.cat-suggestion, .store-suggestion { padding: 8px 14px; background: white; border: 2px solid #CBD5E1; border-radius: 20px; font-size: 14px; cursor: pointer; transition: all 0.2s; white-space: nowrap; }
.cat-suggestion:hover, .store-suggestion:hover { border-color: var(--primary); background: #EEF2FF; }
.cat-suggestion.selected, .store-suggestion.selected { background: var(--primary); color: white; border-color: var(--primary); }
.cat-suggestion.recommended { border-color: var(--success); background: #ECFDF5; }
.cat-suggestion.recommended.selected { background: var(--success); border-color: var(--success); }
.section-label { font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Custom dropdown that opens upward */
.custom-select { position: relative; flex: 1; }
.select-selected { padding: 10px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 15px; background: white; color: var(--text); height: 40px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.select-selected::after { content: '▼'; font-size: 10px; color: var(--text-muted); }
.select-items { position: absolute; bottom: 100%; left: 0; right: 0; background: white; border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 -4px 12px rgba(0,0,0,0.15); max-height: 250px; overflow-y: auto; z-index: 100; margin-bottom: 4px; }
.select-items div { padding: 12px; cursor: pointer; font-size: 15px; }
.select-items div:hover { background: var(--bg); }
.select-hide { display: none; }

/* Checkout Button */
.btn-checkout { padding: 8px 16px; font-size: 0.9rem; }
.list-summary { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

/* History & Favorites */
.history-date-header { font-weight: 600; color: var(--text-muted); padding: 10px 0 4px; font-size: 0.85rem; border-bottom: 1px solid var(--border); margin-top: 6px; }
.history-item, .recipe-item, .recurring-item { background: var(--card-bg); border-radius: var(--radius-sm); padding: 12px; box-shadow: var(--shadow); cursor: pointer; margin-bottom: 8px; }
.history-item:hover, .recipe-item:hover { box-shadow: var(--shadow-lg); }
.favorites-add-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.favorites-add-form input[type="text"]:first-of-type { flex: 2; min-width: 120px; }
.favorites-add-form .fav-qty-input { width: 50px; flex: 0 0 50px; }
.favorites-add-form .fav-cat-select { flex: 1; min-width: 100px; }
.favorites-add-form input, .favorites-add-form select { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.95rem; }
.favorite-item { display: flex; justify-content: space-between; align-items: center; background: var(--card-bg); border-radius: var(--radius-sm); padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 8px; gap: 10px; }
.favorite-item .fav-name { cursor: pointer; flex: 1; font-size: 1rem; font-weight: 500; }
.favorite-item .fav-name:hover { color: var(--primary); }
.favorite-item .fav-details { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }
.favorite-item .fav-delete { background: none; border: none; cursor: pointer; opacity: 0.5; font-size: 1.1rem; padding: 4px; }
.favorite-item .fav-delete:hover { opacity: 1; }

/* Stats */
.stats-card { background: var(--card-bg); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.stats-card h3 { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 4px; }
.stats-card .big-number { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stats-list { margin-top: 8px; }
.stats-list-item { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }

/* Recipe */
.recipe-item { margin-bottom: 8px; }
.recipe-item h4 { margin-bottom: 4px; }
.recipe-item .ingredients { font-size: 0.8rem; color: var(--text-muted); }
.ingredient-row { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; }
.ingredient-row input { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; }
.ingredient-row button { padding: 6px 10px; }

/* Recurring */
.recurring-item { display: flex; justify-content: space-between; align-items: center; }
.recurring-item .info { flex: 1; }
.recurring-item .freq { font-size: 0.75rem; color: var(--primary); background: var(--bg); padding: 2px 8px; border-radius: 10px; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal { background: var(--card-bg); border-radius: var(--radius); width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }
.modal-content { padding: 16px; }
.modal-content form { display: flex; flex-direction: column; gap: 10px; }
.modal-content input, .modal-content select, .modal-content textarea { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 15px; background: var(--bg); color: var(--text); }
.modal-content textarea { min-height: 80px; resize: vertical; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }

/* Toast */
.toast-container { position: fixed; bottom: 350px; left: 50%; transform: translateX(-50%); z-index: 300; }
.toast { background: #1F2937; color: white; padding: 10px 18px; border-radius: var(--radius-sm); font-size: 0.85rem; animation: slideUp 0.3s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Empty State */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .emoji { font-size: 2.5rem; margin-bottom: 12px; }

/* Responsive */
@media (min-width: 768px) {
    .view { max-width: 700px; margin: 0 auto; }
    .add-item-form { max-width: 700px; left: 50%; right: auto; width: calc(100% - 8px); transform: translateX(-50%); }
    .add-item-form.minimized { transform: translateX(-50%) translateY(calc(100% - 50px)); }
}

/* Dinner Voting */
.dinner-actions { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.dinner-poll-card { background: var(--card-bg); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); cursor: pointer; }
.dinner-poll-card:hover { box-shadow: var(--shadow-lg); }
.dinner-poll-card h3 { margin: 0 0 4px; font-size: 1.1rem; }
.dinner-poll-card .poll-meta { font-size: 0.85rem; color: var(--text-muted); }
.dinner-poll-card .poll-meta span { margin-right: 12px; }
.dinner-poll-card.closed { opacity: 0.7; border-left: 3px solid var(--success); }
.dinner-poll-card .winner-badge { background: var(--success); color: white; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; margin-left: 8px; }

.poll-option-card { background: var(--card-bg); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 12px; cursor: grab; transition: transform 0.15s, box-shadow 0.15s, background 0.15s; }
.poll-option-card:active { cursor: grabbing; }
.poll-option-card.dragging { opacity: 0.5; transform: scale(1.02); box-shadow: var(--shadow-lg); }
.poll-option-card.drag-over { background: #EEF2FF; border: 2px dashed var(--primary); }
.drag-handle { font-size: 1.2rem; color: var(--text-muted); cursor: grab; user-select: none; padding: 4px; }
.drag-handle:active { cursor: grabbing; }
.poll-option-card .option-info { flex: 1; }
.poll-option-card .option-name { font-weight: 600; font-size: 1rem; }
.poll-option-card .option-desc { font-size: 0.8rem; color: var(--text-muted); }
.poll-option-card .option-votes { text-align: right; min-width: 60px; }
.poll-option-card .vote-count { font-size: 1.2rem; font-weight: bold; color: var(--primary); }
.poll-option-card .vote-breakdown { font-size: 0.7rem; color: var(--text-muted); }
.poll-option-card.winner { border: 2px solid var(--success); background: rgba(16,185,129,0.1); }

.vote-buttons { display: flex; gap: 6px; }
.vote-btn { padding: 6px 12px; border-radius: 16px; font-size: 0.8rem; border: 2px solid var(--border); background: white; cursor: pointer; transition: all 0.2s; }
.vote-btn:hover { border-color: var(--primary); }
.vote-btn.selected-1 { background: var(--primary); color: white; border-color: var(--primary); }
.vote-btn.selected-2 { background: #8B5CF6; color: white; border-color: #8B5CF6; }

.poll-votes-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.poll-votes-section h3 { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 10px; }
.voter-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.voter-row:last-child { border-bottom: none; }
.voter-choices { color: var(--text-muted); }

.meal-list-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--card-bg); border-radius: var(--radius-sm); margin-bottom: 6px; }
.meal-list-item .meal-name { font-weight: 500; }
.meal-list-item .delete-meal { color: var(--danger); cursor: pointer; opacity: 0.6; }
.meal-list-item .delete-meal:hover { opacity: 1; }

#poll-status { margin-bottom: 12px; }
#poll-status .status-open { color: var(--success); font-weight: 600; }
#poll-status .status-closed { color: var(--text-muted); }
.poll-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
