:root {
  --bg: #edf7fb;
  --panel: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #dbe7ee;
  --blue: #2563eb;
  --green: #059669;
  --red: #dc2626;
  --shadow: 0 18px 45px rgba(36, 64, 84, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #bfeeff 0, var(--bg) 360px, #f8fbfd 100%);
}
a { color: inherit; text-decoration: none; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}
.sidebar {
  padding: 28px 22px;
  border-right: 1px solid rgba(148, 163, 184, .28);
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #111827, #2563eb);
}
.nav { display: grid; gap: 8px; }
.nav a, .logout {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 650;
}
.nav a.active, .nav a:hover, .logout:hover {
  background: rgba(255, 255, 255, .75);
  color: var(--ink);
}
.logout { margin-top: auto; }
.main { padding: 32px; min-width: 0; }

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 34px; }
h2 { font-size: 20px; }
.muted { color: var(--muted); }
.page-title p { margin: 6px 0 0; }
.title-actions, .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions form { margin: 0; }
.switch-form { margin: 0; }
.ios-switch-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 7px 9px 7px 12px;
  background: rgba(255,255,255,.72);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-weight: 800;
}
.switch-copy {
  display: grid;
  gap: 1px;
  text-align: left;
}
.switch-title {
  font-size: 12px;
  color: var(--muted);
}
.switch-state {
  font-size: 13px;
}
.ios-switch {
  width: 46px;
  height: 28px;
  border-radius: 999px;
  padding: 2px;
  background: #cbd5e1;
  display: inline-flex;
  align-items: center;
  transition: background .15s ease;
}
.ios-switch span {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, .26);
  transition: transform .15s ease;
}
.ios-switch.on {
  background: #22c55e;
}
.ios-switch.on span {
  transform: translateX(18px);
}

.panel, .auth-panel, .chart-panel, .empty-state, .site-card, .metric-card {
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(219, 231, 238, .92);
  box-shadow: var(--shadow);
  border-radius: 8px;
}
.panel, .empty-state { padding: 22px; margin-bottom: 20px; }
.auth-panel {
  max-width: 430px;
  margin: 10vh auto;
  padding: 28px;
}
.auth-panel p { margin-top: 8px; }
.chart-panel { height: 390px; padding: 22px; margin-bottom: 20px; }

.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 18px;
}
.site-card {
  display: grid;
  gap: 24px;
  padding: 24px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.site-card:hover { transform: translateY(-2px); }
.site-card-top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}
.site-card-link:hover { text-decoration: underline; }
.site-card h2 { font-size: 24px; }
.site-card p { margin: 6px 0 0; color: var(--muted); }
.site-badges {
  align-self: start;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.favorite-form { margin: 0; }
.status {
  align-self: start;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}
.status.ok { background: #dcfce7; color: #166534; }
.status.off { background: #fee2e2; color: #991b1b; }
.status.favorite {
  border: 0;
  min-width: 28px;
  min-height: 24px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.status.favorite.on {
  background: #ffe4e6;
  color: #be123c;
}
.status.favorite.off {
  background: #fff1f2;
  color: #fb7185;
}
.status.favorite:hover,
.status.favorite:focus-visible {
  background: #fecdd3;
  color: #9f1239;
}
.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.metric-row div {
  min-width: 0;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
}
.metric-row strong { display: block; font-size: 25px; }
.metric-row span { color: var(--muted); font-size: 12px; font-weight: 650; }
.muted-row strong { font-size: 18px; }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}
.metric-card {
  padding: 22px;
}
.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.metric-value {
  margin-top: 10px;
  font-size: 34px;
  font-weight: 850;
}
.metric-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.form { display: grid; gap: 14px; }
.form-note {
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.5;
}
.form-note code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #f1f5f9;
  color: var(--ink);
}
.grid-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}
label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-weight: 700;
  font-size: 14px;
}
.wide { grid-column: 1 / -1; }
.check {
  display: flex;
  align-items: center;
  gap: 9px;
}
input, textarea, select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 42px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.button.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.button.ghost { background: rgba(255,255,255,.65); }
.button.danger { color: var(--red); }

