:root {
    --bg: #F5F5F5;
    --card-bg: #FFFFFF;
    --border: rgba(0, 0, 0, 0.1);
    --text: #333333;
    --text-dim: #666666;
    --color-e: #468499;
    --color-p: #ff00b3;
    --color-ok: #32CD32;
    --color-alert: #FF4500;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

header {
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid var(--border);
    padding: 0 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
    flex-shrink: 0; /* Que el header no se aplaste */
    z-index: 10;
}

h1 {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}
h1 span { color: var(--color-ok); }

/* CONTENEDOR PRINCIPAL: La magia del grid */
main {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    /* Grid responsivo real: columnas de mínimo 130px, máximo lo que de */
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    /* Las filas se adaptan al contenido más alto */
    grid-auto-rows: min-content;
    gap: 10px;
    align-content: start;
    padding-bottom: 80px; /* Espacio extra abajo para que no se corte el scroll */
}

/* TARJETA INDESTRUCTIBLE */
.flavor-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Texto arriba, botones pegados abajo */
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    height: 100%; /* Ocupa toda la altura de la celda del grid */
    min-height: 90px; /* Altura mínima decente */
    position: relative; /* For loading overlay */
}

/* NOMBRE DEL SABOR */
.flavor-name {
    padding: 10px 8px;
    font-weight: 600;
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.3;
    color: var(--text);

    /* Esto hace que el texto ocupe todo el espacio disponible */
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Romper palabras largas si es necesario */
    word-break: break-word;
    hyphens: auto;
}

/* BOTONERA: ZONA SAGRADA */
.indicators {
    display: flex;
    /* Altura fija y flex-shrink 0 para que NADA la aplaste */
    height: 44px;
    min-height: 44px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: #FAFAFA;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    overflow: hidden; /* Solo para redondear bordes internos */
}

.indicator {
    flex: 1;
    border: none;
    background: transparent;
    color: #CCC;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    padding: 0;
    transition: background 0.1s;
    /* Centrado perfecto */
    display: flex;
    align-items: center;
    justify-content: center;
}

.indicator:first-child { border-right: 1px solid var(--border); }

.indicator:active { background: #EEE; }

/* ESTADOS ACTIVOS - Colores fuertes para ciegos */
.indicator.active-e {
    color: #FFF;
    background: var(--color-e);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.indicator.active-p {
    color: #FFF; /* Blanco sobre magenta se lee mejor */
    background: var(--color-p);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* SEPARADORES Y TÍTULOS */
.separator {
    grid-column: 1 / -1; /* Ocupa todo el ancho */
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--text);
    margin: 20px 0 5px 0;
    padding-bottom: 5px;
    border-bottom: 2px solid rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.sub-separator {
    grid-column: 1 / -1;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-alert);
    background: rgba(255, 69, 0, 0.08);
    padding: 6px 10px;
    border-radius: 6px;
    margin-top: 15px;
    letter-spacing: 0.5px;
}

.setup-item {
    padding: 15px 10px;
    background: #FFF;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-dim);
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
    position: relative; /* For loading overlay/state */
}

.setup-item.selected {
    border-color: var(--color-ok);
    background: #F0FFF0;
    color: #006400;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px var(--color-ok);
}

/* FOOTER */
footer {
    padding: 10px;
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-dim);
    background: #FFF;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* CONTROLES IOS STYLE */
.segmented-control {
    display: flex;
    background: #E5E5E5;
    border-radius: 8px;
    padding: 2px;
    position: relative;
    height: 32px;
    width: 160px; /* Ancho fijo para que no baile */
}

.segmented-control input { display: none; }

.segment {
    flex: 1;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 28px;
    z-index: 2;
    cursor: pointer;
    color: #666;
    transition: color 0.2s;
}

.slider {
    position: absolute;
    top: 2px; left: 2px; bottom: 2px;
    width: calc(50% - 2px);
    background: #FFF;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    transition: transform 0.2s ease;
    z-index: 1;
}

#viewMain:checked ~ .slider { transform: translateX(0); }
#viewConfig:checked ~ .slider { transform: translateX(100%); }
#viewMain:checked + label { color: #000; }
#viewConfig:checked + label { color: #000; }

/* HELP BUTTON & MODAL */
#helpBtn {
    position: fixed; bottom: 60px; right: 20px;
    width: 40px; height: 40px;
    border-radius: 50%; background: #FFF; border: 1px solid #DDD;
    font-weight: bold; box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    z-index: 100; cursor: pointer;
}

#overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 1999; backdrop-filter: blur(2px);
}

