/* Prenotazione mezzi SAMP */
:root {
    --bg: #f0f1ed;
    --card: #ffffff;
    --text: #1d2420;
    --muted: #6b756f;
    --line: #dfe3dc;
    --field: #eceee9;
    --primary: #0f5a46;
    --primary-hover: #0b4636;
    --primary-text: #ffffff;
    --busy: #cf6e5a;
    --free-bg: #d9eadf;
    --free-text: #1d5a3f;
    --warn-bg: #f8e6bd;
    --warn-text: #7a5410;
    --done-bg: #e3e6e1;
    --danger: #b3382a;
    --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 6px 20px rgba(20, 30, 25, .04);
    --radius: 12px;
}
:root[data-theme="dark"] {
    --bg: #111715;
    --card: #1a2220;
    --text: #e8ede9;
    --muted: #93a099;
    --line: #2b3732;
    --field: #232d2a;
    --primary: #3fae8b;
    --primary-hover: #52c3a0;
    --primary-text: #0b1512;
    --busy: #d9806c;
    --free-bg: #1f3b30;
    --free-text: #8fd6b6;
    --warn-bg: #4a3a14;
    --warn-text: #f0d189;
    --done-bg: #2a3431;
    --danger: #e0715f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    transition: background .25s, color .25s;
}
.container { max-width: 1280px; margin: 0 auto; padding: 18px 20px 48px; }

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 30px; }
h2 { font-size: 18px; margin-bottom: 14px; }
h3 { font-size: 15px; margin: 22px 0 10px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); margin: -6px 0 12px; font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 16px; }
.brand-logo { height: 54px; width: auto; display: block; }
:root[data-theme="dark"] .brand-logo, :root[data-theme="dark"] .login-logo { background: #fff; border-radius: 8px; padding: 2px 6px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-chip { font-size: 13px; color: var(--muted); padding: 0 6px; }
.inline-form { display: inline; margin: 0; }

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px 18px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}
.card[hidden] { display: none; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

/* Controls */
input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--field);
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 8px 10px;
    min-height: 36px;
    width: 100%;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--primary); }
label { font-size: 12px; font-weight: 600; display: block; margin-bottom: 4px; }
.field { display: flex; flex-direction: column; min-width: 170px; }
.field.grow { flex: 1 1 200px; }
.field label { margin-bottom: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; font-size: 13px; margin: 0 0 8px; cursor: pointer; white-space: nowrap; }

.btn {
    font: inherit; font-weight: 600; font-size: 14px;
    border: 1.5px solid var(--primary);
    color: var(--primary);
    background: transparent;
    border-radius: 6px;
    padding: 8px 18px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s, transform .08s, box-shadow .15s;
}
.btn:hover:not(:disabled) { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: 1px; }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 3px 9px; font-size: 14px; line-height: 1; }
.btn.block { width: 100%; padding: 10px; }
.btn.ghost { border-color: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* Form prenotazione */
.booking-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 14px; }
.form-buttons { display: flex; gap: 10px; margin-bottom: 0; }
.booking-form .check { margin-bottom: 8px; }
.msg { margin: 10px 0 0; font-size: 13px; min-height: 18px; }
.msg.ok { color: var(--free-text); }
.msg.error { color: var(--danger); }

/* Timeline */
.week-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.week-nav select { width: auto; min-width: 220px; }
.week-label { color: var(--muted); font-size: 13px; min-width: 130px; text-align: center; }
.timeline { margin-top: 4px; }
.tl-row { display: grid; grid-template-columns: 74px 1fr; gap: 10px; align-items: center; margin-bottom: 4px; }
.tl-label { font-size: 12px; color: var(--muted); }
.tl-label.today { color: var(--text); font-weight: 700; }
.tl-track {
    position: relative; height: 18px; border-radius: 4px; overflow: hidden;
    border: 1px solid var(--line); background: var(--field);
    background-image: linear-gradient(to right, transparent calc(25% - 1px), var(--line) calc(25% - 1px), var(--line) 25%, transparent 25%,
        transparent calc(50% - 1px), var(--line) calc(50% - 1px), var(--line) 50%, transparent 50%,
        transparent calc(75% - 1px), var(--line) calc(75% - 1px), var(--line) 75%, transparent 75%);
}
.tl-seg { position: absolute; top: 0; bottom: 0; border: 0; padding: 0; }
.tl-seg.busy { background: var(--busy); }
button.tl-seg { cursor: pointer; transition: filter .15s; }
button.tl-seg:hover { filter: brightness(1.12); }
.tl-seg.preview { background: color-mix(in srgb, var(--primary) 22%, transparent); outline: 1.5px dashed var(--primary); outline-offset: -1.5px; }
.tl-axis { position: relative; height: 16px; font-size: 10px; color: var(--muted); }
.tl-axis span { position: absolute; transform: translateX(-50%); }
.tl-axis span:first-child { transform: none; }
.tl-axis span:last-child { transform: translateX(-100%); }
.legend { display: flex; gap: 18px; font-size: 11px; color: var(--muted); margin: 8px 0; }
.swatch { display: inline-block; width: 12px; height: 8px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.swatch.busy { background: var(--busy); }
.swatch.preview { border: 1.5px dashed var(--primary); }
.tl-list { list-style: none; margin: 8px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); font-size: 12px; }
.tl-list li { padding: 2px 0; }

