/* Variables Globales */
:root {
    --primary: #10B981;
    --primary-dark: #059669;
    --bg: #ffffff;
    --fg: #1f2937;
    --card: #f9fafb;
    --border: #e5e7eb;
    --muted: #6b7280;
    --nav-bg: rgba(255, 255, 255, 0.9);
    --error: #ef4444;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --fg: #f1f5f9;
        --card: #1e293b;
        --border: #334155;
        --muted: #94a3b8;
        --nav-bg: rgba(15, 23, 42, 0.9);
    }
}

/* Reset y Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    max-width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.5;
}

/* Layout de Auth (Login/Register) */
main {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.card {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

.card h2 {
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 1.5rem;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Inputs y Botones */
.form-group {
    margin-bottom: 1.5rem;
}

.section-title {
    display: none !important;
}

input, select, .form-input, .form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background-color: var(--bg);
    color: var(--fg);
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background-color: var(--card);
    color: var(--fg);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s;
    text-align: center;
    text-decoration: none;
}

.btn.primary {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

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

.link-primary {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.link-primary:hover {
    text-decoration: underline;
}

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error-msg { color: var(--error); margin-bottom: 1rem; text-align: center; font-size: 0.9rem; }

/* Estilos de la App (Index) */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem;
    text-align: center;
}

.container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: 80px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    padding: 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    text-align: center;
}

.stat-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; color: var(--muted); margin-bottom: 0.25rem; }
.stat-value { font-size: 1.1rem; font-weight: 800; }

.controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: stretch;
    flex-wrap: nowrap;
    width: 100%;
}

.controls .search-box {
    flex: 1;
    min-width: 0;
}

.controls .btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.75rem 1rem;
}

.sort-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: nowrap;
    width: 100%;
    align-items: center;
}
.sort-btn {
    flex: 1;
    min-width: 0;
    padding: 0.6rem 0.75rem;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    background: var(--card);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sort-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.sort-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

#bulkToggleBtn {
    margin-left: auto;
}

.bulk-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.3s ease;
    margin-bottom: 0;
    margin-top: 0;
}

.bulk-actions.active {
    max-height: 200px;
    opacity: 1;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}

.btn-bulk {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: rgba(16, 185, 129, 0.1);
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    flex: 1;
}

.btn-bulk:hover {
    background: var(--primary);
    color: white;
}

.btn-bulk:active {
    transform: scale(0.98);
}

.btn-scan {
    width: 100%;
    margin-bottom: 0.75rem;
    background: rgba(99, 102, 241, 0.07);
    color: #6366f1;
    border: 1px dashed #6366f1;
    font-size: 0.85rem;
    padding: 0.6rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-scan:hover {
    background: rgba(99, 102, 241, 0.15);
}

.finish-container {
    margin-bottom: 1.5rem;
    padding: 0;
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.btn-finish {
    padding: 0.75rem;
    font-size: 0.95rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-finish-delete {
    padding: 0.75rem;
    font-size: 1rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid var(--error);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-finish-delete:hover {
    background: var(--error);
    color: white;
}

/* Burbuja Volver Arriba */
.scroll-top-btn {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 45px;
    height: 45px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    transform: translateY(20px);
}

.scroll-top-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-top-btn:hover {
    background-color: var(--primary-dark);
    transform: scale(1.1);
}

/* Items List */
.item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border-color: var(--primary);
}

.item.checked { opacity: 0.5; }
.item.checked .item-name { text-decoration: line-through; }

.item-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
}

.item-content { flex: 1; }
.item-name { font-weight: 600; font-size: 0.95rem; display: flex; align-items: center; gap: 0.4rem; }
.item-category-icon { font-size: 1.1rem; }
.item-meta { font-size: 0.75rem; color: var(--muted); margin-left: 0; margin-top: 0.2rem; }

.item-btn.delete {
    color: var(--muted);
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
}

.item-btn.delete:hover { color: var(--error); }

/* Modales */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active { display: flex; }

.modal-content {
    background-color: var(--bg);
    border-radius: 1.25rem;
    padding: 2rem;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
}

.promo-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    background-color: var(--card);
}

.promo-toggle.active {
    background-color: rgba(16, 185, 129, 0.1);
    border-color: var(--primary);
}

.promo-toggle-icon {
    font-size: 1.25rem;
}

.promo-toggle-text {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 500;
}

.promo-toggle-check {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.promo-toggle.active .promo-toggle-check {
    background-color: var(--primary);
    border-color: var(--primary);
}

.promo-toggle.active .promo-toggle-check::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background-color: var(--nav-bg);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.5rem 0;
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 0.7rem;
    cursor: pointer;
    flex: 1;
}

.nav-item.active { color: var(--primary); }
.nav-item i { font-size: 1.25rem; margin-bottom: 2px; }

/* Sections */
.section {
    display: none;
}

.section.active {
    display: block;
}

/* Historial Cards - Estilo Mini Minimalista Refinado */
.history-card {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.history-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.history-card.selected {
    border-color: #6366f1;
    background-color: rgba(99, 102, 241, 0.05);
    box-shadow: 0 0 0 1px #6366f1;
}

.history-card:active {
    transform: scale(0.98);
}

.history-header {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.history-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--fg);
}

.history-date {
    font-size: 0.7rem;
    color: var(--muted);
}

.history-right-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.4rem;
}

.history-total {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--primary);
}

.history-actions {
    display: flex;
    gap: 0.4rem;
}

.history-btn {
    background: none;
    border: none;
    color: var(--muted);
    padding: 0.25rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-btn:hover {
    color: var(--fg);
}

.history-btn.view {
    color: var(--primary);
}

.history-btn.delete:hover {
    color: var(--error);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
    font-size: 0.9rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: white;
    color: #1f2937;
    padding: 1rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideIn 0.3s ease-out;
    border-left: 4px solid var(--primary);
}

.toast.error {
    border-left-color: var(--error);
}

@keyframes slideIn {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Recipe Cards */
.recipe-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: all 0.3s ease;
}

.recipe-card-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.recipe-card-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.recipe-expand-icon {
    transition: transform 0.3s ease;
}

.recipe-card.collapsed .recipe-expand-icon {
    transform: rotate(-90deg);
}

.recipe-card.collapsed .recipe-card-body {
    display: none;
}

.recipe-card-body {
    padding: 0 1rem 1rem 1rem;
}

.recipe-ingredients-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.recipe-ingredient {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 0.5rem;
    font-size: 0.85rem;
}

.recipe-ingredient.added {
    background: rgba(16, 185, 129, 0.05);
    border: 1px solid var(--primary);
}

/* AI Report Styles */
.ai-report-body h3 {
    color: #6366f1;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.ai-report-body strong {
    color: var(--fg);
}

.ai-report-body br + br {
    display: block;
    margin-top: 0.5rem;
    content: "";
}

/* Botón Crear Flotante en Nav */
.create-btn-nav {
    width: 56px;
    height: 56px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: -30px;
    z-index: 101;
    border: 4px solid var(--bg);
}

.create-btn-nav:hover {
    background-color: var(--primary-dark);
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.create-btn-nav:active {
    transform: scale(0.95);
}
