/* BNI Agenda — stile mobile-first, sobrio, tema chiaro/scuro */

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #e3e0d8;
  --text: #1d1c1a;
  --muted: #6b675f;
  --faint: #9a958b;
  --accent: #b3122b;
  --accent-ink: #ffffff;
  --accent-soft: #fbe9ec;
  --green: #1f7a4d;   --green-soft: #e3f3ea;
  --blue: #1f5fa8;    --blue-soft: #e5eef9;
  --amber: #9a6100;   --amber-soft: #fcf1dc;
  --red: #b3261e;     --red-soft: #fbe6e4;
  --gray: #5f5b54;    --gray-soft: #ecebe7;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(30, 25, 15, .05), 0 4px 16px rgba(30, 25, 15, .05);
  --nav-h: 64px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1d1c1a;
    --surface-2: #262522;
    --border: #34322e;
    --text: #efece6;
    --muted: #a9a49a;
    --faint: #7d786f;
    --accent: #e0455c;
    --accent-soft: #3a1c21;
    --green: #5cc58f;   --green-soft: #1b3326;
    --blue: #7fb0ec;    --blue-soft: #1a2940;
    --amber: #e5b04f;   --amber-soft: #3a2e17;
    --red: #f07f76;     --red-soft: #3d1f1c;
    --gray: #b8b3a9;    --gray-soft: #2c2b28;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

/* Tema scuro scelto a mano */
:root[data-theme="dark"] {
  --bg: #141312;
  --surface: #1d1c1a;
  --surface-2: #262522;
  --border: #34322e;
  --text: #efece6;
  --muted: #a9a49a;
  --faint: #7d786f;
  --accent: #e0455c;
  --accent-soft: #3a1c21;
  --green: #5cc58f;   --green-soft: #1b3326;
  --blue: #7fb0ec;    --blue-soft: #1a2940;
  --amber: #e5b04f;   --amber-soft: #3a2e17;
  --red: #f07f76;     --red-soft: #3d1f1c;
  --gray: #b8b3a9;    --gray-soft: #2c2b28;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  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.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img, svg { max-width: 100%; }
/* Icone inline: dimensione del testo, salvo regole più specifiche dei componenti */
svg:not([width]) { width: 1.1em; height: 1.1em; vertical-align: -.18em; flex: none; }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.pre { white-space: pre-wrap; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ---- Struttura ---------------------------------------------------------- */

.shell { min-height: 100vh; }
.main {
  width: 100%;
  max-width: 2200px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom));
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar-inner { max-width: 2200px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: .8rem; font-weight: 800; letter-spacing: .02em;
}
.topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none;
}
.icon-btn svg { width: 20px; height: 20px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .9rem; margin-bottom: 6px; }

/* Navigazione in basso (telefono) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--nav-h); text-decoration: none; color: var(--faint); font-size: .7rem; font-weight: 600; position: relative;
}
.bottom-nav a svg { width: 23px; height: 23px; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav .dot {
  position: absolute; top: 9px; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: .65rem; display: grid; place-items: center;
}

/* Barra laterale (desktop) */
.side-nav { display: none; }
@media (min-width: 900px) {
  .bottom-nav { display: none; }
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .side-nav {
    display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh;
    padding: 20px 14px; border-right: 1px solid var(--border); background: var(--surface);
  }
  .side-nav .brand { padding: 4px 10px 18px; }
  .side-nav a.nav-link {
    display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 10px;
    text-decoration: none; color: var(--muted); font-weight: 550; font-size: .95rem;
  }
  .side-nav a.nav-link svg { width: 19px; height: 19px; }
  .side-nav a.nav-link:hover { background: var(--surface-2); color: var(--text); }
  .side-nav a.nav-link.active { background: var(--accent-soft); color: var(--accent); }
  .side-nav .nav-sep { height: 1px; background: var(--border); margin: 10px 8px; }
  .side-nav .count { margin-left: auto; font-size: .75rem; background: var(--accent); color: var(--accent-ink); border-radius: 9px; padding: 0 7px; }
  .topbar { display: none; }
  .main { padding: 28px clamp(24px, 3vw, 56px) 48px; }
}

