* { margin:0; padding:0; box-sizing:border-box; }
body { font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif; background:#f5f5f5; color:#333; line-height:1.6; }
header { background:#2c3e50; color:#fff; padding:1rem; display:flex; justify-content:space-between; align-items:center; }
header h1 { margin:0; font-size:1.5rem; }
nav a { color:#ecf0f1; margin:0 0.5rem; text-decoration:none; font-weight:500; }
nav a:hover, nav a.active, nav a.on { text-decoration:underline; font-weight:700; }
.container { max-width:720px; margin:2rem auto; padding:0 1rem; }
h2 { color:#2c3e50; margin-bottom:1rem; }
.card { background:#fff; border-radius:8px; box-shadow:0 2px 4px rgba(0,0,0,0.1); padding:1.5rem; margin-bottom:1.5rem; }
.auth-container { min-height:100vh; display:flex; align-items:center; justify-content:center; background:#ecf0f1; }
.auth-card { background:#fff; padding:2rem; border-radius:8px; box-shadow:0 4px 6px rgba(0,0,0,0.1); width:100%; max-width:400px; }
.auth-form { display:grid; gap:1rem; margin-top:1.5rem; }
.form-group { margin-bottom:0; }
.form-group label { display:block; margin-bottom:0.3rem; font-weight:500; }
.form-group input { width:100%; padding:1rem; border:1px solid #ddd; border-radius:4px; font-size:1.25rem; }
.btn { width:100%; padding:0.75rem; background:#3498db; color:#fff; border:none; border-radius:4px; font-size:1rem; cursor:pointer; }
.btn:hover { background:#2980b9; }
.btn-secondary { background:#95a5a6; }
.btn-secondary:hover { background:#7f8c8d; }
.btn-block { width:100%; }
.btn-primary { background:#27ae60; }
.btn-primary:hover { background:#219a52; }
.btn-scan { background:#e74c3c; }
.btn-scan:hover { background:#c0392b; }
.alert { padding:1rem; border-radius:4px; margin-bottom:1rem; }
.alert-success { background:#d4edda; color:#155724; border:1px solid #c3e6cb; }
.alert-info { background:#d1ecf1; color:#0c5460; border:1px solid #bee5eb; }
.alert-error { background:#f8d7da; color:#721c24; border:1px solid #f5c6cb; }
.empty-state { text-align:center; color:#7f8c8d; padding:2rem; }
.stats-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(180px, 1fr)); gap:1rem; margin-bottom:1.5rem; }
.stat-card { background:#f8f9fa; padding:1rem; text-align:center; border-radius:6px; }
.stat-card h3 { margin:0 0 0.5rem 0; font-size:0.9rem; color:#7f8c8d; }
.stat-value { font-size:1.8rem; font-weight:bold; color:#2c3e50; }
.supermercato-card { border:1px solid #eee; }
.supermercato-banner { background:#3498db; color:#fff; padding:0.75rem 1rem; border-radius:6px; margin-bottom:1rem; font-size:0.9rem; display:flex; align-items:center; gap:0.5rem; }
.supermercato-banner a { color:#fff; text-decoration:underline; font-size:0.85rem; }
.cambia-sm { margin-left:1rem; font-size:0.8rem; color:#e8f5e9; }
.supermercato-fixed { background:#e8f5e9; color:#2e7d32; padding:0.75rem 1rem; border-radius:6px; font-size:0.95rem; display:flex; align-items:center; gap:0.5rem; border:1px solid #c5e1c5; }
.modal { position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.5); display:flex; align-items:center; justify-content:center; z-index:1000; }
.modal-content { background:#fff; padding:2rem; border-radius:8px; width:90%; max-width:500px; max-height:80vh; overflow-y:auto; }
.hidden { display:none; }
.semaforo-container { text-align:center; padding:2rem; }
.semaforo { display:inline-flex; align-items:center; gap:0.5rem; padding:1.5rem 2rem; border-radius:50px; font-weight:bold; font-size:1.1rem; }
.semaforo-verde { background:#d4edda; color:#155724; }
.semaforo-giallo { background:#fff3cd; color:#856404; }
.semaforo-rosso { background:#f8d7da; color:#721c24; }
.semaforo-icon { font-size:1.5rem; }
.semaforo-label { font-size:1rem; }
.price-details { margin-top:1rem; text-align:center; color:#555; }
.price-details p { margin:0.3rem 0; }

/* ===== Card di sintesi collassabile ===== */
.result-summary-card {
    background:#fff;
    border:1px solid #ddd;
    border-radius:8px;
    margin-bottom:1rem;
    overflow:hidden;
    box-shadow:0 2px 4px rgba(0,0,0,0.05);
}

.summary-header {
    padding:12px 16px;
    cursor:pointer;
    display:flex;
    justify-content:space-between;
    align-items:center;
    background:#f8f9fa;
    border-bottom:1px solid #e0e0e0;
    transition:background 0.2s;
}

.summary-header:hover {
    background:#e9ecef;
}

.summary-title {
    display:flex;
    align-items:center;
    gap:8px;
    flex-wrap:wrap;
}

.summary-product {
    font-weight:600;
    font-size:1.05rem;
    color:#2c3e50;
}

.summary-separator {
    color:#999;
    font-weight:300;
}

.summary-brand {
    color:#555;
    font-size:0.9rem;
}

.summary-status {
    display:flex;
    align-items:center;
    gap:6px;
    padding:4px 12px;
    border-radius:20px;
    font-size:0.85rem;
    font-weight:600;
}

.summary-status.verde {
    background:#d4edda;
    color:#155724;
}

.summary-status.giallo {
    background:#fff3cd;
    color:#856404;
}

.summary-status.rosso {
    background:#f8d7da;
    color:#721c24;
}

.status-icon {
    font-size:1rem;
}

.status-text {
    text-transform:capitalize;
}

.expand-icon {
    font-size:0.8rem;
    transition:transform 0.3s ease;
    margin-left:8px;
}

.result-summary-card.open .expand-icon {
    transform:rotate(180deg);
}

.summary-content {
    max-height:0;
    overflow:hidden;
    transition:max-height 0.3s ease;
}

.result-summary-card.open .summary-content {
    max-height:500px;
}

.summary-grid {
    display:grid;
    grid-template-columns:repeat(auto-fit, minmax(140px, 1fr));
    gap:8px 16px;
    padding:12px 16px;
}

.summary-item {
    display:flex;
    flex-direction:column;
    gap:2px;
}

.summary-label {
    font-size:0.75rem;
    color:#7f8c8d;
    text-transform:uppercase;
    letter-spacing:0.5px;
}

.summary-value {
    font-size:0.95rem;
    font-weight:500;
    color:#2c3e50;
}

.summary-value.up {
    color:#d32f2f;
}

.summary-value.down {
    color:#2e7d32;
}

/* ===== Sezioni collassabili ===== */
.section-header {
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding:10px 14px;
    cursor:pointer;
    background:#f8f9fa;
    border-bottom:1px solid #e0e0e0;
    border-radius:6px 6px 0 0;
    transition:background 0.2s;
}

.section-header:hover {
    background:#e9ecef;
}

.section-header .section-title {
    font-weight:600;
    font-size:0.95rem;
    color:#2c3e50;
}

.section-header .expand-icon {
    font-size:0.8rem;
    transition:transform 0.3s ease;
}

.section-header.open .expand-icon {
    transform:rotate(180deg);
}

.section-content {
    max-height:0;
    overflow:hidden;
    transition:max-height 0.3s ease;
}

.section-header.open + .section-content {
    max-height:800px;
}

/* ===== Dettagli/Summary nativi ===== */
.details-collapsible {
    border:1px solid #e0e0e0;
    border-radius:6px;
    margin:8px 0;
}

.summary-collapsible {
    cursor:pointer;
    padding:8px 12px;
    background:#f8f9fa;
    font-weight:600;
    color:#2c3e50;
    border-radius:6px 6px 0 0;
}

.collapsible-body {
    padding:12px;
}

/* ===== Stati colore ===== */
.status-green { color:#2e7d32; font-weight:600; }
.status-yellow { color:#f57c00; font-weight:600; }
.status-red { color:#d32f2f; font-weight:600; }

/* ========== FIELD PRODOTTO NUOVO MODERNO ========== */
.produto-nome-field {
    background: #f8f9fa;
    border: 2px solid #4caf50;
    border-radius: 12px;
    padding: 1rem;
    margin-top: 0.5rem;
    margin-bottom: 0.25rem;
    font-size: 1.125rem;
    font-weight: 500;
    color: #333;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.produto-nome-field--focus {
    box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.25);
    border-color: #43a047;
}
.produto-nome-field input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1.125rem;
    background: #fff;
    transition: border-color 0.2s ease;
}
.produto-nome-field input:focus {
    outline: none;
    border-color: #4caf50;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

/* ========== PULSANTE CONFERMA MODERNO ========== */
.btn-confirm {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    border: none;
    border-radius: 12px;
    padding: 0.875rem 1.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(39, 174, 96, 0.25), 0 2px 4px -1px rgba(39, 174, 96, 0.1);
    letter-spacing: 0.5px;
}
.btn-confirm:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 8px -2px rgba(39, 174, 96, 0.3), 0 4px 6px -2px rgba(39, 174, 96, 0.15);
    background: linear-gradient(135deg, #229954 0%, #27ae60 100%);
}
.btn-confirm:active {
    transform: translateY(0);
}
.btn-confirm:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ========== EVIDENZIAZIONE CONVENZIONE VERDE ========== */
/* Scansioni più convenienti nella cronologia */
.hist-row--conveniente {
    background: linear-gradient(90deg, #e8f5e9 0%, #f1f8e9 100%);
    border-left: 4px solid #4caf50;
    border-radius: 0 8px 8px 0;
    padding: 0.75rem 1rem;
    transition: all 0.2s ease;
}
.hist-row--conveniente:hover {
    background: linear-gradient(90deg, #d4edda 0%, #e8f5e9 100%);
}
.hist-row--conveniente .hist-price {
    color: #2e7d32;
    font-weight: 600;
}
.hist-row--conveniente .hist-market {
    color: #1b5e20;
}

/* Badge conveniente */
.badge-conveniente {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: #4caf50;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 12px;
    margin-top: 0.25rem;
}

/* Colonna prezzo + badge */
.hist-price-column {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

/* Prezzo verde solo per scansioni convenienti */
.hist-price-conveniente {
    color: #2e7d32;
    font-weight: 600;
}

/* Badge conveniente */
.badge-conveniente {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: #4caf50;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 12px;
    margin-top: 0.25rem;
}

/* ========== CONTAINER CRONOLOGIA SCORREVOLLE ========== */
.history-container {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 0.5rem;
}
.history-container::-webkit-scrollbar {
    width: 6px;
}
.history-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}
.history-container::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}
.history-container::-webkit-scrollbar-thumb:hover {
    background: #90a4ae;
}

@media (max-width:480px) {
    .container { margin:1rem auto; padding:0 0.5rem; }
    .card { padding:1rem; }
    header { flex-direction:column; gap:1rem; text-align:center; }
    nav { margin-top:0.5rem; }
    .btn-confirm { padding: 0.75rem 1rem; font-size: 1rem; }
}
/* Popup errore con tasto di conferma */
.errore-popup {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.errore-popup-box {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem 1rem;
    max-width: 90vw;
    width: 320px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    animation: popup-in 0.2s ease-out;
}
@keyframes popup-in {
    from { opacity:0; transform: translateY(-8px); }
    to   { opacity:1; transform: translateY(0); }
}
.errore-popup-icona {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}
.errore-popup-titolo {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    color: #c0392b;
}
.errore-popup-messaggio {
    margin: 0 0 1rem 0;
    color: #333;
    font-size: 0.95rem;
}