/* NEW MODERN HELP MODAL */
#helpModal.modern-modal, #notesModal.modern-modal, #helpModalClassic.modern-modal, #helpModalManual.modern-modal {
    display: none; /* Toggled via JS */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 420px;
    max-height: 85vh;
    background: #FFF;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    z-index: 2000;
    overflow: hidden;
    flex-direction: column;
    animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translate(-50%, -40%); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #EEE;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #FAFAFA;
    flex-shrink: 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text);
}

.btn-close-modal {
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    color: #999;
    cursor: pointer;
    padding: 0 5px;
    transition: color 0.2s;
}
.btn-close-modal:hover { color: #333; }

.modal-scroll-content {
    padding: 20px;
    overflow-y: auto;
    /* max-height handled by flex parent constraints usually, but fixed here for safety */
    max-height: calc(85vh - 60px);
}

.help-section { margin-bottom: 25px; }

.help-section h4 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: var(--color-e);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #F0F0F0;
    display: inline-block;
    padding-bottom: 3px;
}

.help-section p {
    font-size: 0.9rem;
    color: #555;
    line-height: 1.5;
    margin-bottom: 10px;
}

.help-list {
    padding-left: 20px;
    font-size: 0.85rem;
    color: #666;
    line-height: 1.6;
    margin: 0;
}
.help-list li { margin-bottom: 5px; }

.modal-divider {
    border: 0;
    border-top: 1px solid #F0F0F0;
    margin: 20px 0;
}

/* --- GRAPHICS & MINI UI --- */

/* Segmented Control Demo */
.graphic-container {
    display: flex;
    justify-content: center;
    margin: 15px 0;
    padding: 10px;
    background: #F9F9F9;
    border-radius: 8px;
}
.mini-ui-segment {
    display: flex;
    background: #E5E5E5;
    border-radius: 6px;
    padding: 2px;
    width: 140px;
    height: 28px;
}
.mini-seg {
    flex: 1;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
}
.mini-seg.active {
    background: #FFF;
    border-radius: 4px;
    color: #000;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Stock Card Demo */
.graphic-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin: 15px 0;
    flex-wrap: wrap;
}

.mini-card-demo {
    width: 100px;
    background: #FFF;
    border: 1px solid #DDD;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.mini-card-header {
    font-size: 0.7rem;
    font-weight: bold;
    text-align: center;
    padding: 8px 0;
    color: #333;
}
.mini-card-body {
    display: flex;
    height: 25px;
    border-top: 1px solid #EEE;
}
.mini-ind {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 800;
    color: #FFF;
}
.mini-ind.active-e { background: var(--color-e); }
.mini-ind.active-p { background: var(--color-p); }

.graphic-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.8rem;
}
.legend-item { display: flex; align-items: center; gap: 6px; color: #555; }
.badge {
    padding: 2px 6px;
    border-radius: 4px;
    color: #FFF;
    font-weight: bold;
    font-size: 0.7rem;
}
.badge-e { background: var(--color-e); }
.badge-p { background: var(--color-p); }

.help-note {
    font-size: 0.8rem !important;
    font-style: italic;
    color: #999 !important;
    text-align: center;
    margin-top: -5px;
}

/* Gestures & Interaction */
.interaction-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 15px;
}
.interaction-card {
    background: #F8F9FA;
    padding: 15px 10px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #EEE;
}
.interaction-card h5 {
    margin: 10px 0 5px;
    font-size: 0.85rem;
    color: #333;
}
.interaction-card p {
    font-size: 0.75rem !important;
    margin: 0;
    color: #777;
    line-height: 1.3;
}

.gesture-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto;
    position: relative;
    background: #EEE;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Finger Icon */
