/* ZeroTier Central — tema scuro
   Palette neutra fredda: un solo accento (teal), colori semantici per gli stati.
   Layout: sidebar 248px + contenuto fluido; sotto 980px la sidebar diventa
   una barra orizzontale scorrevole. */

:root {
  --bg: #0a0e13;
  --surface: #111820;
  --surface-2: #161f29;
  --surface-3: #1d2733;
  --border: #24303d;
  --border-strong: #32404f;
  --text: #e6edf3;
  --muted: #8b98a9;
  --muted-2: #64717f;

  --accent: #35c2c9;
  --accent-dim: #1d7f85;
  --ok: #3fb950;
  --warn: #d8a326;
  --danger: #f0645c;
  --info: #5aa9f8;
  --idle: #7c8896;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 14px; }
p { margin: 0; }
small, .small { font-size: 12px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden, [hidden] { display: none !important; }

/* --------------------------------------------------------------- LOGIN */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 500px at 50% -10%, rgba(53, 194, 201, .10), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
  color: var(--accent);
}
.login-brand h1 { font-size: 17px; color: var(--text); }
.login-brand p { font-size: 12px; color: var(--muted); }

.brand-mark { width: 38px; height: 38px; flex: none; }
.brand-mark.small { width: 26px; height: 26px; }

.login-error {
  background: rgba(240, 100, 92, .12);
  border: 1px solid rgba(240, 100, 92, .35);
  color: #ffb3ae;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13px;
  margin: 4px 0 2px;
}

.login-footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  color: var(--muted-2);
  font-size: 11px;
}

/* ------------------------------------------------------------- LAYOUT */

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-head {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--accent);
  padding: 0 6px;
}
.sidebar-head strong { display: block; color: var(--text); font-size: 14px; }
.sidebar-head small { color: var(--muted-2); font-family: var(--mono); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-3); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav-item .ico { width: 16px; text-align: center; opacity: .85; }

.sidebar-foot { display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }

.controller-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
}
.controller-chip .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--idle); flex: none;
}
.controller-chip.ok .dot { background: var(--ok); box-shadow: 0 0 8px rgba(63, 185, 80, .7); }
.controller-chip.bad .dot { background: var(--danger); box-shadow: 0 0 8px rgba(240, 100, 92, .6); }

.sidebar-user {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: 13px;
}
.version { color: var(--muted-2); font-family: var(--mono); font-size: 11px; }

.main { padding: 26px 30px 60px; min-width: 0; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-actions { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }

/* ------------------------------------------------------------- FORM */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12px; color: var(--muted); }

input[type="text"], input[type="password"], input[type="email"], select, textarea {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font: inherit;
  font-size: 13.5px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 194, 201, .14);
}
textarea { resize: vertical; min-height: 70px; font-family: var(--mono); font-size: 12.5px; }
input[readonly] { color: var(--muted); }
input::placeholder { color: var(--muted-2); }

.form-grid { display: grid; gap: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { color: var(--muted-2); font-size: 12px; margin: -4px 0 12px; }

.check { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; font-size: 13px; }
.check input { width: auto; }

.range-picker { display: flex; flex-direction: column; gap: 4px; }
.range-picker > span { font-size: 11px; color: var(--muted); }

/* ------------------------------------------------------------ BUTTONS */

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04211f; font-weight: 600; }
.btn-primary:hover { background: #46d3da; border-color: #46d3da; }
.btn-danger { background: rgba(240, 100, 92, .14); border-color: rgba(240, 100, 92, .5); color: #ff9d97; }
.btn-danger:hover { background: rgba(240, 100, 92, .24); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }

.icon-btn {
  background: transparent; border: 0; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* -------------------------------------------------------------- PANEL */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.panel-head h3 { color: var(--text); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); gap: 16px; margin-bottom: 16px; }
.chart-box { padding: 16px; height: 260px; position: relative; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent); opacity: .8;
}
.kpi.ok::after { background: var(--ok); }
.kpi.warn::after { background: var(--warn); }
.kpi.danger::after { background: var(--danger); }
.kpi.idle::after { background: var(--idle); }
.kpi-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 26px; font-weight: 650; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--muted-2); font-size: 12px; }

