:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #6b7280;
    --border: #e2e5ea;
    --primary: #1f5eff;
    --primary-hover: #1848c9;
    --pos: #12803a;
    --pos-bg: #e6f5ec;
    --neg: #c62828;
    --neg-bg: #fdecec;
    --todo: #9a6700;
    --todo-bg: #fff4d6;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }
.card h2 { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Topbar */
.topbar { background: #141a26; color: #fff; }
.topbar-inner {
    max-width: 1280px; margin: 0 auto; padding: .6rem 16px;
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { color: #c9d1e0; text-decoration: none; padding: .35rem .65rem; border-radius: 6px; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; background: rgba(255,255,255,.15); }
.logout { display: flex; align-items: center; gap: .5rem; margin: 0 0 0 auto; }
.who { color: #c9d1e0; font-size: .85rem; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.3); }

.container { max-width: 1280px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

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

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.empty { color: var(--muted); text-align: center; }
.auth-card { max-width: 380px; margin: 3rem auto; }
.auth-card h1 { margin-bottom: 1rem; }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-success { background: var(--pos-bg); color: var(--pos); }
.alert-error { background: var(--neg-bg); color: var(--neg); }
.alert-info { background: #eef3ff; color: #1848c9; }
.email-preview { width: 100%; height: 640px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

/* Forms */
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; margin-bottom: .9rem; }
.form-inline { display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; }
.form-inline label { flex: 1; min-width: 220px; margin-bottom: 0; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], select {
    font: inherit; padding: .55rem .65rem; border: 1px solid #cbd1da; border-radius: 8px;
    background: #fff; color: var(--text); width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .75rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .35rem; }

.grid-2, .grid-3 { display: grid; gap: 0 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .4rem; }
.form label.check, label.check {
    flex-direction: row; align-items: center; gap: .55rem; font-weight: 400;
    margin: 0; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
label.check:has(input:checked) { border-color: var(--primary); background: #eef3ff; }
label.check input { width: 18px; height: 18px; margin: 0; }
label.check[hidden] { display: none; }
.check-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.check-text small { font-size: .75rem; color: var(--primary); }
.check-text small.altro-negozio { color: var(--todo); }

.presenze-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.presenze-tools[hidden] { display: none; }
.presenze-tools input[type=search] {
    flex: 1; min-width: 180px; font: inherit; padding: .45rem .65rem;
    border: 1px solid #cbd1da; border-radius: 8px;
}
.segmented { display: inline-flex; border: 1px solid #cbd1da; border-radius: 8px; overflow: hidden; }
.segmented button {
    font: inherit; font-size: .85rem; padding: .45rem .75rem; border: 0; background: #fff; cursor: pointer; color: var(--text);
}
.segmented button + button { border-left: 1px solid #cbd1da; }
.segmented button.active { background: var(--primary); color: #fff; }

.form label.check-inline { border: 0; padding: 0; align-self: end; margin-bottom: .9rem; }

.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); }
.filters select, .filters input { min-width: 150px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; cursor: pointer;
    border: 1px solid #cbd1da; background: #fff; color: var(--text); text-decoration: none;
}
.btn:hover { background: #f1f3f6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #fff; border-color: var(--neg); color: var(--neg); }
.btn-danger:hover { background: var(--neg-bg); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-block { width: 100%; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }

/* Fasce */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.tab {
    display: flex; flex-direction: column; gap: .15rem; padding: .7rem .85rem; text-decoration: none; color: var(--text);
    background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
}
.tab:hover { border-color: #aab4c5; }
.tab.active { border-color: var(--primary); background: #eef3ff; }
.tab.closed { opacity: .6; }
.tab-title { font-weight: 700; }
.tab-sub { font-size: .85rem; color: var(--muted); }
.tab .badge { align-self: flex-start; margin-top: .2rem; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; background: #eceff3; color: var(--muted); }
.badge-ok { background: var(--pos-bg); color: var(--pos); }
.badge-todo { background: var(--todo-bg); color: var(--todo); }

/* Stat / preview */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1.1rem; }
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat, .preview > div {
    display: flex; flex-direction: column; gap: .15rem;
    background: var(--bg); border-radius: 8px; padding: .65rem .8rem;
}
.container > .stats .stat { background: var(--surface); border: 1px solid var(--border); }
.stat span, .preview span { font-size: .8rem; color: var(--muted); }
.stat strong, .preview strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.preview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }

.delta.pos { color: var(--pos); }
.delta.neg { color: var(--neg); }
td.delta.pos { background: var(--pos-bg); font-weight: 600; }
td.delta.neg { background: var(--neg-bg); font-weight: 600; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
.card .table-wrap { border: 0; margin: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table thead th, .table tr.colhead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); background: #fafbfc; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot td, .table tr.subtotal td { font-weight: 700; background: #fafbfc; }
.table tr.group th { background: #eef1f6; font-size: .9rem; text-transform: none; letter-spacing: 0; color: var(--text); }
.table tr.group .small { margin-left: .5rem; font-weight: 400; }
.table tr.missing td { color: var(--muted); }
.table tr.inactive td { color: var(--muted); }
.table td.small { white-space: normal; min-width: 180px; }
.table-form td, .table-form th { padding: .35rem .4rem; }
.table-form input[type=time] { min-width: 105px; }
.input-money { min-width: 110px; text-align: right; }

@media (max-width: 720px) {
    .grid-2, .grid-3, .stats, .stats-4, .preview { grid-template-columns: minmax(0, 1fr); }
    .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .preview { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .preview strong { font-size: 1rem; }
    .tabs { gap: .4rem; }
    .tab { padding: .55rem .6rem; }
    .tab-sub { font-size: .75rem; }
    .logout { margin-left: 0; }
    .filters { width: 100%; }
    .filters label { flex: 1; }
    .filters select, .filters input { min-width: 0; }
    h1 { font-size: 1.3rem; }
}
