/* ── Design System ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,500;0,9..144,700;1,9..144,300&family=Plus+Jakarta+Sans:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg:       #040d21;
  --bg1:      #070f28;
  --bg2:      #0c1932;
  --card:     #0a1628;
  --border:   #1a2a4a;
  --border2:  #243554;
  --accent:   #f59e0b;
  --accent2:  #fbbf24;
  --blue:     #3b82f6;
  --green:    #10b981;
  --red:      #ef4444;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --muted2:   #94a3b8;
  --num:      #f59e0b;
  --r:        4px;
  --r2:       8px;
  --shadow:   0 4px 24px rgba(0,0,0,.5);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ────────────────────────────────────────────── */
.display {
  font-family: 'Fraunces', serif;
  font-optical-sizing: auto;
}
.mono { font-family: 'JetBrains Mono', monospace; }

h1,h2,h3 { font-family: 'Fraunces', serif; font-weight: 500; letter-spacing: -.02em; }
h1 { font-size: 2.4rem; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.1rem; }

/* ── Layout ────────────────────────────────────────────────── */
.container  { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.container--sm { max-width: 520px; }
.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }

/* ── Header ────────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(4,13,33,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.header__brand {
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.header__brand span { color: var(--muted2); font-weight: 300; }
.header__user { font-size: 12px; color: var(--muted2); }

/* ── Card ──────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 24px;
}
.card--glow { box-shadow: 0 0 0 1px var(--accent), 0 0 24px rgba(245,158,11,.12); }

/* ── Caso d'uso cards ─────────────────────────────────────── */
.caso-grid {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 20px;
  margin: 32px 0;
}
.caso-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 28px 24px;
  cursor: pointer;
  transition: border-color .2s, transform .15s, box-shadow .2s;
  position: relative;
  overflow: hidden;
}
.caso-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  transition: opacity .3s;
}
.caso-card:hover   { border-color: var(--border2); transform: translateY(-2px); }
.caso-card.active  { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 24px rgba(245,158,11,.15); }
.caso-card.active::before { opacity: 1; }
.caso-card__icon   { font-size: 1.8rem; margin-bottom: 12px; }
.caso-card__title  { font-family: 'Fraunces', serif; font-size: 1.05rem; margin-bottom: 6px; color: var(--text); }
.caso-card__desc   { font-size: 12px; color: var(--muted2); line-height: 1.5; }
.caso-card__badge  {
  display: inline-block; margin-top: 12px;
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  padding: 2px 8px; border-radius: 2px; text-transform: uppercase;
  background: rgba(245,158,11,.12); color: var(--accent); border: 1px solid rgba(245,158,11,.3);
}

/* ── Counter ───────────────────────────────────────────────── */
.counter-panel {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 20px 24px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 57px; z-index: 90;
  backdrop-filter: blur(8px);
}
.counter-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem; font-weight: 500;
  color: var(--accent);
  letter-spacing: -.02em;
  transition: color .3s;
  min-width: 120px;
}
.counter-num.low   { color: var(--red); }
.counter-num.ok    { color: var(--green); }
.counter-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.counter-spinner { display: none; }
.counter-spinner.visible {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Filters ───────────────────────────────────────────────── */
.filters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 20px;
}
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-group.full { grid-column: 1 / -1; }
.filter-label { font-size: 11px; font-weight: 600; color: var(--muted2); text-transform: uppercase; letter-spacing: .08em; }

/* ── Form controls ─────────────────────────────────────────── */
input[type=text], input[type=email], input[type=password], input[type=number],
select, textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder { color: var(--muted); }
select option { background: var(--bg2); }

/* Range slider */
.range-row { display: flex; gap: 8px; align-items: center; }
.range-val  { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--accent); min-width: 28px; text-align: center; }
input[type=range] {
  flex: 1; appearance: none; height: 4px;
  background: var(--border2); border-radius: 2px;
  outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  appearance: none; width: 14px; height: 14px;
  background: var(--accent); border-radius: 50%; cursor: pointer;
  transition: transform .15s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* Checkbox group */
.check-group { display: flex; flex-wrap: wrap; gap: 8px; }
.check-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 20px;
  border: 1px solid var(--border2); cursor: pointer;
  font-size: 12px; color: var(--muted2);
  transition: all .15s; user-select: none;
}
.check-pill input { display: none; }
.check-pill:has(input:checked) {
  border-color: var(--accent); color: var(--accent);
  background: rgba(245,158,11,.08);
}
.check-pill:hover { border-color: var(--border2); color: var(--text); }

