/* ================================================================ */
/* VARIABILI                                                          */
/* ================================================================ */
:root {
    --primary: #1e3a8a;
    --accent: #3b82f6;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
}

body {
    font-family: 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    margin: 0;
    padding: 15px;
    color: var(--text);
}
.container { max-width: 1000px; margin: auto; }

/* ================================================================ */
/* LOGIN                                                              */
/* ================================================================ */
.login-screen {
    min-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: white;
    padding: 35px 30px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(30, 58, 138, 0.15);
    width: 100%;
    max-width: 400px;
    text-align: center;
}
.login-logo {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    width: 70px; height: 70px;
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 0 8px 20px rgba(30, 58, 138, 0.3);
}
.login-card h1 { color: var(--primary); margin: 0 0 5px; font-size: 1.6rem; letter-spacing: -0.5px; }
.login-subtitle { color: var(--muted); font-size: 0.9rem; margin: 0 0 25px; }
.login-body { text-align: left; }
.login-body label { font-size: 0.8rem; font-weight: 700; color: #475569; margin-bottom: 6px; display: block; }
.login-input {
    width: 100%; padding: 12px;
    border: 1.5px solid var(--border); border-radius: 10px;
    font-size: 1rem; box-sizing: border-box; margin-bottom: 15px; background: white;
}
.login-divider {
    display: flex; align-items: center; gap: 10px;
    margin: 18px 0; color: var(--muted); font-size: 0.8rem;
}
.login-divider::before, .login-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
}
.hint-box {
    background: #eff6ff;
    color: #1e40af;
    font-size: 0.78rem;
    padding: 10px 12px;
    border-radius: 8px;
    margin: 0 0 15px;
    line-height: 1.45;
}
.hint-box strong {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    background: white;
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid #dbeafe;
}

/* ---------------- Profili recenti ---------------- */
.recent-users { margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--border); }
.recent-label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 10px;
}
.recent-list { display: flex; flex-wrap: wrap; gap: 6px; }
.recent-chip {
    display: inline-flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 30px;
    overflow: hidden;
    transition: border-color 0.15s;
}
.recent-chip:hover { border-color: var(--accent); }
.recent-chip-btn {
    background: none; border: none; cursor: pointer;
    padding: 7px 4px 7px 14px;
    font-weight: 600; font-size: 0.85rem; color: var(--primary);
    font-family: inherit;
}
.recent-chip-x {
    background: none; border: none; cursor: pointer;
    padding: 7px 10px 7px 4px;
    color: var(--muted); display: flex; align-items: center;
}
.recent-chip-x:hover { color: var(--danger); }

/* ================================================================ */
/* HEADER                                                             */
/* ================================================================ */
.brand-header {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white; padding: 25px; border-radius: 15px;
    box-shadow: 0 10px 20px rgba(30, 58, 138, 0.2);
    margin-bottom: 20px;
    display: flex; align-items: center; gap: 20px;
}
.brand-logo { background: rgba(255,255,255,0.2); padding: 12px; border-radius: 12px; display: flex; }
.brand-info { flex: 1; }
.brand-info h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.5px; }
.brand-info p { margin: 5px 0 0; font-size: 0.85rem; opacity: 0.9; }
.user-badge {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.15);
    padding: 8px 12px; border-radius: 30px;
    font-size: 0.85rem; font-weight: 600;
}
.btn-logout {
    background: rgba(255,255,255,0.2); border: none; color: white;
    width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.3); }

