:root {
  --bg: #101114;
  --bg2: #16181d;
  --card: #1b1e24;
  --line: #2a2e36;
  --line2: #363b45;
  --txt: #eceae4;
  --txt2: #a9a69e;
  --txt3: #75726b;
  --accent: #f2b441;        /* ambra: luci di palco */
  --accent-ink: #1a1405;
  --ok: #5fbf7f;
  --warn: #e8a13a;
  --bad: #e0685c;
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--txt); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--txt2); font-size: 13px; }
.err { color: var(--bad); min-height: 20px; margin: 0; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line2);
  background: var(--card); color: var(--txt); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--txt3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--txt2); font-size: 18px; cursor: pointer; padding: 6px 10px; border-radius: 8px; }
.icon-btn:hover { background: var(--card); color: var(--txt); }
input, select, textarea { font: inherit; color: var(--txt); background: var(--bg2); border: 1px solid var(--line2); border-radius: 9px; padding: 8px 11px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; width: 100%; }

/* ── Login ── */
.auth { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.auth-card p { color: var(--txt2); margin: 0; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 17px; letter-spacing: -.02em; }
.brand-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px var(--accent); }

/* ── Barra superiore ── */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg); }
.tabs { display: flex; gap: 2px; margin-left: 12px; }
.tabs button { background: none; border: 0; color: var(--txt2); font: inherit; font-weight: 550; padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.tabs button:hover { color: var(--txt); }
.tabs button.on { color: var(--txt); background: var(--card); }
.agent-pill { margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line2);
  background: var(--bg2); color: var(--txt2); font: inherit; font-size: 13px; cursor: pointer; }
.pill-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--txt3); }
.agent-pill.on { color: var(--txt); }
.agent-pill.on .pill-dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.agent-pill.test .pill-dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.banner { padding: 9px 16px; background: color-mix(in srgb, var(--warn) 14%, var(--bg)); border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); font-size: 13px; }
.banner button { margin-left: 8px; }

.view { display: none; flex: 1; min-height: 0; overflow: auto; }
.view.on { display: block; }
#view-map.on { display: flex; }

/* ── Mappa ── */
.map-wrap { position: relative; flex: 1; }
#map { position: absolute; inset: 0; background: #0b0c0e; }
.map-filters { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 500; display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: 720px; }
.map-filters > * { pointer-events: auto; }
.map-filters input { width: min(320px, 100%); background: rgba(22,24,29,.92); backdrop-filter: blur(6px); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line2); background: rgba(22,24,29,.92);
  color: var(--txt2); font: inherit; font-size: 12px; cursor: pointer; }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; }
.chip.off { opacity: .45; }
.chip b { color: var(--txt); font-weight: 600; }
.map-legend { position: absolute; bottom: 14px; left: 12px; z-index: 500; background: rgba(22,24,29,.92); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 12px; color: var(--txt2); }
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--card); color: var(--txt); }
.venue-marker { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #0b0c0e; box-shadow: 0 0 0 1px rgba(255,255,255,.25); }
.marker-cluster { background: rgba(242,180,65,.28) !important; }
.marker-cluster div { background: rgba(242,180,65,.92) !important; color: var(--accent-ink); font: 700 12px/30px var(--font) !important; }
.leaflet-control-attribution { background: rgba(16,17,20,.8) !important; color: var(--txt3) !important; }
.leaflet-control-attribution a { color: var(--txt2) !important; }

/* ── Pipeline ── */
.kanban { display: flex; gap: 12px; padding: 16px; min-height: 100%; align-items: flex-start; overflow-x: auto; }
.col { flex: 0 0 260px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 110px); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13px; }
.col-head .n { margin-left: auto; color: var(--txt3); font-weight: 500; }
.col-body { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.vcard { background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; cursor: pointer; }
.vcard:hover { border-color: var(--line2); }
.vcard .t { font-weight: 600; }
.vcard .s { color: var(--txt3); font-size: 12px; display: flex; gap: 8px; }
.score { display: inline-block; min-width: 30px; text-align: center; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--txt2); }
.score.hi { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }

