/* ==========================================================================
   IcoBot Portal — Design System
   Dark moderno, glassmorphism, gradienti indigo/violet
   ========================================================================== */

:root {
  --bg: #06060e;
  --bg-soft: #0b0b18;
  --card: rgba(255, 255, 255, 0.045);
  --card-strong: rgba(255, 255, 255, 0.07);
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #f4f4f8;
  --muted: #9b9bb4;
  --accent: #6366f1;
  --accent-2: #a855f7;
  --grad: linear-gradient(135deg, #6366f1 0%, #a855f7 55%, #ec4899 115%);
  --grad-soft: linear-gradient(135deg, rgba(99, 102, 241, 0.16), rgba(168, 85, 247, 0.12));
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #fb7185;
  --info: #38bdf8;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(99, 102, 241, 0.45); }

/* ------------------------------- Sfondo animato --------------------------- */

.bg-scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(ellipse 90% 60% at 70% -10%, #12122b 0%, var(--bg) 60%);
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  animation: float 18s ease-in-out infinite;
}

.orb-1 {
  width: 480px; height: 480px;
  background: #4338ca;
  top: -160px; left: -120px;
}

.orb-2 {
  width: 420px; height: 420px;
  background: #7e22ce;
  top: 30%; right: -140px;
  animation-delay: -6s;
}

.orb-3 {
  width: 360px; height: 360px;
  background: #0e7490;
  bottom: -140px; left: 35%;
  opacity: 0.35;
  animation-delay: -12s;
}

.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 75% 65% at 50% 35%, black 30%, transparent 75%);
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.06); }
  66% { transform: translate(-30px, 25px) scale(0.96); }
}

/* --------------------------------- Tipografia ------------------------------ */

h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }

h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 600; }

.grad-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 0.82rem; }

/* --------------------------------- Logo ------------------------------------ */

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.logo-mark {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--grad);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.45);
  flex-shrink: 0;
}

/* --------------------------------- Bottoni --------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.68rem 1.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
  white-space: nowrap;
  color: var(--text);
  background: transparent;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 8px 26px rgba(124, 58, 237, 0.4);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(124, 58, 237, 0.55);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--card-border);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

.btn-danger-ghost {
  background: rgba(251, 113, 133, 0.08);
  border-color: rgba(251, 113, 133, 0.3);
  color: #fda4af;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: rgba(251, 113, 133, 0.16);
  transform: translateY(-1px);
}

.btn-success-ghost {
  background: rgba(52, 211, 153, 0.09);
  border-color: rgba(52, 211, 153, 0.3);
  color: #6ee7b7;
}

.btn-success-ghost:hover:not(:disabled) {
  background: rgba(52, 211, 153, 0.17);
  transform: translateY(-1px);
}

.btn-sm { padding: 0.42rem 0.8rem; font-size: 0.82rem; border-radius: 10px; }
.btn-block { width: 100%; }

.btn.loading { pointer-events: none; }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------ Campi di input ----------------------------- */

.field { margin-bottom: 1.1rem; }

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.45rem;
  letter-spacing: 0.01em;
}

.input {
  width: 100%;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.input::placeholder { color: rgba(155, 155, 180, 0.55); }

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.22);
  background: rgba(255, 255, 255, 0.065);
}

textarea.input { resize: vertical; min-height: 90px; }

/* Select: lista opzioni leggibile (testo scuro su sfondo bianco) */
select.input,
select.tipologia-select {
  cursor: pointer;
  color-scheme: light;
}

select.input option,
select.tipologia-select option {
  color: #111827;
  background-color: #ffffff;
}

select.input option:checked,
select.tipologia-select option:checked {
  color: #ffffff;
  background-color: #6366f1;
}

.input-hint { font-size: 0.78rem; color: var(--muted); margin-top: 0.4rem; }

.input-wrap { position: relative; }