/* Multi-select tags */
.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px;
  min-height: 38px; padding: 5px 8px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--r); cursor: text;
}
.tag-input:focus-within { border-color: var(--accent); }
.tag {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 8px; background: rgba(245,158,11,.15);
  border: 1px solid rgba(245,158,11,.3); border-radius: 3px;
  font-size: 11px; color: var(--accent);
}
.tag__remove { cursor: pointer; font-size: 14px; line-height: 1; color: var(--muted); }
.tag__remove:hover { color: var(--red); }
.tag-input input {
  border: none; background: none; flex: 1; min-width: 80px; padding: 2px 4px;
  font-size: 12px; color: var(--text);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border-radius: var(--r);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; outline: none;
  transition: all .15s; white-space: nowrap;
}
.btn-primary {
  background: var(--accent); color: #040d21;
}
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: transparent; color: var(--muted2);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger {
  background: rgba(239,68,68,.15); color: var(--red);
  border: 1px solid rgba(239,68,68,.3);
}
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Agent banner ──────────────────────────────────────────── */
.agent-banner {
  display: none;
  border: 1px solid rgba(59,130,246,.4);
  background: rgba(59,130,246,.08);
  border-radius: var(--r2);
  padding: 16px 20px;
  margin-top: 16px;
  align-items: flex-start;
  gap: 12px;
}
.agent-banner.visible { display: flex; }
.agent-banner__icon { font-size: 1.4rem; flex-shrink: 0; }
.agent-banner__body { flex: 1; }
.agent-banner__title { font-size: 13px; font-weight: 600; color: var(--blue); margin-bottom: 4px; }
.agent-banner__text  { font-size: 12px; color: var(--muted2); }
.agent-response {
  margin-top: 12px; padding: 12px;
  background: var(--bg2); border-radius: var(--r);
  font-size: 12px; line-height: 1.7; color: var(--text);
  white-space: pre-wrap;
}

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--bg2); border-bottom: 1px solid var(--border); }
th { padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 600; color: var(--muted2); text-transform: uppercase; letter-spacing: .07em; }
td { padding: 10px 14px; font-size: 12px; border-bottom: 1px solid rgba(26,42,74,.5); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(245,158,11,.03); }
td.mono { font-family: 'JetBrains Mono', monospace; font-size: 11px; }
.badge {
  display: inline-block; padding: 2px 7px; border-radius: 3px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
}
.badge-blue   { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-amber  { background: rgba(245,158,11,.15); color: var(--accent); }
.badge-green  { background: rgba(16,185,129,.15); color: #34d399; }
.badge-gray   { background: rgba(100,116,139,.15); color: var(--muted2); }

/* ── Distribuzione chart ───────────────────────────────────── */
.dist-bars { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.dist-row { display: flex; align-items: center; gap: 10px; }
.dist-label { font-size: 11px; color: var(--muted2); width: 80px; flex-shrink: 0; }
.dist-bar-wrap { flex: 1; background: var(--bg2); height: 6px; border-radius: 3px; overflow: hidden; }
.dist-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width .5s ease; }
.dist-num { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted2); min-width: 48px; text-align: right; }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 16px; }
.page-btn {
  padding: 5px 10px; border-radius: var(--r);
  border: 1px solid var(--border2); background: transparent;
  color: var(--muted2); font-size: 12px; cursor: pointer; transition: all .15s;
}
.page-btn:hover  { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); color: #040d21; border-color: var(--accent); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Steps ──────────────────────────────────────────────────── */
.steps { display: flex; gap: 0; margin-bottom: 32px; border-bottom: 1px solid var(--border); }
.step {
  padding: 12px 20px; font-size: 12px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  cursor: default; display: flex; align-items: center; gap: 8px;
  transition: color .2s;
}
.step.active { color: var(--accent); border-bottom-color: var(--accent); }
.step.done   { color: var(--green); }
.step__num {
  width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid currentColor; display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; flex-shrink: 0;
}

/* ── Login page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 40%, rgba(245,158,11,.06) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 60%, rgba(59,130,246,.06) 0%, transparent 60%),
              var(--bg);
}
.login-card {
  width: 100%; max-width: 400px;
  padding: 40px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center; margin-bottom: 32px;
}
.login-logo h1 { font-size: 1.8rem; color: var(--accent); }
.login-logo p  { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: 11px; font-weight: 600; color: var(--muted2); text-transform: uppercase; letter-spacing: .07em; }
.error-msg { color: var(--red); font-size: 12px; margin-top: 8px; }

/* ── Toast ──────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast-item {
  padding: 12px 16px; border-radius: var(--r2);
  font-size: 13px; min-width: 260px; max-width: 360px;
  display: flex; align-items: center; gap: 10px;
  animation: slideUp .3s ease;
  box-shadow: var(--shadow);
}
.toast-item.success { background: rgba(16,185,129,.2); border: 1px solid rgba(16,185,129,.4); color: #34d399; }
.toast-item.error   { background: rgba(239,68,68,.2);  border: 1px solid rgba(239,68,68,.4);  color: #f87171; }
.toast-item.info    { background: rgba(59,130,246,.2); border: 1px solid rgba(59,130,246,.4); color: #60a5fa; }
@keyframes slideUp { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:none; } }

/* ── Misc ───────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: 14px; }
.text-muted { color: var(--muted2); }
.text-accent { color: var(--accent); }
.text-red    { color: var(--red); }
.text-green  { color: var(--green); }
.mt-1 { margin-top: 8px; }  .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }

.loading { text-align: center; padding: 40px; color: var(--muted); }

.external-note {
  display: none; font-size: 11px; color: #60a5fa;
  background: rgba(59,130,246,.08); border: 1px solid rgba(59,130,246,.2);
  border-radius: var(--r); padding: 8px 12px; margin-top: 8px;
}
.external-note.visible { display: block; }

@media (max-width: 768px) {
  .caso-grid { grid-template-columns: 1fr; }
  .filters-grid { grid-template-columns: 1fr; }
  .counter-panel { flex-direction: column; gap: 12px; align-items: flex-start; }
}