.finger {
    width: 14px;
    height: 20px;
    background: #666;
    border-radius: 10px 10px 4px 4px;
    position: relative;
    z-index: 2;
    transform: rotate(-10deg) translateY(4px);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.finger::after {
    content: '';
    position: absolute;
    top: 2px; left: 3px;
    width: 8px; height: 5px;
    background: rgba(255,255,255,0.4);
    border-radius: 4px;
}

/* Tap Animation */
.tap-ring {
    position: absolute;
    width: 24px; height: 24px;
    border: 2px solid var(--color-ok);
    border-radius: 50%;
    opacity: 0;
    animation: ripple 2s infinite;
}
@keyframes ripple {
    0% { transform: scale(0.5); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0; }
    100% { opacity: 0; }
}

/* Hold Animation */
.hold-ring {
    position: absolute;
    width: 30px; height: 30px;
    border: 3px solid var(--color-alert);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

.mini-menu-float {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    background: #FFF;
    border: 1px solid #CCC;
    padding: 2px 4px;
    border-radius: 4px;
    display: flex; gap: 2px;
    font-size: 0.5rem;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 5;
    animation: floatUp 1.5s infinite alternate ease-in-out;
}
@keyframes floatUp {
    from { transform: translateX(-50%) translateY(0); }
    to { transform: translateX(-50%) translateY(-4px); }
}

.help-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.75rem;
    color: #AAA;
    border-top: 1px solid #F5F5F5;
    padding-top: 15px;
}

@media (max-width: 360px) {
    .interaction-grid { grid-template-columns: 1fr; }
}

/* MEDIA QUERIES PARA CELULARES CHICOS */
@media (max-width: 380px) {
    main { grid-template-columns: repeat(2, 1fr); } /* Forzar 2 columnas */
    h1 span { display: none; } /* Ocultar el _ito si no entra */
    .flavor-name { font-size: 0.8rem; }
}

/* TOAST SYSTEM */
#toastContainer {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
    width: 100%;
    max-width: 400px;
    padding: 0 20px;
}

