:root {
  color-scheme: light;
  --background: #f3f5f9;
  --surface: #ffffff;
  --text: #172338;
  --muted: #526179;
  --line: #dce3ee;
  --header: #15243b;
  --primary: #2456c4;
  --primary-hover: #1944a4;
  --success: #126545;
  --danger: #a32338;
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 0;
  background: var(--background);
  color: var(--text);
  line-height: 1.5;
}

h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: clamp(2rem, 4vw, 2.85rem); line-height: 1.12; letter-spacing: -.04em; }
h2 { font-size: clamp(1.35rem, 3vw, 1.65rem); line-height: 1.2; letter-spacing: -.02em; }
h3 { font-size: 1.08rem; line-height: 1.3; }
a { color: var(--primary); }
button, input { font: inherit; }
label { display: block; font-size: .9rem; font-weight: 650; }

:focus-visible {
  outline: 3px solid #3374ec;
  outline-offset: 3px;
}

.shell { width: min(100% - 3rem, 77rem); margin-inline: auto; }
.main { display: grid; gap: 2rem; padding-block: 2.25rem 3.5rem; }
.muted { color: var(--muted); }
.endpoint { margin-top: .5rem; overflow-wrap: anywhere; }
section[id], aside[id] { scroll-margin-block: 1rem; }

.sr-only, .skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
}

.skip-link {
  position: absolute;
  z-index: 1;
  top: .5rem;
  left: .5rem;
  padding: .5rem .75rem;
  background: var(--surface);
  border-radius: .4rem;
}

.topbar { background: var(--header); color: #fff; }
.topbar-inner { display: flex; align-items: center; gap: clamp(.85rem, 4vw, 3rem); min-height: 4.25rem; }
.brand { display: inline-flex; align-items: center; gap: .65rem; color: inherit; font-weight: 750; text-decoration: none; white-space: nowrap; }
.brand-mark { width: .9rem; height: .9rem; border: 3px solid #81a8ff; border-radius: 35%; transform: rotate(45deg); }
.topbar-nav { flex: 1; display: flex; align-items: center; gap: clamp(1rem, 3vw, 2rem); }
.topbar-nav a { color: #e2eafe; font-size: .9rem; text-decoration: none; }
.topbar-nav a:hover { color: #fff; text-decoration: underline; }

.page-heading, .section-heading, .card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1rem;
}

.section-heading { margin-bottom: .95rem; flex-wrap: wrap; }
.monitor-status { font-size: .875rem; }
.monitor-status[data-state="down"] { color: var(--danger); }
.profile-count { font-variant-numeric: tabular-nums; }

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 6px #15243b06;
}

.overview-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; }
.overview-card, .create-card, .empty-card, .chart-card { padding: clamp(1rem, 2.3vw, 1.5rem); }
.metrics-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem .75rem; margin-top: 1rem; }
.network-metrics { border-top: 1px solid var(--line); padding-top: 1rem; }
.metric dt, .profile-traffic dt { color: var(--muted); font-size: .8rem; }
.metric dd, .profile-traffic dd { margin-top: .25rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .22rem .55rem;
  border-radius: 999px;
  font-size: .73rem;
  line-height: 1.3;
  font-weight: 650;
  white-space: nowrap;
  background: #eaf0f8;
  color: #42526d;
}