.input-wrap .input-action {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

/* ---------------------------------- Badge ---------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.26rem 0.68rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.015em;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.ok   { background: rgba(52, 211, 153, 0.11); color: #6ee7b7; border-color: rgba(52, 211, 153, 0.28); }
.badge.warn { background: rgba(251, 191, 36, 0.11); color: #fcd34d; border-color: rgba(251, 191, 36, 0.28); }
.badge.err  { background: rgba(251, 113, 133, 0.11); color: #fda4af; border-color: rgba(251, 113, 133, 0.28); }
.badge.info { background: rgba(56, 189, 248, 0.11); color: #7dd3fc; border-color: rgba(56, 189, 248, 0.28); }
.badge.muted { background: rgba(155, 155, 180, 0.12); color: var(--muted); border-color: rgba(155, 155, 180, 0.25); }

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

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 1.5rem;
  animation: rise 0.5s ease both;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.15rem;
  flex-wrap: wrap;
}

.card-head .card-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--grad-soft);
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: grid;
  place-items: center;
  color: #a5b4fc;
  flex-shrink: 0;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --------------------------------- Stat card ------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  padding: 1.15rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  animation: rise 0.5s ease both;
}

.stat:nth-child(2) { animation-delay: 0.05s; }
.stat:nth-child(3) { animation-delay: 0.1s; }
.stat:nth-child(4) { animation-delay: 0.15s; }

.stat-num { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; }
.stat-label { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.stat-sub { font-size: 0.72rem; color: rgba(155, 155, 180, 0.75); margin-top: 0.15rem; }

/* ------------------------------ Quota e consumi --------------------------- */

.quota-bar {
  height: 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.quota-bar.big { height: 12px; margin: 0.35rem 0 1.3rem; }

.quota-bar > span {
  display: block;
  height: 100%;
  border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.quota-bar > span.quota-ok { background: linear-gradient(90deg, #6366f1, #a855f7); }
.quota-bar > span.quota-warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.quota-bar > span.quota-danger { background: linear-gradient(90deg, #f43f5e, #fb7185); }

.quota-cell { min-width: 170px; }

.quota-line {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.quota-pct { margin-left: auto; font-weight: 700; font-size: 0.8rem; }
.quota-pct.quota-ok { color: var(--ok); }
.quota-pct.quota-warn { color: var(--warn); }
.quota-pct.quota-danger { color: var(--err); }

.quota-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: -0.4rem 0 1.2rem;
}

/* Card consumo nella dashboard azienda */

.usage-card { margin-bottom: 1.5rem; }

.usage-headline {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-top: 0.4rem;
}

.usage-of {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.usage-pct {
  font-size: 1.15rem;
  font-weight: 800;
  padding: 0.3rem 0.75rem;
  border-radius: 99px;
  border: 1px solid var(--card-border);
  background: var(--card-strong);
}

.usage-pct.usage-ok { color: #c7d2fe; }
.usage-pct.usage-warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.4); }
.usage-pct.usage-danger { color: var(--err); border-color: rgba(251, 113, 133, 0.45); }

.usage-periods {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.9rem;
  margin-top: 0.4rem;
}

.usage-period {
  background: var(--card-strong);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  transition: transform 0.25s ease, border-color 0.25s ease;
}

.usage-period:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.4);
}

.usage-period-num { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; }
.usage-period-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.usage-period-sub { font-size: 0.72rem; color: rgba(155, 155, 180, 0.75); margin-top: 0.15rem; }

.usage-alert {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.1rem;
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.usage-alert.warn {
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.32);
  color: #fde68a;
}

.usage-alert.danger {
  background: rgba(251, 113, 133, 0.1);
  border: 1px solid rgba(251, 113, 133, 0.35);
  color: #fecdd3;
}

/* Grafico a barre del dettaglio admin */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 130px;
  padding: 0.6rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
}

.chart-bar {
  flex: 1;
  min-width: 3px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, #a855f7, #6366f1);
  transition: opacity 0.2s ease;
}

.chart-bar:hover { opacity: 0.7; }

.op-list { display: grid; gap: 0.5rem; }

.op-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 0.85rem;
  background: var(--card-strong);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.op-name { flex: 1; font-weight: 600; }
.op-tokens { color: var(--muted); }
.op-cost { font-weight: 700; min-width: 90px; text-align: right; }

@media (max-width: 560px) {
  .usage-headline { font-size: 1.7rem; }
  .op-row { flex-wrap: wrap; }
  .op-cost { text-align: left; }
}

/* --------------------------------- Layout app ------------------------------ */

.layout {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--card-border);
  background: rgba(9, 9, 20, 0.6);
  backdrop-filter: blur(18px);
  padding: 1.5rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.nav { display: flex; flex-direction: column; gap: 0.3rem; }

.nav-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  padding: 0 0.7rem;
  margin-bottom: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  border: 1px solid transparent;
  transition: all 0.18s ease;
}

.nav-item:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

.nav-item.active {
  color: var(--text);
  background: var(--grad-soft);
  border-color: rgba(99, 102, 241, 0.35);
}

.main.main--tenant {
  max-width: none;
  width: 100%;
  margin: 0;
  min-width: 0;
  box-sizing: border-box;
}

.kb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
}

.kb-tab {
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.kb-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.kb-tab.active {
  color: var(--text);
  background: var(--grad-soft);
  border-color: rgba(99, 102, 241, 0.35);
}

.kb-tab[hidden] { display: none !important; }

.kb-panel[hidden] { display: none !important; }

.main--tenant .page-head h1 {
  font-size: clamp(1.65rem, 2.5vw, 2rem);
  letter-spacing: -0.02em;
}

.sidebar-foot { margin-top: auto; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
}

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--grad);
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-chip .user-meta { min-width: 0; flex: 1; }
.user-chip .user-mail {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
}

.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.1); transform: translateY(-1px); }

