:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --text: #0f1b2d;
  --muted: #5d6b80;
  --line: #e2e7ef;
  --brand: #0e4da4;
  --brand-strong: #0a3a7d;
  --brand-soft: #e7effb;
  --green: #12a150;
  --red: #d62839;
  --luce: #f2a900;
  --luce-soft: #fff6dc;
  --gas: #0b8fd6;
  --gas-soft: #e2f3fc;
  --tel: #6c4cdb;
  --tel-soft: #eee9fc;
  --agenda: #12a150;
  --agenda-soft: #e3f6ea;
  --contatti: #e0612f;
  --contatti-soft: #fdebe3;
  --danger: #c62835;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .05), 0 6px 20px rgba(15, 27, 45, .06);
  --header-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c121c;
    --surface: #151d2a;
    --surface-2: #1b2534;
    --text: #e9eef6;
    --muted: #9aa8bc;
    --line: #263247;
    --brand: #4d8ef0;
    --brand-strong: #78a9f5;
    --brand-soft: #18263d;
    --luce-soft: #2c2512;
    --gas-soft: #10283a;
    --tel-soft: #221c3d;
    --agenda-soft: #12291d;
    --contatti-soft: #33201a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
svg.i { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .02em; color: var(--text); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; }
.brand-name { font-size: 17px; line-height: 1; }
.brand-name b { color: var(--brand); }
.brand-name small { display: block; font-size: 10px; letter-spacing: .24em; color: var(--muted); font-weight: 700; margin-top: 3px; }
.icon-btn {
  position: relative; width: 42px; height: 42px; border-radius: 12px; border: 0;
  background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.badge {
  position: absolute; top: 5px; right: 5px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; border: 2px solid var(--surface);
}

/* ---------- Layout ---------- */
main {
  max-width: 980px; margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) calc(110px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; line-height: 1.15; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 2px 10px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty svg.i { width: 34px; height: 34px; opacity: .55; margin-bottom: 6px; }

/* ---------- Tiles home ---------- */
.tiles-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tile {
  --c: var(--brand); --soft: var(--brand-soft);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 14px;
  min-height: 128px; padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  color: var(--text); cursor: pointer; text-align: left; transition: transform .12s ease, box-shadow .12s ease;
}
.tile:active { transform: scale(.98); }
@media (hover: hover) { .tile:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(15, 27, 45, .1); } }
.tile .ico { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--soft); color: var(--c); }
.tile .ico svg.i { width: 26px; height: 26px; }
.tile strong { font-size: 18px; letter-spacing: .02em; }
.tile span.sub { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.tile.luce { --c: var(--luce); --soft: var(--luce-soft); }
.tile.gas { --c: var(--gas); --soft: var(--gas-soft); }
.tile.tel { --c: var(--tel); --soft: var(--tel-soft); }
.tile.agenda { --c: var(--agenda); --soft: var(--agenda-soft); }
.tile.contatti { --c: var(--contatti); --soft: var(--contatti-soft); }
.tile.wide { flex-direction: row; align-items: center; min-height: 84px; width: 100%; }
.tile.wide .grow { flex: 1; }
.tile.wide .chev { color: var(--muted); }
.stack { display: grid; gap: 12px; margin-top: 12px; }
.tiles-admin { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 720px) {
  .tiles-admin { grid-template-columns: repeat(3, 1fr); }
  .stack.two { grid-template-columns: 1fr 1fr; }
  .tile { min-height: 150px; padding: 20px; }
}
@media (max-width: 380px) {
  .tiles-3 { gap: 8px; }
  .tile { padding: 12px; min-height: 112px; }
  .tile strong { font-size: 15px; }
  .tile .ico { width: 40px; height: 40px; }
}
.tile .count { font-size: 13px; color: var(--muted); }

.hello { margin: 2px 0 18px; }
.hello h1 { margin: 0; font-size: 26px; }
.hello p { margin: 2px 0 0; color: var(--muted); text-transform: capitalize; }

.today {
  display: flex; gap: 14px; align-items: center; padding: 14px 16px; margin-bottom: 16px;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: #fff;
  border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; border: 0; width: 100%; text-align: left;
}
.today .num { font-size: 30px; font-weight: 800; line-height: 1; min-width: 44px; text-align: center; }
.today .grow { flex: 1; }
.today small { opacity: .85; display: block; }

/* ---------- Search ---------- */
.search { position: relative; margin-bottom: 16px; }
.search svg.i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 20px; height: 20px; }
.search input {
  width: 100%; height: 50px; padding: 0 16px 0 44px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); outline: none;
}
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }

