/* ===================================================
   BASE
   =================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Accent */
    --accent:       #22c55e;
    --accent-dim:   rgba(34, 197, 94, .12);
    --accent-hover: #16a34a;

    /* Backgrounds */
    --bg:    #0c0d10;
    --bg-2:  #111318;
    --bg-3:  #16181e;
    --bg-4:  #1c1f28;

    /* Borders */
    --border:   #252830;
    --border-2: #1c1f27;

    /* Text */
    --text:   #e8eaf0;
    --muted:  #8b90a8;
    --faint:  #454b63;

    /* Status */
    --blue:    #60a5fa;
    --red:     #f87171;
    --orange:  #fb923c;

    /* Geometry */
    --radius:    8px;
    --radius-lg: 12px;
    --shadow:    0 4px 20px rgba(0,0,0,.5);
    --shadow-lg: 0 8px 40px rgba(0,0,0,.7);
}

html { color-scheme: dark; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* ===================================================
   LAYOUT
   =================================================== */
.container { width: 90%; max-width: none; margin: 0 auto; padding: 0; }

main { padding: 28px 0 64px; }

/* ===================================================
   HEADER
   =================================================== */
header {
    background: rgba(12, 13, 16, .85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    height: 52px;
    display: flex;
    align-items: center;
}
header .inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}
header .logo {
    font-weight: 700;
    font-size: .95rem;
    color: var(--text);
    letter-spacing: -.01em;
    display: flex;
    align-items: center;
    gap: 7px;
}
header nav {
    display: flex;
    align-items: center;
    gap: 2px;
}
header nav a {
    padding: 5px 12px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    font-size: .85rem;
    font-weight: 500;
    transition: color .15s, background .15s;
}
header nav a:hover { color: var(--text); background: var(--bg-4); }
header nav a.active { color: var(--text); background: var(--bg-3); }

/* ===================================================
   CARDS
   =================================================== */
.card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 12px;
}

/* ===================================================
   LOGIN
   =================================================== */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse 60% 40% at 50% 0%, rgba(34,197,94,.08) 0%, transparent 70%);
}
.login-box {
    width: 100%;
    max-width: 360px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 36px 32px;
}
.login-box h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 24px;
    text-align: center;
    letter-spacing: -.02em;
}

/* ===================================================
   FORMS
   =================================================== */
label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 5px;
    letter-spacing: .02em;
    text-transform: uppercase;
}
input[type=text],
input[type=password],
input[type=time],
input[type=number],
input[type=date],
select {
    width: 100%;
    padding: 8px 11px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, .12);
}
input::placeholder { color: var(--faint); }
select option { background: var(--bg-3); color: var(--text); }

.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* ===================================================
   BUTTONS
   =================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid transparent;
    border-radius: 7px;
    font-size: .83rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    letter-spacing: .01em;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    color: #050a05;
    border-color: var(--accent);
}
.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 0 16px rgba(34, 197, 94, .25);
}

.btn-secondary {
    background: var(--bg-4);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-3); border-color: var(--muted); }

.btn-danger {
    background: rgba(248, 113, 113, .1);
    color: var(--red);
    border-color: rgba(248, 113, 113, .25);
}
.btn-danger:hover {
    background: rgba(248, 113, 113, .18);
    border-color: var(--red);
}

.btn-sm  { padding: 5px 10px; font-size: .78rem; border-radius: 6px; }
.btn-block { width: 100%; justify-content: center; }

/* ===================================================
   BADGES
   =================================================== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.badge-executed         { background: rgba(34,197,94,.15);  color: #4ade80; }
.badge-skipped_rain     { background: rgba(96,165,250,.15); color: #93c5fd; }
.badge-error            { background: rgba(248,113,113,.15);color: #fca5a5; }
.badge-skipped_schedule { background: rgba(139,144,168,.1); color: var(--muted); }

/* ===================================================
   TABLE
   =================================================== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-3); }

/* ===================================================
   MODAL
   =================================================== */
