:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #687586;
  --line: #dce2ea;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --soft: #e9f4f2;
  --shadow: 0 16px 42px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  min-height: 42px;
  padding: 0 16px;
}

.button-link {
  display: inline-grid;
  min-height: 42px;
  align-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 0 16px;
  text-decoration: none;
}

.button-link:hover {
  background: var(--accent-strong);
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 9px 11px;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 28px;
  line-height: 1.15;
}

h3 {
  font-size: 17px;
}

.hidden {
  display: none !important;
}

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

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 26px;
}

.form-error {
  color: var(--danger);
  min-height: 18px;
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 24px;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.nav-link {
  border-radius: 6px;
  color: #475569;
  font-weight: 800;
  padding: 11px 12px;
  text-decoration: none;
}

.nav-link.active,
.nav-link:hover {
  background: var(--soft);
  color: var(--accent-strong);
}

.ghost-button,
.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: #334155;
}

.ghost-button:hover,
.secondary-button:hover {
  background: #f8fafc;
  color: var(--accent-strong);
}

.sidebar .ghost-button {
  margin-top: auto;
}

.content {
  display: grid;
  gap: 26px;
  padding: 28px;
}

.page-section {
  display: grid;
  gap: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.form-grid,
.rule-form,
.upload-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  align-items: end;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

.rule-form {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.wide-field {
  grid-column: span 2;
}

.checkbox-line {
  display: flex;
  align-items: center;
  min-height: 42px;
}

.checkbox-line input {
  width: 18px;
  min-height: 18px;
}

.upload-preview {
  display: none;
  width: 72px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
}

.upload-preview[src] {
  display: block;
}

.cards-grid,
.rules-list {
  display: grid;
  gap: 12px;
}

.site-card,
.rule-card,
.table-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.site-card,
.rule-card {
  display: grid;
  gap: 14px;
}

.card-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.pill-row,
.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  border-radius: 999px;
  background: #eef2f6;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 9px;
}

.pill.ok {
  background: var(--soft);
  color: var(--accent-strong);
}

.pill.off {
  background: #fef3f2;
  color: var(--danger);
}

.code-line {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111827;
  color: #d1fae5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  padding: 10px;
  white-space: nowrap;
}

.agent-install {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.recent-url-list {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: #475569;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  padding: 10px;
}

.recent-url-list div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-grid,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 8px;
}

.stat-cell {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.stat-cell span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-cell strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

.event-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.event-item {
  display: grid;
  grid-template-columns: 160px 150px minmax(0, 1fr);
  gap: 10px;
  border-top: 1px solid var(--line);
  color: #475569;
  font-size: 13px;
  padding-top: 8px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
  padding: 13px 15px;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .sidebar nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .metric-grid,
  .form-grid,
  .rule-form,
  .upload-row,
  .rule-grid,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .content,
  .sidebar {
    padding: 18px;
  }

  .sidebar nav,
  .metric-grid,
  .form-grid,
  .rule-form,
  .upload-row,
  .rule-grid,
  .stats-grid,
  .event-item {
    grid-template-columns: 1fr;
  }

  .wide-field {
    grid-column: span 1;
  }

  .section-head,
  .card-top {
    align-items: stretch;
    flex-direction: column;
  }
}
