/* ═══════════════════════════════════════════════════════════════════════════
   Finest Frozen Food — Delivery Operations Console
   Sistema di stili. Console da sala operativa: densa, scura, gerarchica.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* superfici, dalla più profonda alla più in rilievo */
  --bg:        #0d141d;
  --surface:   #131d29;
  --surface-2: #1a2634;
  --surface-3: #223142;
  --line:      #2c3d51;
  --line-soft: #223142;

  /* testo */
  --text:      #e9eef5;
  --text-2:    #9fb0c4;
  --text-3:    #6b7f95;

  /* marchio e stati */
  --brand:     #1a7fc9;
  --brand-2:   #33b5e5;
  --green:     #2fbf71;
  --red:       #ef5350;
  --amber:     #f0b429;
  --violet:    #8b7cf6;

  --green-bg:  rgba(47,191,113,.13);
  --red-bg:    rgba(239,83,80,.13);
  --amber-bg:  rgba(240,180,41,.13);
  --brand-bg:  rgba(26,127,201,.15);

  --radius:    9px;
  --radius-sm: 6px;
  --shadow:    0 8px 28px rgba(0,0,0,.42);
  --nav-w:     216px;
  --top-h:     56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.spacer { flex: 1; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #2e4258; }

/* ── LOGIN ───────────────────────────────────────────────────────────────── */
.login-view {
  height: 100%; display: grid; place-items: center;
  background: radial-gradient(1100px 600px at 50% -10%, #16273a 0%, var(--bg) 62%);
}
.login-card {
  width: 340px; padding: 34px 30px 26px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.logo-lg { width: 190px; max-width: 100%; }
.login-sub { margin: -4px 0 6px; color: var(--text-3); font-size: 12px; letter-spacing: .5px; text-transform: uppercase; }
.login-card input { width: 100%; }
.error { color: var(--red); font-size: 12.5px; min-height: 16px; text-align: center; }

/* ── CAMPI ───────────────────────────────────────────────────────────────── */
input, select, textarea {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px; font: inherit; font-size: 13.5px; outline: none;
  transition: border-color .14s, box-shadow .14s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-bg);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
label.field { display: block; margin-bottom: 12px; }
label.field > span {
  display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-3); margin-bottom: 5px;
}
label.field > input, label.field > select, label.field > textarea { width: 100%; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── BOTTONI ─────────────────────────────────────────────────────────────── */
.btn {
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background .14s, border-color .14s, transform .06s;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { background: #2a3c50; border-color: #3a5069; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #2090dd; border-color: #2090dd; }
.btn.danger { background: transparent; border-color: rgba(239,83,80,.45); color: var(--red); }
.btn.danger:hover { background: var(--red-bg); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.icon-btn {
  background: transparent; border: none; color: var(--text-2);
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 16px; line-height: 1;
  display: grid; place-items: center; transition: background .14s, color .14s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ── STRUTTURA ───────────────────────────────────────────────────────────── */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: var(--top-h) 1fr;
  grid-template-areas: "topbar topbar" "sidenav content";
}
.app.nav-collapsed { grid-template-columns: 60px 1fr; }
.app.nav-collapsed .nav-item span { display: none; }
.app.nav-collapsed .nav-item { justify-content: center; }

.topbar {
  grid-area: topbar; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.logo-sm { height: 26px; }
.topbar-title { font-size: 15px; font-weight: 600; margin-left: 6px; }
.search-wrap input { width: 280px; padding: 7px 11px; font-size: 13px; }

.conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); padding: 0 6px; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.conn.on  .dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.conn.off .dot { background: var(--red);   box-shadow: 0 0 0 3px var(--red-bg); }

.sidenav {
  grid-area: sidenav; background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 10px 8px; display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-2); cursor: pointer; user-select: none;
  font-size: 13.5px; font-weight: 500; position: relative;
  transition: background .13s, color .13s;
}
.nav-item i { font-style: normal; font-size: 15px; width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-bg); color: var(--brand-2); }
.nav-item.active i { opacity: 1; }
.nav-sep { height: 1px; background: var(--line-soft); margin: 8px 4px; }
.nav-badge {
  margin-left: auto; background: var(--surface-3); color: var(--text-2);
  font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 10px;
}
.nav-badge:empty { display: none; }
.nav-badge.alert { background: var(--red); color: #fff; }

.content { grid-area: content; overflow-y: auto; padding: 18px 20px 32px; }

/* ── INTESTAZIONI DI SEZIONE ─────────────────────────────────────────────── */
.view-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.view-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.view-head .sub { color: var(--text-3); font-size: 12.5px; }

.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-3); font-weight: 700; margin: 22px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ── SCHEDE / PANNELLI ───────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card.pad0 { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line-soft);
}
.card-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }

.grid { display: grid; gap: 14px; }
.grid.k4 { grid-template-columns: repeat(4, 1fr); }
.grid.k3 { grid-template-columns: repeat(3, 1fr); }
.grid.k2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1180px) { .grid.k4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px)  { .grid.k3, .grid.k2 { grid-template-columns: 1fr; } }

/* ── KPI ─────────────────────────────────────────────────────────────────── */
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--text-3);
}
.kpi.ok::before    { background: var(--green); }
.kpi.bad::before   { background: var(--red); }
.kpi.warn::before  { background: var(--amber); }
.kpi.info::before  { background: var(--brand-2); }
.kpi .k-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); font-weight: 600; }
.kpi .k-value { font-size: 27px; font-weight: 700; line-height: 1.1; }
.kpi .k-note  { font-size: 11.5px; color: var(--text-3); }
.kpi.clickable { cursor: pointer; transition: border-color .14s; }
.kpi.clickable:hover { border-color: var(--brand); }

