/* Colori e font ispirati a olimpiacalcioquarrata.it (rosso #CD1A1A, nero, giallo del logo; Roboto / Open Sans) */
:root {
  --red: #CD1A1A;
  --red-dark: #A81414;
  --red-soft: #FDECEC;
  --yellow: #F2D600;
  --ink: #241C1C;
  --ink-2: #313131;
  --muted: #6b6363;
  --line: #e6e1e1;
  --bg: #f5f3f3;
  --card: #ffffff;
  --green: #1E8E3E;
  --green-soft: #E6F4EA;
  --amber-soft: #FFF6D6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(36, 28, 28, .06), 0 4px 14px rgba(36, 28, 28, .06);
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  font-family: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink-2);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, .kicker, .btn, .tabbar button, .kpi-value {
  font-family: "Roboto", system-ui, sans-serif;
}
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--red-dark); background: var(--red-soft); padding: .6rem .8rem; border-radius: 10px; margin: .5rem 0; }

/* ---------- Form controls ---------- */
label { display: block; font-weight: 600; font-size: .92rem; margin: .9rem 0 0; color: var(--ink); }
input[type=email], input[type=password], input[type=search], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: .35rem;
  font: inherit; font-weight: 400; color: var(--ink);
  padding: .75rem .85rem; min-height: 48px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
  outline: none; transition: border-color .15s;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(205, 26, 26, .12); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 48px; padding: .7rem 1.2rem; border-radius: 999px; border: 2px solid transparent;
  font-size: .95rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  cursor: pointer; transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-outline { background: #fff; color: var(--ink); border-color: var(--ink); }
.btn-outline-danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn[disabled] { opacity: .6; pointer-events: none; }
.btn-ghost { background: transparent; border: 1.5px solid rgba(255,255,255,.6); color: #fff; border-radius: 999px; padding: .4rem .9rem; font: 600 .85rem "Roboto", sans-serif; cursor: pointer; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(160deg, var(--red) 0%, var(--red-dark) 55%, var(--ink) 100%);
}
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 20px; padding: 28px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); text-align: center; }
.login-card form { text-align: left; margin-top: 8px; }
.login-card .btn { margin-top: 1.4rem; }
.login-logo { width: 150px; height: auto; margin: -4px auto 6px; display: block; }
.login-card h1 { margin: .2rem 0 0; color: var(--red); font-size: 1.5rem; font-weight: 900; text-transform: uppercase; }
.login-card p { margin: .2rem 0 .4rem; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--red); color: #fff;
  border-bottom: 4px solid var(--yellow);
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.topbar-logo { height: 46px; width: auto; flex: none; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 1.15rem; font-weight: 900; text-transform: uppercase; letter-spacing: .02em; line-height: 1.1; }
.kicker { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; opacity: .9; font-weight: 500; }

main { max-width: 900px; margin: 0 auto; padding: 12px 16px calc(var(--tabbar-h) + 96px + var(--safe-b)); }

/* ---------- Toolbar ---------- */
.toolbar { position: sticky; top: 70px; z-index: 10; background: var(--bg); padding: 4px 0 10px; }
.toolbar input[type=search] { margin-top: 0; }
.toolbar-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.toolbar-row select { flex: 1 1 160px; margin-top: 0; }