/* ---- Componenti --------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head a { font-size: .88rem; color: var(--muted); text-decoration: none; white-space: nowrap; }
.card.flush { padding: 0; }
/* Angoli arrotondati senza overflow:hidden, che taglierebbe i menu a tendina */
.card.flush > :first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.card.flush > :last-child, .card.flush > .list > li:last-child > .item { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.card.flush > .table-wrap { border-radius: var(--radius); }
.card.flush > .card-head { padding: 14px 16px 0; }
.card.accent { border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); background: linear-gradient(0deg, var(--surface), color-mix(in srgb, var(--accent-soft) 40%, var(--surface))); }

.grid { display: grid; gap: 16px; }
@media (min-width: 720px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-decoration: none; color: inherit; }
a.item:hover { background: var(--surface-2); }
.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: .86rem; overflow: hidden; text-overflow: ellipsis; }
.item-side { text-align: right; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.card:not(.flush) .item { padding-left: 0; padding-right: 0; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: .85rem; letter-spacing: .02em;
}
.avatar.lg { width: 64px; height: 64px; font-size: 1.3rem; }
.avatar.green { background: var(--green-soft); color: var(--green); }
.avatar.blue { background: var(--blue-soft); color: var(--blue); }
.avatar.amber { background: var(--amber-soft); color: var(--amber); }
.avatar.red { background: var(--red-soft); color: var(--red); }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 650; background: var(--gray-soft); color: var(--gray); white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* Pulsanti */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: .93rem;
  text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.whatsapp { background: #1f8f4e; border-color: #1f8f4e; color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--red); }
.btn.sm { min-height: 34px; padding: 0 11px; font-size: .85rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn[disabled], .btn.loading { opacity: .6; pointer-events: none; }
.btn.loading::after {
  content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row.end { justify-content: flex-end; }
form.inline { display: inline; margin: 0; }

/* Azioni */
.action { display: flex; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--border); }
.action:first-child { border-top: 0; }
.action-icon {
  width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted);
}
.action-icon svg { width: 19px; height: 19px; }
.action-icon.cadence { background: var(--blue-soft); color: var(--blue); }
.action-icon.no_reply { background: var(--amber-soft); color: var(--amber); }
.action-icon.missing_note { background: var(--accent-soft); color: var(--accent); }
.action-icon.followup { background: var(--green-soft); color: var(--green); }
.action-body { flex: 1; min-width: 0; }
.action-title { font-weight: 600; }
.action-detail { color: var(--muted); font-size: .86rem; margin-bottom: 8px; }
.action.removing { opacity: 0; transform: translateX(20px); transition: all .25s; }

details.menu { position: relative; display: inline-block; }
details.menu > summary { list-style: none; cursor: pointer; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu .menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
  padding: 6px;
}
.menu-panel button, .menu-panel a {
  display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; border-radius: 8px;
  background: none; font: inherit; font-size: .9rem; color: var(--text); cursor: pointer; text-decoration: none;
}
.menu-panel button:hover, .menu-panel a:hover { background: var(--surface-2); }
.menu-panel .menu-row { display: flex; gap: 6px; padding: 6px; }
.menu-panel input { flex: 1; }

/* Statistiche */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .95rem; color: var(--muted); font-weight: 600; }
.stat-label { color: var(--muted); font-size: .83rem; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.progress.green > span { background: var(--green); }

/* Moduli */
label, .label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
textarea.tall { min-height: 220px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
.row { display: grid; gap: 12px; }
@media (min-width: 560px) { .row-2 { grid-template-columns: 1fr 1fr; } .row-3 { grid-template-columns: repeat(3, 1fr); } }
.check { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
fieldset { border: 0; margin: 0 0 14px; padding: 0; }
legend { font-weight: 600; font-size: .88rem; margin-bottom: 6px; padding: 0; }

/* Scala 1–5 */
.scale { display: flex; gap: 6px; }
.scale input { position: absolute; opacity: 0; pointer-events: none; }
.scale label {
  flex: 1; min-width: 40px; height: 42px; margin: 0; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 650; color: var(--muted);
}
.scale input:checked + label { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.scale input:focus-visible + label { outline: 2px solid var(--accent); }

/* Chip e schede */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); text-decoration: none; font-size: .86rem; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { font-size: .75rem; opacity: .7; }

/* Avvisi */
.flash-stack { position: fixed; left: 12px; right: 12px; top: calc(env(safe-area-inset-top) + 12px); z-index: 100; display: grid; gap: 8px; max-width: 520px; margin: 0 auto; }
.flash {
  padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,.12); font-size: .92rem; display: flex; gap: 10px; align-items: flex-start;
  animation: flashIn .25s ease-out;
}
.flash.success { border-left: 4px solid var(--green); }
.flash.error { border-left: 4px solid var(--red); }
.flash.warning { border-left: 4px solid var(--amber); }
.flash.info { border-left: 4px solid var(--blue); }
.flash button { margin-left: auto; background: none; border: 0; color: var(--faint); cursor: pointer; font-size: 1.1rem; line-height: 1; }
@keyframes flashIn { from { opacity: 0; transform: translateY(-8px); } }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); color: var(--muted); font-size: .9rem; margin-bottom: 14px; }
.notice.amber { background: var(--amber-soft); color: var(--amber); }
.notice.accent { background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty svg { width: 36px; height: 36px; color: var(--faint); margin-bottom: 6px; }

/* Tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
td.r, th.r { text-align: right; }
tfoot td { font-weight: 700; border-bottom: 0; }

/* Timeline scheda membro */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 8px; bottom: -8px; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--faint); }
.timeline li.done::after { border-color: var(--green); background: var(--green); }
.timeline li.upcoming::after { border-color: var(--accent); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.note-block { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: .92rem; }
.note-block strong { display: block; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }

.ai-box { border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--border)); background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface)); border-radius: 12px; padding: 12px 14px; }
.ai-box .label { color: var(--accent); }

