/* Kiosk Web Panel — stile coerente col WPF originale (verde scuro + crema + accenti vino). */

:root {
  --bg: #1B2D1B;
  --panel: #2A3F2A;
  --panel-2: #223322;
  --accent: #8E2C2C;
  --warn: #5E3A1E;
  --green: #4A7A48;
  --cream: #F5F1E5;
  --muted: #A0AAA0;
  --border: #444;
  --bg-input: #0F1F0F;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* L'attributo HTML `hidden` deve vincere su qualsiasi `display:` specificato sotto.
   Senza !important, classi come .view/.modal-backdrop/.cam-fullscreen (display:flex)
   restano visibili anche con hidden e impilano tutte le view della SPA insieme. */
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--cream);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  min-height: 100vh;
}

a, a:visited { color: var(--cream); text-decoration: underline; }
a:hover { color: white; }

.view { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------------- AUTH ---------------- */
.auth-view { justify-content: center; align-items: center; padding: 24px; }
.auth-card {
  background: var(--panel);
  padding: 32px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
}
.auth-title { margin: 0 0 8px; font-size: 22px; }
.auth-sub { margin: 0 0 24px; color: var(--muted); }
.auth-footer { margin: 24px 0 0; color: var(--muted); font-size: 11px; text-align: center; }
.auth-card form label {
  display: block;
  margin: 12px 0;
}
.auth-card form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--cream);
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 14px;
}

