/* =========================================
   1. GLOBAL & VARS (THEME: RUSTIC ELEGANCE)
   ========================================= */
:root { 
    /* PALETTE */
    --my-red: #731F2A;    /* Mattone */
    --my-green: #284730;  /* Verde Bosco */
    --my-beige: #D9C596;  /* Beige Dorato */
    --my-bg: #F2F2F2;     /* Grigio Perla */
    
    /* MAPPING */
    --primary: var(--my-red);
    --primary-hover: #5a1820; 
    --accent: var(--my-green);
    
    --background: var(--my-bg);
    --card-bg: #ffffff;
    --text-color: #333333;
    --muted-color: #666666;
    
    --card-radius: 16px;
    --shadow-soft: 0 4px 15px rgba(0, 0, 0, 0.08);
    --del-color: #b91c1c;
}

/* OVERRIDE PICO.CSS */
[data-theme="light"], :root {
    --primary: var(--my-red);
    --primary-hover: #5a1820;
    --primary-focus: rgba(115, 31, 42, 0.25);
    --background-color: var(--my-bg);
    --color: var(--text-color);
    --h1-color: var(--my-red); --h2-color: var(--my-red); --h3-color: var(--my-red);
    --h4-color: var(--my-red); --h5-color: var(--my-red); --h6-color: var(--my-red);
    --form-element-active-border-color: var(--my-green);
    --form-element-focus-color: var(--my-green);
}

body { 
    padding-top: 70px; 
    font-family: 'Segoe UI', system-ui, sans-serif; 
    background-color: var(--background);
    padding-bottom: 140px; 
}

/* INPUTS */
input, select, textarea { 
    background-color: white !important; 
    border: 1px solid #ccc !important; 
    color: #333 !important; 
    border-radius: 8px !important;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--my-green) !important;
    box-shadow: 0 0 0 2px rgba(40, 71, 48, 0.2) !important;
}

/* SEARCH INPUT */
.search-input {
    border-radius: 30px !important;
    padding: 10px 20px 10px 45px !important; 
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 15px center;
    background-size: 18px;
}

/* NAVIGAZIONE */
.main-nav {
    position: fixed; top: 0; left: 0; right: 0; height: 65px; 
    background-color: var(--background);
    border-bottom: 1px solid rgba(40, 71, 48, 0.1); 
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 15px; z-index: 9999; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.main-nav ul { margin: 0; padding: 0; list-style: none; display: flex; align-items: center; }
.main-nav a { color: var(--my-red); font-size: 1.4rem; transition: opacity 0.2s; }

.view-indicators li { 
    font-size: 0.95rem; margin: 0 5px; display: flex; align-items: center; gap: 6px; 
    cursor: pointer; color: var(--muted-color); font-weight: 600; 
    padding: 6px 12px; border-radius: 20px; transition: all 0.2s;
}
.view-indicators li.active { color: white; background-color: var(--my-red); }

/* BOTTONI & FAB */
button.btn-primary, .fab { 
    background-color: var(--my-beige) !important; 
    color: #2c2c2c !important; 
    border: none !important; font-weight: bold; 
}
.fab { 
    background-color: var(--my-red) !important; 
    color: white !important;
    position: fixed; bottom: 85px; 
    right: 25px; 
    width: 60px; height: 60px; border-radius: 50%; 
    font-size: 24px; display: flex; align-items: center; justify-content: center; 
    box-shadow: var(--shadow-soft); z-index: 90;
}
button.outline {
    border: 1px solid var(--my-red) !important;
    color: var(--my-red) !important;
    background: transparent !important;
}
button.btn-tiny { padding: 4px 10px; font-size: 0.8rem; width: auto; display: inline-block; margin: 0;}

/* =========================================
   2. DIARIO / PLANNER
   ========================================= */
.planner-carousel { display: flex; flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x mandatory; gap: 15px; padding: 10px 5px 20px 5px; scrollbar-width: none; align-items: flex-start; }
.planner-carousel::-webkit-scrollbar { display: none; }

.planner-card { 
    flex: 0 0 85vw; scroll-snap-align: center; 
    background: white; border-radius: var(--card-radius); 
    box-shadow: var(--shadow-soft); overflow: hidden; 
    opacity: 0.6; transform: scale(0.96); transition: all 0.3s;
    border: 1px solid transparent;
}
.planner-card.is-today { opacity: 1; transform: scale(1); border: 2px solid var(--my-red); }
.planner-header { 
    background: #f8f8f8; padding: 12px; text-align: center; 
    border-bottom: 1px solid #eee; color: var(--my-red);
}
.today-badge { background: var(--my-red); color: white; padding: 2px 8px; border-radius: 8px; font-size: 0.7em;}

.planner-body-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; padding: 15px; }
.meal-col { display: flex; flex-direction: column; gap: 10px; }
.meal-col small { text-align: center; color: var(--my-green); font-size: 0.75em; text-transform: uppercase; font-weight: bold; letter-spacing: 1px;}

