/* zero1dev AI Gateway — webui. Dark tech theme, dev-tool style. */

:root {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #171b24;
  --border: #262b36;
  --text: #e7e9ee;
  --text-dim: #9aa1b2;
  --text-faint: #666d80;
  --accent: #7c6cf6;
  --accent-2: #a78bfa;
  --accent-soft: rgba(124, 108, 246, 0.15);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --warning: #fbbf24;
  --radius: 10px;
  --radius-lg: 14px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
svg { width: 16px; height: 16px; flex-shrink: 0; }

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

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ── Layout ─────────────────────────────────────────────────────────── */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.brand-text { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.brand-text small { display: block; font-weight: 400; font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.nav { padding: 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-2); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-faint);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; }
.topbar .sub { color: var(--text-faint); font-size: 12.5px; }

.content { padding: 24px; flex: 1; }

.nav-toggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; top: 0; bottom: 0; transform: translateX(-100%); transition: transform 200ms ease; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 16px; }
  .nav-toggle { display: inline-flex; }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 30; }
}

/* ── Componenti ─────────────────────────────────────────────────────── */

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 860px) { .grid-4, .grid-2 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.stat-tile { display: flex; flex-direction: column; gap: 6px; }
.stat-tile .label { font-size: 12px; color: var(--text-faint); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-tile .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-tile .value.accent { color: var(--accent-2); }
.stat-tile .delta { font-size: 12px; color: var(--text-dim); }

.section-title { font-size: 14px; font-weight: 600; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.section-title .hint { font-size: 12px; font-weight: 400; color: var(--text-faint); margin-left: auto; }
.section-title svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-dim); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-faint); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.on { background: var(--success-soft); color: var(--success); }
.badge.off { background: var(--danger-soft); color: var(--danger); }
.badge.neutral { background: var(--surface-2); color: var(--text-dim); }
.badge.sm { padding: 2px 7px; font-size: 10.5px; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background 150ms ease, border-color 150ms ease, opacity 150ms;
}
.btn:hover { background: #1e222c; border-color: #333a49; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { background: #6c5ce6; }
.btn.danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn svg { width: 15px; height: 15px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-faint); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { margin: 4px 0; }

/* Form */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-dim); margin-bottom: 6px; }
.field .helper { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }
input[type="text"], input[type="password"], input[type="number"], input[type="url"],
input[type="email"], input[type="date"], input[type="time"], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; color: var(--text); font-size: 13.5px; font-family: inherit;
}
/* Cromo nativo di type="date"/type="time" (icona calendario/orologio,
   indicatori) resta chiaro anche su sfondo scuro se non forzato — stesso bug
   gia' visto su type="email"/type="date", stessa correzione. */
input[type="date"], input[type="time"] { color-scheme: dark; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); }
.checkbox-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 16px; }
@media (max-width: 560px) { .checkbox-grid { grid-template-columns: 1fr 1fr; } }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px 4px 11px; font-size: 12.5px; font-family: var(--font-mono); }
.chip button { background: none; border: none; color: var(--text-faint); cursor: pointer; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.chip button:hover { background: var(--danger-soft); color: var(--danger); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 100%; max-width: 560px; padding: 22px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-header button { background: none; border: none; color: var(--text-faint); cursor: pointer; padding: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; font-size: 13px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,0.4); animation: toast-in 200ms ease; }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.status-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.status-row:last-child { border-bottom: none; }
.status-row .k { color: var(--text-dim); flex-shrink: 0; }
/* Valori lunghi (URL del price map, ecc.) vanno a capo invece di uscire dal
   riquadro — min-width:0 serve perche' il figlio di un flex item non si
   restringe sotto il proprio contenuto senza, anche con word-break. */
.status-row .v { font-family: var(--font-mono); font-size: 12.5px; color: var(--text); text-align: right; word-break: break-all; min-width: 0; }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent-2); border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; }
.login-card .brand { padding: 0 0 20px; border: none; justify-content: center; }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.route-card { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px; }
.route-card .name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.route-card .meta { color: var(--text-faint); font-size: 12px; font-family: var(--font-mono); }
.route-card .actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Dipendenti (card, non tabella — troppo stretta con 5+ azioni per riga) ── */

.group-chip-list { display: flex; flex-wrap: wrap; gap: 10px; }
.group-chip {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 8px 8px 14px;
}
.group-chip-info { display: flex; flex-direction: column; gap: 2px; }
.group-chip-name { font-weight: 600; font-size: 13.5px; }
.group-chip-count { font-size: 11.5px; color: var(--text-faint); }
.group-chip-actions { display: flex; gap: 6px; }
.group-chip-add {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px dashed var(--border); border-radius: 10px;
  color: var(--text-dim); font-size: 13px; font-weight: 500; padding: 10px 16px;
  cursor: pointer; transition: border-color 150ms ease, color 150ms ease;
}
.group-chip-add:hover { border-color: var(--accent); color: var(--text); }

.emp-list { display: flex; flex-direction: column; gap: 12px; }
.emp-card { display: flex; flex-direction: column; gap: 16px; }
.emp-card-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.emp-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.emp-email { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emp-group-field { display: flex; align-items: center; gap: 8px; }
.emp-group-field .k { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.emp-group-field select { width: auto; min-width: 160px; }
.emp-ignore-auth-field { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.emp-ignore-auth-field .k { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.emp-ignore-auth-field input { width: 15px; height: 15px; accent-color: var(--accent); }
.emp-card-stats {
  display: flex; flex-wrap: wrap; gap: 28px;
  padding: 14px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.emp-stat { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.emp-stat .k { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.emp-card-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.access-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 8px; border-radius: 8px; transition: background 150ms; cursor: pointer; position: relative; }
.access-row:hover { background: var(--surface-2); }
.access-row.dragging { opacity: 0.4; background: var(--surface-2); border: 1px dashed var(--accent); }
.access-row.disabled { opacity: 0.6; }
.access-drag-handle { color: var(--text-faint); cursor: grab; padding: 2px 0; margin-top: 2px; }
.access-drag-handle:active { cursor: grabbing; }
.access-check { display: flex; align-items: center; margin-top: 2px; }
.access-check input { width: 17px; height: 17px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.access-row-info { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.access-row-name { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.access-row-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.access-row-toggle { flex-shrink: 0; margin-left: 8px; }
.access-list-sortable { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }

/* Listino prezzi: tabella larga con filtri per colonna */
.table-scroll { overflow: auto; max-height: calc(100vh - 250px); }
.table-scroll table { width: max-content; min-width: 100%; }
.table-scroll thead th { position: sticky; background: var(--surface); z-index: 2; white-space: nowrap; }
.table-scroll thead tr:first-child th { top: 0; cursor: pointer; user-select: none; }
.table-scroll thead tr.filter-row th { top: 33px; padding: 4px 6px; cursor: default; text-transform: none; }
.table-scroll .filter-row input, .table-scroll .filter-row select { width: 100%; min-width: 64px; font-size: 12px; padding: 4px 6px; }
.table-scroll td { white-space: nowrap; }
.sort-ind { color: var(--accent-2); margin-left: 4px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 4px 2px; color: var(--text-dim); font-size: 12.5px; flex-wrap: wrap; }
