:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #dde3ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --green-bg: #e3f5e8; --green-fg: #1b6b34;
  --amber-bg: #fff3d6; --amber-fg: #8a5a00;
  --red-bg: #fde4e4; --red-fg: #a11d1d;
  --grey-bg: #eceff3; --grey-fg: #4b5563;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2029;
    --surface-2: #202834;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --border: #2d3644;
    --accent: #4f8cff;
    --danger: #ff6b6b;
    --green-bg: #183626; --green-fg: #7fd99b;
    --amber-bg: #3a2e12; --amber-fg: #f2c063;
    --red-bg: #3d1c1c; --red-fg: #ff9a9a;
    --grey-bg: #2a323d; --grey-fg: #b4bdc9;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

h1 { font-size: 1.45rem; margin: 0 0 1rem; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; font-weight: 650; }

.boot { padding: 3rem; text-align: center; color: var(--muted); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.92em; }
small { font-size: 0.85em; }

/* --- Barra superiore ---------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.6rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand strong { display: block; font-size: 1rem; }
.brand small { display: block; color: var(--muted); }
.logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
}

.tabs { display: flex; gap: 0.25rem; flex: 1; flex-wrap: wrap; }
.tabs a {
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 550;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--surface-2); color: var(--accent); }

.user { display: flex; align-items: center; gap: 0.75rem; }

.banner {
  display: flex; align-items: center; justify-content: center; gap: 1rem;
  padding: 0.6rem 1.5rem;
  background: var(--amber-bg); color: var(--amber-fg);
  border-bottom: 1px solid var(--border);
}

main { padding: 1.5rem; max-width: 1280px; margin: 0 auto; }
main.center { display: flex; justify-content: center; align-items: flex-start; padding-top: 10vh; }

/* --- Schede -------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.card.login { width: 100%; max-width: 420px; }
.card.login .brand { margin-bottom: 1.25rem; }

.stack > * + * { margin-top: 0.9rem; }

.heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.heading h1 { margin-bottom: 0.5rem; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.tile-label { display: block; color: var(--muted); font-size: 0.88rem; }
.tile strong { display: block; font-size: 1.7rem; font-weight: 650; margin: 0.2rem 0; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); }

.facts {
  display: grid;
  grid-template-columns: minmax(180px, max-content) 1fr;
  gap: 0.4rem 1.5rem;
  margin: 0;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }

/* --- Moduli -------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field > span { font-weight: 550; }
.field small { color: var(--muted); }
.field.narrow { max-width: 360px; }

input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; }
input:focus, select:focus, textarea:focus, button:focus-visible, .tabs a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

fieldset.choices { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
fieldset.choices legend { font-weight: 550; margin-bottom: 0.5rem; }
.choice {
  display: flex; gap: 0.75rem; align-items: flex-start;
  padding: 0.75rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.choice input { margin-top: 0.25rem; }
.choice strong { display: block; }
.choice small { color: var(--muted); }

.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.75rem; }

.toolbar { display: flex; gap: 0.75rem; margin: 0.75rem 0; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { max-width: 360px; }
.toolbar select { width: auto; }
label.inline { display: inline-flex; align-items: center; gap: 0.35rem; }

.actions { display: flex; gap: 0.6rem; justify-content: flex-end; }
.actions.left { justify-content: flex-start; margin-top: 1rem; }

button {
  font: inherit;
  font-weight: 550;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }
button.secondary { background: transparent; color: var(--text); border-color: var(--border); }
button.secondary:hover { background: var(--surface-2); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.link { background: none; border: 0; color: var(--accent); padding: 0.25rem 0.4rem; }
button.link.danger { color: var(--danger); background: none; }
button.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }

.form-error { color: var(--danger); margin: 0.25rem 0; }
.note { color: var(--amber-fg); }
.empty { color: var(--muted); padding: 0.5rem 0; }

/* --- Tabelle ------------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.82rem; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.retired td { color: var(--muted); }
td small { display: block; }
.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.green { background: var(--green-bg); color: var(--green-fg); }
.badge.amber { background: var(--amber-bg); color: var(--amber-fg); }
.badge.red { background: var(--red-bg); color: var(--red-fg); }
.badge.grey { background: var(--grey-bg); color: var(--grey-fg); }

.ports { margin: 0; padding-left: 1.2rem; }
.ports li { margin: 0.2rem 0; }

pre.log, pre.code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  overflow: auto;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.4;
}
pre.log { height: 65vh; white-space: pre-wrap; word-break: break-all; }

/* --- Finestra di dialogo e avvisi ----------------------------------------- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.25rem;
  width: min(480px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgba(10, 14, 20, 0.45); }
dialog form > * + * { margin-top: 0.9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

#toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 20;
}
#toast.error { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  main { padding: 1rem; }
  .topbar { padding: 0.6rem 1rem; gap: 0.75rem; }
  .facts { grid-template-columns: 1fr; }
  .facts dd { margin-bottom: 0.4rem; }
}