/* -------------------------------------------------------------- PILLS */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  border: 1px solid transparent; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-authorized { background: rgba(63, 185, 80, .13); color: var(--ok); border-color: rgba(63, 185, 80, .3); }
.pill-paused { background: rgba(216, 163, 38, .13); color: var(--warn); border-color: rgba(216, 163, 38, .3); }
.pill-revoked { background: rgba(240, 100, 92, .12); color: var(--danger); border-color: rgba(240, 100, 92, .3); }
.pill-pending { background: rgba(124, 136, 150, .14); color: var(--idle); border-color: rgba(124, 136, 150, .3); }
.pill-online { background: rgba(63, 185, 80, .13); color: var(--ok); border-color: rgba(63, 185, 80, .3); }
.pill-offline { background: rgba(124, 136, 150, .12); color: var(--muted); border-color: rgba(124, 136, 150, .28); }
.pill-net { background: rgba(90, 169, 248, .12); color: var(--info); border-color: rgba(90, 169, 248, .3); }

/* ------------------------------------------------------------- TABLES */

.table-panel { margin-bottom: 16px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 10px 14px;
  color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid rgba(36, 48, 61, .6); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.table td.actions { text-align: right; white-space: nowrap; }
.row-title { font-weight: 550; }
.row-sub { color: var(--muted-2); font-size: 12px; }

.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 6px; font-size: 15px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* ------------------------------------------------------------ NETWORK */

.network-list { display: grid; gap: 14px; }

.network-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.network-card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 14px; padding: 15px 17px; cursor: pointer;
}
.network-card-head:hover { background: var(--surface-2); }
.network-card-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.network-card-title h3 { font-size: 15px; }
.network-meta {
  display: flex; gap: 16px; flex-wrap: wrap;
  color: var(--muted); font-size: 12px; margin-top: 7px;
}
.network-meta .mono { color: var(--text); }
.network-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.network-body { border-top: 1px solid var(--border); background: var(--surface-2); padding: 14px 17px; }
.network-desc { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px; margin-bottom: 12px;
}
.detail-box {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.detail-box .k { color: var(--muted-2); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.detail-box .v { font-family: var(--mono); font-size: 12.5px; margin-top: 3px; word-break: break-all; }

/* -------------------------------------------------------------- GAUGE */

.gauges { padding: 16px; display: grid; gap: 16px; }
.gauge-label { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.gauge-label span:last-child { font-family: var(--mono); color: var(--muted); }
.gauge-track { height: 7px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.gauge-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }
.gauge-fill.ok { background: var(--ok); }
.gauge-fill.warn { background: var(--warn); }
.gauge-fill.danger { background: var(--danger); }

.kv { margin: 0; padding: 16px; display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); text-align: right; word-break: break-all; font-size: 12.5px; }

.steps { margin: 0; padding: 16px 16px 4px 34px; color: var(--muted); font-size: 13px; }
.steps li { margin-bottom: 8px; }

/* ------------------------------------------------------ EVENTI FEED */

.event-feed { max-height: 260px; overflow-y: auto; }
.event-item {
  display: flex; gap: 10px; align-items: baseline;
  padding: 9px 16px; border-bottom: 1px solid rgba(36, 48, 61, .55); font-size: 12.5px;
}
.event-item:last-child { border-bottom: 0; }
.event-time { color: var(--muted-2); font-family: var(--mono); font-size: 11.5px; flex: none; }
.event-action { font-family: var(--mono); font-size: 11.5px; color: var(--accent); flex: none; }
.event-detail { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* -------------------------------------------------------------- MODAL */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 7, 10, .72);
  display: grid; place-items: center; padding: 20px; z-index: 60;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  width: 100%; max-width: 620px;
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 9px; background: var(--surface-2);
  border-radius: 0 0 12px 12px;
}
.modal-error {
  background: rgba(240, 100, 92, .12); border: 1px solid rgba(240, 100, 92, .35);
  color: #ffb3ae; border-radius: var(--radius-sm); padding: 9px 11px; margin-bottom: 12px; font-size: 13px;
}
.modal-error[hidden] { display: none; }

/* ------------------------------------------------------------- TOASTS */

.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 80;
  display: flex; flex-direction: column; gap: 9px; max-width: 380px;
}
.toast {
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13px;
  box-shadow: var(--shadow); animation: toast-in .18s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all .2s ease; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------- RESPONSIVE */

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center;
    gap: 14px; overflow-x: auto; padding: 10px 14px;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .sidebar-head { flex: none; }
  .sidebar-head div { display: none; }
  .nav { flex-direction: row; flex: none; }
  .nav-item { white-space: nowrap; }
  .nav-item.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .sidebar-foot { flex-direction: row; flex: none; margin-left: auto; align-items: center; }
  .version, .controller-chip { display: none; }
  .main { padding: 18px 16px 50px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); }
  .kpi-value { font-size: 22px; }
  .page-head { flex-direction: column; align-items: stretch; }
}