/* ============================================================
   Gestionale Palestra — stile (mobile first)
   ============================================================ */
:root {
  --accent: #ff5a1f;
  --accent-2: color-mix(in srgb, var(--accent) 12%, #fff);
  --accent-3: color-mix(in srgb, var(--accent) 22%, #fff);
  --accent-dark: color-mix(in srgb, var(--accent) 72%, #000);
  --on-accent: #fff;
  --bg: #f3f4f8; --surface: #ffffff; --surface-2: #f7f8fb; --border: #e6e8ef; --border-2: #d9dce6;
  --text: #171a26; --muted: #6b7185;
  --side: #121521; --side-2: #1b2031; --side-text: #b8bdcc;
  --ok: #1f9d55; --ok-bg: #e7f6ee; --warn: #d97706; --warn-bg: #fff4e0;
  --bad: #e11d48; --bad-bg: #fde8ee; --info: #2563eb; --info-bg: #e8effd;
  --radius: 16px; --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 6px 20px -10px rgba(20, 24, 40, .18);
  --shadow-lg: 0 18px 40px -18px rgba(20, 24, 40, .35);
  --bottom-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent-2: color-mix(in srgb, var(--accent) 18%, #151923);
    --accent-3: color-mix(in srgb, var(--accent) 30%, #151923);
    --bg: #0d1017; --surface: #151923; --surface-2: #1b202c; --border: #262c3a; --border-2: #323a4c;
    --text: #e8eaf0; --muted: #9aa1b3;
    --side: #0a0c12; --side-2: #161a25;
    --ok: #34d399; --ok-bg: #0f2a20; --warn: #fbbf24; --warn-bg: #2d2410;
    --bad: #fb7185; --bad-bg: #3a1622; --info: #60a5fa; --info-bg: #13233d;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 18px 40px -18px rgba(0,0,0,.8);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--text); overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; }
h3 { font-size: .98rem; }
small, .muted { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; font-size: .88em; word-break: break-all; }
.ic { width: 20px; height: 20px; flex-shrink: 0; }

/* ------------------------------------------------ brand */
.brand { display: flex; align-items: center; gap: 11px; font-weight: 750; color: inherit; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 10px; background: #fff; padding: 3px; flex-shrink: 0; }
.brand-tile { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 80%, #fff), var(--accent-dark)); color: #fff;
  box-shadow: 0 6px 16px -6px var(--accent); }
.brand-tile .ic { width: 22px; height: 22px; stroke-width: 2.2; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .82rem;
  background: var(--accent-3); color: var(--accent-dark); flex-shrink: 0; }
.avatar:hover { text-decoration: none; }

/* ------------------------------------------------ layout desktop */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 252px; background: linear-gradient(180deg, var(--side), var(--side-2)); color: var(--side-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; z-index: 60; }
.sidebar .brand { padding: 20px 18px 16px; color: #fff; font-size: 1.02rem; }
.sidebar nav { flex: 1; padding: 6px 12px; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; color: var(--side-text); padding: 10px 12px; border-radius: 11px; margin-bottom: 2px; font-weight: 500; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: color-mix(in srgb, var(--accent) 22%, transparent); color: #fff; }
.sidebar nav a.active .ic { color: var(--accent); }
.sidebar nav .sep { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #6c7389; padding: 16px 12px 6px; }
.side-foot { padding: 14px 14px 14px 18px; border-top: 1px solid rgba(255,255,255,.07); display: flex; align-items: center; gap: 10px; }
.side-foot .who { flex: 1; min-width: 0; font-size: .88rem; }
.side-foot .who b { color: #fff; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .avatar { background: rgba(255,255,255,.1); color: #fff; }
.icon-btn { background: none; border: 0; color: inherit; padding: 8px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255,255,255,.08); }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main { flex: 1; padding: 6px 30px 44px; width: 100%; max-width: 1480px; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 22px 0 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.55rem; margin: 0; flex: 1; min-width: 200px; font-weight: 750; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.appbar, .bottom-nav, .scrim, .only-mobile { display: none; }
.appbar-right { display: flex; align-items: center; gap: 4px; }
.appbar-right form { margin: 0; }
.appbar-logout { color: var(--muted); }
.appbar-logout .ic { width: 22px; height: 22px; }
.logout-big { margin-top: 18px; }

/* ------------------------------------------------ cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 18px; }
.grid > .card { margin-bottom: 0; }
.grid + .grid, .grid + .card, .card + .grid { margin-top: 18px; }
.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: grid; gap: 18px; align-content: start; }
.stack > .card { margin: 0; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
.stat .n { font-size: 1.85rem; font-weight: 780; line-height: 1.1; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: .84rem; }
.stat .ic { color: var(--accent); margin-bottom: 6px; width: 22px; height: 22px; }

/* hero (dashboard) */
.hero { position: relative; overflow: hidden; border-radius: 22px; padding: 26px 26px 22px; margin: 18px 0 18px; color: #fff;
  background: radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--accent) 70%, #fff) 0%, var(--accent) 38%, var(--accent-dark) 100%);
  box-shadow: 0 20px 40px -22px var(--accent); }
.hero::after { content: ""; position: absolute; right: -60px; bottom: -80px; width: 260px; height: 260px; border-radius: 50%;
  background: rgba(255,255,255,.08); }
.hero-top { display: flex; align-items: center; gap: 16px; position: relative; z-index: 1; }
.hero .brand-logo, .hero .brand-tile { width: 62px; height: 62px; border-radius: 16px; }
.hero .brand-tile { background: rgba(255,255,255,.18); box-shadow: none; }
.hero .brand-tile .ic { width: 34px; height: 34px; }
.hero h1 { margin: 0; font-size: 1.6rem; font-weight: 800; }
.hero-sub { opacity: .9; font-size: .95rem; }
.hero .hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; position: relative; z-index: 1; }
.hero .btn { background: rgba(255,255,255,.18); border-color: transparent; color: #fff; }
.hero .btn:hover { background: rgba(255,255,255,.28); }
.hero .btn-light { background: #fff; color: var(--accent-dark); }
.hero .btn-light:hover { background: #fff; filter: brightness(.96); }
.hero-stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; margin-top: 18px; position: relative; z-index: 1; }
.hero-stats.two { grid-template-columns: repeat(2, minmax(0,1fr)); max-width: 560px; }
.hero-stats div { background: rgba(255,255,255,.14); border-radius: 14px; padding: 10px 12px; backdrop-filter: blur(4px); }
.hero-stats b { display: block; font-size: 1.45rem; line-height: 1.15; }
.hero-stats small { color: rgba(255,255,255,.85); font-size: .78rem; }

/* ------------------------------------------------ buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  padding: 8px 15px; min-height: 38px; border-radius: 11px; font: inherit; font-size: .92rem; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1.2;
  transition: background .15s, filter .15s, transform .05s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn .ic { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: 0 6px 14px -8px var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: transparent; }
.btn-danger:hover { background: var(--bad-bg); }
.btn-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: transparent; }
.btn-ok:hover { background: var(--ok-bg); }
.btn-sm { padding: 5px 11px; min-height: 32px; font-size: .84rem; border-radius: 9px; }
.btn-xs { padding: 3px 9px; min-height: 28px; font-size: .78rem; border-radius: 8px; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; margin: 0; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------ forms */
label { display: block; font-size: .84rem; font-weight: 650; margin-bottom: 5px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=time], input[type=tel], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 10px 12px; min-height: 42px; border: 1px solid var(--border-2); border-radius: 11px; font: inherit; background: var(--surface); color: var(--text); }
input[type=file] { padding: 8px; }
select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7185' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
select[size] { background-image: none; padding-right: 12px; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 18px; height: 18px; }
textarea { min-height: 88px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; gap: 9px; align-items: center; font-weight: 500; }
.check input { flex-shrink: 0; margin: 0; }
.help { font-size: .8rem; color: var(--muted); margin-top: 4px; font-weight: 400; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips label { font-weight: 550; border: 1px solid var(--border-2); border-radius: 999px; padding: 7px 14px; cursor: pointer; margin: 0; display: flex; gap: 7px; align-items: center; }
.chips label:has(input:checked) { background: var(--accent-2); border-color: var(--accent); color: var(--accent-dark); }
.chips input { margin: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filters input[type=search] { min-width: 240px; }
.swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.swatches label { width: 36px; height: 36px; border-radius: 50%; cursor: pointer; margin: 0; position: relative; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.swatches label input { position: absolute; opacity: 0; }
.swatches label:has(input:checked) { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px currentColor; }

/* ------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }

/* ------------------------------------------------ badges & flash */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge-bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge-info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.badge-accent { background: var(--accent-2); color: var(--accent-dark); border-color: transparent; }
@media (prefers-color-scheme: dark) { .badge-accent, .avatar { color: var(--accent); } }
.flash { padding: 12px 16px; border-radius: 13px; margin-bottom: 14px; font-weight: 550; animation: pop .25s ease-out; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--bad-bg); color: var(--bad); }
.flash-warning { background: var(--warn-bg); color: var(--warn); }
.flash-info { background: var(--info-bg); color: var(--info); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.empty { color: var(--muted); padding: 22px 16px; text-align: center; border: 1.5px dashed var(--border-2); border-radius: 13px; }

.bar { height: 7px; background: color-mix(in srgb, var(--muted) 16%, transparent); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ok); border-radius: 999px; }
.bar.mid > span { background: var(--warn); }
.bar.full > span { background: var(--bad); }

/* ------------------------------------------------ calendario */
.cal-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cal-nav .range { font-weight: 700; margin: 0 6px; }
.day-strip { display: none; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 140px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.day.past { opacity: .7; }
.day-head { padding: 10px 11px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.day-head b { font-size: .9rem; }
.day-body { padding: 8px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.slot { border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 11px; padding: 8px 9px; background: var(--surface-2); font-size: .85rem; position: relative; }
.slot.mid { border-left-color: var(--warn); }
.slot.full { border-left-color: var(--bad); }
.slot.closed { border-left-color: var(--muted); opacity: .6; }
.slot.gone { opacity: .45; }
.slot.mine { background: var(--accent-2); border-color: color-mix(in srgb, var(--accent) 45%, transparent); border-left-color: var(--accent); }
.slot .time { font-weight: 750; }
.slot .title { color: var(--muted); font-size: .8rem; }
.slot .meta { display: flex; justify-content: space-between; align-items: center; margin: 4px 0; gap: 6px; }
.slot .names { font-size: .76rem; color: var(--muted); margin-top: 5px; line-height: 1.35; }
.slot .names span.att { color: var(--ok); }
.slot .names span.ns { color: var(--bad); text-decoration: line-through; }
.slot .act form { margin-top: 6px; }
.slot a.cover { color: inherit; display: block; }
.slot a.cover:hover { text-decoration: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* abbonamento */
.sub { border: 1px solid var(--border); border-radius: 14px; padding: 14px 15px; background: var(--surface-2); }
.sub + .sub { margin-top: 10px; }
.sub .top { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; }
.big { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }

/* liste compatte (prenotazioni ecc.) */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.date-chip { width: 50px; flex-shrink: 0; text-align: center; border-radius: 12px; background: var(--accent-2); color: var(--accent-dark); padding: 5px 0; line-height: 1.1; }
.date-chip small { display: block; color: inherit; font-size: .68rem; text-transform: uppercase; font-weight: 700; letter-spacing: .04em; }
.date-chip b { font-size: 1.25rem; }
@media (prefers-color-scheme: dark) { .date-chip { color: var(--accent); } }

/* schede */
.plan-day { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; background: var(--surface); overflow: hidden; box-shadow: var(--shadow); }
.plan-day > header { background: var(--surface-2); padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.plan-day > header h3 { margin: 0; flex: 1; }
.plan-day table td, .plan-day table th { padding: 9px 12px; }
.ex-table input { padding: 7px 9px; min-height: 38px; font-size: .9rem; }
.ex-table td { padding: 4px 4px; border-bottom: 0; }
.ex-table th { padding: 6px 4px; }
.ex-table .c-name { min-width: 180px; }
.ex-table .c-s { width: 70px; }
.ex-table .c-m { width: 100px; }
.ex-table .c-act { width: 104px; white-space: nowrap; }
.editor-day-head .day-name { font-weight: 650; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 550; }
.tabs a.active, .tabs a:hover { color: var(--text); border-bottom-color: var(--accent); text-decoration: none; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 7px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; }
.tpl-list { display: flex; flex-direction: column; gap: 8px; }
.tpl { border: 1px solid var(--border); border-radius: 13px; background: var(--surface-2); }
.tpl.off { opacity: .6; }
.tpl summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 11px 14px; font-weight: 500; }
.tpl summary::-webkit-details-marker { display: none; }
.tpl summary .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.tpl summary input { flex-shrink: 0; }
.tpl-edit { color: var(--muted); display: grid; }
.tpl[open] { background: var(--surface); border-color: var(--accent); }
.tpl[open] summary { border-bottom: 1px solid var(--border); margin-bottom: 0; }
.tpl form { padding: 14px; }
.sticky-save { position: sticky; bottom: 10px; z-index: 5; margin-top: 0; box-shadow: var(--shadow-lg); }
details summary { cursor: pointer; font-weight: 650; }
details[open] summary { margin-bottom: 10px; }

/* login */
.login-bg { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px;
  background: radial-gradient(90% 60% at 50% -10%, color-mix(in srgb, var(--accent) 55%, transparent), transparent 70%),
              radial-gradient(60% 50% at 100% 110%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 70%), var(--bg); }
.login-card { width: 100%; max-width: 400px; padding: 30px 26px; border-radius: 24px; box-shadow: var(--shadow-lg); }
.login-head { text-align: center; margin-bottom: 22px; }
.login-head .brand-logo, .login-head .brand-tile { width: 92px; height: 92px; border-radius: 24px; margin: 0 auto 14px; display: grid; }
.login-head .brand-logo { padding: 6px; box-shadow: var(--shadow); }
.login-head .brand-tile .ic { width: 50px; height: 50px; }
.login-head h1 { font-size: 1.5rem; margin: 0 0 4px; font-weight: 800; }
.login-head p { margin: 0; color: var(--muted); }
.logo-preview { width: 120px; height: 120px; border-radius: 22px; border: 1px solid var(--border); background: #fff; display: grid; place-items: center; overflow: hidden; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-preview .brand-logo { width: 100%; height: 100%; border-radius: 0; padding: 8px; background: transparent; }
.logo-preview .brand-tile { width: 100%; height: 100%; border-radius: 0; }
.logo-preview .brand-tile .ic { width: 56px; height: 56px; }

/* ------------------------------------------------ tablet */
@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .week { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ------------------------------------------------ smartphone */
@media (max-width: 860px) {
  body { font-size: 15.5px; }
  input, select, textarea { font-size: 16px !important; }   /* evita lo zoom automatico su iPhone */
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-105%); transition: transform .22s ease; width: 280px; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(10,12,20,.45); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .sidebar.open + .scrim { opacity: 1; pointer-events: auto; }
  .appbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; top: 0; z-index: 40;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px); border-bottom: 1px solid var(--border); }
  .appbar .brand { font-size: 1.02rem; }
  .appbar .brand-logo, .appbar .brand-tile { width: 34px; height: 34px; border-radius: 10px; }
  .bottom-nav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    height: calc(var(--bottom-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--border); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: .68rem; font-weight: 650; position: relative; }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav a .ic { width: 23px; height: 23px; }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav a.active::before { content: ""; position: absolute; top: 0; width: 30px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .main { padding: 0 14px calc(var(--bottom-h) + var(--safe-b) + 24px); }
  .topbar { padding: 16px 0 12px; gap: 10px; }
  .topbar h1 { font-size: 1.3rem; min-width: 0; flex-basis: 100%; }
  .topbar .actions { width: 100%; }
  .topbar .actions > .btn, .topbar .actions > form { flex: 1; }
  .topbar .actions > form .btn { width: 100%; }
  .card { padding: 16px; border-radius: 18px; margin-bottom: 14px; }
  .grid { gap: 14px; }
  .grid + .grid, .grid + .card, .card + .grid { margin-top: 14px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .n { font-size: 1.5rem; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .btn-xs { min-height: 32px; padding: 4px 11px; }
  .filters > div { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .filters > div:has(input[type=search]), .filters > div:only-child, .filters > button, .filters > .btn { flex: 1 1 100%; }
  .filters input[type=search] { min-width: 0; }
  .filters .check { flex: 1 1 100%; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .form-actions .btn { flex: 1; }
  .kv { grid-template-columns: 110px 1fr; }
  .hero { border-radius: 20px; padding: 20px 18px 16px; margin-top: 14px; }
  .hero h1 { font-size: 1.3rem; }
  .hero .brand-logo, .hero .brand-tile { width: 52px; height: 52px; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .hero .hero-actions .btn { flex: 1; }

  /* tabelle -> schede impilate (etichette aggiunte da app.js) */
  table.rt thead { display: none; }
  table.rt, table.rt tbody, table.rt tr, table.rt td { display: block; width: 100%; }
  table.rt tr { border: 1px solid var(--border); border-radius: 14px; padding: 8px 12px; margin-bottom: 10px; background: var(--surface-2); }
  table.rt tbody tr:hover { background: var(--surface-2); }
  table.rt td { border: 0; padding: 5px 0; display: flex; gap: 12px; justify-content: space-between; align-items: center; text-align: right; }
  table.rt td::before { content: attr(data-label); color: var(--muted); font-size: .76rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; text-align: left; flex-shrink: 0; }
  table.rt td[data-label=""]::before { display: none; }
  table.rt td:first-child { text-align: left; justify-content: flex-start; font-size: 1rem; }
  table.rt td:first-child::before { display: none; }
  table.rt td.num { justify-content: flex-end; }
  table.rt td:empty { display: none; }
  table.rt td .row-actions { justify-content: flex-end; }

  /* calendario: un giorno alla volta, con selettore giorni e swipe */
  .day-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; position: sticky; top: calc(55px + env(safe-area-inset-top, 0px)); z-index: 30;
    margin: 0 -14px 12px; padding: 8px 14px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
  .ds-item { border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 7px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 1px;
    font: inherit; color: var(--text); cursor: pointer; }
  .ds-item span { font-size: .66rem; text-transform: uppercase; color: var(--muted); font-weight: 700; letter-spacing: .04em; }
  .ds-item b { font-size: 1.12rem; line-height: 1.2; }
  .ds-item i { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
  .ds-item i.mid { background: var(--warn); } .ds-item i.full { background: var(--bad); } .ds-item i.none { background: transparent; }
  .ds-item.today { border-color: var(--accent); }
  .ds-item.sel { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 8px 16px -10px var(--accent); }
  .ds-item.sel span { color: rgba(255,255,255,.85); }
  .ds-item.sel i { background: #fff; }
  .ds-item.past:not(.sel) { opacity: .5; }
  .week { display: block; }
  .week .day { display: none; background: none; border: 0; box-shadow: none; min-height: 0; }
  .week .day.sel { display: block; animation: pop .2s ease-out; }
  .week .day.past { opacity: 1; }
  .day-head { padding: 2px 2px 10px; border: 0; }
  .day-head b { font-size: 1.05rem; }
  .day-body { padding: 0; gap: 10px; }
  .slot { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; padding: 13px 14px; border-radius: 15px; font-size: .92rem; background: var(--surface); box-shadow: var(--shadow); }
  .slot .time { font-size: 1.08rem; }
  .slot .bar { grid-column: 1 / -1; margin-top: 8px; }
  .slot .names { grid-column: 1 / -1; font-size: .82rem; }
  .slot .act { grid-row: 1 / span 3; grid-column: 2; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
  .slot .act form { margin: 0; }
  .slot .act .btn { min-height: 40px; padding: 8px 18px; font-size: .9rem; }
  .slot a.cover { display: contents; }
  .role-client .slot.gone { display: none; }
  .slot.gone { opacity: .5; }
  .only-mobile { display: block; }
  .cal-page { display: flex; flex-direction: column; }
  .cal-page > .cal-top { order: 1; }
  .cal-page > .day-strip { order: 2; }
  .cal-page > .week { order: 3; }
  .cal-page > .cal-subs { order: 4; margin-top: 16px; }
  .cal-top .legend span:not(.keep) { display: none; }
  .cal-top .legend { margin-top: 8px; }
  .cal-top .filters { width: 100%; }
  .cal-nav { width: 100%; justify-content: space-between; }
  .cal-nav .range { order: -1; flex-basis: 100%; margin: 0 0 4px; text-align: center; }
  .cal-nav .btn { flex: 1; }

  .sticky-save { bottom: calc(var(--bottom-h) + var(--safe-b) + 8px); }
  .sticky-save .btn-ghost { display: none; }
  /* editor schede */
  .ex-table thead { display: none; }
  .ex-table, .ex-table tbody { display: block; }
  .ex-table tr { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-2); }
  .ex-table td { padding: 0; width: auto !important; min-width: 0 !important; }
  .ex-table td.c-name { grid-column: 1 / -1; }
  .ex-table td:nth-child(6) { grid-column: 1 / -1; }
  .ex-table td.c-act { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 6px; }
  .plan-day > header > div { min-width: 100% !important; }
}
@media (max-width: 380px) {
  .form-grid { grid-template-columns: 1fr; }
  .ex-table tr { grid-template-columns: repeat(2, 1fr); }
}

@media print {
  .sidebar, .appbar, .bottom-nav, .topbar .actions, .no-print, .flash { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; color: #000; }
  .card, .plan-day { box-shadow: none; break-inside: avoid; }
}
