/* Dashboard di regia: portatile in regia, tema chiaro o scuro secondo il sistema. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
}

h1, h2 { margin: 0; }

button, select, input { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar h1 span { font-weight: 400; color: var(--text-secondary); }

.topbar-status {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.save-state { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-neutral);
}

.badge[data-state="ok"]::before { background: var(--status-good); }
.badge[data-state="warning"]::before { background: var(--status-warning); }
.badge[data-state="critical"]::before { background: var(--status-critical); }
.badge[data-state="critical"] { border-color: var(--status-critical); }

.layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr));
  gap: 20px;
  padding: 20px 24px 40px;
  max-width: 1800px;
  margin: 0 auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: 0;
}

.panel-wide, .charts { grid-column: 1 / -1; }

.panel h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.panel-head h2 { margin-bottom: 0; }
.panel-sub { margin: 0 0 12px; font-size: 13px; color: var(--text-secondary); overflow-wrap: anywhere; }

.fields {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 32px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.field-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); padding: 0; }
.field-hint { font-size: 12px; color: var(--text-muted); }

select {
  min-width: 260px;
  max-width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--raised);
}

select:focus-visible, button:focus-visible, .segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  width: fit-content;
}

.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented span {
  display: block;
  padding: 7px 18px;
  cursor: pointer;
  background: var(--raised);
  font-weight: 600;
}

.segmented label + label span { border-left: 1px solid var(--border); }
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); }

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 20px;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chart-card-head h2 { margin: 0; }
.chart-card-head a { font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }

.axis-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "x swap" "y swap";
  align-items: center;
  gap: 10px 8px;
}

.axis-row [data-setting-field="x"] { grid-area: x; }
.axis-row [data-setting-field="y"] { grid-area: y; }
.axis-row [data-swap] { grid-area: swap; align-self: center; margin-top: 18px; }

.axis-row select, .chart-card select { min-width: 0; width: 100%; }

.icon-button {
  color: var(--text-primary);
  font-size: 18px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--raised);
  cursor: pointer;
  line-height: 1;
}

.preview {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #121211;
}

.preview iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 1920px;
  height: 1080px;
  border: 0;
  transform-origin: 0 0;
  pointer-events: none;
}

.actions {
  display: grid;
  gap: 14px;
}

.action {
  display: grid;
  grid-template-columns: 240px 1fr;
  align-items: center;
  gap: 14px;
}

.action p { margin: 0; font-size: 13px; color: var(--text-secondary); }

@media (max-width: 640px) {
  .action { grid-template-columns: 1fr; gap: 6px; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .layout { padding: 16px; }
}

button {
  padding: 9px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}

button.secondary {
  background: var(--raised);
  color: var(--text-primary);
  border-color: var(--border);
}

button.danger { background: var(--status-critical); color: #ffffff; }
button[disabled] { opacity: 0.6; cursor: progress; }

.table-wrap { overflow-x: auto; }

.status-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.status-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.status-table td {
  padding: 8px 10px 8px 0;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
}

.status-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.status-table td:nth-child(3) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.status-table .error { color: var(--text-secondary); overflow-wrap: anywhere; }

.state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.state::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-neutral);
}

.state[data-state="ok"]::before { background: var(--status-good); }
.state[data-state="critical"]::before { background: var(--status-critical); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(90vw, 560px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text-primary);
  color: var(--surface);
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.toast[data-kind="error"] { background: var(--status-critical); color: #ffffff; }

.muted { color: var(--text-muted); }

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.checkbox input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---- Sullo schermo ---- */

.screen-panel { border-color: var(--accent); border-width: 2px; }
.screen-link { font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.screen-panel .fields { margin-top: 4px; }
.screen-panel .segmented { flex-wrap: wrap; }

.slides {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--grid);
}

.slides-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slides-nav button { font-size: 18px; padding: 8px 16px; }

.slides-current {
  font-size: 18px;
  font-weight: 700;
  min-width: 0;
  overflow-wrap: anywhere;
}

.slides-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.slide-chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--raised);
  color: var(--text-primary);
  font-weight: 500;
  font-size: 13px;
}

.slide-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---- Etichette degli assi dei Boston ---- */

.axis-labels {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
}

.axis-labels summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.axis-labels[open] summary { margin-bottom: 6px; }
.axis-labels .field-hint { margin: 0 0 10px; }

.axis-labels-group {
  margin: 0 0 12px;
  padding: 0;
  border: 0;
}

.axis-labels-group legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
}

.axis-labels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
  gap: 10px;
}

.axis-labels input[type=text] {
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--raised);
}

.axis-labels input[type=text]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.link-button {
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}