/* ── Lista ── */
.list-head { display: flex; gap: 8px; padding: 14px 16px; flex-wrap: wrap; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.list-head input { flex: 1 1 220px; }
.table-wrap { overflow-x: auto; padding: 0 16px 24px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--txt3); font-weight: 550; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--bg2); }
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12px; }
.status .sw { width: 8px; height: 8px; border-radius: 50%; }

/* ── Attività ── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; padding: 16px 16px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--txt2); font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card h3 { font-size: 14px; margin-bottom: 10px; }
.feed { display: flex; flex-direction: column; }
.feed-item { padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.feed-item:first-child { border-top: 0; }
.feed-item .t { font-weight: 600; }
.log { font: 12px/1.55 ui-monospace, Consolas, monospace; color: var(--txt2); max-height: 60vh; overflow: auto; }
.log .error { color: var(--bad); }
.log .warn { color: var(--warn); }

/* ── Impostazioni ── */
.settings { max-width: 860px; margin: 0 auto; padding: 16px 16px 60px; display: flex; flex-direction: column; gap: 14px; }
.fs { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.fs > h3 { font-size: 15px; }
.fs > p.muted { margin: 4px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: 12px; color: var(--txt2); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 0; border-top: 1px solid var(--line); }
.switch-row:first-of-type { border-top: 0; }
.switch-row.field { flex-direction: row; }
.switch-row .l b { display: block; font-weight: 600; }
.switch-row .l small { color: var(--txt2); }
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line2); transition: .15s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--txt2); transition: .15s; }
.switch input:checked + span { background: color-mix(in srgb, var(--ok) 40%, transparent); }
.switch input:checked + span::after { left: 21px; background: var(--ok); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.save-bar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 35%); }
pre.code { background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; padding: 10px; white-space: pre-wrap; font: 12px/1.5 ui-monospace, Consolas, monospace; max-height: 260px; overflow: auto; }

/* ── Dettaglio ── */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--bg2); border-left: 1px solid var(--line); z-index: 1000;
  display: flex; flex-direction: column; box-shadow: -20px 0 50px rgba(0,0,0,.4); }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-head > div { flex: 1; min-width: 0; }
.drawer-head h2 { font-size: 18px; }
.drawer-body { overflow-y: auto; padding: 14px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13px; }
.kv > span { color: var(--txt3); }
.kv > div { min-width: 0; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.timeline { display: flex; flex-direction: column; gap: 8px; }
.tl { border-left: 2px solid var(--line2); padding: 2px 0 2px 12px; }
.tl.in { border-color: var(--accent); }
.tl .h { font-size: 12px; color: var(--txt3); }
.tl .sum { font-weight: 550; }
.tl details { margin-top: 4px; }
.tl details summary { color: var(--txt2); font-size: 12px; cursor: pointer; }
.tl pre { white-space: pre-wrap; font: 12px/1.5 var(--font); color: var(--txt2); margin: 6px 0 0; background: var(--bg); border-radius: 8px; padding: 8px; }

/* ── Modale e toast ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 1100; display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(640px, 100%); max-height: 90vh; background: var(--bg2); border: 1px solid var(--line2); border-radius: 14px; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { flex: 1; font-size: 15px; }
.modal-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--card); border: 1px solid var(--line2); padding: 10px 16px; border-radius: 10px;
  z-index: 1200; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.bad { border-color: var(--bad); }

/* ── Telefono ── */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  .tabs button { flex: 0 0 auto; }
  .agent-pill { font-size: 12px; }
  .two-col { grid-template-columns: 1fr; }
  .drawer { width: 100%; top: 8vh; border-left: 0; border-top: 1px solid var(--line2); border-radius: 16px 16px 0 0; }
  .col { flex-basis: 78vw; }
  .kv { grid-template-columns: 90px 1fr; }
}