.main {
  padding: 2rem 2.4rem 3rem;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

.page-head { margin-bottom: 1.8rem; animation: rise 0.4s ease both; }
.page-head p { color: var(--muted); margin: 0.4rem 0 0; }

.stack { display: flex; flex-direction: column; gap: 1.5rem; }

/* ---------------------------------- Tabella -------------------------------- */

.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.tbl th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

.tbl td {
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
  vertical-align: middle;
}

.tbl tbody tr { transition: background 0.15s ease; }
.tbl tbody tr:hover { background: rgba(255, 255, 255, 0.035); }
.tbl tbody tr:last-child td { border-bottom: none; }

.tbl .cell-main { font-weight: 600; }
.tbl .cell-sub { font-size: 0.78rem; color: var(--muted); }
.tbl .actions { display: flex; gap: 0.45rem; justify-content: flex-end; }

.row-file { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.row-file .file-ic {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.13);
  border: 1px solid rgba(99, 102, 241, 0.25);
  display: grid; place-items: center;
  color: #a5b4fc;
  flex-shrink: 0;
}
.row-file .fname {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

/* --------------------------- Upload progresso ----------------------------- */

.upload-progress {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--card-border);
  font-size: 0.86rem;
}

.upload-row .name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.upload-row .bar {
  width: 90px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  flex-shrink: 0;
}

.upload-row .bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--grad);
  transition: width 0.25s ease;
}

.upload-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1.1rem;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.upload-tab {
  flex: 1;
  padding: 0.55rem 0.85rem;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.upload-tab:hover {
  color: var(--text);
}

.upload-tab.active {
  background: rgba(99, 102, 241, 0.18);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.35);
}

.upload-panel .field + .field {
  margin-top: 0.85rem;
}

.link-url {
  color: var(--accent);
  word-break: break-all;
  text-decoration: none;
}

.link-url:hover {
  text-decoration: underline;
}

.tipologia-select {
  min-width: 9rem;
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
}

.upload-overall {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.25);
}

.upload-overall-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
  font-size: 0.88rem;
}

.upload-overall-bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.upload-overall-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--grad);
  transition: width 0.2s ease;
}