.planned-item { 
    background: white; border: 1px solid #eee; border-left: 4px solid var(--my-beige); 
    padding: 10px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); font-weight: 600; font-size: 0.9rem;
    display:flex; justify-content:space-between; align-items: center; gap: 5px;
}
.btn-slot-empty { 
    width: 100%; height: 45px; 
    border: 2px dashed var(--my-green); opacity: 0.4;
    background: transparent; color: var(--my-green); 
    border-radius: 8px; display: flex; align-items: center; justify-content: center; 
    margin: 0; padding:0;
}

/* =========================================
   3. CATALOGO RICETTE
   ========================================= */
.horizontal-scroll { display: flex; gap: 15px; overflow-x: auto; padding-bottom: 20px; scrollbar-width: none; }
.horizontal-scroll::-webkit-scrollbar { display: none; }

.compact-card { 
    flex: 0 0 160px; background: white; border-radius: 12px; 
    overflow: hidden; box-shadow: var(--shadow-soft); position: relative;
    border-left: 5px solid var(--my-green);
}
.compact-body { padding: 12px; }
.compact-body strong { color: var(--my-red); font-size: 0.95rem; display: block; margin-bottom: 5px; line-height: 1.2;}
.pill-tag { background: #eee; color: #555; padding: 2px 6px; border-radius: 4px; font-size: 0.65em; margin-right: 4px; display:inline-block;}

/* =========================================
   4. SHOPPING LIST (FIX ALIGNMENT)
   ========================================= */
.add-shopping-row { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: nowrap; }
.add-shopping-row input { flex: 1; margin-bottom: 0 !important; }
.add-shopping-row button { flex: 0 0 auto; width: 50px; background: var(--my-beige); color: #222; border:none; border-radius:8px;}

.dept-header {
    color: var(--my-green); font-size: 0.85rem; font-weight: 800; text-transform: uppercase;
    margin: 20px 0 10px 0; letter-spacing: 1px; border-bottom: 1px solid #ddd; padding-bottom: 5px;
}
.shopping-item { 
    background: white; padding: 10px 15px; border-radius: 12px; margin-bottom: 8px; 
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid #f0f0f0;
}
.shopping-item.checked { opacity: 0.5; background: #fafafa; }
.shopping-item.checked span { text-decoration: line-through; }

.shopping-content { flex: 1; }
.shopping-content label { color: var(--text-color); font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 12px; margin-bottom:0}
.shopping-content input[type="checkbox"] { accent-color: var(--my-red); width: 20px; height: 20px; margin: 0; }
.shopping-details { margin: 2px 0 0 32px; font-size: 0.8rem; color: var(--muted-color); list-style: none; padding: 0; }

/* QUANTITY CONTROLS (FIXED) */
.qty-controls { 
    display: flex; 
    align-items: center; 
    justify-content: center;
    gap: 0; 
    margin-right: 12px; 
    background: #f0f0f0; 
    padding: 3px; 
    border-radius: 20px; 
    height: 32px; 
}

.qty-btn { 
    width: 26px; height: 26px; 
    border-radius: 50%; border: none; 
    background: white; color: var(--my-green); 
    font-weight: bold; font-size: 1.1rem; line-height: 1;
    display: flex; align-items: center; justify-content: center; 
    cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    margin: 0; padding: 0; 
}

.qty-display { 
    font-size: 0.9em; font-weight: bold; color: #333; 
    min-width: 24px; text-align: center;
    line-height: 1;
}

/* =========================================
   5. DETTAGLIO RICETTA
   ========================================= */
.swipe-card { 
    background: white; border-radius: var(--card-radius); 
    box-shadow: var(--shadow-soft); overflow: hidden; margin: 0; border: none; 
}
.method-header { 
    background: var(--my-red); color: white; padding: 15px; 
    border-radius: var(--card-radius) var(--card-radius) 0 0; 
}
.params-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    background: #fafafa; padding: 15px; border-radius: 8px;
    border: 1px solid #eee; margin-bottom: 20px;
}
.param-label { font-size: 0.7em; text-transform: uppercase; color: var(--my-green); font-weight: 800; letter-spacing: 1px; }
.param-value { font-size: 0.95rem; color: #333; font-weight: 600; }

.step-row { display: flex; gap: 15px; margin-bottom: 20px; align-items: flex-start; }
.step-num { 
    background: var(--my-green); color: white; 
    width: 28px; height: 28px; flex-shrink: 0; 
    border-radius: 50%; display: flex; align-items: center; justify-content: center; 
    font-size: 0.9em; font-weight: bold; margin-top: 2px;
}
.step-text { line-height: 1.6; color: #444; font-size: 1rem; flex:1; }

/* =========================================
   6. EDITOR STYLES
   ========================================= */
.edit-item-box {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 12px;
    background-color: #fcfcfc;
    display: flex;
    flex-wrap: wrap; 
    gap: 8px;
    align-items: center;
    position: relative;
}
.edit-item-box .input-qty { flex: 1 1 60px; min-width: 60px; }
.edit-item-box .input-unit { flex: 1 1 60px; min-width: 60px; }
.edit-item-box .input-name { flex: 10 1 150px; min-width: 150px; font-weight: 600; }
.edit-item-box textarea { width: 100%; margin: 5px 0 0 0 !important; }

/* TIMER INPUT NELL'EDITOR */
.input-timer { flex: 0 0 80px; text-align:center; font-weight:bold; color:var(--my-red); border-color:#fadbd8 !important; }

.btn-remove-item {
    color: white; background: var(--del-color);
    width: 30px; height: 30px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0; border: none;
}

/* =========================================
   7. CUSTOM MODAL & TABLES
   ========================================= */
.custom-modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px; animation: fadeIn 0.2s ease-out;
}
.custom-modal-box {
    background: white; width: 100%; max-width: 400px;
    border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    overflow: hidden; animation: slideUp 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
.modal-header {
    background: var(--my-red); color: white; padding: 15px 20px;
    font-weight: bold; font-size: 1.1rem;
}
.modal-body { padding: 20px; color: #444; }
.modal-footer {
    padding: 15px 20px; background: #f9fafb; display: flex; gap: 10px; justify-content: flex-end;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Stats Panel */
.stats-panel { 
    background: white !important; 
    padding: 20px; border-radius: var(--card-radius); margin-top: 20px; 
    box-shadow: var(--shadow-soft); color: #333;
}
.stats-panel h6 { color: var(--my-red) !important; margin-bottom: 15px; }
.stat-item { margin-bottom: 8px; }
.stat-label { display:flex; justify-content:space-between; font-size:0.85em; color: var(--my-green); font-weight:600;}
progress { background: #eee; height: 8px; border-radius: 4px; }
progress::-webkit-progress-value { background-color: var(--my-red); }

/* Menu a tendina */
details.dropdown { position: relative; display: inline-block; }
details.dropdown summary { list-style: none; cursor: pointer; outline: none; }
details.dropdown ul { 
    position: absolute; right: 0; top: 100%; margin-top: 5px; 
    background: white; border: 1px solid var(--my-green); border-radius: 8px; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.1); z-index: 100; min-width: 180px; 
    padding: 0; list-style: none; 
}
details.dropdown a { display: block; padding: 10px 15px; color: #333; }
details.dropdown[open] summary::before { content: " "; position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 80; cursor: default; }

.table-scroll { max-height: 350px; overflow-y: auto; display: block; font-size: 0.9rem;}
.table-scroll table { width: 100%; border-collapse: collapse; }
.table-scroll th { position: sticky; top: 0; background: #eee; z-index: 1; padding: 10px;}
.table-scroll td { padding: 8px; border-bottom: 1px solid #eee; text-align: left; vertical-align: middle;}
.dept-select { 
    width: 100%; min-width: 150px; 
    margin:0; padding: 5px 25px 5px 5px; 
    height: 35px; font-size: 0.85em; 
    text-overflow: ellipsis;
}

/* =========================================
   8. GLOBAL TIMER BAR (NO FLASH)
   ========================================= */
.global-timer-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: #2c3e50; color: white;
    padding: 12px 20px; z-index: 1000;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: 0 -4px 15px rgba(0,0,0,0.1);
    animation: slideUp 0.3s ease-out;
}
.timer-info { display: flex; flex-direction: column; }
.timer-label { font-size: 0.8rem; color: #aaa; }
.timer-countdown { font-size: 1.3rem; font-weight: bold; font-family: monospace; color: #e74c3c; }
.timer-controls { display: flex; gap: 10px; }
.btn-stop-timer { background: #c0392b !important; color: white !important; font-size: 0.9rem; padding: 8px 16px; border:none; border-radius:20px;}