.toast {
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 12px 20px;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error { background: #ff4757; }
.toast.success { background: #2ed573; }
.toast.info { background: #1e90ff; }

/* ACCESSIBILITY & UX IMPROVEMENTS */
button:focus-visible, .setup-item:focus-visible, input:focus-visible {
    outline: 3px solid var(--text);
    outline-offset: 2px;
}

/* Patterns for Color Blindness */
.indicator.active-e {
    background-image: repeating-linear-gradient(45deg, transparent, transparent 5px, rgba(255,255,255,0.1) 5px, rgba(255,255,255,0.1) 10px);
}
.indicator.active-p {
    background-image: radial-gradient(circle, rgba(255,255,255,0.2) 2px, transparent 2.5px);
    background-size: 8px 8px;
}

/* Long Names Truncation */
.flavor-name {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-height: 4em;
}

/* Setup Item Disabled State */
.setup-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f9f9f9;
    color: #aaa;
    pointer-events: none; /* Prevent clicks */
}

/* Sort Button */
#btnSortMode {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    background: #FFF;
    transition: background 0.2s;
}
#btnSortMode.active {
    background: #EEE;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

/* MANUAL MODE STYLES */
.manual-container {
    display: flex;
    flex-direction: row;
    gap: 20px;
    overflow-x: auto;
    overflow-y: hidden;
    height: 100%;
    padding-bottom: 20px; /* Scrollbar space */
    align-items: flex-start; /* Top align */
}

.manual-vitrina, .manual-rest {
    display: grid;
    grid-template-rows: repeat(2, 1fr); /* 2 Flexible Rows */
    grid-auto-flow: column; /* Grow horizontally */
    gap: 10px;
    height: 100%;
    min-height: 320px; /* Min height for 2 rows */
}

/* Explicitly sizing columns for desktop consistency */
.manual-vitrina {
    grid-template-columns: repeat(12, 180px); /* Slightly wider cards */
}

.manual-rest {
    grid-auto-columns: 180px;
}

/* Enhanced Card Styling for Manual Mode */
.manual-vitrina .flavor-card, .manual-rest .flavor-card {
    justify-content: space-between;
}
.manual-vitrina .flavor-name, .manual-rest .flavor-name {
    font-size: 1.1rem;
    font-weight: 700;
    padding: 20px 10px; /* More padding */
}
.manual-vitrina .indicators, .manual-rest .indicators {
    height: 60px; /* Taller buttons */
}
.manual-vitrina .indicator, .manual-rest .indicator {
    font-size: 1.2rem;
}

.manual-divider {
    width: 4px;
    background: var(--border);
    border-radius: 2px;
    flex-shrink: 0;
    height: 90%;
    align-self: center;
}

.manual-slot {
    background: repeating-linear-gradient(45deg, #f9f9f9, #f9f9f9 10px, #eeeeee 10px, #eeeeee 20px);
    border: 2px dashed #ddd;
    border-radius: 12px;
    min-width: 130px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ccc;
    font-weight: bold;
    font-size: 1.5rem;
    cursor: pointer; /* Clickable */
}

/* Fix aspect ratio for mobile cards to prevent stretching */
@media (max-width: 768px) {
    .manual-vitrina .flavor-card, .manual-rest .flavor-card {
        min-height: 130px; /* Keep reasonable height */
    }
    /* Revert styling for mobile if needed, but taller buttons are good on mobile too */
    .manual-vitrina, .manual-rest {
        height: auto;
        min-height: auto;
    }
}

.flavor-card.pastel-red {
    background: #FFF0F5; /* Lavender Blush (Redish pastel) */
    border-color: #FFB6C1;
}
.flavor-card.pastel-red .flavor-name {
    color: #C71585; /* Darker text */
}

/* MOBILE LAYOUT */
@media (max-width: 768px) {
    .manual-container {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: visible; /* Let main scroll handle it */
        height: auto;
        gap: 30px;
    }

    .manual-vitrina, .manual-rest {
        display: grid;
        grid-template-rows: none; /* Reset */
        grid-template-columns: repeat(2, 1fr); /* 2 Columns */
        grid-auto-flow: row; /* Vertical flow */
        width: 100%;
        height: auto;
        direction: rtl; /* Invert columns: 1st Col (PC Top Row) becomes Right */
    }

    /* Reset text direction for cards inside RTL container */
    .manual-vitrina .flavor-card, .manual-rest .flavor-card {
        direction: ltr;
    }

    .manual-divider {
        width: 100%;
        height: 4px;
        margin: 10px 0;
    }
}

/* SELECT FLAVOR MODAL */
#modalFlavorSelect {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center; justify-content: center;
}
#modalFlavorSelect.show { display: flex; }
.modal-content {
    background: #FFF;
    width: 90%; max-width: 400px; max-height: 80vh;
    border-radius: 12px;
    display: flex; flex-direction: column;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
.modal-header {
    padding: 15px; border-bottom: 1px solid var(--border);
    font-weight: 800; display: flex; justify-content: space-between;
}
.modal-body {
    padding: 10px; overflow-y: auto;
}
.flavor-option {
    padding: 12px; border-bottom: 1px solid #eee;
    cursor: pointer; font-size: 0.95rem;
}
.flavor-option:active { background: #f0f0f0; }

.manual-hide { display: none !important; }

/* Selected Slot Highlight */
.selected-slot {
    border-color: var(--color-ok) !important;
    background-color: #F0FFF0 !important;
    box-shadow: 0 0 0 3px rgba(50, 205, 50, 0.4) !important;
    transform: scale(1.02);
    z-index: 50; /* Bring to front */
}

/* --- ADMIN PANEL --- */
.admin-panel {
    position: fixed;
    inset: 0;
    background: #F0F2F5;
    z-index: 2000;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
}

.admin-container {
    width: 100%;
    max-width: 1200px;
    background: transparent;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    background: #FFF;
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.admin-header h2 { margin: 0; font-size: 1.2rem; }

.btn-close {
    background: none; border: none; font-size: 2rem;
    cursor: pointer; line-height: 1; color: #666;
}

.admin-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

@media (max-width: 768px) {
    .admin-grid { grid-template-columns: 1fr; }
    .admin-panel { padding: 10px; }
}

.admin-card {
    background: #FFF;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.admin-card h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

/* FLAVOR MANAGEMENT */
.add-flavor-row {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.add-flavor-row input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.btn-primary {
    background: var(--color-ok);
    color: white;
    border: none;
    padding: 0 20px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
}

.flavor-list-scroll {
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 6px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th {
    text-align: left;
    padding: 10px;
    background: #f9f9f9;
    font-size: 0.8rem;
    color: #666;
    position: sticky; top: 0;
    background: #fff;
    z-index: 1;
    border-bottom: 2px solid #eee;
}

.admin-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
}

.edit-name-input {
    width: 100%;
    padding: 6px;
    border: 1px solid transparent;
    background: transparent;
    font-size: 0.9rem;
    border-radius: 4px;
}
.edit-name-input:focus {
    background: #fff;
    border-color: var(--color-ok);
    outline: none;
}

.action-buttons {
    display: flex;
    gap: 5px;
}

.btn-icon {
    border: none;
    background: #f0f0f0;
    width: 30px; height: 30px;
    border-radius: 4px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.btn-icon:hover { background: #e0e0e0; }
.btn-icon.delete:hover { background: #ffebee; color: red; }
.btn-icon.save:hover { background: #e8f5e9; color: green; }

/* TOOLS */
.tools-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-tool {
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    text-align: left;
    color: #FFF;
    font-size: 0.9rem;
}

.btn-warning { background: #f39c12; }
.btn-danger { background: #e74c3c; }
.btn-info { background: #3498db; }

/* BACKUPS */
.small-text { font-size: 0.8rem; color: #999; margin-bottom: 10px; }
.admin-table.small { font-size: 0.85rem; }
.btn-small {
    padding: 4px 8px;
    font-size: 0.75rem;
    background: #eee;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

/* BACKUP DETAILS */
.backup-detail-row {
    background: #f8f9fa;
}
.backup-detail-content {
    padding: 10px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #eee;
}
.backup-nested-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-top: 5px;
}
.backup-nested-table thead {
    background: #eee;
}
.backup-nested-table th, .backup-nested-table td {
    padding: 6px;
    border-bottom: 1px solid #eee;
}
.backup-nested-table th {
    text-align: left;
    font-weight: 600;
}
.toggle-backup {
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 0.7rem;
    line-height: 1;
}

/* --- PUCHO COUNT BADGE --- */
.indicator {
    position: relative; /* Para posicionar el badge */
}

.pucho-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #FFF;
    color: var(--color-p);
    border: 1px solid var(--color-p);
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 0.7rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    z-index: 5;
    pointer-events: none; /* Que no interfiera con el click del botón */
}

/* --- PUCHO MENU (Long Press) --- */
#puchoMenu {
    display: none;
    position: fixed;
    background: #FFF;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1000;
    flex-direction: row;
    align-items: center;
    gap: 5px;
}
#puchoMenu.show { display: flex; animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.pucho-menu-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #EEE;
    border-radius: 6px;
    background: #F9F9F9;
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.pucho-menu-btn:active { background: #EEE; }

.pucho-menu-val {
    font-weight: bold;
    font-size: 1.1rem;
    width: 30px;
    text-align: center;
}

/* --- LOADING OVERLAY --- */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    z-index: 20;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--color-ok);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Setup item loading */
.setup-item.is-updating {
    opacity: 0.6;
    pointer-events: none;
}
.setup-item.is-updating::after {
    content: '';
    position: absolute;
    top: 50%; right: 10px;
    transform: translateY(-50%);
    width: 12px; height: 12px;
    border: 2px solid #ccc;
    border-top: 2px solid var(--color-ok);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* --- NOTES FEATURE --- */

/* Note Button on Card */
.note-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    color: #CCC;
    transition: all 0.2s;
    z-index: 5;
    filter: grayscale(100%);
}

.note-btn:hover {
    background: #F0F0F0;
    color: #999;
}

.note-btn.has-notes {
    color: #333;
    filter: none;
}

.note-btn.has-notes::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background: var(--color-alert);
    border-radius: 50%;
    border: 1px solid #FFF;
}

/* Notes List in Modal */
.notes-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding-bottom: 20px;
}

.note-item {
    background: #F9F9F9;
    border: 1px solid #EEE;
    border-radius: 8px;
    padding: 10px 12px;
    position: relative;
}

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

.note-meta {
    font-size: 0.75rem;
    color: #999;
    display: flex;
    gap: 8px;
}

.note-text {
    font-size: 0.95rem;
    color: #333;
    line-height: 1.4;
    white-space: pre-wrap; /* Respect line breaks */
    word-break: break-word;
}

.btn-delete-note {
    background: none;
    border: none;
    color: #CCC;
    cursor: pointer;
    padding: 4px;
    font-size: 1.2rem;
    line-height: 1;
}
.btn-delete-note:hover {
    color: #ff4757;
}

/* Notes Footer (Input) */
.notes-footer {
    position: sticky;
    bottom: 0;
    background: #FFF;
    padding: 15px 0 0 0;
    border-top: 1px solid #EEE;
    display: flex;
    gap: 10px;
    margin-top: auto;
}

.note-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #DDD;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
}
.note-input:focus {
    outline: none;
    border-color: var(--color-ok);
}

.empty-notes {
    text-align: center;
    color: #CCC;
    font-style: italic;
    padding: 20px;
}

/* FIX VISUAL BUG IN MANUAL MODE */

/* 1. Hide slider when Setup is hidden */
label[for="viewConfig"].manual-hide ~ .slider {
    display: none;
}

/* 2. Style Container when in Manual Mode (Setup hidden) */
/* We use the active state of the sibling button since we can't select parent based on child without :has */
#btnSortMode.active ~ .segmented-control {
    background: transparent;
}

/* 3. Style 'Vitrina' Label in Manual Mode */
#btnSortMode.active ~ .segmented-control label[for="viewMain"] {
    width: 100%;
    background: #FFF;
    border: 1px solid rgba(0,0,0,0.1); /* var(--border) */
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    color: #000;
}

/* GALAXY WATCH / SMALL WEARABLES (< 360px, or larger 1:1 watches like Galaxy Watch 6) */
@media (max-width: 360px), (max-width: 500px) and (max-height: 500px) {
    /* 1. Layout: Single Column & Rotary Scroll Support */
    main {
        grid-template-columns: 1fr; /* Force 1 column */
        padding: 40px 10px; /* Safe zone padding top/bottom */
        scroll-snap-type: y mandatory; /* Rotary friendly */
        gap: 15px;
    }

    .flavor-card {
        scroll-snap-align: center; /* Snap each card to center */
        min-height: 110px; /* Slightly taller for better touch targets */
        margin-bottom: 5px; /* Visual separation */
    }

    /* 2. Header Optimization */
    header {
        height: 50px; /* Compress header */
        padding: 0 8px;
        justify-content: center; /* Center content */
    }

    h1 {
        display: none; /* Hide title to save space */
    }

    /* 3. Segmented Control Compact Mode */
    .segmented-control {
        width: 120px; /* Smaller width */
        height: 28px;
    }
    .segment {
        font-size: 0.65rem;
        line-height: 24px;
    }

    /* 4. Button Adjustments */
    #btnSortMode {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
    #btnLogout {
        font-size: 1rem;
    }

    /* 5. Typography & Touch Targets */
    .flavor-name {
        font-size: 1rem; /* Larger text for readability */
        padding: 15px 10px;
    }

    .indicators {
        height: 50px; /* Taller buttons for fat fingers */
    }
    .indicator {
        font-size: 1.1rem;
    }

    /* 6. Manual Mode Fixes */
    .manual-container {
        flex-direction: column;
        height: auto;
        overflow-y: visible;
    }

    .manual-vitrina, .manual-rest {
        grid-template-columns: 1fr;
        grid-auto-flow: row;
        direction: ltr; /* Reset direction */
        width: 100%;
        height: auto;
    }

    .manual-vitrina .flavor-card, .manual-rest .flavor-card {
        min-height: 110px;
    }

    .manual-divider {
        display: none; /* Hide divider line */
    }

    /* 7. Hide non-essential UI */
    #helpBtn {
        bottom: 10px;
        right: 10px;
        width: 30px;
        height: 30px;
        font-size: 0.8rem;
    }

    /* Toast higher up */
    #toastContainer {
        bottom: 50px;
    }
}

/* --- PREMIUM HELP MODAL --- */

.premium-modal {
    display: none; /* Toggled via JS */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 420px;
    z-index: 2000;
    animation: modalSlideUp 0.3s ease-out;

    background: #FFF;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
    flex-direction: column;
    max-height: 90vh;
}

.premium-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 20px 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.premium-header h3 {
    font-size: 1.4rem;
    font-weight: 800;
    margin: 0;
    background: linear-gradient(90deg, #333, #666);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.premium-content {
    padding: 25px;
    overflow-y: auto;
    background: #FFF;
}

/* Hero Section */
.hero-section {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 16px;
    position: relative;
    overflow: hidden;
}

.hero-icon {
    font-size: 3rem;
    margin-bottom: 10px;
    display: inline-block;
    animation: bounceIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.hero-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 5px;
}

.hero-desc {
    font-size: 0.9rem;
    color: #666;
    line-height: 1.5;
}

/* Feature Blocks */
.feature-block {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: 25px;
    opacity: 0;
    animation: fadeInUp 0.5s forwards;
}

.feature-block:nth-child(1) { animation-delay: 0.1s; }
.feature-block:nth-child(2) { animation-delay: 0.2s; }
.feature-block:nth-child(3) { animation-delay: 0.3s; }
.feature-block:nth-child(4) { animation-delay: 0.4s; }

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

.feature-icon {
    width: 40px;
    height: 40px;
    background: #f1f3f5;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    color: var(--color-ok);
}

.feature-text h4 {
    margin: 0 0 5px 0;
    font-size: 1rem;
    font-weight: 700;
    color: #333;
}

.feature-text p {
    margin: 0;
    font-size: 0.9rem;
    color: #666;
    line-height: 1.5;
}

/* Demo Area */
.demo-area {
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    margin-top: 15px;
}

.demo-btn {
    background: #FFF;
    border: 1px solid #ddd;
    border-radius: 50px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none; /* iOS Safari */
    -webkit-touch-callout: none; /* iOS Safari */
}

.demo-btn:active {
    transform: scale(0.95);
    background: #f1f3f5;
}

.demo-btn.success {
    background: var(--color-ok);
    color: #FFF;
    border-color: var(--color-ok);
    animation: pulseSuccess 0.5s;
}

@keyframes pulseSuccess {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Visual Indicators for Features */
.stock-visual {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.stock-pill {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stock-pill.e { background: rgba(70, 132, 153, 0.15); color: var(--color-e); }
.stock-pill.p { background: rgba(255, 0, 179, 0.15); color: var(--color-p); }
.stock-pill.low { background: rgba(255, 69, 0, 0.15); color: var(--color-alert); }

/* Progress Ring Animation for Long Press */
.progress-ring {
    position: absolute;
    top: -2px; left: -2px; right: -2px; bottom: -2px;
    border-radius: 50px;
    border: 2px solid transparent;
}

.demo-btn.pressing .progress-ring {
    border-color: var(--color-ok);
    clip-path: inset(0 100% 0 0); /* Start hidden */
    animation: fillRing 0.8s linear forwards; /* Match JS timeout */
}
/* Note: CSS-only circular progress on a pill button is tricky.
   Let's simplify: A background fill or a pseudo-element expanding. */

.demo-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(50, 205, 50, 0.2);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.8s linear;
}

.demo-btn.pressing::before {
    transform: scaleX(1);
}

.demo-hint {
    font-size: 0.8rem;
    color: #999;
    margin-top: 10px;
    font-style: italic;
}

/* Floating Elements Animation */
.float { animation: floating 3s ease-in-out infinite; }
@keyframes floating {
    0% { transform: translate(0, 0px); }
    50% { transform: translate(0, -8px); }
    100% { transform: translate(0, 0px); }
}