.modal-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
}
.modal-wide { max-width: 620px; }
.modal h2 { font-size: 1rem; font-weight: 700; margin-bottom: 18px; letter-spacing: -.01em; }
.modal-close {
    position: absolute; top: 14px; right: 14px;
    background: var(--bg-4); border: 1px solid var(--border);
    border-radius: 6px; width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; cursor: pointer; color: var(--muted);
    transition: all .15s;
}
.modal-close:hover { color: var(--text); background: var(--bg-3); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ===================================================
   DAYS CHECKBOXES
   =================================================== */
.days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}
.day-toggle { display: none; }
.day-toggle + label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .72rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--muted);
    background: var(--bg-3);
    transition: all .15s;
    letter-spacing: .02em;
}
.day-toggle:checked + label {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: rgba(34, 197, 94, .35);
}

/* ===================================================
   PAGE TOOLBAR
   =================================================== */
.page-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.page-title { font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; }

/* ===================================================
   SCHEDULE CARDS
   =================================================== */
.sched-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.sched-title-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sched-name { font-weight: 700; font-size: .95rem; letter-spacing: -.01em; }
.sched-actions { display: flex; gap: 6px; flex-shrink: 0; }
.sched-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: .8rem;
    color: var(--muted);
    margin-bottom: 8px;
}

/* ===================================================
   FORM SECTION (zone nel modal)
   =================================================== */
