:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --border-strong: #cbd1da;
  --text: #1a1f27;
  --text-dim: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --up: #15803d;
  --up-bg: #e8f6ee;
  --down: #b91c1c;
  --down-bg: #fdeceb;
  --warn: #a16207;
  --warn-bg: #fef6e0;
  --unknown: #4b5563;
  --unknown-bg: #eef0f3;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

h1 { font-size: 22px; font-weight: 640; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 620; margin: 0; }

code { font-family: var(--mono); font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* --- layout --- */

.shell {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 640;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--up);
  box-shadow: 0 0 0 3px var(--up-bg);
}

.nav { display: flex; gap: 4px; }

.nav a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 520;
}
.nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--bg); color: var(--text); }

.logout-form {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.who { color: var(--text-dim); font-size: 13px; }

.page-shell {
  flex: 1;
  width: 100%;
  display: flex;
}
.page {
  padding: 28px 24px 56px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.page-auth {
  flex: 1;
  width: 100%;
  min-height: 0;
}
.page-auth > .page {
  flex: 1;
  max-width: none;
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.footer {
  padding: 18px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.footer-inner { display: flex; justify-content: center; gap: 10px; }
.footer-dim { opacity: 0.65; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.breadcrumb { font-size: 12.5px; color: var(--text-dim); margin-bottom: 4px; }

.url-line {
  color: var(--text-dim);
  margin: 4px 0 0;
  word-break: break-all;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.two-col > * { min-width: 0; }
.two-col .card { overflow-x: auto; }

/* --- cards --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card.flush { padding: 0; overflow-x: auto; }
.card.flush .table { min-width: 640px; }
.card.empty { text-align: center; padding: 40px 24px; }
.card.empty p { max-width: 460px; margin: 8px auto 18px; }

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

.pad { padding: 4px 0 0; }
.muted { color: var(--text-dim); margin: 0; }
.dim { color: var(--text-dim); }

.hint {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* --- stats --- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 26px;
  font-weight: 620;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.stat-unit { font-size: 15px; color: var(--text-dim); margin-left: 1px; }
.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 560;
}

.stat-up .stat-value { color: var(--up); }
.stat-down .stat-value { color: var(--down); }
.stat-unknown .stat-value { color: var(--unknown); }

/* --- badges --- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 640;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
  line-height: 1.5;
}
.badge-up { background: var(--up-bg); color: var(--up); }
.badge-down { background: var(--down-bg); color: var(--down); }
.badge-unknown { background: var(--unknown-bg); color: var(--unknown); }
.badge-muted { background: var(--unknown-bg); color: var(--text-dim); }

/* --- tables --- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 620;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table tbody tr:last-child td { border-bottom: none; }
.table-compact td { padding: 7px 10px; }
.table-compact th { padding: 7px 10px; }
.table-hover tbody tr:hover { background: #fafbfc; }
.table .right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate {
  display: block;
  max-width: min(320px, 100%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table { table-layout: fixed; }
.table th, .table td { overflow-wrap: anywhere; }

.table-scroll {
  max-height: 420px;
  overflow: auto;
  scrollbar-gutter: stable;
}
.table-scroll .table th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.table-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dashboard-table { min-width: 480px; }
.dashboard-table .col-monitor { width: 25%; }
.dashboard-table .col-when { width: 22%; }
.dashboard-table .col-duration { width: 20%; }

.strong-link { font-weight: 560; color: var(--text); }
.strong-link:hover { color: var(--accent); }

.error-text { color: var(--down); }

/* --- key/value lists --- */

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 7px 20px;
  margin: 0;
  font-size: 13px;
}
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; }
.kv-wide { gap: 9px 24px; }

.setting-key { width: 300px; }

/* --- filters --- */

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 520;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); text-decoration: none; }
.chip.active { background: var(--text); border-color: var(--text); color: #fff; }

/* --- months --- */

.month-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.month {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.month-clean { background: var(--up-bg); border-color: #cdebd9; }
.month-dirty { background: var(--down-bg); border-color: #f8d5d2; }
.month-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 600;
}
.month-value { font-size: 13.5px; font-weight: 600; }
.month-sub { font-size: 11.5px; color: var(--text-dim); }

/* --- buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 560;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-ghost:hover { background: var(--bg); border-color: var(--text-dim); }

.btn-danger { color: var(--down); }
.btn-danger:hover { background: var(--down-bg); border-color: var(--down); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }

form.inline { display: inline; }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.inline-form label { color: var(--text-dim); font-size: 13px; }
.inline-form input { flex: 1; min-width: 200px; }

/* --- forms --- */

.form { display: flex; flex-direction: column; gap: 18px; max-width: 640px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

label { font-size: 13px; font-weight: 560; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.field-hint { font-size: 12.5px; color: var(--text-dim); margin: 0; }
.field-error { font-size: 12.5px; color: var(--down); margin: 0; font-weight: 520; }
.field.has-error input, .field.has-error select { border-color: var(--down); }

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
.checkbox input { width: auto; }

.form-actions { display: flex; gap: 10px; padding-top: 4px; }

.section-divider { height: 1px; background: var(--border); margin: 22px 0 18px; }
.card h3 { font-size: 15px; margin: 0 0 6px; }

/* --- alerts --- */

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 13px;
}
.alert-error { background: var(--down-bg); border-color: #f8d5d2; color: #7f1d1d; }
.alert-ok { background: var(--up-bg); border-color: #cdebd9; color: #14532d; }
.alert-warn { background: var(--warn-bg); border-color: #f5e2ae; color: #78350f; }

/* --- auth --- */

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  padding: 28px;
}
.auth-card h1 { margin-bottom: 4px; }
.auth-card > .muted { margin-bottom: 20px; }

.stack { display: flex; flex-direction: column; gap: 14px; }

/* --- responsive --- */

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
  .topbar-inner { gap: 12px; padding: 0 16px; }
  .nav a { padding: 6px 8px; }
  .who { display: none; }
  .page { padding: 20px 16px 40px; min-width: 0; }
  .field-row { grid-template-columns: 1fr; }
  .setting-key { width: auto; }
  .truncate { max-width: 100%; }
  .page-shell { overflow-x: hidden; }
}

@media (max-width: 620px) {
  .nav { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
