/* Stile condiviso tra gestionale e app clienti */
:root {
  --brand: #8b5cf6;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, white);
  --brand-ink: color-mix(in srgb, var(--brand) 75%, black);
  --bg: #f6f6fb;
  --surface: #ffffff;
  --surface-2: #f1f1f7;
  --border: #e4e4ee;
  --text: #1d1b2e;
  --muted: #6b6a80;
  --ok: #059669;
  --ok-soft: #e7f7f0;
  --warn: #d97706;
  --warn-soft: #fdf3e2;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --info: #2563eb;
  --info-soft: #e9f0fe;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 16, 50, .05), 0 4px 16px rgba(20, 16, 50, .06);
  --shadow-lg: 0 12px 40px rgba(20, 16, 50, .18);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-soft: color-mix(in srgb, var(--brand) 22%, #17151f);
    --brand-ink: color-mix(in srgb, var(--brand) 55%, white);
    --bg: #111018; --surface: #1a1824; --surface-2: #232131; --border: #2f2c40;
    --text: #ecebf5; --muted: #a09eb5;
    --ok-soft: #0f2e24; --warn-soft: #33260f; --danger-soft: #3a1717; --info-soft: #14223f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand-soft: color-mix(in srgb, var(--brand) 22%, #17151f);
  --brand-ink: color-mix(in srgb, var(--brand) 55%, white);
  --bg: #111018; --surface: #1a1824; --surface-2: #232131; --border: #2f2c40;
  --text: #ecebf5; --muted: #a09eb5;
  --ok-soft: #0f2e24; --warn-soft: #33260f; --danger-soft: #3a1717; --info-soft: #14223f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.45;
  -webkit-font-smoothing: antialiased; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; font-weight: 650; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 .75em; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }

/* Bottoni */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 46px; padding: 0 20px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 28px; }

/* Form */
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 550; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px; min-height: 36px; width: 100%; outline: none; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; min-height: 0; accent-color: var(--brand); }
input[type=color] { padding: 2px; height: 36px; width: 56px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.search { position: relative; }
.search input { padding-left: 32px; }
.search::before { content: ""; position: absolute; left: 10px; top: 50%; width: 12px; height: 12px; margin-top: -8px;
  border: 2px solid var(--muted); border-radius: 50%; }

/* Card, tabelle, badge */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); min-width: 0; }
.card.flat { box-shadow: none; }
.card h3 { margin-bottom: 12px; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--surface-2); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px;
  font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 650; color: #fff; background: var(--brand); flex: none; font-size: 13px; }

/* KPI */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; font-weight: 600; }
.kpi .btn { align-self: flex-start; margin-top: 4px; }
.delta.up { color: var(--ok); } .delta.down { color: var(--danger); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--brand-ink); border-color: var(--brand); }

/* Modale e toast */
.modal-back { position: fixed; inset: 0; background: rgba(15, 12, 35, .45); display: flex; align-items: flex-start;
  justify-content: center; padding: 6vh 16px; z-index: 100; overflow-y: auto; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px;
  animation: pop .18s; }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
  border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border);
  flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: flex;
  flex-direction: column; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-weight: 550; animation: pop .2s; max-width: 380px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--info-soft); color: var(--info); font-size: 13px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Grafici SVG */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center;
  font-size: 13px; padding: 5px 0; }
.bar-track { background: var(--surface-2); height: 10px; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 99px; }

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
}