.form-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 6px;
    background: var(--bg-3);
}
.form-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.form-section-title { font-weight: 700; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.zone-row {
    display: grid;
    grid-template-columns: 1fr 110px 120px auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.zone-duration-wrap { display: flex; align-items: center; gap: 5px; }
.zone-duration-wrap input { flex: 1; min-width: 0; }
.zone-duration-label { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.zone-empty-msg { font-size: .82rem; color: var(--faint); text-align: center; padding: 14px 0; }

/* ===================================================
   TOGGLE SWITCH
   =================================================== */
.toggle-wrap { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.switch { position: relative; display: inline-block; width: 38px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; inset: 0;
    background: var(--bg-4);
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    transition: .2s;
}
.slider:before {
    position: absolute; content: '';
    height: 14px; width: 14px;
    left: 2px; top: 2px;
    background: var(--muted); border-radius: 50%;
    transition: .2s;
}
input:checked + .slider { background: var(--accent-dim); border-color: rgba(34,197,94,.4); }
input:checked + .slider:before { transform: translateX(18px); background: var(--accent); }

/* ===================================================
   TOAST
   =================================================== */
#toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-4);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 500;
    opacity: 0;
    transition: all .25s cubic-bezier(.34,1.56,.64,1);
    z-index: 999;
    white-space: nowrap;
    box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { background: var(--accent-dim); border-color: rgba(34,197,94,.35); color: #4ade80; }
#toast.error   { background: rgba(248,113,113,.1); border-color: rgba(248,113,113,.3); color: var(--red); }

/* ===================================================
   MISC
   =================================================== */
.empty { text-align: center; color: var(--faint); padding: 32px; font-size: .9rem; }
.pagination { text-align: center; margin-top: 16px; }

/* ===================================================
   CALENDARIO
   =================================================== */
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-title {
    font-size: 1rem; font-weight: 700;
    letter-spacing: -.01em;
    min-width: 190px; text-align: center;
    text-transform: capitalize;
}
.cal-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .75rem;
    color: var(--muted);
    flex-wrap: wrap;
}
.cal-legend-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* Griglia */
.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
}
.cal-weekday {
    text-align: center;
    padding: 10px 4px;
    font-size: .7rem;
    font-weight: 700;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: .06em;
}
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}
.cal-cell {
    border-right: 1px solid var(--border-2);
    border-bottom: 1px solid var(--border-2);
    min-height: 115px;
    padding: 8px 7px;
    cursor: pointer;
    transition: background .12s;
    overflow: hidden;
    background: var(--bg-2);
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell:hover { background: var(--bg-3); }
.cal-cell--empty { background: var(--bg); cursor: default; pointer-events: none; }
.cal-cell--past  { background: var(--bg); }
.cal-cell--today { background: rgba(34,197,94,.04); }
.cal-cell--excluded { background: rgba(248,113,113,.04); }

/* Numero giorno */
.cal-day-num { margin-bottom: 4px; }
.cal-day-num span {
    display: inline-flex;
    align-items: center; justify-content: center;
    width: 22px; height: 22px;
    font-size: .8rem; font-weight: 700;
    border-radius: 50%;
    color: var(--muted);
}
.cal-cell--today .cal-day-num span {
    background: var(--accent);
    color: #050a05;
}
.cal-cell--past .cal-day-num span  { color: var(--faint); }
.cal-cell--excluded .cal-day-num span { color: var(--red); }

/* Meteo */
.cal-weather {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: .68rem;
    color: var(--muted);
    margin-bottom: 3px;
    flex-wrap: wrap;
    line-height: 1.3;
}
.cal-rain { font-weight: 700; }
.cal-rain.rain-high { color: var(--red); }
.cal-rain.rain-mid  { color: var(--orange); }
.cal-rain.rain-low  { color: var(--blue); }
.cal-temp { color: var(--faint); }

/* Chip eventi */
.cal-chip {
    font-size: .65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.5;
}
.cal-chip--planned          { background: var(--accent-dim);          color: #4ade80; }
.cal-chip--executed         { background: rgba(74,222,128,.12);       color: #4ade80; }
.cal-chip--skipped_rain     { background: rgba(96,165,250,.12);       color: var(--blue); }
.cal-chip--skipped_schedule { background: rgba(139,144,168,.08);      color: var(--muted); }
.cal-chip--error            { background: rgba(248,113,113,.12);      color: var(--red); }
.cal-chip--excluded         { background: rgba(248,113,113,.12);      color: var(--red); }
.cal-chip--more             { background: var(--bg-4);                color: var(--faint); font-style: italic; }

/* Modal giorno */
.day-weather-block {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 16px;
}
.day-weather-icon { font-size: 2.2rem; line-height: 1; }

.day-excl-block {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(248,113,113,.07);
    border: 1px solid rgba(248,113,113,.2);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: .85rem;
    flex-wrap: wrap;
}

.day-section-title {
    font-size: .7rem;
    font-weight: 700;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin: 18px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-2);
}

.day-sched-block {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 8px;
}
.day-sched-name { font-weight: 700; font-size: .88rem; margin-bottom: 7px; }
.day-zone-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    font-size: .82rem;
    color: var(--muted);
    padding: 5px 0;
    border-top: 1px solid var(--border-2);
}
.day-zone-row span:not(:first-child) { text-align: right; }

.day-log-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: .82rem;
    padding: 7px 0;
    border-top: 1px solid var(--border-2);
}
.day-log-note { color: var(--faint); font-style: italic; }

/* ===================================================
   RESPONSIVE
   =================================================== */
@media (max-width: 768px) {
    .form-row-4 { grid-template-columns: 1fr 1fr; }
    .sched-header { flex-direction: column; }
}
@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; }
    .days-grid { grid-template-columns: repeat(4, 1fr); }
    .zone-row { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
    .zone-row .zone-remove-btn { grid-column: 2; justify-self: end; }
    .cal-cell { min-height: 72px; padding: 4px; }
    .cal-weather, .cal-temp { display: none; }
    .cal-chip { font-size: .6rem; padding: 1px 4px; }
    .cal-title { min-width: 140px; font-size: .9rem; }
    .cal-legend { display: none; }
    .page-toolbar { flex-direction: column; align-items: flex-start; gap: 10px; }
}
