:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e3e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --up: #16a34a;
  --up-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --down: #dc2626;
  --down-soft: #fee2e2;
  --idle: #9ca3af;
  --idle-soft: #f3f4f6;
  --bar-empty: #e5e7eb;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #161d27;
    --border: #263040;
    --text: #e5e7eb;
    --muted: #9aa4b2;
    --brand: #3b82f6;
    --brand-hover: #60a5fa;
    --up: #22c55e;
    --up-soft: #14532d;
    --warn: #f59e0b;
    --warn-soft: #713f12;
    --down: #f87171;
    --down-soft: #7f1d1d;
    --idle: #6b7280;
    --idle-soft: #1f2937;
    --bar-empty: #263040;
    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;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }

.container { max-width: 1040px; margin: 0 auto; padding: 24px 16px 48px; }
.narrow { max-width: 760px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--up); box-shadow: 0 0 0 4px var(--up-soft); }
.nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.nav a { color: var(--muted); }
.nav a[aria-current="page"] { color: var(--text); font-weight: 600; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  font: inherit; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; white-space: nowrap;
}
.btn:hover { background: var(--brand-hover); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--idle-soft); }
.btn-danger { background: var(--down); }
.btn-danger:hover { background: var(--down); filter: brightness(0.92); }
.btn-small { padding: 4px 10px; font-size: 0.85rem; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.link-btn:hover { color: var(--text); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.85rem; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
.hint { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.field-error { font-size: 0.8rem; color: var(--down); margin-top: 4px; }
.form-error { color: var(--down); margin: 8px 0 0; min-height: 1.2em; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.inline-form > * { flex: 1 1 160px; }
.inline-form > .grow { flex: 3 1 240px; }
.inline-form > .btn { flex: 0 0 auto; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td .sub { display: block; font-size: 0.8rem; color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.paused td { opacity: 0.55; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600;
  padding: 2px 10px; border-radius: 999px; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-up { background: var(--up-soft); color: var(--up); }
.badge-down { background: var(--down-soft); color: var(--down); }
.badge-pending, .badge-paused { background: var(--idle-soft); color: var(--idle); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.stat-value { font-size: 1.25rem; font-weight: 700; margin-top: 2px; }

/* Public status page */
.banner { border-radius: var(--radius); padding: 18px 20px; font-weight: 700; font-size: 1.1rem; margin-bottom: 20px; color: #fff; }
.banner-up { background: var(--up); }
.banner-down { background: var(--down); }
.banner-pending { background: var(--idle); }
.service { padding: 16px 0; border-bottom: 1px solid var(--border); }
.service:last-child { border-bottom: 0; }
.service-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.service-name { font-weight: 600; }
.bars { display: flex; gap: 2px; height: 34px; }
.bar { flex: 1 1 0; border-radius: 2px; background: var(--bar-empty); min-width: 2px; }
.bar.good { background: var(--up); }
.bar.warn { background: var(--warn); }
.bar.bad { background: var(--down); }
.bars-legend { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-top: 6px; }

/* Chart */
.chart-wrap { position: relative; }
.chart { width: 100%; height: 220px; display: block; }
.chart-line { fill: none; stroke: var(--brand); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.chart-area { fill: var(--brand); opacity: 0.08; }
.chart-fail { stroke: var(--down); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-grid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-axis { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.chart-max { position: absolute; top: 0; left: 4px; font-size: 0.75rem; color: var(--muted); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; font: inherit; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--idle-soft); color: var(--text); font-weight: 600; }

.incident { padding: 10px 0; border-bottom: 1px solid var(--border); }
.incident:last-child { border-bottom: 0; }

.login { max-width: 360px; margin: 12vh auto 0; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  font-weight: 500; box-shadow: 0 4px 12px rgb(0 0 0 / 0.2); max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--down); color: #fff; }

footer.site { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 0 16px 32px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bars { height: 28px; gap: 1px; }
}
