:root {
  --background: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e5e9;
  --text: #0f172a;
  --text-muted: #5b6474;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --good: #0ca30c;
  --good-text: #067a06;
  --good-bg: #e7f6e7;
  --warn: #fab219;
  --warn-text: #8a5a00;
  --warn-bg: #fff4dc;
  --bad: #d03b3b;
  --bad-text: #b42323;
  --bad-bg: #fde8e8;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #eceef1;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #111214;
    --surface: #1a1b1e;
    --border: #2c2e33;
    --text: #f1f2f4;
    --text-muted: #a3a8b3;
    --accent: #3b82f6;
    --good-text: #4cc94c;
    --good-bg: #13301a;
    --warn-text: #f5c04a;
    --warn-bg: #3a2c0b;
    --bad-text: #f07373;
    --bad-bg: #3d1717;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #26282d;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--background);
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 600;
}

h2 {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 600;
}

code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(127, 127, 127, 0.15);
  font-size: 13px;
}

.container {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- Header / footer ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding: 12px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  padding: 4px 7px;
  border-radius: 6px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: #ffffff;
  font-size: 12px;
  letter-spacing: 0.5px;
}

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

.main-nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-muted);
}

.main-nav a:hover {
  background: var(--background);
  text-decoration: none;
}

.main-nav a.is-active {
  background: var(--background);
  color: var(--text);
  font-weight: 500;
}

.page {
  padding: 28px 0 40px;
}

.site-footer {
  padding: 20px 0 32px;
  color: var(--text-muted);
  font-size: 13px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head p {
  margin: 0;
  overflow-wrap: anywhere;
}

.back {
  margin: 0 0 12px;
}

/* ---------- Cards / notices ---------- */

.card {
  margin-bottom: 20px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

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

.card-head h2 {
  margin: 0;
}

.section-title {
  margin: 28px 0 14px;
  font-size: 19px;
}

.section-title .muted {
  font-size: 14px;
  font-weight: 400;
}

h3 {
  margin: 22px 0 10px;
  font-size: 15px;
  font-weight: 600;
}

.stat-value .delta {
  font-size: 14px;
  font-weight: 500;
}

.url-cell {
  min-width: 160px;
  max-width: 360px;
  overflow-wrap: anywhere;
}

.steps {
  margin: 0 0 12px;
  padding-left: 22px;
}

.steps li {
  margin-bottom: 6px;
}

/* Lets wide tables scroll inside their card instead of stretching the grid. */
.two-col > * {
  min-width: 0;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.notice {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.notice-warn {
  background: var(--warn-bg);
  border-color: transparent;
}

.notice-good {
  background: var(--good-bg);
  border-color: transparent;
}

.notice-bad {
  background: var(--bad-bg);
  border-color: transparent;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 13px;
}

.stat-value {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-value small {
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 400;
}

/* ---------- Tables ---------- */

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

thead th {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

tbody th {
  font-weight: 500;
}

tbody tr:last-child td,
tbody tr:last-child th {
  border-bottom: none;
}

.site-table tbody tr:hover {
  background: var(--background);
}

.site-table td {
  white-space: nowrap;
}

.site-name {
  font-weight: 600;
}

.site-url {
  color: var(--text-muted);
  font-size: 13px;
}

.num {
  font-variant-numeric: tabular-nums;
}

.check-value {
  max-width: 420px;
  overflow-wrap: anywhere;
}

/* ---------- Scores (status color always comes with an icon) ---------- */

.score,
.check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.score-good,
.check-pass {
  background: var(--good-bg);
  color: var(--good-text);
}

.score-warn,
.check-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.score-bad,
.check-fail {
  background: var(--bad-bg);
  color: var(--bad-text);
}

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

.http-ok {
  color: var(--good-text);
  font-weight: 500;
}

.fail-count {
  color: var(--bad-text);
  font-weight: 500;
}

.delta {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.delta-up {
  color: var(--good-text);
}

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

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 50%;
}

.dot-good {
  background: var(--good);
}

.dot-warn {
  background: var(--warn);
}

.dot-bad {
  background: var(--bad);
}

.dot-none {
  background: var(--border);
}

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

.issue-list {
  margin: 0;
  padding-left: 20px;
}

.issue-list li {
  margin-bottom: 6px;
}

.legend {
  font-size: 13px;
  line-height: 2.2;
}

/* ---------- Trend chart ---------- */

.trend-chart {
  position: relative;
}

.trend-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.chart-legend span::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 2px;
  background: var(--swatch);
}

.chart-tooltip {
  position: absolute;
  top: 0;
  z-index: 2;
  min-width: 150px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 13px;
  pointer-events: none;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 4px;
}

.chart-tooltip div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.chart-tooltip i {
  display: inline-block;
  width: 10px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 2px;
}

.chart-empty {
  padding: 32px 0;
  color: var(--text-muted);
  text-align: center;
}

.table-view {
  margin-top: 12px;
  font-size: 14px;
}

.table-view summary {
  color: var(--accent);
  cursor: pointer;
}

/* ---------- Forms ---------- */

.button {
  display: inline-block;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.button:hover {
  filter: brightness(1.08);
}

.button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.button-small {
  padding: 5px 12px;
  font-size: 13px;
}

.button-danger {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--bad-text);
}

.recheck-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.recheck-note {
  font-size: 13px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
}

input[type="text"],
input[type="url"],
input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--text);
  font: inherit;
}

.add-form {
  display: grid;
  grid-template-columns: 1fr 1.5fr auto;
  align-items: end;
  gap: 12px;
}

.actions {
  text-align: right;
}

.actions form {
  margin: 0;
}

/* ---------- Login ---------- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.login-box {
  width: min(380px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.login-box .brand {
  margin-bottom: 22px;
}

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-error {
  margin: 0;
  color: var(--bad-text);
  font-size: 14px;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .two-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  h1 {
    font-size: 20px;
  }

  .stat-value {
    font-size: 26px;
  }

  .card {
    padding: 16px;
  }

  .add-form {
    grid-template-columns: 1fr;
  }

  .recheck-form {
    flex-wrap: wrap;
  }
}