/* ================================================================ */
/* TABS                                                               */
/* ================================================================ */
.view-tabs {
    display: flex; gap: 8px; background: white;
    padding: 6px; border-radius: 12px; margin-bottom: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.tab-btn {
    flex: 1; background: transparent; border: none;
    padding: 10px; border-radius: 8px; font-weight: 600;
    color: var(--muted); cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: all 0.2s; font-size: 0.85rem; font-family: inherit;
}
.tab-btn.active { background: var(--primary); color: white; }

/* ================================================================ */
/* TOOLBAR                                                            */
/* ================================================================ */
.toolbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 15px; }
.btn {
    cursor: pointer; border: none; border-radius: 10px; padding: 12px;
    font-weight: 600; font-size: 0.9rem; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 8px; font-family: inherit;
}
.btn:hover { transform: translateY(-1px); }
.btn-file { background: white; color: var(--primary); border: 1px solid var(--border); }
.btn-print { background: var(--primary); color: white; grid-column: span 3; }
.btn-primary { background: var(--primary); color: white; width: 100%; }
.btn-secondary { background: white; color: var(--primary); border: 1.5px solid var(--border); width: 100%; margin-top: 8px; }
.btn-add { background: var(--success); color: white; flex: 1; }
.btn-danger { background: var(--danger); color: white; flex: 1; }
.btn-small { padding: 8px 12px; font-size: 0.8rem; }