/* Calendario slot */
.week { margin-bottom: 18px; }
.week-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.day-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.day-label { width: 76px; flex: none; font-weight: 650; font-size: .9rem; }
.day-label small { display: block; color: var(--muted); font-weight: 500; }
.day-slots { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.slot-pill { padding: 6px 10px; border-radius: 9px; font-size: .84rem; font-weight: 600; border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: inherit; }
.slot-pill.free { border-color: color-mix(in srgb, var(--green) 45%, var(--border)); color: var(--green); background: var(--green-soft); }
.slot-pill.busy { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.slot-pill.closed, .slot-pill.past { color: var(--faint); text-decoration: line-through; background: var(--surface-2); }
.slot-pill.too_soon { color: var(--amber); background: var(--amber-soft); border-color: transparent; }

/* Pagina pubblica */
.public-body { background: var(--bg); }
.public-wrap { max-width: 620px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 28px) 16px 48px; }
.public-head { text-align: center; margin-bottom: 26px; }
.public-head .brand-mark { width: 46px; height: 46px; border-radius: 13px; margin: 0 auto 14px; font-size: 1rem; }
.public-head h1 { font-size: 1.6rem; }
.public-head p { color: var(--muted); max-width: 32rem; margin: 10px auto 0; }
.slot-list { display: grid; gap: 8px; }
.slot-option { position: relative; }
.slot-option input { position: absolute; opacity: 0; }
.slot-option label {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; padding: 14px 16px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500;
}
.slot-option label:hover { border-color: var(--faint); }
.slot-option input:checked + label { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; background: var(--accent-soft); }
.slot-option input:focus-visible + label { outline: 2px solid var(--accent); }
.slot-date { font-weight: 650; }
.slot-meta { color: var(--muted); font-size: .86rem; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; margin: 22px 0 10px; }
.success-panel { text-align: center; padding: 28px 18px; }
.success-panel .check-circle { width: 58px; height: 58px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: grid; place-items: center; margin: 0 auto 12px; }
.success-panel .check-circle svg { width: 30px; height: 30px; }
.public-foot { text-align: center; color: var(--faint); font-size: .8rem; margin-top: 28px; }

.login-card { max-width: 400px; margin: 10vh auto 0; }

/* Utilità */
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.hidden { display: none !important; }
.stack > * + * { margin-top: 8px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-1 { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Pannello "Altro" su telefono */
dialog.sheet {
  border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%;
  border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .35); }
.sheet-inner { padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet .item { padding-left: 0; padding-right: 0; }

/* Colonna principale + laterale solo quando c'è spazio per entrambe */
@media (min-width: 1100px) {
  .grid-main { grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); align-items: start; }
}

/* Schermi larghi: più colonne, niente spazi vuoti ai lati */
.grid > * { min-width: 0; }
@media (min-width: 1400px) {
  .grid-main { grid-template-columns: minmax(0, 2.2fr) minmax(340px, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1800px) {
  .grid-2 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 2.6fr) minmax(380px, 1fr); }
}
td select { min-width: 175px; width: auto; }
td a { text-decoration: none; font-weight: 550; }
td a:hover { text-decoration: underline; }

/* Selettore del tema */
.theme-toggle { display: inline-flex; align-items: center; gap: 8px; }
.theme-toggle .ti { display: none; }
:root[data-theme-choice="auto"] .theme-toggle .ti-auto,
:root:not([data-theme-choice]) .theme-toggle .ti-auto,
:root[data-theme-choice="light"] .theme-toggle .ti-light,
:root[data-theme-choice="dark"] .theme-toggle .ti-dark { display: inline-flex; }
td.r, th.r { white-space: nowrap; }
.theme-toggle .ti { align-items: center; gap: 8px; }
.side-nav .theme-toggle { justify-content: flex-start; color: var(--muted); }

/* Menu a tendina: sopra tutto, e verso l'alto quando sotto non c'è spazio */
details.menu[open] { z-index: 40; }
details.menu .menu-panel { z-index: 50; }
details.menu.up .menu-panel { top: auto; bottom: calc(100% + 6px); }
details.menu.left .menu-panel { right: auto; left: 0; }
details.menu .menu-panel { overflow-y: auto; overscroll-behavior: contain; }

/* Chat con l'assistente (presentazioni) */
@media (min-width: 1100px) { .sticky-side { position: sticky; top: 20px; } }
.ai-chat .card-head h2 { display: flex; align-items: center; gap: 8px; }
.chat-log { max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 2px; }
.chat-msg { padding: 9px 12px; border-radius: 12px; font-size: .9rem; line-height: 1.45; white-space: pre-wrap; max-width: 92%; }
.chat-msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.chat-msg.bot { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.chat-msg.error { background: var(--red-soft); color: var(--red); }
.chat-proposal { margin-top: 8px; padding: 8px 10px; border-radius: 9px; background: var(--surface); border: 1px dashed var(--border); font-size: .85rem; max-height: 180px; overflow-y: auto; }
.chat-actions { display: flex; gap: 6px; margin-top: 6px; }
.chat-msg.typing { color: var(--muted); font-style: italic; }
.btn.active-flag { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

/* Proposte del lunedì: compatte, il testo si apre al tocco */
details.pitch { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface); }
details.pitch > summary { list-style: none; cursor: pointer; display: block; }
details.pitch > summary::-webkit-details-marker { display: none; }
details.pitch .pitch-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
details.pitch .pitch-head strong { font-size: .95rem; }
details.pitch .pitch-preview { display: block; color: var(--muted); margin-top: 4px; }
details.pitch[open] .pitch-preview { display: none; }
details.pitch[open] > summary { padding-bottom: 8px; border-bottom: 1px solid var(--border); }
