/* ==================================================================
   Console operatore - foglio di stile
   ================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1c2230;
  --text-dim: #626c7d;
  --text-faint: #8b95a5;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eff4ff;
  --green: #12a150;
  --green-soft: #e8f7ef;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber: #c2740a;
  --amber-soft: #fdf4e3;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .07);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --sidebar-w: 248px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* L'attributo hidden deve vincere sulle regole display dei componenti. */
[hidden] { display: none !important; }

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

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }

/* ------------------------------ bottoni ------------------------- */

.btn {
  font: inherit;
  font-weight: 550;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.btn:active { transform: translateY(.5px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label { display: block; font-size: 13px; font-weight: 550; color: var(--text-dim); }
label input, label select { margin-top: 5px; font-weight: 400; color: var(--text); }

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

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #eef2f9 0%, #f6f7f9 55%, #edf1f7 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 32px 30px;
  display: grid;
  gap: 16px;
}
.login-logo {
  display: flex; align-items: center; gap: 9px;
  color: var(--accent); font-weight: 700; font-size: 16px;
  letter-spacing: -.02em;
}
.login-card h1 { font-size: 19px; margin-bottom: 2px; }
.form-error {
  background: var(--red-soft); color: var(--red);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px;
}

/* ------------------------------ layout -------------------------- */

#appView { display: flex; height: 100%; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 14px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 4px 8px 2px;
  color: var(--accent); font-weight: 700; letter-spacing: -.02em;
}
.nav { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  font: inherit; font-weight: 500;
  text-align: left;
  background: none; border: 0; cursor: pointer;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.nav-ico { width: 18px; text-align: center; opacity: .85; font-size: 13px; }
.nav-badge {
  margin-left: auto; background: var(--green-soft); color: var(--green);
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px;
}

.quick-connect {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid; gap: 8px;
}
.quick-connect label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
#quickCode { font-family: var(--mono); letter-spacing: .08em; text-align: center; }
#quickPassword { font-family: var(--mono); letter-spacing: .06em; text-align: center; }
.qc-hint { margin: 0; font-size: 10.5px; line-height: 1.35; color: var(--text-faint); }

.sidebar-foot { margin-top: auto; display: grid; gap: 9px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 650; font-size: 13px;
}
.user-meta { display: grid; line-height: 1.3; min-width: 0; }
.user-meta strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta span { font-size: 11px; color: var(--text-faint); }
.conn-state { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-faint); padding: 0 4px; }
.conn-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.conn-state.ok i { background: var(--green); }
.conn-state.ko i { background: var(--red); }

.main { flex: 1; overflow-y: auto; padding: 22px 26px 60px; }
.view-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.head-actions { display: flex; align-items: center; gap: 10px; }
.search { width: 260px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.check input { width: auto; margin: 0; }

/* ------------------------------ pannelli ------------------------ */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.panel-hint { margin: 0; padding: 11px 16px; font-size: 12.5px; color: var(--text-dim); background: var(--surface-2); border-bottom: 1px solid var(--border); }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 26px; font-weight: 650; letter-spacing: -.02em; }
.stat span { font-size: 12px; color: var(--text-dim); }
.stat.is-live b { color: var(--green); }

/* ------------------------------ tabelle ------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-faint);
  padding: 9px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap;
}
td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.t-actions { text-align: right; white-space: nowrap; }
.empty { padding: 34px 16px; text-align: center; color: var(--text-faint); font-size: 13px; }

.tag {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px; background: var(--surface-2);
  color: var(--text-dim); border: 1px solid var(--border);
}
.tag.ok { background: var(--green-soft); color: var(--green); border-color: transparent; }
.tag.off { background: var(--surface-2); color: var(--text-faint); }
.tag.warn { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.tag.bad { background: var(--red-soft); color: var(--red); border-color: transparent; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ------------------------------ dispositivi --------------------- */

.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 12px;
}
.dev-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  display: grid; gap: 10px;
}
.dev-card.is-online { border-color: #bfe3cd; }
.dev-top { display: flex; align-items: flex-start; gap: 9px; }
.dev-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); margin-top: 6px; flex: none; }
.dev-card.is-online .dev-dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dev-name { font-weight: 600; line-height: 1.35; }
.dev-sub { font-size: 12px; color: var(--text-dim); }
.dev-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 11.5px; color: var(--text-faint); }
.dev-code { font-family: var(--mono); letter-spacing: .06em; }
.dev-actions { display: flex; gap: 7px; }
.dev-actions .btn { flex: 1; }
.star { background: none; border: 0; cursor: pointer; font-size: 15px; color: var(--border-strong); padding: 0 2px; margin-left: auto; }
.star.on { color: #eab308; }

/* ------------------------------ sessione ------------------------ */

.session { position: fixed; inset: 0; background: #14161c; display: flex; flex-direction: column; z-index: 50; }
.session-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 12px; background: #1d2029; border-bottom: 1px solid #2c303c;
  color: #d8dde7; font-size: 13px;
}
.sb-left { display: flex; align-items: center; gap: 9px; min-width: 0; }
.sb-left strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-center { display: flex; align-items: center; gap: 7px; margin: 0 auto; }
.sb-right { display: flex; align-items: center; gap: 7px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.sb-timer { font-family: var(--mono); font-size: 12px; color: #98a1b3; }
.sb-btn {
  position: relative;
  background: #262a35; border: 1px solid #343947; color: #cbd2de;
  border-radius: 6px; padding: 5px 10px; cursor: pointer; font: inherit; font-size: 13px;
}
.sb-btn:hover { background: #303542; color: #fff; }
.sb-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sb-select {
  background: #262a35; border: 1px solid #343947; color: #cbd2de;
  border-radius: 6px; padding: 5px 8px; width: auto; font-size: 12.5px;
}
.sb-select:focus { box-shadow: none; border-color: var(--accent); }
.sb-toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: #cbd2de; }
.sb-toggle input { width: auto; margin: 0; }
.sb-badge {
  position: absolute; top: -5px; right: -5px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 20px; padding: 0 5px; min-width: 16px;
}

.session-body { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; position: relative; display: grid; place-items: center; overflow: hidden; background: #0d0f14; }
#screen { max-width: 100%; max-height: 100%; display: block; cursor: crosshair; outline: none; image-rendering: auto; }
#screen.no-control { cursor: default; }
.stage-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 16px;
  background: rgba(13,15,20,.93); color: #cbd2de; text-align: center; padding: 24px;
}
.stage-overlay p { margin: 0; max-width: 420px; }
.spinner {
  width: 30px; height: 30px; border: 3px solid #333a48; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
.stage-stats {
  position: absolute; left: 10px; bottom: 10px;
  background: rgba(0,0,0,.6); color: #9fb0c8; font-family: var(--mono); font-size: 11px;
  padding: 4px 9px; border-radius: 5px; pointer-events: none;
}

.side-panel {
  width: 320px; flex: none; background: #1d2029; border-left: 1px solid #2c303c;
  display: flex; flex-direction: column; color: #d8dde7;
}
.sp-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 13px; border-bottom: 1px solid #2c303c; }
.sp-close { background: none; border: 0; color: #8b95a5; font-size: 15px; cursor: pointer; padding: 2px 5px; }
.sp-close:hover { color: #fff; }

.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 7px 11px; border-radius: 11px; font-size: 13px; line-height: 1.4; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.them { align-self: flex-start; background: #2a2f3b; border-bottom-left-radius: 3px; }
.msg time { display: block; font-size: 10px; opacity: .6; margin-top: 2px; }
.msg.sys { align-self: center; background: none; color: #78829a; font-size: 11.5px; font-style: italic; }
.chat-form { display: flex; gap: 7px; padding: 10px; border-top: 1px solid #2c303c; }
.chat-form input { background: #262a35; border-color: #343947; color: #e6eaf1; }

.fp-send { padding: 11px; border-bottom: 1px solid #2c303c; }
.drop {
  display: grid; place-items: center; text-align: center;
  border: 1.5px dashed #3c4252; border-radius: var(--radius);
  padding: 16px 12px; font-size: 12.5px; color: #98a1b3; cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(37,99,235,.08); color: #cbd2de; }
.drop small { color: #6d778c; }
.fp-browse { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.fp-path { display: flex; gap: 6px; padding: 9px 11px; }
.fp-path input { background: #262a35; border-color: #343947; color: #a9b3c4; font-family: var(--mono); font-size: 11.5px; }
.fp-entries { flex: 1; overflow-y: auto; padding: 0 6px 8px; }
.fp-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 6px; cursor: pointer; font-size: 12.5px;
}
.fp-item:hover { background: #2a2f3b; }
.fp-item .sz { margin-left: auto; color: #6d778c; font-size: 11px; font-family: var(--mono); }
.fp-transfers { border-top: 1px solid #2c303c; max-height: 190px; overflow-y: auto; padding: 8px 11px; display: grid; gap: 7px; }
.tr { font-size: 12px; }
.tr-name { display: flex; justify-content: space-between; gap: 8px; }
.tr-name span:last-child { color: #8b95a5; font-size: 11px; white-space: nowrap; }
.bar { height: 4px; background: #2c303c; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.tr.done .bar i { background: var(--green); }
.tr.err .bar i { background: var(--red); }

/* ------------------------------ modale -------------------------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,20,28,.5);
  display: grid; place-items: center; padding: 24px; z-index: 80;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: 13px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px; max-height: 88vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; overflow-y: auto; display: grid; gap: 13px; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 9px; }
.modal-body .hint { font-size: 12.5px; color: var(--text-dim); margin: 0; }
.copybox {
  display: flex; gap: 7px; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px;
}
.copybox code { flex: 1; font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

/* ------------------------------ toast --------------------------- */

.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 9px; z-index: 100; }
.toast {
  background: #1d2029; color: #e6eaf1; border-radius: var(--radius-sm);
  padding: 11px 15px; font-size: 13px; box-shadow: var(--shadow-lg);
  max-width: 340px; animation: slideIn .18s ease-out;
}
.toast.ok { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(14px) } }

@media (max-width: 860px) {
  .sidebar { width: 68px; padding: 14px 8px; }
  .brand span, .nav-item:not(.is-active) span:not(.nav-ico), .quick-connect, .user-meta, .conn-state { display: none; }
  .nav-item { justify-content: center; }
  .main { padding: 16px 14px 50px; }
  .search { width: 160px; }
  .side-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 5; }
  .sb-center { gap: 5px; }
}