/* ---------------- TOPBAR ---------------- */
.topbar {
  background: #0F1F0F;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #000;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar strong { font-size: 16px; }
.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #C04040;
  box-shadow: 0 0 6px rgba(0,0,0,0.5);
}
.dot.ok { background: #4A7A48; }
.dot.warn { background: #C0A040; }

/* ---------------- DASHBOARD ---------------- */
.dashboard { padding: 12px; flex: 1; }
.statusbar {
  background: #0F1F0F;
  padding: 6px 16px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid #000;
}
.grid-2 {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 12px;
  align-items: stretch;
}
.col { display: flex; flex-direction: column; gap: 12px; }

/* Sub-grid 2 colonne dentro la col destra (replica del layout WPF) */
.grid-2-sub {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid-2-sub > div { display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 1400px) {
  .grid-2-sub { grid-template-columns: 1fr; }
}
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}


/* ---------------- CARDS ---------------- */
.card {
  background: var(--panel);
  padding: 14px;
  border-radius: 6px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card:last-child { margin-bottom: 0; }
.card h2 { margin: 0 0 10px; font-size: 14px; font-weight: bold; }
.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
}

/* ---------------- BUTTONS ---------------- */
.btn, .btn-primary, .btn-ghost {
  background: var(--green);
  color: var(--cream);
  border: none;
  padding: 8px 14px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover, .btn-primary:hover, .btn-ghost:hover { filter: brightness(1.15); }
.btn:active, .btn-primary:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--cream); color: var(--panel); width: 100%; padding: 12px; font-size: 14px; margin-top: 12px; }
.btn-ghost { background: transparent; padding: 6px 10px; font-size: 12px; border: 1px solid var(--border); }
.btn-danger { background: var(--accent); }
.btn-warn { background: var(--warn); }
.btn-active { background: var(--cream); color: var(--panel); }

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

@media (max-width: 700px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------- STATUS GRID ---------------- */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
}
.status-grid > div { display: flex; align-items: center; gap: 6px; }
.status-grid > div.span-2 { grid-column: 1 / -1; }
.status-grid .label { color: var(--muted); white-space: nowrap; }
.status-grid .val { font-weight: 600; }
.status-grid .val.temps { display: inline-flex; flex-wrap: wrap; gap: 6px 10px; font-weight: 500; }
.temp-chip { padding: 1px 6px; border-radius: 4px; font-size: 12px; line-height: 1.5; white-space: nowrap; }
.temp-chip .tname { color: var(--muted); margin-right: 4px; font-weight: 500; }
.temp-ok   { background: rgba( 76,175, 80,0.18); color:#9CCC65; }
.temp-warn { background: rgba(255,193,  7,0.20); color:#FFD54F; }
.temp-hot  { background: rgba(244, 67, 54,0.25); color:#FF8A80; }
.temp-na   { background: rgba(255,255,255,0.06); color:#777; }
.label { color: var(--muted); }
.val-big { font-size: 22px; font-weight: bold; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.center { text-align: center; }
.wrap { word-break: break-all; }
.mt8 { margin-top: 8px; }
.mb8 { margin-bottom: 8px; }
.err { color: #ff8a8a; font-size: 12px; margin: 8px 0 0; min-height: 16px; }

/* ---------------- PREVIEW ----------------
   Niente container "decorativo" attorno all'immagine: solo l'img col suo bordo
   aderente. In questo modo non ci sono mai bande/aree verde scuro attorno al
   monitor vero. Il `.preview-wrap` si limita a centrarla orizzontalmente. */
.preview-wrap {
  display: flex;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
}
#preview-img {
  max-width: 100%;
  max-height: 70vh;
  cursor: crosshair;
  display: block;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #000;
}

/* ---------------- SPEEDTEST ---------------- */
.speed-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  text-align: center;
  margin-bottom: 8px;
}
.speed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------------- SELECT / INPUT ---------------- */
.select-multi, select, input[type="text"], input[type="email"], input[type="password"], input[type="date"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--cream);
  padding: 6px 8px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
}
.select-multi { width: 100%; }

/* ---------------- VIEWPORT ---------------- */
.viewport-row { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.pan-pad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 36px);
  gap: 3px;
}
.pan-btn { padding: 0; }
.pan-pad .btn-danger { padding: 4px 2px; font-size: 11px; }
.zoom-stack { display: flex; flex-direction: column; gap: 4px; min-width: 220px; }

.sched-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.sched-row label, .days-row label { display: flex; flex-direction: column; gap: 4px; }
.days-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.days-row label { flex-direction: row; align-items: center; gap: 4px; }

/* ---------------- CAM ---------------- */
.cam-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.cam-warning {
  background: rgba(142, 44, 44, 0.30);
  border: 1px solid var(--accent);
  border-left: 6px solid var(--accent);
  padding: 12px 16px;
  margin-bottom: 14px;
  border-radius: 4px;
  color: var(--cream);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.cam-warning::before {
  content: "⚠️";
  font-size: 22px;
  flex-shrink: 0;
}
.cam-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 800px) { .cam-grid { grid-template-columns: 1fr; } }

/* ---------------- CONNESSIONE DVR (scan rete + set IP) ---------------- */
.dvr-conn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.dvr-conn-summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 14px;
}
.dvr-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.dvr-badge-ok { background: rgba(74, 122, 72, 0.30); color: #9CCC65; }
.dvr-badge-err { background: rgba(192, 64, 64, 0.30); color: #FF8A80; }
.dvr-badge-unknown { background: rgba(255, 255, 255, 0.08); color: var(--muted); }
.dvr-conn-body { font-size: 14px; }
.dvr-scan-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 13px;
}
.dvr-scan-table th, .dvr-scan-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.dvr-scan-table thead th { color: var(--muted); font-weight: 600; }
.dvr-row-candidate { background: rgba(74, 122, 72, 0.16); }
.dvr-manual {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.dvr-manual-label { display: flex; flex-direction: column; gap: 4px; flex: 1 1 240px; }
.dvr-manual-label input { margin: 0; }
.btn-small { padding: 4px 10px; font-size: 12px; }

.cam-cell {
  position: relative;
  border: 1px solid var(--border);
  background: #0A1A0A;
  min-height: 280px;
  border-radius: 4px;
  overflow: hidden;
}
.cam-cell .cam-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: pointer;
  background: #000;
}
/* Quando l'<img> non ha src ancora (cam appena attivata o cam spenta),
   nascondi l'icona broken + alt-text che il browser mostra di default. */
.cam-cell .cam-img:not([src]),
.cam-cell .cam-img[src=""] { visibility: hidden; }
.cam-title {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(0,0,0,0.5);
  padding: 4px 10px;
  font-weight: 600;
  border-radius: 3px;
}
.cam-toggle {
  position: absolute;
  top: 8px; right: 8px;
  padding: 4px 10px;
  font-size: 12px;
}
.cam-err {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 8px;
}

/* Badge LIVE: comunica che il flusso è in tempo reale (l'orologio sovrimpresso
   dal DVR è indietro e potrebbe far pensare a immagini vecchie). */
.cam-live-badge {
  position: absolute;
  bottom: 8px; left: 8px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(142, 44, 44, 0.92);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1px;
  padding: 3px 9px;
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.cam-live-badge::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #ff3b30;
  box-shadow: 0 0 6px #ff3b30;
  animation: cam-live-pulse 1.4s ease-in-out infinite;
}
@keyframes cam-live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}
.cam-fs-live { bottom: 14px; left: 14px; font-size: 14px; padding: 5px 12px; z-index: 1001; }
.cam-note { margin-top: 12px; line-height: 1.55; }
.cam-live-inline {
  color: #FF8A80;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* Fullscreen cam */
.cam-fullscreen {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cam-fullscreen img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.cam-fs-close {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 1001;
}
.cam-fs-title {
  position: absolute;
  top: 12px; left: 12px;
  background: rgba(0,0,0,0.5);
  padding: 6px 12px;
  border-radius: 4px;
}

/* ---------------- ELENA HISTORY ---------------- */
.elena-summary { cursor: pointer; padding: 6px 0; }
.elena-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr) 2fr;
  gap: 16px;
  background: var(--panel-2);
  padding: 10px;
  border-radius: 4px;
  margin-bottom: 10px;
  text-align: center;
}
.elena-lang-wrap { text-align: left; }
.lang-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.lang-badge {
  background: var(--panel);
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 12px;
}
.lang-badge strong { color: var(--cream); margin-right: 4px; }

.elena-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  margin-bottom: 10px;
}
.elena-filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.elena-filters input, .elena-filters select { color: black; background: white; }

.elena-table, .users-table {
  width: 100%;
  border-collapse: collapse;
}
.elena-table th, .elena-table td, .users-table th, .users-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #333;
  text-align: left;
}
.elena-table thead th, .users-table thead th {
  background: #0F1F0F;
  font-weight: bold;
}
.elena-table tbody tr:nth-child(odd), .users-table tbody tr:nth-child(odd) {
  background: var(--panel-2);
}

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

