:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-strong: #f0f4f8;
  --ink: #172033;
  --muted: #68758c;
  --line: #dbe2ea;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --accent: #f59e0b;
  --danger: #dc2626;
  --success: #15803d;
  --shadow: 0 20px 60px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 32%),
    linear-gradient(315deg, rgba(245, 158, 11, 0.1), transparent 36%),
    var(--bg);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 20px;
  background: #101827;
  color: #eef5ff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #111827;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 3px;
  color: #9fb0c7;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #bdc8d9;
  text-decoration: none;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.nav-item span {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #cbd7e8;
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.16);
}

.main {
  display: grid;
  align-content: start;
  gap: 22px;
  padding: 30px;
}

.topbar,
.domain-switcher,
.panel,
.metric-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 3vw, 40px);
  line-height: 1.05;
}

h2 {
  font-size: 19px;
}

.topbar-actions,
.domain-health,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.icon-button,
.action-grid button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  font-weight: 700;
}

.primary-button {
  padding: 0 16px;
  background: var(--brand);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--brand-strong);
}

.secondary-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.icon-button {
  width: 42px;
  background: #fff7ed;
  color: #92400e;
}

.domain-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
}

.domain-switcher label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pill.success {
  background: #dcfce7;
  color: var(--success);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 22px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 142px;
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card strong {
  font-size: 33px;
}

.split-layout,
.rules-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.6fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.chart {
  display: grid;
  grid-template-columns: repeat(16, minmax(14px, 1fr));
  align-items: end;
  gap: 8px;
  height: 260px;
  padding: 18px 10px 4px;
  border-radius: 8px;
  background:
    linear-gradient(to top, rgba(104, 117, 140, 0.12) 1px, transparent 1px) 0 0 / 100% 52px,
    #f8fafc;
}

.bar {
  min-height: 14px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--brand), #14b8a6);
}

.bar.blocked {
  background: linear-gradient(180deg, var(--accent), #fbbf24);
}

.origin-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.origin-card small,
.event small,
.rule small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.origin-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #ccfbf1;
  color: var(--brand-strong);
  font-weight: 800;
}

.toggle-list,
.rule-list,
.event-stream,
.proxy-hosts {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.toggle-list label,
.rule,
.event,
.proxy-host {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.toggle-list label {
  display: flex;
  gap: 10px;
  align-items: center;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.proxy-badge {
  color: var(--brand-strong);
  font-weight: 800;
}

.rule {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rule strong {
  display: block;
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: var(--brand);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.action-grid {
  display: grid;
  gap: 10px;
}

.action-grid button {
  padding: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  text-align: left;
}

.proxy-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.proxy-form > label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.proxy-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.proxy-host {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.proxy-host strong,
.proxy-host small {
  display: block;
}

.proxy-host small {
  margin-top: 4px;
  color: var(--muted);
}

.event {
  display: grid;
  grid-template-columns: 98px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.event-type {
  color: var(--brand-strong);
  font-weight: 800;
}

.event.block .event-type {
  color: var(--danger);
}

dialog {
  width: min(460px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dialog-card .checkline {
  display: flex;
  align-items: center;
  gap: 9px;
}

.checkline input {
  width: auto;
  min-height: auto;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 8px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 13px 14px;
  border-radius: 8px;
  background: #101827;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 24, 39, 0.72);
}

.login-overlay.hidden {
  display: none;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  padding: 24px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

.login-card .brand-mark {
  margin-bottom: 2px;
}

.login-card h2 {
  margin-bottom: 4px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-card small {
  color: var(--muted);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    overflow-x: auto;
  }

  .nav-list {
    display: flex;
  }

  .sidebar-footer {
    display: none;
  }

  .metrics-grid,
  .split-layout,
  .rules-layout {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .domain-switcher,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics-grid,
  .split-layout,
  .rules-layout {
    grid-template-columns: 1fr;
  }

  .event {
    grid-template-columns: 1fr;
  }
}
