/* 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: 100px;
    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);
}

.finish-container {
    margin-top: 2rem;
    padding: 1rem 0;
    display: flex;
    justify-content: center;
}

.btn-finish {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
    font-size: 1.1rem;
    border-radius: 1rem;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

/* 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;
}

.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;
}

.emoji-item {
    font-size: 1.5rem;
    padding: 0.5rem;
    cursor: pointer;
    text-align: center;
    border-radius: 0.25rem;
    transition: background 0.2s;
}

.emoji-item:hover {
    background: var(--border);
}

.emoji-item.selected {
    background: var(--primary);
    color: white;
}

#addCategoryInlineBtn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--primary);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

#addCategoryInlineBtn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.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 */
.history-card {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

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

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.history-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

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

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

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

.history-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.history-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--fg);
}

.history-btn:hover {
    background: var(--border);
}

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

.history-btn.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error);
}

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

.history-btn.view:hover {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--primary);
}

/* Modal de Confirmación Estilo Nativo */
.confirm-modal-content {
    text-align: center;
}

.confirm-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

.confirm-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.confirm-text {
    color: var(--muted);
    margin-bottom: 2rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: var(--card);
    color: var(--fg);
    padding: 0.75rem 1.25rem;
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    animation: toastIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55), toastOut 0.3s ease-in 2.7s forwards;
    border: 1px solid var(--border);
}

.toast i {
    font-size: 1.2rem;
}

.toast.success {
    border-left: 4px solid var(--primary);
}

.toast.success i {
    color: var(--primary);
}

.toast.error {
    border-left: 4px solid var(--error);
}

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

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

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

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

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

.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

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

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#loadingText {
    color: white;
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.create-btn-nav {
    width: 50px; height: 50px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    cursor: pointer;
    margin-top: -25px;
}

/* Emoji Picker Grid */
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-top: 0.5rem;
}

.emoji-item {
    font-size: 1.5rem;
    padding: 0.5rem;
    text-align: center;
    cursor: pointer;
    border-radius: 0.25rem;
}

.emoji-item:hover, .emoji-item.selected {
    background-color: var(--primary);
    color: white;
}

/* Sugerencias de Categorías */
.suggested-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.suggest-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 2rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.suggest-item:hover {
    border-color: var(--primary);
    background-color: rgba(16, 185, 129, 0.05);
}

.suggest-item i {
    font-size: 1rem;
    color: var(--primary);
}

.suggest-item.added {
    background-color: rgba(16, 185, 129, 0.1);
    border-color: var(--primary);
    cursor: default;
}

.suggest-item.added i {
    color: var(--primary);
}

.suggest-item.loading i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}


/* Estilos de Recetas */
.recipe-card {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1rem 1.5rem;
    margin-top: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
}

.recipe-card.collapsed {
    padding: 0.75rem 1.5rem;
}

.recipe-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.recipe-card-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--primary);
    flex: 1;
}

.recipe-card-body {
    margin-top: 1rem;
    max-height: 2000px;
    opacity: 1;
    transition: all 0.3s ease;
}

.recipe-card.collapsed .recipe-card-body {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    pointer-events: none;
}

.recipe-expand-icon {
    margin-left: 1rem;
    transition: transform 0.3s ease;
    color: var(--muted);
}

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

.recipe-card h3 {
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.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 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.recipe-ingredient.added {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--primary);
}

.recipe-ingredient.added span {
    color: var(--primary);
    font-weight: 600;
}

.recipe-ingredient .btn.small {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    transition: transform 0.2s;
}

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

.recipe-ingredient .btn:active {
    transform: scale(0.9);
}

