* { box-sizing: border-box; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: #f4f5f7;
    color: #222;
    line-height: 1.45;
}
a { color: #2c3e50; }

/* ---------- Topbar / nav ---------- */
.topbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding: .65rem 1.25rem;
    background: #2c3e50;
    color: #fff;
}
.topbar a { color: #fff; text-decoration: none; }
.brand { font-size: 1.05rem; }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.mainnav a {
    padding: .35rem .7rem;
    border-radius: 4px;
    font-size: .95rem;
}
.mainnav a:hover { background: rgba(255,255,255,.08); }
.mainnav a.active { background: rgba(255,255,255,.18); }
.spacer { flex: 1; }
.userinfo { font-size: .9rem; opacity: .9; }
.userinfo small { opacity: .7; }

/* ---------- Layout ---------- */
main {
    max-width: 1100px;
    margin: 1.5rem auto;
    padding: 0 1rem 3rem;
}
h1 { margin: 0 0 1rem; font-size: 1.4rem; }
.muted { color: #6b7280; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* ---------- Cards (dashboard) ---------- */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.card {
    display: block;
    background: #fff;
    padding: 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    text-decoration: none;
    color: inherit;
    transition: transform .12s, box-shadow .12s;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,.1);
}
.card-num { font-size: 2rem; font-weight: 600; color: #2c3e50; }
.card-label { font-size: .9rem; color: #6b7280; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: .4rem .85rem;
    background: #e5e7eb;
    color: #1f2937;
    border-radius: 4px;
    text-decoration: none;
    font-size: .9rem;
    border: 0;
    cursor: pointer;
    line-height: 1.3;
}
.btn:hover { background: #d1d5db; }
.btn-primary { background: #2c3e50; color: #fff; }
.btn-primary:hover { background: #34495e; }
.btn-light { background: rgba(255,255,255,.15); color: #fff; }
.btn-light:hover { background: rgba(255,255,255,.25); }
.btn-sm { padding: .25rem .55rem; font-size: .82rem; }
.inline { display: inline; }

/* ---------- Tables ---------- */
.data {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    font-size: .92rem;
}
.data th, .data td {
    padding: .6rem .75rem;
    text-align: left;
    border-bottom: 1px solid #eef0f3;
    vertical-align: middle;
}
.data th {
    background: #f9fafb;
    font-weight: 600;
    color: #4b5563;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.data tbody tr:last-child td { border-bottom: 0; }
.data tr.inactive { color: #9ca3af; background: #fafafa; }
.row-actions { white-space: nowrap; }
.row-actions form { margin-left: .25rem; }

/* ---------- Forms ---------- */
.form {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    max-width: 520px;
}
.form label {
    display: block;
    margin-bottom: 1rem;
    font-size: .9rem;
    color: #374151;
}
.form input[type="text"],
.form input[type="password"],
.form input[type="number"],
.form select {
    display: block;
    width: 100%;
    padding: .5rem .65rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 1rem;
    margin-top: .25rem;
    background: #fff;
}
.form input:focus, .form select:focus {
    outline: 2px solid #93c5fd;
    border-color: #93c5fd;
}
.form input[type="color"] {
    width: 60px;
    height: 36px;
    padding: 2px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
}
.color-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-top: .25rem;
}
.form .checkbox {
    display: flex;
    gap: .5rem;
    align-items: center;
}
.form .checkbox input { margin: 0; }
.form small { display: block; margin-top: .25rem; font-size: .82rem; }
.form-actions {
    display: flex;
    gap: .5rem;
    margin-top: 1rem;
}

/* ---------- Login ---------- */
body.centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
    width: 320px;
}
.login h1 { margin: 0 0 1rem; font-size: 1.25rem; }
.login label { display: block; margin-bottom: 1rem; font-size: .9rem; }
.login input {
    display: block;
    width: 100%;
    padding: .5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    margin-top: .25rem;
}
.login button {
    width: 100%;
    padding: .6rem;
    background: #2c3e50;
    color: #fff;
    border: 0;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
}
.login button:hover { background: #34495e; }

/* ---------- Flash messages ---------- */
.flash {
    padding: .65rem .9rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: .92rem;
}
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error   { background: #fdecea; color: #b71c1c; border: 1px solid #fecaca; }
.error         { background: #fdecea; color: #b71c1c; padding: .5rem .75rem; border-radius: 4px; margin-bottom: 1rem; font-size: .9rem; }

/* ---------- Misc ---------- */
.badge {
    display: inline-block;
    padding: .12rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.badge-ok  { background: #d1fae5; color: #065f46; }
.badge-off { background: #f3f4f6; color: #6b7280; }

.color-swatch {
    display: inline-block;
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1px solid #d1d5db;
    vertical-align: middle;
    margin-right: .35rem;
}

/* ---------- Calendario mensile ---------- */
.month-nav {
    display: flex;
    align-items: center;
    gap: .35rem;
    flex-wrap: wrap;
}
.month-nav select,
.month-nav input[type="number"] {
    padding: .3rem .45rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: .9rem;
    background: #fff;
}
.month-nav input[type="number"] { width: 84px; }
.btn-light-bg { background: #2c3e50; color: #fff; }
.btn-light-bg:hover { background: #34495e; }

.calendar-scroll {
    overflow-x: auto;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.calendar {
    border-collapse: separate;
    border-spacing: 0;
    font-size: .85rem;
    width: max-content;
    min-width: 100%;
}
.calendar th, .calendar td {
    border-right: 1px solid #eef0f3;
    border-bottom: 1px solid #eef0f3;
    text-align: center;
    padding: 0;
    height: 32px;
    min-width: 32px;
    width: 32px;
    box-sizing: border-box;
}

/* Pagina calendario: usa tutta la larghezza dello schermo */
body.page-calendar main {
    max-width: none;
    margin: 1rem auto;
    padding: 0 .75rem 1.5rem;
}
body.page-calendar .calendar {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
}
body.page-calendar .calendar th,
body.page-calendar .calendar td {
    min-width: 0;
    width: auto;
}
body.page-calendar .calendar .col-person {
    width: 160px;
    min-width: 160px;
}
body.page-calendar .calendar .col-summary {
    width: 30px;
    min-width: 30px;
}
body.page-calendar .calendar .col-hours {
    width: 50px;
    min-width: 50px;
}
/* Soglia minima: sotto i 1100px torna lo scroll orizzontale per non comprimere troppo le celle */
@media (max-width: 1100px) {
    body.page-calendar .calendar {
        width: max-content;
        table-layout: auto;
    }
    body.page-calendar .calendar th,
    body.page-calendar .calendar td {
        min-width: 32px;
        width: 32px;
    }
}
.calendar thead th {
    background: #f9fafb;
    color: #4b5563;
    font-weight: 600;
    font-size: .78rem;
    user-select: none;
}
.calendar .row-day-letter th {
    color: #9ca3af;
    font-weight: 400;
    font-size: .7rem;
    border-bottom: 2px solid #d1d5db;
}
.calendar .col-person {
    text-align: left;
    padding: 0 .65rem;
    min-width: 180px;
    width: 180px;
    font-size: .9rem;
    background: #fff;
}
.calendar thead .col-person { background: #f9fafb; }
.calendar .sticky-left {
    position: sticky;
    left: 0;
    z-index: 2;
    box-shadow: 1px 0 0 #e5e7eb;
}
.calendar thead .sticky-left { z-index: 3; }
.calendar tbody td.col-person { font-weight: 500; }

.calendar td.cell {
    cursor: pointer;
    font-weight: 600;
    color: #1f2937;
    transition: outline .08s;
}
.calendar td.cell:empty::before { content: ''; }
.calendar td.cell:hover { outline: 2px solid #93c5fd; outline-offset: -2px; }
.calendar th.we, .calendar td.we { background: #f3f4f6; }
.calendar th.today { background: #fff7ed; color: #9a3412; }
.calendar td.today { background: #fffbeb; }

.calendar td.col-summary {
    background: #fafbfc;
    color: #4b5563;
    font-weight: 600;
    min-width: 36px;
    width: 36px;
    cursor: default;
}
.calendar th.col-summary {
    background: #eef2f7;
    border-left: 2px solid #d1d5db;
}
.calendar td.col-summary {
    border-left: 1px solid #e5e7eb;
}
.calendar td.col-hours, .calendar th.col-hours {
    min-width: 56px;
    width: 56px;
    color: #1f2937;
}

/* tfoot: totali per giorno per ogni tipo di turno */
.calendar tfoot tr.tfoot-day-totals th,
.calendar tfoot tr.tfoot-day-totals td {
    background: #fafbfc;
    color: #4b5563;
    font-weight: 600;
}
.calendar tfoot tr.tfoot-day-totals:first-child th,
.calendar tfoot tr.tfoot-day-totals:first-child td {
    border-top: 2px solid #d1d5db;
}
.calendar tfoot th.tfoot-label {
    text-align: left;
    padding: 0 .65rem;
    font-size: .85rem;
    color: #1f2937;
}
.calendar tfoot th.tfoot-label .color-swatch {
    width: 12px;
    height: 12px;
    margin-right: .35rem;
    vertical-align: middle;
}
.calendar tfoot td[data-date]:empty { color: transparent; }
.calendar tfoot td.we { background: #f3f4f6; }
.calendar tfoot td.today { background: #fffbeb; }

.legend-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #d1d5db;
    vertical-align: middle;
    margin-right: .15rem;
}
.legend-dot.oncall { border-color: rgba(0,0,0,.15); }
.small { font-size: .85rem; }

/* ---------- Cell popover ---------- */
.cell-popover {
    position: absolute;
    z-index: 50;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,.18);
    padding: .85rem;
    width: 280px;
    border: 1px solid #e5e7eb;
}
.cell-popover[hidden] { display: none; }
.cell-popover-title {
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: .65rem;
    color: #374151;
}
.cell-popover label {
    display: block;
    margin-bottom: .65rem;
    font-size: .85rem;
    color: #4b5563;
}
.cell-popover label.checkbox {
    display: flex;
    align-items: center;
    gap: .5rem;
}
.cell-popover select {
    width: 100%;
    padding: .4rem .5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    margin-top: .25rem;
    font-size: .9rem;
}
.cell-popover .form-actions { margin-top: .25rem; }
.cell-popover .form-actions-stack {
    display: flex;
    flex-direction: column;
    gap: .35rem;
}
.cell-popover .form-actions-row {
    display: flex;
    gap: .35rem;
    justify-content: space-between;
}
.cell-popover .form-actions-row .btn {
    flex: 1;
    text-align: center;
}
.btn-block { display: block; width: 100%; text-align: center; }
.kbd {
    display: inline-block;
    padding: 0 .35rem;
    border: 1px solid rgba(255,255,255,.4);
    border-radius: 3px;
    font-size: .7rem;
    font-family: ui-monospace, monospace;
    margin-left: .35rem;
    opacity: .85;
}
.btn-danger { background: #b91c1c; color: #fff; }
.btn-danger:hover { background: #991b1b; }

/* ---------- Report mensile ---------- */
table.data.report tfoot tr.grand th {
    background: #eef2f7;
    border-top: 2px solid #d1d5db;
    color: #1f2937;
}
table.data.report td, table.data.report th { text-align: center; }
table.data.report td:first-child, table.data.report th:first-child { text-align: left; }

/* ---------- Settings: blocchi affiancati per ambulanza/notte ---------- */
.form.form-wide { max-width: 720px; }
.oncall-fieldset {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 1rem 1.25rem 1.25rem;
    margin: 1.25rem 0;
}
.oncall-fieldset legend {
    padding: 0 .5rem;
    font-weight: 600;
    color: #374151;
    font-size: .95rem;
}
.oncall-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: .75rem;
}
.oncall-controls > label { flex: 1; min-width: 200px; margin-bottom: 0; }

/* legenda calendario: piccola cella con stile reperibilità "vivo" */
.legend-cell {
    display: inline-block;
    width: 18px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    font-size: .65rem;
    font-weight: 700;
    color: #1f2937;
    border: 1px solid #d1d5db;
    vertical-align: middle;
    margin-right: .15rem;
}

/* ---------- Anteprima stili reperibilità (Impostazioni) ---------- */
.oncall-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
}
.preview-item {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: .5rem;
    width: 130px;
    text-align: center;
}
.preview-item.is-current {
    border-color: #2c3e50;
    box-shadow: 0 0 0 2px rgba(44,62,80,.15);
}
.preview-cell {
    width: 56px;
    height: 36px;
    line-height: 36px;
    margin: 0 auto .5rem;
    border: 1px solid #d1d5db;
    font-weight: 700;
    color: #1f2937;
}
.preview-label {
    font-size: .8rem;
    color: #4b5563;
    line-height: 1.2;
}