/* ---------------- MODAL ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 24px;
}
.modal-card {
  background: var(--panel);
  border-radius: 6px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 12px; }
.modal-body label { display: block; margin: 8px 0; }
.modal-body input[type="text"],
.modal-body input[type="email"],
.modal-body input[type="password"] {
  width: 100%;
  display: block;
  margin-top: 4px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---------------- QR (2FA setup) ---------------- */
.qr-wrap {
  background: white;
  padding: 16px;
  border-radius: 4px;
  margin: 8px 0;
  text-align: center;
  color: #333;
}
.qr-wrap > div:last-child { margin-top: 8px; }
#twofa-qr-canvas { display: flex; justify-content: center; }
#twofa-qr-canvas svg, #twofa-qr-canvas canvas, #twofa-qr-canvas img {
  width: 220px;
  height: 220px;
  display: block;
  margin: 0 auto;
}

/* ===== Scanner di rete ===== */
.netscan-summary { cursor: pointer; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.netscan-title { margin: 0; display: inline; }
.netscan-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.netscan-filter {
  flex: 1 1 220px; min-width: 150px; padding: 8px 10px; border-radius: 6px;
  background: var(--bg-input); border: 1px solid var(--border); color: var(--cream);
}
.netscan-status { margin-left: auto; }
.netscan-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.netscan-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
.netscan-table th {
  text-align: left; padding: 6px 10px; color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; background: var(--panel); z-index: 1;
}
.netscan-table td { padding: 6px 10px; border-bottom: 1px solid rgba(68,68,68,0.5); vertical-align: middle; }
.netscan-table tbody tr:hover { background: rgba(255,255,255,0.04); }
.netscan-th-dot { width: 22px; }
.netscan-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 6px rgba(74,122,72,0.85);
}
.netscan-ip { font-weight: 600; }
.netscan-vendor { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.netscan-ping { white-space: nowrap; color: var(--muted); }
.netscan-act { white-space: nowrap; }
.netscan-empty { padding: 14px 4px; }

.netscan-tag {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 10px;
  font-size: 10px; font-weight: 700; vertical-align: middle; white-space: nowrap;
}
.netscan-tag-self { background: #2b4a6b; color: #cfe5ff; }
.netscan-tag-router { background: #3a3a3a; color: #dddddd; }
.netscan-tag-dvr { background: var(--green); color: var(--cream); }
.netscan-tag-candidate { background: var(--warn); color: #ffd9a8; }

.netscan-ports { display: flex; flex-wrap: wrap; gap: 4px; }
.netscan-chip {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px;
  padding: 1px 6px; font-size: 11px; white-space: nowrap;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
.netscan-chip-dvr { background: var(--warn); border-color: #7a5a30; color: #ffd9a8; font-weight: 700; }

.netscan-row-self { background: rgba(43,74,107,0.18); }
.netscan-row-router { background: rgba(255,255,255,0.04); }
.netscan-row-dvr { background: rgba(74,122,72,0.22); }
.netscan-row-candidate { background: rgba(94,58,30,0.30); }

/* Registrazioni */
.rec-cam-checkboxes { line-height: 1.7; }
.rec-cam-checkboxes label { display: inline-block; margin-right: 14px; font-size: 13px; cursor: pointer; }
.rec-cam-checkboxes input[type="checkbox"] { margin-right: 4px; }
.rec-results { display: flex; flex-direction: column; gap: 4px; }
.rec-result-row { padding: 2px 0; }
.rec-controls { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 10px; }
.rec-seek-row { display: flex; align-items: center; gap: 10px; }
.rec-seek-row input[type="range"] { flex: 1 1 auto; min-width: 0; cursor: pointer; }