.badge::before { content: ""; flex: 0 0 .42rem; height: .42rem; border-radius: 50%; background: currentColor; }
.badge[data-state="up"] { background: #e1f3eb; color: var(--success); }
.badge[data-state="down"] { background: #fbe8eb; color: var(--danger); }

.profile-layout { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(16rem, 1fr); align-items: start; gap: 1rem; }
.profile-list { display: grid; gap: .65rem; min-width: 0; }
.empty-card { color: var(--muted); }
.profile-card summary { display: flex; align-items: center; gap: .8rem; padding: 1rem 1.2rem; cursor: pointer; list-style: none; border-radius: var(--radius); }
.profile-card summary::-webkit-details-marker { display: none; }
.profile-card summary::after { content: ""; flex: 0 0 .48rem; height: .48rem; border-inline-end: 2px solid #64738a; border-block-end: 2px solid #64738a; margin-inline: .3rem; transform: rotate(45deg); }
.profile-card[open] summary::after { transform: rotate(225deg); }
.profile-identity { flex: 1; display: grid; min-width: 0; overflow-wrap: anywhere; }
.profile-identity .muted { font-size: .83rem; }
.profile-content { display: grid; gap: 1rem; padding: 0 1.2rem 1.2rem; }
.profile-traffic { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; }
.profile-traffic dd { margin-top: .08rem; }
.profile-links, .rename-form { display: grid; gap: .4rem; }
.profile-links:empty { display: none; }
.profile-links > a { justify-self: start; margin-top: .2rem; }
.help { font-size: .8rem; }
.profile-actions { display: flex; flex-wrap: wrap; gap: .5rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.create-card form { display: grid; gap: .55rem; margin-top: .8rem; }
.create-card .button { justify-self: start; margin-top: .2rem; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.65rem;
  padding: .5rem .85rem;
  border: 1px solid #ccd6e5;
  border-radius: .65rem;
  background: var(--surface);
  color: var(--text);
  font-size: .875rem;
  font-weight: 650;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button:hover { background: #edf2fb; border-color: #b7c8e1; }
.button:disabled { opacity: .58; cursor: default; }
.button.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.button.primary:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.button.danger { border-color: #edc5cd; color: var(--danger); }
.button.danger:hover { background: #fbe8eb; }
.button.sign-out { color: #fff; border-color: #53647d; background: transparent; }
.button.sign-out:hover { background: #2a3b54; }

input:not([type="hidden"]) {
  min-width: 0;
  width: 100%;
  min-height: 2.65rem;
  padding: .45rem .65rem;
  border: 1px solid #b8c5d9;
  border-radius: .62rem;
  color: var(--text);
  background: var(--surface);
}

input[readonly] { background: #f6f8fb; color: #384960; }
.input-row { display: flex; align-items: stretch; gap: .45rem; }
.input-row .button { flex-shrink: 0; }

.chart-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.chart-card canvas, .chart-empty { display: block; width: 100%; height: 9.75rem; margin-block: .6rem .45rem; }
.chart-empty { display: grid; place-items: center; color: var(--muted); font-size: .85rem; background: #f6f8fb; border-radius: .5rem; text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: .35rem .85rem; color: var(--muted); font-size: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend span::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: #2f61cc; }
.legend .legend-green::before { background: #15806c; }

.flashes { display: grid; gap: .5rem; }
.flash { border: 1px solid #b9daca; border-radius: .65rem; padding: .75rem 1rem; background: #e9f5ef; color: #185c41; }
.flash--error { border-color: #efc3ca; background: #fcebee; color: #962335; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-shell { width: min(100%, 27rem); display: grid; gap: .75rem; }
.login-card { padding: clamp(1.4rem, 6vw, 2.25rem); }
.login-card h1 { margin-top: 1.3rem; font-size: 2rem; }
.login-card .brand-mark { border-color: var(--primary); }
.login-form { display: grid; gap: .45rem; margin-top: 1.5rem; }
.login-form label:not(:first-of-type) { margin-top: .3rem; }
.login-form button { margin-top: .6rem; }

@media (max-width: 62rem) {
  .overview-grid { grid-template-columns: 1fr 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 46rem) {
  .shell { width: calc(100% - 2rem); }
  .main { padding-block: 1.5rem 2rem; gap: 1.6rem; }
  .overview-grid, .profile-layout { grid-template-columns: 1fr; }
  .create-card { grid-row: 1; }
}

@media (max-width: 34rem) {
  .topbar-inner { display: grid; grid-template-columns: 1fr auto; gap: .6rem 1rem; padding-block: .7rem; }
  .topbar-nav { grid-row: 2; grid-column: 1 / -1; gap: 1.2rem; }
  .page-heading { align-items: start; flex-direction: column; }
  .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 23rem) {
  .input-row { flex-wrap: wrap; }
  .card-heading { align-items: start; flex-direction: column; }
}
