/* ═══ Componenti riutilizzabili ═════════════════════════════════════════════ */

/* ─── Contenitori ─────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 16px; }
.stack > .card-title, .stack > .alert { margin-bottom: 0; }

/* ─── Pulsanti ────────────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: 700 15px/1.2 var(--font-ui);
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-small { width: auto; min-height: 40px; padding: 8px 14px; font-size: 14px; }

.btn-primary { background: var(--accent-strong); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #5b6af0; }
.btn-success { background: var(--green); color: #0a1a12; }
.btn-success:hover:not(:disabled) { background: #52d99a; }
.btn-warn { background: var(--amber); color: #1a0e00; }
.btn-warn:hover:not(:disabled) { background: #f5b070; }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }
.btn-danger { background: transparent; border-color: var(--border); color: var(--red); }
.btn-danger:hover:not(:disabled) { border-color: var(--red); background: var(--red-soft); }
.btn-danger-solid { background: var(--red); color: #1a0505; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s, color .15s;
}
.icon-btn:hover:not(:disabled), .icon-btn.is-active { border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { opacity: .3; cursor: default; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ─── Moduli ──────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* font-size 16px: evita lo zoom automatico di iOS quando si tocca un campo */
input, select {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: 16px var(--font-mono);
  color-scheme: dark;
  appearance: none;
  -webkit-appearance: none;
}
input::placeholder { color: var(--muted); opacity: .7; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a90b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
}
input[type="file"] { padding: 10px 14px; font-size: 14px; }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; padding: 0; flex-shrink: 0; accent-color: var(--accent); }

.pw { position: relative; }
.pw input { padding-right: 52px; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.pw-toggle:hover, .pw-toggle[aria-pressed="true"] { color: var(--accent); }

.check-group { border: 0; padding: 0; margin: 0; min-width: 0; }
.check-group legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }

/* ─── Messaggi ────────────────────────────────────────────────────────── */
.alert { padding: 11px 14px; border: 1px solid; border-radius: var(--radius-sm); font-size: 14px; }
.alert-error { background: var(--red-soft); border-color: rgba(240, 91, 91, .3); color: var(--red); }
.alert-info { background: var(--accent-soft); border-color: rgba(91, 106, 240, .3); color: #a9b1ff; }
.alert-warn { background: var(--amber-soft); border-color: rgba(240, 160, 80, .3); color: var(--amber); }

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  width: min(92vw, 420px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast { padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid; font-size: 14px; font-weight: 600; background: var(--surface-2); animation: toast-in .2s ease-out; }
.toast-success { border-color: rgba(62, 207, 142, .5); color: var(--green); }
.toast-error { border-color: rgba(240, 91, 91, .5); color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 900px) { .toasts { bottom: 24px; } }

/* ─── Chip, tab, badge ────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.scroll-x { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.scroll-x::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  min-height: 40px;
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font: 600 14px var(--font-ui);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.is-active { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.chip-admin { border-color: rgba(240, 160, 80, .35); }

.badge { margin-left: 4px; padding: 1px 7px; border-radius: 6px; background: var(--amber-soft); color: var(--amber); font-size: 11px; }

.segmented { display: flex; margin-bottom: 20px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg { flex: 1; min-height: 46px; border: 0; background: var(--surface-2); color: var(--muted); font: 700 14px var(--font-ui); cursor: pointer; }
.seg.is-active { background: var(--accent-strong); color: #fff; }

.tag { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.tag-warn { background: var(--amber-soft); color: var(--amber); }
.tag-star { background: var(--accent-soft); color: #a9b1ff; }
.tags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.star { color: var(--amber); }

/* ─── Caricamento ─────────────────────────────────────────────────────── */
.loader { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--bg); color: var(--muted); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Finestre modali (<dialog>) ──────────────────────────────────────── */
.dialog {
  width: min(560px, 100% - 24px);
  max-height: min(86vh, 86dvh);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}
.dialog::backdrop { background: rgba(0, 0, 0, .72); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.dialog-title { font-size: 18px; font-weight: 700; }
.dialog-body { padding: 16px 20px 20px; }
.dialog-confirm { width: min(420px, 100% - 24px); }
.confirm-message { font-size: 16px; }

/* Su telefono le finestre salgono dal basso, più comode da raggiungere col pollice */
@media (max-width: 899px) {
  .dialog { margin: auto auto 0; width: 100%; max-width: none; border-radius: var(--radius) var(--radius) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .dialog-confirm { margin: auto; width: min(420px, 100% - 24px); border-radius: var(--radius); }
}

/* ─── Selettore lingua (IT / DE) ──────────────────────────────────────── */
.lang { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); }
.lang-btn {
  min-width: 40px;
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 700 13px var(--font-ui);
  letter-spacing: .04em;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.lang-btn:hover { color: var(--text); }
.lang-btn.is-active { background: var(--accent-strong); color: #fff; }
.lang-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
