:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #dfe2e6;
  --line-soft: #edeff1;
  --ink: #1f2328;
  --muted: #656d76;
  --faint: #8c959f;
  --link: #0b57d0;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
  --chart-safe: #86b8a0;
  --chart-attention: #ddb257;
  --chart-danger: #cc6259;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 13px;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

/* ---------- Gate ---------- */

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 28px 26px;
}

.gate-card h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.gate-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.gate-card label {
  display: block;
  margin: 22px 0 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}

.gate-card input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--ink);
  background: var(--surface);
}

.gate-card input:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.12);
}

.gate-card button {
  width: 100%;
  margin-top: 14px;
  padding: 7px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.gate-card button:hover {
  background: #000;
}

.gate-error {
  margin: 10px 0 0;
  min-height: 18px;
  font-size: 12px;
  color: var(--danger);
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  height: 52px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.wordmark {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.divider {
  width: 1px;
  height: 18px;
  background: var(--line);
}

.org {
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface);
}

.segmented button {
  border: none;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button:first-child {
  border-left: none;
}

.segmented button:hover {
  background: var(--bg);
}

.segmented button.active {
  background: #eef1f4;
  color: var(--ink);
  font-weight: 500;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.btn:hover {
  background: var(--bg);
}

.btn[disabled] {
  color: var(--faint);
  cursor: not-allowed;
}

.btn[disabled]:hover {
  background: var(--surface);
}

/* ---------- Layout ---------- */

.content {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 20px 56px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.panel-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.split {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
}

@media (max-width: 960px) {
  .split {
    grid-template-columns: 1fr;
  }
}

/* ---------- Metrics ---------- */

.metrics {
  display: flex;
  flex-wrap: wrap;
}

.metric {
  flex: 1 1 0;
  min-width: 150px;
  padding: 14px 16px;
  border-left: 1px solid var(--line-soft);
}

.metric:first-child {
  border-left: none;
}

.metric-label {
  font-size: 12px;
  color: var(--muted);
}

.metric-value {
  margin-top: 2px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.metric.is-link {
  cursor: pointer;
}

.metric.is-link:hover {
  background: var(--bg);
}

.metric.danger .metric-value {
  color: var(--danger);
}

.metric.warn .metric-value {
  color: var(--warn);
}

.metrics-note {
  margin: 0;
  padding: 9px 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
}

.metrics-note button {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--link);
  cursor: pointer;
}

.metrics-note button:hover {
  text-decoration: underline;
}

/* ---------- Chart ---------- */

.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.key {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}

.key.safe {
  background: var(--chart-safe);
}
.key.attention {
  background: var(--chart-attention);
}
.key.high_risk {
  background: var(--chart-danger);
}

.chart-wrap {
  padding: 14px 14px 6px;
}

#trend-chart {
  width: 100%;
  height: 200px;
  display: block;
}

/* ---------- Tables ---------- */

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

.table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--bg);
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.table .zero {
  color: var(--faint);
}

.table .hit {
  color: var(--danger);
  font-weight: 600;
}

.table.rows-link tbody tr {
  cursor: pointer;
}

.truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.truncate-sm {
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

.empty {
  padding: 28px 14px;
  text-align: center;
  color: var(--muted);
}

/* ---------- Status ---------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status.safe {
  color: var(--ok);
}
.status.attention {
  color: var(--warn);
}
.status.high_risk {
  color: var(--danger);
}
.status.bassa {
  color: var(--muted);
}
.status.media {
  color: var(--warn);
}
.status.alta {
  color: var(--danger);
}

.flag {
  margin-left: 8px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- Reasons ---------- */

.reasons {
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
}

.reason {
  display: grid;
  grid-template-columns: 1fr 84px 32px;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  cursor: pointer;
}

.reason:hover .label {
  color: var(--link);
}

.reason .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reason .track {
  height: 4px;
  background: var(--line-soft);
  border-radius: 2px;
  overflow: hidden;
}

.reason .track span {
  display: block;
  height: 100%;
  background: #a9b2bc;
}

.reason .n {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Filters ---------- */

.head-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 9px;
  font: inherit;
  font-size: 12px;
  min-width: 210px;
  color: var(--ink);
  background: var(--surface);
}

.search:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.12);
}

.active-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px 2px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
}

.chip em {
  font-style: normal;
  color: var(--faint);
  font-size: 13px;
  line-height: 1;
}

.chip:hover {
  border-color: var(--faint);
}

.chip:hover em {
  color: var(--danger);
}

.chip-clear {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--link);
  cursor: pointer;
}

.chip-clear:hover {
  text-decoration: underline;
}

/* ---------- Pager ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 9px 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Print ---------- */

@media print {
  body {
    background: #fff;
  }
  .topbar-actions,
  .head-tools,
  .pager,
  .gate {
    display: none !important;
  }
  .topbar {
    position: static;
  }
  .panel {
    break-inside: avoid;
  }
}