.ingest-activity {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius-sm);
  background: rgba(56, 189, 248, 0.07);
  border: 1px solid rgba(56, 189, 248, 0.28);
}

.ingest-activity-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.ingest-kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.35rem 1rem;
  font-size: 0.88rem;
  margin: 0;
}

.ingest-kv dt { color: var(--muted); font-weight: 500; margin: 0; }
.ingest-kv dd { margin: 0; font-weight: 600; }

.upload-row.ok { border-color: rgba(52, 211, 153, 0.35); }
.upload-row.err { border-color: rgba(251, 113, 133, 0.35); }

/* --------------------------- Dataset / JSONL live ------------------------- */

.qa-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.qa-stat {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
}

.qa-stat .stat-num {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.jsonl-panel { margin-top: 1.2rem; }

.jsonl-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.jsonl-viewer {
  background: #07070f;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  max-height: 360px;
  overflow-y: auto;
  padding: 0.7rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.74rem;
  line-height: 1.55;
}

.jsonl-empty {
  padding: 1.4rem 0.8rem;
  text-align: center;
  font-family: var(--font);
  font-size: 0.88rem;
}

.jsonl-line {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 0.55rem;
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  animation: rise 0.35s ease both;
}

.jsonl-line:hover { background: rgba(99, 102, 241, 0.08); }

.jsonl-line .idx {
  color: #818cf8;
  font-weight: 700;
}

.jsonl-line .q { color: #e9d5ff; }
.jsonl-line .a { color: #a7f3d0; margin-top: 0.2rem; }
.jsonl-line .src { color: var(--muted); margin-top: 0.25rem; font-size: 0.68rem; }

@media (max-width: 720px) {
  .qa-stats { grid-template-columns: 1fr; }
}

/* ------------------------------- Empty state ------------------------------- */

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}

.empty .empty-ic {
  width: 64px; height: 64px;
  margin: 0 auto 1rem;
  border-radius: 20px;
  background: var(--grad-soft);
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: grid; place-items: center;
  color: #a5b4fc;
}

.empty h3 { color: var(--text); margin-bottom: 0.35rem; }
.empty p { margin: 0; font-size: 0.9rem; }

/* --------------------------------- Dropzone -------------------------------- */

.dropzone {
  border: 2px dashed rgba(99, 102, 241, 0.4);
  border-radius: var(--radius);
  background: rgba(99, 102, 241, 0.05);
  padding: 2.4rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone:hover { background: rgba(99, 102, 241, 0.09); border-color: rgba(99, 102, 241, 0.6); }

.dropzone.dragover {
  background: rgba(99, 102, 241, 0.14);
  border-color: var(--accent-2);
  transform: scale(1.01);
}

.dropzone .dz-ic {
  width: 58px; height: 58px;
  margin: 0 auto 0.9rem;
  border-radius: 18px;
  background: var(--grad);
  display: grid; place-items: center;
  color: #fff;
  box-shadow: 0 10px 28px rgba(124, 58, 237, 0.45);
}

.dropzone h3 { margin-bottom: 0.3rem; }
.dropzone p { margin: 0; color: var(--muted); font-size: 0.85rem; }

/* ---------------------------------- Banner --------------------------------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  border: 1px solid;
  animation: rise 0.4s ease both;
}

.banner.info { background: rgba(56, 189, 248, 0.08); border-color: rgba(56, 189, 248, 0.28); color: #bae6fd; }
.banner.success { background: rgba(52, 211, 153, 0.08); border-color: rgba(52, 211, 153, 0.28); color: #a7f3d0; }
.banner.warn { background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.28); color: #fde68a; }
.banner svg { flex-shrink: 0; margin-top: 2px; }

/* ---------------------------------- Modal ---------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  background: rgba(4, 4, 12, 0.72);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.modal.open { opacity: 1; pointer-events: auto; }

.modal-box {
  width: 100%;
  max-width: 520px;
  background: #101020;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 1.7rem;
  transform: translateY(16px) scale(0.98);
  transition: transform 0.22s ease;
  max-height: 88vh;
  overflow-y: auto;
}

.modal.open .modal-box { transform: translateY(0) scale(1); }

.modal-box-wide { max-width: 760px; }

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.3rem;
}

.modal-head p { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.87rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1.4rem;
}

/* ----------------------------------- Code ---------------------------------- */

.code-block {
  position: relative;
  background: #07070f;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 1rem 3.2rem 1rem 1rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  color: #c4b5fd;
  overflow-x: auto;
  white-space: pre;
}

.code-block .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

.kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.45rem 1rem;
  font-size: 0.88rem;
  align-items: center;
}

.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; font-weight: 600; word-break: break-all; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 1.25rem;
}

@media (max-width: 760px) {
  .settings-grid { grid-template-columns: 1fr; }
}

.color-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.color-row input[type="color"] {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.embed-kv { margin-top: 0.5rem; }

.checklist {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
  line-height: 1.6;
}

.checklist li { margin-bottom: 0.45rem; }

.contact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (max-width: 760px) {
  .contact-grid { grid-template-columns: 1fr; }
}

.contact-box {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.contact-box h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.contact-list {
  margin: 0;
  padding-left: 1.1rem;
  line-height: 1.55;
}

.contact-list li { margin-bottom: 0.35rem; }

.logo-upload {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.logo-preview {
  width: 88px;
  height: 88px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
  display: block;
}

.logo-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.logo-field { margin-bottom: 1.35rem; }

/* ---------------------------------- Toast ---------------------------------- */

.toasts {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: min(380px, calc(100vw - 2rem));
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1.05rem;
  border-radius: var(--radius-sm);
  background: #131324;
  border: 1px solid var(--card-border);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  transform: translateX(24px);
  transition: all 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.toast.show { opacity: 1; transform: translateX(0); }

.toast-success { border-color: rgba(52, 211, 153, 0.45); color: #a7f3d0; }
.toast-error { border-color: rgba(251, 113, 133, 0.45); color: #fecdd3; }
.toast-info { border-color: rgba(99, 102, 241, 0.45); color: #c7d2fe; }
.toast-warn { border-color: rgba(251, 191, 36, 0.45); color: #fde68a; }

/* --------------------------------- Skeleton -------------------------------- */

.skel {
  height: 52px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.04) 25%,
    rgba(255, 255, 255, 0.09) 50%,
    rgba(255, 255, 255, 0.04) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  margin-bottom: 0.6rem;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ------------------------------- Pagina login ------------------------------ */

.auth {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  min-height: 100vh;
}

.auth-hero {
  position: relative;
  padding: 3rem 3.4rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.auth-hero .hero-mid { max-width: 460px; }

.auth-hero h1 {
  font-size: clamp(1.9rem, 3.4vw, 2.7rem);
  font-weight: 800;
  line-height: 1.12;
  margin-bottom: 1rem;
}

.auth-hero .lead { color: var(--muted); font-size: 1.02rem; max-width: 420px; }

.hero-feats { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 2rem; }

.hero-feat {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.92rem;
  color: #cfcfe4;
}

.hero-feat .feat-ic {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--grad-soft);
  border: 1px solid rgba(99, 102, 241, 0.35);
  display: grid; place-items: center;
  color: #a5b4fc;
  flex-shrink: 0;
}

.auth-hero .hero-foot { color: var(--muted); font-size: 0.8rem; }

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 22px;
  backdrop-filter: blur(18px);
  padding: 2.2rem;
  box-shadow: var(--shadow);
  animation: rise 0.55s ease both;
}

.auth-card .auth-title { margin: 1.4rem 0 0.3rem; }
.auth-card .auth-sub { color: var(--muted); font-size: 0.9rem; margin: 0 0 1.7rem; }

.form-error {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: rgba(251, 113, 133, 0.1);
  border: 1px solid rgba(251, 113, 133, 0.35);
  color: #fda4af;
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 1.1rem;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* --------------------------------- Switch ---------------------------------- */

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  transition: 0.2s;
  cursor: pointer;
}
.switch .track::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ------------------------------- Dettagli log ------------------------------ */

details.log-box {
  margin-top: 1rem;
  background: #07070f;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  font-size: 0.8rem;
}

details.log-box summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  user-select: none;
}

details.log-box pre {
  margin: 0.7rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #a5b4fc;
  font-family: ui-monospace, monospace;
  max-height: 220px;
  overflow-y: auto;
}

/* ------------------------- Card fonti per tipologia ------------------------ */

.src-groups {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* Interruttore (toggle switch) per il live JSONL */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer; border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--card-border);
  transition: background 0.2s ease;
}
.switch .slider::before {
  content: ''; position: absolute; height: 16px; width: 16px; left: 2px; top: 50%;
  transform: translateY(-50%);
  border-radius: 50%; background: #fff; transition: left 0.2s ease;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { left: 18px; }

.jsonl-controls { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.jsonl-live-state { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; }
.jsonl-live-dot { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,0.25); }
.jsonl-live-dot.on { background: var(--ok); animation: pulse-dot 1.6s ease-in-out infinite; }
@keyframes pulse-dot { 0%,100% { opacity: 1; transform: scale(1);} 50% { opacity: 0.5; transform: scale(0.75);} }

.src-group {
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.src-group-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.1rem;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--card-border);
}

.src-group-head .badge { margin-left: auto; }
.src-group-title {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
}
.src-group-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

.src-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 0.9rem;
  padding: 1rem;
}

/* Singola card documento/link — glassmorphism con bordo luminoso in hover */
.src-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1.05rem 1.1rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.025));
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
  transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
  overflow: hidden;
}

/* alone sfumato che segue l'hover */
.src-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: var(--grad);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.src-card:hover {
  transform: translateY(-4px);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(99, 102, 241, 0.18);
}
.src-card:hover::before { opacity: 0.6; }

.src-card-top {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.src-ic {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--grad-soft);
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: grid;
  place-items: center;
  color: #a5b4fc;
  flex-shrink: 0;
}

.src-name {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
}

.src-name .fname { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.src-url {
  display: block;
  font-size: 0.82rem;
  color: #a5b4fc;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.src-url:hover { text-decoration: underline; }

.src-comment {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.src-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.73rem;
  color: var(--muted);
}

.src-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.src-foot .actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* select tipologia dentro la card */
.src-card .tipologia-select { width: 100%; font-size: 0.8rem; padding: 0.4rem 0.55rem; }

/* ------------------------- Nav toggle (hamburger) -------------------------- */

.nav-toggle { display: none; }

/* -------------------------------- Responsive ------------------------------- */

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.8rem;
    padding: 0.9rem 1.1rem;
    border-right: none;
    border-bottom: 1px solid var(--card-border);
  }

  .nav-toggle { display: inline-flex; order: 3; margin-left: auto; }

  .sidebar .nav {
    order: 4;
    flex-basis: 100%;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.28s ease;
    display: none;
  }
  .sidebar.nav-open .nav { display: flex; max-height: 480px; }

  .nav-label { display: none; }
  .sidebar-foot { margin-top: 0; margin-left: 0; order: 5; flex-basis: 100%; }
  .user-chip .user-meta { display: none; }

  .main { padding: 1.4rem 1.1rem 2.5rem; }

  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }

  .card { padding: 1.15rem; }
  .card-head { gap: 0.6rem; }
  .page-head h1 { font-size: 1.7rem; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .src-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .src-grid { grid-template-columns: 1fr; }
  .qa-stats { grid-template-columns: 1fr; }
  .card { padding: 1rem; }
  .page-head h1 { font-size: 1.45rem; }
  .btn { font-size: 0.82rem; }
}

/* --------------------------- Accessibilità motion -------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
