:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1c2330;
  --muted: #667085;
  --border: #d9dde4;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a9d55;
  --off: #9aa3b2;
  --warn: #c77700;
  --danger: #c93636;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161d;
    --surface: #1a2029;
    --surface-2: #232b37;
    --text: #e6e9ef;
    --muted: #8f9aad;
    --border: #2d3644;
    --accent: #4c8dff;
    --accent-text: #0b1220;
    --ok: #3ecf7f;
    --off: #5c6678;
    --warn: #f0a63a;
    --danger: #ff6b6b;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12161d;
  --surface: #1a2029;
  --surface-2: #232b37;
  --text: #e6e9ef;
  --muted: #8f9aad;
  --border: #2d3644;
  --accent: #4c8dff;
  --accent-text: #0b1220;
  --ok: #3ecf7f;
  --off: #5c6678;
  --warn: #f0a63a;
  --danger: #ff6b6b;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

button, select, input {
  font: inherit;
  color: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: default; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--danger); }
button.icon { padding: 6px 9px; }

input[type="text"], input[type="password"], input[type="search"], select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 7px 10px;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.muted { color: var(--muted); }

.logo { display: block; flex: none; object-fit: contain; }
.login-card .logo { margin: 0 auto; }
.customer .logo { margin-top: 28px; }

/* ---- accesso ---- */

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card label { display: grid; gap: 4px; font-weight: 600; }

/* ---- dashboard ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 17px; flex: 1; }
.topbar .user { color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: 20px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs button {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  padding: 8px 14px;
  color: var(--muted);
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1; min-width: 180px; max-width: 360px; }
.toolbar .spacer { flex: 1; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--off);
  margin-right: 8px;
}
.dot.online { background: var(--ok); }
.dot.busy { background: var(--warn); }

.key-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
}
.key-box code { flex: 1; font-size: 15px; word-break: break-all; }

/* ---- account ---- */

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 22px 24px;
  width: min(540px, 94vw);
  max-height: 92vh;
  overflow: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog h3 { margin: 18px 0 8px; font-size: 15px; }
dialog section { border-top: 1px solid var(--border); padding-top: 4px; }
dialog section:first-of-type { border-top: 0; }
.field { display: grid; gap: 4px; margin-bottom: 10px; font-weight: 600; }
.field input { font-weight: 400; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.qr { display: block; background: #fff; padding: 8px; border-radius: 8px; margin: 8px 0; }
.secret { font-family: ui-monospace, Consolas, monospace; word-break: break-all; letter-spacing: .06em; }
.codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 16px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 15px;
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 6px;
  margin: 8px 0 12px;
}
.ok { color: var(--ok); }
button.icon.on { background: var(--surface-2); }

.error { color: var(--danger); min-height: 1.4em; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.console-note { margin: 0 0 14px; }

/* ---- pagina del cliente ---- */

.customer { max-width: 560px; }
.customer .brand { margin: 8px 0 0; font-weight: 600; }
.customer h1 { margin: 4px 0 4px; font-size: 26px; }
.customer .lead { font-size: 16px; margin: 0 0 20px; color: var(--muted); }
.steps { padding-left: 22px; display: grid; gap: 18px; }
.steps li { padding-left: 4px; }
.steps li > * { display: block; }
.steps li strong { font-size: 16px; }
.steps li div { margin-top: 10px; }
.button {
  display: inline-block;
  border-radius: 6px;
  padding: 10px 18px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--border);
}
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.note { margin-top: 24px; }
.problem {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-radius: 6px;
  color: var(--danger);
}

/* ---- viewer ---- */

body.viewer { display: flex; flex-direction: column; height: 100vh; overflow: hidden; background: #0d1015; }

.vbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.vbar .title { font-weight: 600; }
.vbar .grow { flex: 1; }
.vbar label { display: inline-flex; align-items: center; gap: 6px; }
.vbar select { padding: 4px 8px; }
.vbar .stats { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 190px; text-align: right; }
.vbar .rights {
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 13px;
  cursor: help;
}

.work { flex: 1; display: flex; min-height: 0; }

.files {
  width: 340px;
  flex: none;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.files h2 { margin: 0 0 6px; font-size: 14px; }
.files p { margin: 0 0 8px; }
.files-head { display: flex; justify-content: space-between; align-items: center; }
.transfers, .fs-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.transfers li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; background: var(--surface-2); padding: 8px 10px; border-radius: 6px; }
.transfer-name { grid-column: 1 / -1; font-weight: 600; word-break: break-all; }
.transfers progress { width: 100%; grid-column: 1 / -1; }
.fs-bar { display: flex; gap: 6px; align-items: center; }
.fs-path { flex: 1; font-size: 12px; color: var(--muted); word-break: break-all; }
.fs-list li { display: flex; gap: 8px; align-items: center; }
.fs-list .file-name { flex: 1; word-break: break-all; }
button.linklike { border: 0; background: none; padding: 2px 0; text-align: left; color: var(--accent); word-break: break-all; }
button.linklike:hover:not(:disabled) { background: none; text-decoration: underline; }

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
}
.stage canvas { display: block; background: #000; outline: none; touch-action: none; }
.stage canvas:focus { box-shadow: 0 0 0 2px var(--accent); }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  justify-items: center;
  text-align: center;
  background: rgba(13, 16, 21, .86);
  color: #e6e9ef;
  padding: 20px;
}
.overlay p { margin: 0; font-size: 16px; }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

@media (max-width: 640px) {
  main { padding: 12px; }
  .topbar { padding: 10px 12px; }
}

/* ---- aziende, note e utenti ---- */
td.notes { max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.link-cell { display: flex; gap: 6px; align-items: center; }
input.link { width: 330px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
td select { padding: 4px 8px; max-width: 220px; }
#user-form input[type="text"], #user-form input[type="password"] { width: 220px; }
