/* SaaS Cloud - Design system
   Token in un unico punto: light di default, dark via OS o toggle esplicito. */

:root {
  color-scheme: light;

  /* Superfici */
  --surface-0: #f7f7f5;
  --surface-1: #fcfcfb;
  --surface-2: #f1f1ee;
  --surface-inset: #ececea;

  /* Testo */
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #86857f;
  --text-inverse: #ffffff;

  /* Bordi */
  --border: #e0e0da;
  --border-strong: #c9c9c1;

  /* Identita': indigo saturo, stile fintech (Stripe/Ramp/Mercury) */
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef2ff;

  /* Stati: sempre accompagnati da icona o etichetta, mai colore da solo */
  --ok: #008300;
  --ok-soft: #e6f4e6;
  --ok-solid: #16a34a;
  --warn: #eda100;
  --warn-soft: #fdf3de;
  --warn-solid: #f59e0b;
  --danger: #e34948;
  --danger-soft: #fceaea;
  --danger-solid: #dc2626;
  --info: #4a3aa7;
  --info-soft: #ecebf7;
  --info-solid: #4f46e5;
  --neutral-solid: #64748b;

  /* Serie categoriche (ordine fisso, mai ciclato) */
  --series-1: #4f46e5;
  --series-2: #f97316;
  --series-3: #16a34a;
  --series-4: #ef4444;
  --series-1-soft: #eef2ff;
  --series-2-soft: #fff3e8;
  --series-3-soft: #e8f8ee;
  --series-4-soft: #fde8e8;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(11, 11, 11, .06), 0 1px 3px rgba(11, 11, 11, .04);
  --shadow-md: 0 4px 12px rgba(11, 11, 11, .08), 0 2px 4px rgba(11, 11, 11, .04);
  --shadow-lg: 0 12px 32px rgba(11, 11, 11, .12), 0 4px 8px rgba(11, 11, 11, .06);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  /* Sidebar: SEMPRE dark, indipendente da prefers-color-scheme/data-theme —
     e' una scelta di brand (mockup fintech), non segue il tema del contenuto. */
  --sidebar-bg: #0b1220;
  --sidebar-bg-elevated: #111a2e;
  --sidebar-border: #1e293b;
  --sidebar-text: #e2e8f0;
  --sidebar-text-dim: #64748b;
  --sidebar-text-active: #ffffff;
  --sidebar-item-hover: #172234;
  --sidebar-item-active-bg: rgba(29, 58, 143, .18);
  --sidebar-item-active-text: #93b4ff;
  --sidebar-item-active-border: #4f6fff;
  --sidebar-brand: #4f6fff;
  --sidebar-brand-2: #22d3ee;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --surface-inset: #2b2b29;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8d8c83;
    --text-inverse: #0b0b0b;
    --border: #33332f;
    --border-strong: #4a4a45;
    --brand: #3987e5;
    --brand-hover: #4f96ea;
    --brand-soft: #16283c;
    --ok: #3fa23f;
    --ok-soft: #16281a;
    --ok-solid: #3fa23f;
    --warn: #c98500;
    --warn-soft: #2e2410;
    --warn-solid: #c98500;
    --danger: #e66767;
    --danger-soft: #33191a;
    --danger-solid: #e66767;
    --info: #9085e9;
    --info-soft: #201d38;
    --info-solid: #9085e9;
    --neutral-solid: #6b7280;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-1-soft: #1b2340;
    --series-2-soft: #3a2414;
    --series-3-soft: #123322;
    --series-4-soft: #3a2b10;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --surface-inset: #2b2b29;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8d8c83;
  --text-inverse: #0b0b0b;
  --border: #33332f;
  --border-strong: #4a4a45;
  --brand: #3987e5;
  --brand-hover: #4f96ea;
  --brand-soft: #16283c;
  --ok: #3fa23f;
  --ok-soft: #16281a;
  --ok-solid: #3fa23f;
  --warn: #c98500;
  --warn-soft: #2e2410;
  --warn-solid: #c98500;
  --danger: #e66767;
  --danger-soft: #33191a;
  --danger-solid: #e66767;
  --info: #9085e9;
  --info-soft: #201d38;
  --info-solid: #9085e9;
  --neutral-solid: #6b7280;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-1-soft: #1b2340;
  --series-2-soft: #3a2414;
  --series-3-soft: #123322;
  --series-4-soft: #3a2b10;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--surface-0);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.011em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Accessibilita': focus sempre visibile */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Controlli ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  font: inherit; font-weight: 560; font-size: 14px;
  border: 1px solid transparent; border-radius: var(--radius);
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .06s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-secondary { background: var(--surface-1); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text-primary); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 560; color: var(--text-secondary); }
.field input, .field select, .field textarea {
  padding: 10px 12px;
  font: inherit; font-size: 15px;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field .hint { font-size: 12px; color: var(--text-muted); }

/* ---------- Messaggi di stato ---------- */

.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  border: 1px solid transparent;
  margin-bottom: 16px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: var(--info); }
.alert[hidden] { display: none; }

/* ---------- Badge di stato: icona + testo, mai solo colore ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  font-size: 12px; font-weight: 560;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--text-secondary); border-color: var(--border-strong); }
.badge-info { background: var(--info-soft); color: var(--info); border-color: var(--info); }

/* Variante piena/satura (mockup fintech): combinabile con .badge-ok/warn/danger/info/neutral. */
.badge-solid { color: #fff; border-color: transparent; font-weight: 650; }
.badge-solid.badge-ok { background: var(--ok-solid); }
.badge-solid.badge-warn { background: var(--warn-solid); color: #1a1200; }
.badge-solid.badge-danger { background: var(--danger-solid); }
.badge-solid.badge-info { background: var(--info-solid); }
.badge-solid.badge-neutral { background: var(--neutral-solid); }

/* ---------- Card ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }

/* ---------- Tabelle ---------- */

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px; font-weight: 620;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.num-warn { color: var(--warn); font-weight: 620; }

/* Intestazioni ordinabili: th[data-sort], stato attivo via .sort-asc/.sort-desc. */
table.data th[data-sort] { cursor: pointer; user-select: none; }
table.data th[data-sort]:hover { color: var(--text-secondary); }
table.data th[data-sort]::after { content: '↕'; margin-left: 5px; opacity: .35; font-size: 10px; }
table.data th[data-sort].sort-asc::after { content: '↑'; opacity: 1; color: var(--brand); }
table.data th[data-sort].sort-desc::after { content: '↓'; opacity: 1; color: var(--brand); }

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 32px; display: block; margin-bottom: 12px; opacity: .6; }