/* ── TABELLE ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid-table th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-3); font-weight: 700; padding: 9px 12px;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
table.grid-table td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid-table tbody tr { transition: background .11s; }
table.grid-table tbody tr:hover { background: var(--surface-2); }
table.grid-table tbody tr.sel { background: var(--brand-bg); }
table.grid-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid-table td.actions { text-align: right; white-space: nowrap; }
.t-main { font-weight: 500; }
.t-sub { color: var(--text-3); font-size: 11.5px; }
.empty { padding: 34px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ── BADGE ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  padding: 3px 8px; border-radius: 20px; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge.green  { background: var(--green-bg); color: var(--green); }
.badge.red    { background: var(--red-bg);   color: var(--red); }
.badge.amber  { background: var(--amber-bg); color: var(--amber); }
.badge.blue   { background: var(--brand-bg); color: var(--brand-2); }
.badge.grey   { background: var(--surface-3); color: var(--text-3); }
.dot-live { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-live.on { background: var(--green); }
.dot-live.off { background: var(--text-3); }

/* ── FILTRI ──────────────────────────────────────────────────────────────── */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2);
  padding: 5px 11px; border-radius: 16px; font-size: 12px; cursor: pointer;
  transition: background .13s, color .13s, border-color .13s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.chip .cnt { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ── AVVISI ──────────────────────────────────────────────────────────────── */
.alert-row {
  display: flex; align-items: center; gap: 11px; padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.alert-row:last-child { border-bottom: none; }
.alert-row .ico { font-size: 15px; width: 20px; text-align: center; }
.alert-row.warn .ico { color: var(--amber); }
.alert-row.bad  .ico { color: var(--red); }
.alert-row.info .ico { color: var(--brand-2); }
.alert-row .txt { flex: 1; }
.alert-row .txt b { font-weight: 600; }

/* ── MAPPA ───────────────────────────────────────────────────────────────── */
#map, .map-box { width: 100%; border-radius: var(--radius); background: var(--surface-2); }
.map-full { height: calc(100vh - var(--top-h) - 96px); }
.map-small { height: 300px; }
.leaflet-container { background: #16202c; border-radius: var(--radius); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-2); color: var(--text); }
.pin {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  font-size: 12px; font-weight: 700; color: #fff; border: 2px solid rgba(255,255,255,.85);
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
}

/* ── CHAT ────────────────────────────────────────────────────────────────── */
.chat-layout {
  display: grid; grid-template-columns: 260px 1fr; gap: 14px;
  height: calc(100vh - var(--top-h) - 74px);
}
.chat-list { overflow-y: auto; }
.chat-peer {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft); cursor: pointer; transition: background .12s;
}
.chat-peer:hover { background: var(--surface-2); }
.chat-peer.active { background: var(--brand-bg); }
.chat-peer .who { flex: 1; min-width: 0; }
.chat-peer .who .nm { font-weight: 600; font-size: 13px; }
.chat-peer .who .last { color: var(--text-3); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-peer .unread { background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 10px; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 9px; }
.msg { max-width: 66%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; position: relative; }
.msg .meta { font-size: 10.5px; color: var(--text-3); margin-top: 4px; }
.msg.out { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 3px; }
.msg.out .meta { color: rgba(255,255,255,.7); }
.msg.in  { align-self: flex-start; background: var(--surface-3); border-bottom-left-radius: 3px; }
.msg audio { width: 230px; height: 34px; margin-top: 2px; }
.chat-compose { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-compose input { flex: 1; }
.chat-day { align-self: center; font-size: 11px; color: var(--text-3); padding: 2px 10px; background: var(--surface-2); border-radius: 10px; }

/* ── MODALE ──────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(5,9,14,.72);
  display: grid; place-items: center; z-index: 900; padding: 20px;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-card.wide { max-width: 900px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ── PANNELLO LATERALE ───────────────────────────────────────────────────── */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 94vw;
  background: var(--surface); border-left: 1px solid var(--line);
  z-index: 910; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 15px; font-weight: 600; flex: 1; }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1; }
.scrim { position: fixed; inset: 0; background: rgba(5,9,14,.5); z-index: 905; }

/* ── DETTAGLIO: coppie etichetta/valore ──────────────────────────────────── */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 7px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; }
.kv dd { margin: 0; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img {
  width: 92px; height: 92px; object-fit: cover; border-radius: var(--radius-sm);
  border: 1px solid var(--line); cursor: pointer; background: var(--surface-2);
}
.sig-box { background: #fff; border-radius: var(--radius-sm); padding: 6px; display: inline-block; }
.sig-box img { max-width: 240px; display: block; }

/* ── TOAST ───────────────────────────────────────────────────────────────── */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 950; }
.toast {
  background: var(--surface-3); border: 1px solid var(--line); border-left: 3px solid var(--brand);
  padding: 11px 15px; border-radius: var(--radius-sm); font-size: 13px;
  box-shadow: var(--shadow); animation: slideIn .18s ease-out; max-width: 340px;
}
.toast.ok  { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ── VARIE ───────────────────────────────────────────────────────────────── */
.muted { color: var(--text-3); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bar { height: 6px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.bar > i.green { background: var(--green); }
.bar > i.amber { background: var(--amber); }
.bar > i.red   { background: var(--red); }

@media (max-width: 860px) {
  .app { grid-template-columns: 60px 1fr; }
  .nav-item span { display: none; }
  .search-wrap { display: none; }
  .chat-layout { grid-template-columns: 1fr; }
}

/* ── PANNELLO CHIAMATA ───────────────────────────────────────────────────── */
.call-panel {
  position: fixed; right: 18px; bottom: 18px; z-index: 960;
  background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid var(--green);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 16px; min-width: 268px;
  display: flex; align-items: center; gap: 14px;
  animation: slideIn .18s ease-out;
}
.call-panel.incoming {
  border-left-color: var(--brand-2);
  animation: slideIn .18s ease-out, pulseCall 1.4s ease-in-out infinite;
}
@keyframes pulseCall {
  0%, 100% { box-shadow: var(--shadow); }
  50%      { box-shadow: 0 0 0 4px var(--brand-bg), var(--shadow); }
}
.call-who { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; }
.call-avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-bg); color: var(--brand-2); font-size: 17px; flex: none;
}
.call-name { font-weight: 600; font-size: 14px; }
.call-status {
  font-size: 11.5px; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.call-actions { display: flex; gap: 6px; flex: none; }