/* Flotta */
.fleet { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.fleet-card {
    font: inherit; text-align: left; color: inherit; cursor: pointer;
    background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
    display: flex; flex-direction: column; gap: 8px; justify-content: space-between;
    transition: border-color .15s, transform .12s, box-shadow .15s;
}
.fleet-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.fleet-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.fleet-top strong { font-size: 13px; }
.plate { font-size: 12px; font-weight: 600; letter-spacing: .04em; }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill.free, .pill.prenotato { background: var(--free-bg); color: var(--free-text); }
.pill.busy, .pill.ritirato { background: var(--warn-bg); color: var(--warn-text); }
.pill.riconsegnato, .pill.off { background: var(--done-bg); color: var(--muted); }

/* Tabelle */
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.toolbar input.grow { flex: 1 1 260px; width: auto; }
.toolbar select { width: auto; min-width: 220px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: color-mix(in srgb, var(--field) 55%, transparent); }
.table small { font-size: 11px; }
.table .notes { max-width: 260px; color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { color: var(--muted); text-align: center; padding: 18px 0 4px; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab {
    font: inherit; font-weight: 600; background: transparent; color: var(--muted);
    border: 1px solid var(--line); border-radius: 999px; padding: 7px 16px; cursor: pointer;
    transition: all .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* Dialog */
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 22px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dialog::backdrop { background: rgba(10, 18, 14, .55); backdrop-filter: blur(2px); }
.small-dialog { width: min(400px, calc(100vw - 32px)); }
.dialog-form .field { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.dialog-buttons { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 14px; }
.dialog-buttons .spacer { flex: 1; }
.confirm-text { margin: 0 0 6px; font-size: 15px; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; background:
    radial-gradient(900px 500px at 15% 0%, color-mix(in srgb, var(--primary) 14%, transparent), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, color-mix(in srgb, var(--busy) 14%, transparent), transparent 60%), var(--bg); }
.login-wrap { width: 100%; padding: 20px; display: grid; place-items: center; }
.login-card {
    width: min(400px, 100%); background: var(--card); border: 1px solid var(--line);
    border-radius: 16px; padding: 28px 28px 22px; box-shadow: 0 18px 50px rgba(20, 30, 25, .12); text-align: center;
    animation: rise .5s ease both;
}
.login-card form { text-align: left; margin-top: 18px; }
.login-card .field { margin-bottom: 14px; }
.login-logo { width: 220px; height: auto; margin: 0 auto 14px; display: block; }
.login-card h1 { font-size: 26px; }
.theme-toggle { margin-top: 12px; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

@media (max-width: 720px) {
    h1 { font-size: 24px; }
    .tl-row { grid-template-columns: 58px 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.pill.you { margin-left: 8px; }
.dialog-form small { margin-top: 4px; font-size: 11px; }

/* Timeline "tutti i veicoli": etichette nelle fasce */
.tl-seg { overflow: hidden; }
.tl-seg .tl-text { display: block; padding: 0 6px; font-size: 11px; line-height: 18px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; font-weight: 600; pointer-events: none; }
:root[data-theme="dark"] .tl-seg .tl-text { color: #1b1410; }

/* Campo disattivato (es. riconsegna con "Tutto il giorno") */
input:disabled, select:disabled, textarea:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
label.dim { opacity: .4; }