.table-wrap { overflow-x: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
.compact table { min-width: 420px; }
th, td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tables-grid .panel {
  padding: 16px;
}
.tables-grid h2 {
  font-size: 17px;
}
.tables-grid .table-wrap {
  margin-top: 10px;
}
.tables-grid table {
  font-size: 13px;
  line-height: 1.25;
}
.tables-grid th,
.tables-grid td {
  padding: 8px 8px;
}
.tables-grid th {
  font-size: 10px;
}
.tables-grid td:first-child {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.stat-card-grid {
  align-items: stretch;
}
.stat-card {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  max-height: var(--stat-card-max-height, 100cqw);
  min-height: 0;
  overflow: hidden;
}
.stat-card .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.stat-card .panel-footer,
.stat-card .attribution {
  flex: 0 0 auto;
}
.page-open-link {
  font-size: 12px;
  font-weight: 800;
  text-decoration: underline;
  white-space: nowrap;
}
.attribution {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
}
.attribution a {
  text-decoration: underline;
}
.panel-footer {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}
.website-note-card .note-content {
  margin-top: 12px;
  color: #344054;
  line-height: 1.6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.website-note-card .note-content a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: underline;
}

.range-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(210px, 1fr)) auto;
  align-items: end;
  gap: 14px;
  min-width: 0;
}
.range-form label { min-width: 0; }
.range-form input,
.range-form select,
.range-form .button {
  height: 52px;
}
.range-form .button {
  min-width: 110px;
}
.tables-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  align-items: stretch;
}
.tables-grid .panel { margin-bottom: 0; }
.note-panel code {
  display: block;
  overflow-x: auto;
  padding: 14px;
  background: #0f172a;
  color: #e0f2fe;
  border-radius: 8px;
}
.flash {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-weight: 700;
  background: #dcfce7;
  color: #166534;
}
.flash.error { background: #fee2e2; color: #991b1b; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid rgba(148, 163, 184, .28);
    padding: 18px;
  }
  .nav { grid-template-columns: repeat(3, max-content); overflow-x: auto; }
  .logout { margin-top: 0; }
  .main { padding: 22px; }
  .page-title { align-items: flex-start; flex-direction: column; }
  .title-actions {
    width: 100%;
  }
  .grid-form, .tables-grid, .range-form { grid-template-columns: 1fr; }
  .range-form {
    width: 100%;
    overflow: hidden;
  }
  .range-form label,
  .range-form input,
  .range-form select,
  .range-form .button {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
}

@media (max-width: 520px) {
  h1 { font-size: 28px; }
  .main { padding: 16px; }
  .site-card, .panel, .chart-panel { padding: 16px; }
  .ios-switch-button,
  .title-actions > .button {
    width: 100%;
    justify-content: space-between;
  }
  .tables-grid {
    width: 100%;
    gap: 14px;
  }
  .tables-grid .panel,
  .tables-grid .metric-card {
    min-width: 0;
    width: 100%;
    padding: 12px;
  }
  .tables-grid .table-wrap {
    width: 100%;
    overflow-x: hidden;
  }
  table,
  .compact table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
  }
  .tables-grid table {
    font-size: 11px;
  }
  .tables-grid th,
  .tables-grid td {
    padding: 6px 5px;
  }
  .tables-grid th {
    font-size: 9px;
  }
  .tables-grid th:not(:first-child),
  .tables-grid td:not(:first-child) {
    width: 54px;
    text-align: right;
  }
  .tables-grid td:first-child {
    max-width: 0;
    overflow-wrap: anywhere;
    word-break: break-all;
  }
  .site-card { gap: 18px; }
  .metric-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .metric-row div {
    padding: 10px 8px;
  }
  .metric-row strong {
    font-size: 21px;
  }
  .metric-row span {
    font-size: 11px;
  }
  .range-form input[type="date"] {
    display: block;
    appearance: none;
    -webkit-appearance: none;
    text-align: left;
  }
}
