:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #101828;
  --muted: #667085;
  --up: #12b76a;
  --up-soft: #ecfdf3;
  --down: #f04438;
  --down-soft: #fef3f2;
  --partial: #f79009;
  --none: #e4e7ec;
  --accent: #101828;
  --accent-text: #ffffff;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c111d;
    --surface: #161b26;
    --border: #2a3140;
    --text: #f5f5f6;
    --muted: #94969c;
    --up-soft: #0b2a1d;
    --down-soft: #2d1414;
    --none: #2a3140;
    --accent: #f5f5f6;
    --accent-text: #0c111d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
h1 { font-size: 24px; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 64px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.err-text { color: var(--down); }

/* Barra superiore */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--up); box-shadow: 0 0 0 4px var(--up-soft); }
.topbar nav { display: flex; align-items: center; gap: 20px; }
.topbar nav a, .linklike { color: var(--muted); text-decoration: none; font: inherit; }
.topbar nav a:hover, .linklike:hover { color: var(--text); }
.topbar nav form { margin: 0; }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; }

/* Bottoni */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--down); }
.btn.danger:hover { border-color: var(--down); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Messaggi */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.flash.ok { background: var(--up-soft); border-color: var(--up); }
.flash.err { background: var(--down-soft); border-color: var(--down); }

/* Card e form */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.form label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 14px; }
.form label small { display: block; font-weight: 400; color: var(--muted); margin-top: 4px; }
.form input, .form textarea, #filter {
  display: block; width: 100%; margin-top: 6px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
  font: inherit; font-weight: 400;
}
.form textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; resize: vertical; }
.form input:focus, .form textarea:focus, #filter:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-actions { margin-top: 8px; }
.narrow { max-width: 620px; }
.back { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 16px; font-size: 14px; }
.back:hover { color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 .card { margin-bottom: 16px; }

/* Login */
.login { max-width: 380px; margin: 10vh auto 0; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; margin-bottom: 20px; }
.login .btn { width: 100%; }

/* Stato */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--none); flex: none; }
.dot.up { background: var(--up); }
.dot.down { background: var(--down); box-shadow: 0 0 0 4px var(--down-soft); animation: pulse 1.6s infinite; }
.dot.paused { background: transparent; border: 2px solid var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px transparent; } }
@media (prefers-reduced-motion: reduce) { .dot.down { animation: none; } }

.summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.headline { display: flex; align-items: center; gap: 12px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.headline .dot { width: 14px; height: 14px; }
.headline.down { color: var(--down); }
.counts { display: flex; gap: 18px; color: var(--muted); }
.counts b { color: var(--text); }

.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toolbar #filter { margin: 0; max-width: 320px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { margin: 0; }

/* Tabella siti */
.table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; align-items: center; gap: 12px;
  grid-template-columns: 22px minmax(0, 1fr) 200px 70px 70px 80px 120px;
  padding: 12px 16px; border-top: 1px solid var(--border); text-decoration: none;
}
.row:first-child { border-top: 0; }
a.row:hover { background: var(--bg); }
.row.head { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding-top: 10px; padding-bottom: 10px; }
.row.down { background: var(--down-soft); }
.row.paused { opacity: .6; }
.cell.name { display: flex; flex-direction: column; min-width: 0; }
.cell.name > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell.name span { font-size: 13px; }
.cell.num, .cell.when { text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.cell.when { color: var(--muted); font-size: 13px; }
.row.head .cell { text-align: left; }
.row.head .cell.num, .row.head .cell.when { text-align: right; }

.bars { display: flex; gap: 2px; height: 22px; }
.bar { flex: 1; border-radius: 2px; background: var(--none); }
.bar.up { background: var(--up); }
.bar.down { background: var(--down); }
.bar.partial { background: var(--partial); }

.empty { text-align: center; padding: 48px 20px; }

/* Dettaglio sito */
.site-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.site-head h1 { margin-bottom: 4px; }
.site-head a { text-decoration: none; word-break: break-all; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 14px; }
.pill.up { background: var(--up-soft); border-color: var(--up); }
.pill.down { background: var(--down-soft); border-color: var(--down); color: var(--down); }
.site-head + .flash, .site-head + .actions { margin-top: 0; }
section.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 16px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat span { display: block; color: var(--muted); font-size: 13px; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }

.chart { margin: 0; }
.chart svg { width: 100%; height: 160px; display: block; }
.chart .line { fill: none; stroke: var(--up); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.chart .fail { stroke: var(--down); stroke-width: 2; opacity: .5; vector-effect: non-scaling-stroke; }
.chart figcaption { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td form { margin: 0; }

/* Mobile */
@media (max-width: 900px) {
  .row { grid-template-columns: 22px minmax(0, 1fr) 70px 70px 110px; }
  .row .history, .row .cell.num:nth-of-type(6) { display: none; }
  section.stats { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .row.head { display: none; }
  .row { grid-template-columns: 22px minmax(0, 1fr) auto; row-gap: 4px; }
  .row .cell.num, .row .history { display: none; }
  .row .cell.num:nth-of-type(4) { display: block; }
  .row .when { grid-column: 2 / -1; text-align: left; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar #filter { max-width: none; }
  .headline { font-size: 19px; }
  .topbar nav { gap: 14px; }
}