.autosave-status {
    background: #dcfce7; color: #166534;
    padding: 8px 12px; border-radius: 8px;
    font-size: 0.8rem; font-weight: 600; margin-bottom: 15px; text-align: center;
}
.autosave-status.warning { background: #fef3c7; color: #92400e; }

/* ---------------- Banner fonte dati ---------------- */
.source-banner {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: 10px;
    font-size: 0.85rem; font-weight: 600;
    margin-bottom: 15px;
}
.source-banner.source-ok {
    background: #dcfce7; color: #166534;
}
.source-banner.source-warn {
    background: #fef3c7; color: #92400e;
}
.source-banner strong { font-weight: 800; }
.banner-btn {
    margin-left: auto;
    background: white;
    color: inherit;
    border: 1.5px solid currentColor;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    opacity: 0.75;
    transition: opacity 0.2s;
}
.banner-btn:hover { opacity: 1; }

/* ================================================================ */
/* STATISTICHE                                                        */
/* ================================================================ */
.report-summary {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 25px;
}
.stat-card {
    background: white; padding: 15px; border-radius: 12px;
    text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.stat-card span { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.stat-card div { font-size: 1.2rem; font-weight: 800; color: var(--primary); }

/* ================================================================ */
/* FORM                                                               */
/* ================================================================ */
.card {
    background: white; padding: 20px; border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); margin-bottom: 25px;
}
.form-title {
    font-weight: 700; color: var(--primary); font-size: 1rem;
    margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.form-title.editing { color: var(--warning); }
.grid-inputs { display: grid; grid-template-columns: 1fr; gap: 15px; }
label { font-size: 0.8rem; font-weight: 700; color: #475569; margin-bottom: 5px; display: block; }
input, select {
    width: 100%; padding: 12px;
    border: 1.5px solid var(--border); border-radius: 10px;
    font-size: 1rem; box-sizing: border-box; font-family: inherit;
}
.form-actions { display: flex; gap: 10px; margin-top: 15px; }

/* ================================================================ */
/* TABELLA                                                            */
/* ================================================================ */
.table-container {
    background: white; border-radius: 15px; overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); border: 1px solid var(--border);
}
table { width: 100%; border-collapse: collapse; }
thead th {
    background: var(--bg); color: var(--muted);
    font-size: 0.75rem; text-transform: uppercase;
    padding: 15px; text-align: left; font-weight: 700;
}
tbody td { padding: 15px; border-top: 1px solid #f1f5f9; font-size: 0.9rem; vertical-align: middle; }

.progress-container { width: 100px; }
.progress-bg { background: var(--border); height: 6px; border-radius: 10px; overflow: hidden; margin-top: 4px; }
.progress-fill { height: 100%; transition: width 0.3s; }

.status-pill {
    display: inline-flex; align-items: center;
    padding: 4px 8px; border-radius: 50px;
    font-size: 0.75rem; font-weight: 600; gap: 5px;
}
.pill-ottimale { background: #dcfce7; color: #166534; }
.pill-consumata { background: #fee2e2; color: #991b1b; }
.pill-deteriorata { background: #fef3c7; color: #92400e; }
.pill-sostituita { background: #dbeafe; color: #1e40af; }
.dot { height: 6px; width: 6px; border-radius: 50%; background: currentColor; }

.row-actions { display: flex; gap: 8px; }
.btn-row {
    background: none; border: none; cursor: pointer;
    padding: 5px 8px; border-radius: 6px;
    font-weight: 600; font-size: 0.85rem; font-family: inherit;
}
.btn-edit { color: var(--warning); }
.btn-edit:hover { background: #fef3c7; }
.btn-delete { color: var(--danger); }
.btn-delete:hover { background: #fee2e2; }

/* ================================================================ */
/* CALENDARIO                                                         */
/* ================================================================ */
.calendar-card {
    background: white; padding: 20px; border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); margin-bottom: 20px;
}
.calendar-header {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px;
}
.cal-title { font-weight: 700; color: var(--primary); font-size: 1.1rem; text-transform: capitalize; }
.cal-nav {
    background: var(--bg); border: 1px solid var(--border);
    width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--primary); transition: background 0.2s;
}
.cal-nav:hover { background: var(--border); }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 8px; }
.cal-weekdays div {
    text-align: center; font-size: 0.7rem; font-weight: 700;
    color: var(--muted); text-transform: uppercase; padding: 6px 0;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day {
    aspect-ratio: 1; background: var(--bg); border-radius: 10px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    position: relative; cursor: pointer; transition: all 0.2s;
    border: 1.5px solid transparent; padding: 4px; box-sizing: border-box;
}
.cal-day:hover:not(.empty) { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(30, 58, 138, 0.12); }
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.today { border-color: var(--accent); background: #dbeafe; }
.cal-day.has-events { background: linear-gradient(135deg, var(--primary), var(--accent)); color: white; font-weight: 700; }
.cal-day.selected { box-shadow: 0 0 0 3px var(--accent); }
.cal-daynum { font-size: 0.95rem; font-weight: 600; }
.cal-badge { font-size: 0.65rem; font-weight: 700; opacity: 0.9; margin-top: 2px; }

.day-detail {
    background: white; padding: 20px; border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.day-detail-header { display: flex; justify-content: space-between; align-items: center; }
.day-detail-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.day-detail-date { font-size: 1.2rem; font-weight: 700; color: var(--primary); text-transform: capitalize; }
.btn-close {
    background: var(--bg); border: 1px solid var(--border);
    width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; color: var(--muted);
}

/* ================================================================ */
/* MAPPA                                                              */
/* ================================================================ */
.map-empty {
    background: white; padding: 50px 25px; border-radius: 15px;
    text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border: 2px dashed var(--border);
}
.map-empty-icon {
    width: 80px; height: 80px; margin: 0 auto 15px;
    background: var(--bg); border-radius: 50%;
    display: flex; align-items: center; justify-content: center; color: var(--accent);
}
.map-empty h3 { color: var(--primary); margin: 0 0 8px; }
.map-empty p { color: var(--muted); font-size: 0.9rem; max-width: 380px; margin: 0 auto 20px; line-height: 1.5; }
.map-empty .btn-primary { max-width: 250px; margin: 0 auto; }

.map-toolbar {
    background: white; border-radius: 12px; padding: 10px;
    margin-bottom: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.map-mode-group { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; flex: 1; }
.mode-btn {
    flex: 1; background: transparent; border: none;
    padding: 8px 10px; border-radius: 7px;
    font-weight: 600; font-size: 0.8rem; color: var(--muted);
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px;
    transition: all 0.15s; font-family: inherit;
}
.mode-btn.active { background: var(--primary); color: white; box-shadow: 0 2px 6px rgba(30, 58, 138, 0.25); }

.map-hint {
    background: #dbeafe; color: #1e40af;
    padding: 10px 14px; border-radius: 10px;
    font-size: 0.85rem; font-weight: 600; margin-bottom: 12px; text-align: center;
}

.map-container {
    position: relative; background: white;
    border-radius: 15px; overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border: 1px solid var(--border);
    line-height: 0;
    margin-bottom: 15px;
    user-select: none;
    -webkit-user-select: none;
}
.map-container.mode-add { cursor: crosshair; }
.map-image { width: 100%; height: auto; display: block; }
.map-markers {
    position: absolute; inset: 0; pointer-events: none;
}
.map-markers > * { pointer-events: auto; }

.map-marker {
    position: absolute;
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.7rem;
    border: 3px solid white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    cursor: pointer;
    transform: translate(-50%, -50%);
    transition: transform 0.15s, box-shadow 0.15s;
    text-align: center; line-height: 1;
    touch-action: none;
}
.map-marker:hover { transform: translate(-50%, -50%) scale(1.15); box-shadow: 0 6px 14px rgba(0,0,0,0.4); }
.map-marker.ottimale   { background: var(--success); }
.map-marker.deteriorata { background: var(--warning); }
.map-marker.consumata  { background: var(--danger); }
.map-marker.sostituita { background: var(--accent); }
.map-marker.nessuno    { background: #94a3b8; }
.map-marker.dragging   { transform: translate(-50%, -50%) scale(1.25); box-shadow: 0 10px 20px rgba(0,0,0,0.4); z-index: 50; }

.map-container.mode-move .map-marker { cursor: grab; }
.map-container.mode-move .map-marker.dragging { cursor: grabbing; }

.map-legend {
    background: white; padding: 12px 15px; border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex; flex-wrap: wrap; gap: 14px;
    font-size: 0.8rem; color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid white; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }

/* ================================================================ */
/* MODAL                                                              */
/* ================================================================ */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 20px; animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
    background: white; border-radius: 16px; padding: 25px;
    max-width: 440px; width: 100%;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    max-height: 90vh; overflow-y: auto;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;
}
.modal-header h2 { margin: 0; color: var(--primary); font-size: 1.15rem; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; min-width: 100px; }
.modal-actions .btn-secondary { margin-top: 0; }

.field { margin-bottom: 12px; }
.field label { margin-bottom: 5px; }

.trap-info { background: var(--bg); padding: 12px; border-radius: 10px; margin-bottom: 12px; }
.trap-info-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 0.88rem; }
.trap-info-row span:first-child { color: var(--muted); font-weight: 600; }
.trap-info-row span:last-child { font-weight: 700; color: var(--text); }

.trap-history-title {
    font-size: 0.75rem; color: var(--muted);
    text-transform: uppercase; font-weight: 700; margin: 15px 0 8px;
}
.trap-history-item {
    background: var(--bg); padding: 10px 12px; border-radius: 8px;
    margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center;
    font-size: 0.85rem;
}
.trap-history-item .h-date { color: var(--muted); font-weight: 600; }
.trap-history-empty { color: var(--muted); font-size: 0.85rem; font-style: italic; text-align: center; padding: 15px; }

/* ================================================================ */
/* RESPONSIVE                                                         */
/* ================================================================ */
@media (max-width: 768px) {
    .brand-header { flex-wrap: wrap; }
    .user-badge { margin-left: auto; }
    .toolbar { grid-template-columns: 1fr 1fr; }
    .btn-print { grid-column: span 2; }
    .grid-inputs { grid-template-columns: 1fr; }

    thead { display: none; }
    tbody tr { display: block; padding: 15px; border-bottom: 8px solid #f1f5f9; }
    tbody td { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border: none; }
    tbody td::before { content: attr(data-label); font-weight: 700; color: var(--muted); }
    .progress-container { width: 140px; }

    .cal-day { font-size: 0.85rem; }
    .cal-daynum { font-size: 0.85rem; }

    .tab-btn { font-size: 0.75rem; padding: 8px 4px; }
    .map-marker { width: 30px; height: 30px; font-size: 0.65rem; }
    .map-mode-group { flex-wrap: wrap; }
}

@media print {
    .no-print { display: none !important; }
    body { padding: 0; }
    .brand-header { break-inside: avoid; }
    .map-container { break-inside: avoid; }
}