.segmented { display: inline-flex; background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; flex: 1 1 240px; }
.segmented button {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  font: 600 .85rem "Open Sans", sans-serif; color: var(--muted); padding: 0 .5rem; white-space: nowrap;
}
.segmented button.active { background: var(--ink); color: #fff; }
.segmented-block { display: flex; width: 100%; }
.segmented-block button.active { background: var(--red); }

/* ---------- Lista prenotazioni ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.group-title {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 14px 2px 2px; padding-bottom: 4px; border-bottom: 2px solid var(--red);
  font: 900 .95rem "Roboto", sans-serif; text-transform: uppercase; color: var(--ink); letter-spacing: .03em;
}
.group-title span { font: 600 .8rem "Open Sans", sans-serif; color: var(--muted); text-transform: none; letter-spacing: 0; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; align-items: stretch; overflow: hidden; border-left: 5px solid var(--red);
}
.card.paid { border-left-color: var(--green); }
.card.free { border-left-color: var(--line); }
.card-main { flex: 1; min-width: 0; padding: 12px 12px 12px 14px; cursor: pointer; background: none; border: 0; text-align: left; font: inherit; color: inherit; }
.card-name { font-weight: 700; color: var(--ink); font-size: 1.02rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { font: 700 .68rem "Roboto", sans-serif; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 999px; background: var(--ink); color: #fff; }
.badge-yellow { background: var(--yellow); color: var(--ink); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pill { font-size: .8rem; background: var(--bg); border-radius: 999px; padding: 2px 9px; color: var(--ink-2); }
.card-note { margin-top: 6px; font-size: .85rem; background: var(--amber-soft); border-radius: 8px; padding: 4px 8px; color: #6a5300; }
.card-side { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 6px; padding: 10px 12px 10px 4px; }
.card-total { font: 900 1.05rem "Roboto", sans-serif; color: var(--ink); white-space: nowrap; }
.pay-btn {
  min-height: 40px; min-width: 104px; border-radius: 999px; border: 2px solid var(--red); background: #fff; color: var(--red);
  font: 700 .78rem "Roboto", sans-serif; text-transform: uppercase; cursor: pointer; padding: 0 .7rem;
}
.pay-btn.paid { background: var(--green); border-color: var(--green); color: #fff; }
.pay-btn.free { border-color: var(--line); color: var(--muted); cursor: default; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }

/* ---------- Riepilogo ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.kpi-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 1.6rem; font-weight: 900; color: var(--ink); line-height: 1.15; margin-top: 2px; }
.kpi-sub { font-size: .8rem; color: var(--muted); }
.kpi.accent { background: var(--red); color: #fff; }
.kpi.accent .kpi-label, .kpi.accent .kpi-sub { color: rgba(255,255,255,.85); }
.kpi.accent .kpi-value { color: #fff; }
.kpi.ok .kpi-value { color: var(--green); }
.kpi.warn .kpi-value { color: var(--red); }
.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--green); border-radius: 999px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.section-title { font: 900 1rem "Roboto", sans-serif; text-transform: uppercase; color: var(--ink); margin: 22px 2px 8px; letter-spacing: .03em; }
.table-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
th { font: 700 .72rem "Roboto", sans-serif; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #faf8f8; }
@media (max-width: 480px) { .opt { display: none; } th, td { padding: 9px 7px; } }
tfoot td { font-weight: 700; color: var(--ink); border-bottom: 0; background: #faf8f8; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions .btn { flex: 1 1 200px; }

/* ---------- FAB & tabbar ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + 18px + var(--safe-b)); z-index: 30;
  width: 60px; height: 60px; border-radius: 50%; border: 3px solid var(--yellow);
  background: var(--red); color: #fff; font-size: 2rem; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 18px rgba(205, 26, 26, .4);
}
.fab:active { transform: scale(.95); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; background: var(--ink); padding-bottom: var(--safe-b);
  border-top: 3px solid var(--red);
}
.tabbar button {
  flex: 1; height: var(--tabbar-h); background: none; border: 0; color: rgba(255,255,255,.65); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .74rem; font-weight: 500; text-transform: uppercase; letter-spacing: .04em;
}
.tabbar .ico { font-size: 1.25rem; filter: grayscale(1); opacity: .8; }
.tabbar button.active { color: #fff; box-shadow: inset 0 3px 0 var(--yellow); }
.tabbar button.active .ico { filter: none; opacity: 1; }

/* ---------- Bottom sheet ---------- */
.sheet {
  border: 0; padding: 0; width: 100%; max-width: 560px; max-height: 92dvh;
  margin: auto auto 0; border-radius: 20px 20px 0 0; background: #fff; color: inherit;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
.sheet::backdrop { background: rgba(36, 28, 28, .55); }
.sheet[open] { animation: slide-up .2s ease-out; display: flex; }
.sheet form { display: flex; flex-direction: column; width: 100%; max-height: 92dvh; }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 4px solid var(--red); }
.sheet-head h2 { margin: 0; font-size: 1.1rem; font-weight: 900; text-transform: uppercase; color: var(--ink); }
.btn-close { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--bg); font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--ink); }
.sheet-body { overflow-y: auto; padding: 12px 16px 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); background: #fff; }
.sheet-foot .btn-primary { flex: 1; }

.steppers { margin-top: 1rem; display: flex; flex-direction: column; gap: 8px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--bg); border-radius: 12px; padding: 8px 8px 8px 12px; }
.stepper.disabled { opacity: .4; pointer-events: none; }
.stepper-label { font-weight: 600; color: var(--ink); font-size: .92rem; }
.stepper-label small { display: block; font-weight: 400; color: var(--muted); }
.stepper-ctrl { display: flex; align-items: center; gap: 6px; }
.stepper-ctrl button {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--red); background: #fff; color: var(--red);
  font-size: 1.4rem; line-height: 1; cursor: pointer; font-weight: 700;
}
.stepper-ctrl button[data-step="1"] { background: var(--red); color: #fff; }
.stepper-ctrl output { min-width: 32px; text-align: center; font: 900 1.25rem "Roboto", sans-serif; color: var(--ink); }

.total-box { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--ink); color: #fff; }
.total-box strong { font: 900 1.35rem "Roboto", sans-serif; color: var(--yellow); }

.switch { display: flex; align-items: center; gap: 12px; margin-top: 14px; cursor: pointer; font-size: 1rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { width: 52px; height: 30px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .switch-ui { background: var(--green); }
.switch input:checked + .switch-ui::after { transform: translateX(22px); }
.switch input:focus-visible + .switch-ui { outline: 3px solid rgba(205,26,26,.35); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red-dark); }

/* ---------- Stampa ---------- */
@media print {
  .topbar, .tabbar, .fab, .toolbar, .actions, .toast { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .card, .kpi, .table-wrap { box-shadow: none; border: 1px solid #ccc; }
}