/* ---------- Provider grid ---------- */
.prov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.prov {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 12px; text-align: center;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  cursor: pointer; color: var(--text); transition: transform .12s ease;
}
.prov:active { transform: scale(.98); }
.prov .avatar { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #fff; }
.prov strong { font-size: 16px; }
.prov .cat { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.dots { display: flex; gap: 6px; }
.dot-label { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.dot-label.on { background: var(--agenda-soft); color: var(--green); border-color: transparent; }

.segments { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .segments { grid-template-columns: 1fr; } }
.segment {
  display: flex; align-items: center; gap: 16px; padding: 22px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text); cursor: pointer; text-align: left;
}
.segment .ico { width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.segment .ico svg.i { width: 30px; height: 30px; }
.segment strong { font-size: 20px; letter-spacing: .04em; display: block; }
.segment small { color: var(--muted); }
.segment.off { opacity: .55; cursor: default; }
.provider-hero { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.provider-hero .avatar { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; font-weight: 800; font-size: 24px; color: #fff; }
.provider-hero h1 { margin: 0; font-size: 26px; }
.provider-hero p { margin: 2px 0 0; color: var(--muted); }

/* ---------- Agenda ---------- */
.week { display: grid; grid-template-columns: 36px repeat(7, 1fr) 36px; gap: 4px; align-items: center; padding: 10px 8px; }
.week .day {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; border-radius: 12px;
  border: 0; background: transparent; cursor: pointer; color: var(--text);
}
.week .day small { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.week .day b { font-size: 18px; }
.week .day i { width: 6px; height: 6px; border-radius: 3px; background: transparent; }
.week .day.has i { background: var(--brand); }
.week .day.today b { color: var(--brand); }
.week .day.sel { background: var(--brand); color: #fff; }
.week .day.sel small, .week .day.sel b { color: #fff; }
.week .day.sel i { background: #fff; }
.week .nav { width: 36px; height: 36px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.week .nav:hover { background: var(--surface-2); }
.agenda-date { display: flex; align-items: center; justify-content: space-between; margin: 18px 2px 8px; gap: 8px; }
.agenda-date h2 { margin: 0; font-size: 19px; text-transform: capitalize; }
.list { display: grid; gap: 10px; }
.item {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
}
.item .time { min-width: 52px; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; padding-top: 1px; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 650; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; white-space: pre-line; }
.item .actions { display: flex; gap: 2px; }
.item.done .title { text-decoration: line-through; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); text-transform: uppercase; letter-spacing: .04em; vertical-align: 2px; margin-left: 6px; }
.chip.green { background: var(--agenda-soft); color: var(--green); }
.chip.gray { background: var(--surface-2); color: var(--muted); }
.chip.fb { background: #e7f0fe; color: #1877f2; }
.chip.red { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.check {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; flex: none; color: #fff; padding: 0;
}
.check.on { background: var(--green); border-color: var(--green); }
.check svg.i { width: 16px; height: 16px; stroke-width: 3; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 650; cursor: pointer; white-space: nowrap;
}
.btn svg.i { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.danger { color: var(--danger); }
.btn.small { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.fab {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 15;
  height: 56px; padding: 0 22px; border-radius: 28px; border: 0; background: var(--brand); color: #fff;
  font-weight: 700; display: flex; align-items: center; gap: 8px; box-shadow: 0 10px 24px rgba(14, 77, 164, .35); cursor: pointer;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 14px; font-weight: 650; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); outline: none; font-size: 16px;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); background: var(--surface); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg-toggle { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg-toggle button { border: 0; background: transparent; height: 40px; border-radius: 9px; font-weight: 650; cursor: pointer; color: var(--muted); }
.seg-toggle button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 2px; }
.tabs button { border: 1px solid var(--line); background: var(--surface); height: 40px; padding: 0 16px; border-radius: 99px; font-weight: 650; cursor: pointer; white-space: nowrap; color: var(--muted); }
.tabs button.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.hint { color: var(--muted); font-size: 14px; }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--text); margin-bottom: 16px; font-size: 14px; }
.notice svg.i { color: var(--brand); }

/* ---------- Collegamento Facebook ---------- */
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.guide ol { margin: 0; padding-left: 22px; display: grid; gap: 10px; }
.guide li { padding-left: 4px; }
.guide code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 13px; }
.guide .hint { margin-top: 4px; }

/* ---------- Admin lists ---------- */
.rows { display: grid; gap: 10px; }
.rowcard { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); }
.rowcard .top { display: flex; align-items: center; gap: 12px; }
.rowcard .top .grow { flex: 1; min-width: 0; }
.rowcard .name { font-weight: 700; overflow-wrap: anywhere; }
.rowcard .sub { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
@media (max-width: 520px) { .slots { grid-template-columns: 1fr; } }
.slot { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); }
.slot.on { border-style: solid; }
.slot .label { font-size: 12px; font-weight: 800; letter-spacing: .1em; color: var(--muted); }
.slot .file { font-size: 14px; margin: 4px 0 10px; overflow-wrap: anywhere; }
.contact-line { display: flex; align-items: center; gap: 10px; padding: 8px 0; color: var(--text); }
.contact-line svg.i { color: var(--brand); width: 20px; height: 20px; }
.contact-line + .contact-line { border-top: 1px solid var(--line); }

/* ---------- Sheet / modal ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(8, 14, 24, .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 16px; font-size: 20px; }
.sheet .foot { display: flex; gap: 10px; margin-top: 6px; }
.sheet .foot .btn { flex: 1; }
@media (min-width: 640px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 22px; padding-bottom: 22px; }
  .sheet .grab { display: none; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--surface); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px); animation: up .2s ease;
}

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), transparent), var(--bg); }
.auth .card { width: 100%; max-width: 400px; padding: 28px 22px; }
.auth .logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; text-align: center; }
.auth .logo img { width: 76px; height: 76px; border-radius: 22px; box-shadow: var(--shadow); }
.auth .logo h1 { margin: 0; font-size: 24px; letter-spacing: .03em; }
.auth .logo h1 b { color: var(--brand); }
.auth .logo p { margin: 0; color: var(--muted); font-size: 14px; letter-spacing: .2em; font-weight: 700; }
.flag { display: flex; height: 4px; width: 54px; border-radius: 2px; overflow: hidden; }
.flag i { flex: 1; } .flag i:nth-child(1) { background: #12a150; } .flag i:nth-child(2) { background: #fff; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); } .flag i:nth-child(3) { background: #d62839; }

.divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.passkey-list { margin-top: 12px; border-top: 1px solid var(--line); }
.passkey-list .grow { flex: 1; min-width: 0; }
#quickLogin svg.i { width: 22px; height: 22px; }

.loading { min-height: 60vh; display: grid; place-items: center; color: var(--muted); }

@media print { .topbar, .fab { display: none; } }
