:root {
  --ink: #102525;
  --muted: #607172;
  --surface: #ffffff;
  --surface-soft: #f4f8f7;
  --line: #dce7e5;
  --brand: #0d726e;
  --brand-dark: #075855;
  --brand-soft: #dff3ef;
  --good: #19714d;
  --good-soft: #e5f5ec;
  --warn: #8a5a05;
  --warn-soft: #fff2d4;
  --danger: #a43d35;
  --danger-soft: #fdeae7;
  --shadow: 0 20px 55px rgba(22, 66, 64, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #eef6f4; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(96, 194, 175, 0.17), transparent 32rem),
    linear-gradient(180deg, #f5faf9 0, #edf5f3 50rem, #eef6f4 100%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 100;
  padding: .7rem 1rem;
  background: var(--ink);
  color: white;
  border-radius: 8px;
}
.skip-link:focus { top: 1rem; }

.topbar {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: .8rem;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.65rem;
  height: 2.65rem;
  border-radius: 14px;
  color: white;
  background: var(--brand);
  box-shadow: 0 10px 24px rgba(13, 114, 110, .22);
  font-size: 1.25rem;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: .98rem; letter-spacing: -.015em; }
.brand small { color: var(--muted); font-size: .76rem; }
.top-actions { display: flex; align-items: center; gap: .65rem; }

.shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 1.8rem auto 5rem;
}

.panel {
  border: 1px solid rgba(210, 226, 222, .9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow);
}

.hero {
  min-height: 15rem;
  padding: clamp(1.5rem, 4vw, 3.4rem);
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(16rem, .75fr);
  align-items: center;
  gap: clamp(2rem, 7vw, 6rem);
  overflow: hidden;
  position: relative;
}
.hero::after {
  content: "";
  position: absolute;
  width: 19rem;
  height: 19rem;
  right: -8rem;
  top: -11rem;
  border-radius: 50%;
  background: linear-gradient(150deg, rgba(33, 153, 141, .18), rgba(33, 153, 141, 0));
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 .42rem;
  color: var(--brand);
  font-weight: 750;
  font-size: .74rem;
  letter-spacing: .09em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .7rem; font-size: clamp(2rem, 5vw, 3.55rem); line-height: 1.04; letter-spacing: -.045em; }
h2 { margin-bottom: .45rem; font-size: clamp(1.45rem, 3vw, 2rem); line-height: 1.15; letter-spacing: -.025em; }
h3 { margin-bottom: 0; font-size: 1.15rem; letter-spacing: -.015em; }
.lead { max-width: 44rem; color: #435b5b; font-size: clamp(1rem, 2vw, 1.15rem); margin-bottom: 0; }
.muted, .context-note { color: var(--muted); }
.context-note { max-width: 29rem; margin: 0; font-size: .88rem; text-align: right; }

.progress-wrap { position: relative; z-index: 1; }
.progress-copy { display: flex; justify-content: space-between; gap: 1rem; font-size: .88rem; font-weight: 680; margin-bottom: .55rem; }
progress { width: 100%; height: .75rem; border: 0; border-radius: 999px; overflow: hidden; background: var(--surface-soft); }
progress::-webkit-progress-bar { background: var(--surface-soft); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--brand); border-radius: 999px; transition: width .2s ease; }
progress::-moz-progress-bar { background: var(--brand); border-radius: 999px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  width: fit-content;
  padding: .4rem .68rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 720;
  white-space: nowrap;
}
.status-badge.neutral, .notice.neutral { color: #476060; background: #edf3f2; }
.status-badge.good, .notice.good { color: var(--good); background: var(--good-soft); }
.status-badge.warn, .notice.warn { color: var(--warn); background: var(--warn-soft); }
.status-badge.danger, .notice.danger { color: var(--danger); background: var(--danger-soft); }

.button {
  border: 0;
  border-radius: 11px;
  padding: .68rem .95rem;
  font-weight: 720;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, select:focus-visible, .history-item:focus-visible, .device-choice:focus-visible {
  outline: 3px solid rgba(13, 114, 110, .3);
  outline-offset: 2px;
}
.button.primary { color: white; background: var(--brand); box-shadow: 0 9px 20px rgba(13, 114, 110, .16); }
.button.primary:hover { background: var(--brand-dark); }
.button.secondary { color: var(--brand-dark); background: var(--brand-soft); }
.button.ghost { color: var(--brand-dark); background: rgba(255,255,255,.7); border: 1px solid var(--line); }
.button:disabled { cursor: wait; opacity: .62; transform: none; }

.action-panel, .pair-panel {
  margin-top: 1rem;
  padding: clamp(1.4rem, 3vw, 2rem);
  display: grid;
  grid-template-columns: minmax(0, .7fr) minmax(18rem, 1.3fr);
  gap: 2rem;
}
.device-choices { display: grid; gap: .7rem; }
.device-choice {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .9rem 1rem;
  color: var(--ink);
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.device-choice:hover { border-color: #84b9b2; background: #f7fbfa; }
.device-choice strong, .device-choice small { display: block; }
.device-choice small { color: var(--muted); margin-top: .16rem; }

.dashboard { margin-top: 2.5rem; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; margin: 2.5rem 0 1rem; }
.section-heading.compact { margin-top: 3.4rem; }
.selector-wrap { display: grid; grid-template-columns: auto minmax(13rem, 18rem); align-items: center; gap: .7rem; }
label { color: #415555; font-size: .82rem; font-weight: 680; }
select, input {
  min-height: 2.7rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: white;
  padding: .58rem .75rem;
}

.summary-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 1rem; }
.quality-card, .event-card { padding: clamp(1.3rem, 3vw, 1.8rem); }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.3rem; }
.fact-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .7rem; margin: 0; }
.fact-grid div { min-width: 0; padding: .85rem; border-radius: 13px; background: var(--surface-soft); }
.fact-grid dt { color: var(--muted); font-size: .72rem; }
.fact-grid dd { margin: .22rem 0 0; font-size: 1.15rem; font-weight: 760; font-variant-numeric: tabular-nums; }
.notice { margin: 1rem 0 0; padding: .78rem .9rem; border-radius: 12px; font-size: .84rem; }
.quality-warnings { margin-top: .55rem; }
.quality-warnings summary { cursor: pointer; font-weight: 700; }
.quality-warnings ul { margin: .45rem 0 0; padding-left: 1.2rem; }
.quality-warnings li { overflow-wrap: anywhere; }

.event-list { display: grid; gap: .65rem; }
.event-empty { color: var(--good); background: var(--good-soft); padding: 1rem; border-radius: 13px; font-size: .9rem; }
.event-item { display: grid; grid-template-columns: auto 1fr; gap: .7rem; align-items: start; padding: .85rem; background: var(--danger-soft); color: #6f2d28; border-radius: 13px; }
.event-icon { font-weight: 800; }
.event-item strong, .event-item small { display: block; }
.event-item small { margin-top: .12rem; opacity: .82; }

.metric-groups { display: grid; gap: 1rem; }
.metric-group { padding: clamp(1.2rem, 3vw, 1.7rem); }
.metric-group-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.metric-count { color: var(--muted); font-size: .78rem; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .65rem; }
.metric {
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}
.metric-label { min-height: 2.7em; color: #4e6262; font-size: .79rem; }
.metric-value { margin: .3rem 0 .25rem; font-size: 1.3rem; font-weight: 780; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-meta { color: var(--muted); font-size: .7rem; }
.metric.unavailable { background: #f7f8f8; }
.metric.unavailable .metric-value { color: var(--muted); font-size: .95rem; }
.metric-reason { margin: .35rem 0 0; color: var(--muted); font-size: .72rem; }
.unavailable-details { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .85rem; }
.unavailable-details summary { width: fit-content; cursor: pointer; color: var(--muted); font-size: .82rem; font-weight: 700; }
.unavailable-details summary:hover { color: var(--ink); }
.unavailable-details summary:focus-visible { border-radius: .25rem; outline: 3px solid rgba(13, 114, 110, .3); outline-offset: .2rem; }
.unavailable-grid { margin-top: .85rem; }

.history-list { overflow: hidden; }
.history-empty { padding: 1.4rem; color: var(--muted); }
.history-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(9rem, .8fr) minmax(8rem, .65fr) minmax(10rem, 1fr) auto;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  background: white;
}
.history-item:last-child { border-bottom: 0; }
.history-item:hover { background: #f8fbfa; }
.history-item strong, .history-item span { min-width: 0; }
.history-item span { color: var(--muted); font-size: .8rem; }
.history-state { justify-self: end; }
#history-more { margin-top: .8rem; }

.pair-form { align-self: center; }
.input-action { display: grid; grid-template-columns: 1fr auto; gap: .55rem; margin-top: .35rem; }
.form-result { min-height: 1.5rem; margin: .5rem 0 0; color: var(--muted); font-size: .82rem; }
.fatal-panel { margin-top: 1rem; padding: 2rem; border-color: #efcbc7; background: #fff8f7; }

footer {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.6rem 0 2rem;
  display: flex;
  justify-content: center;
  gap: .55rem;
  color: var(--muted);
  font-size: .78rem;
  text-align: center;
}

.hidden { display: none !important; }

@media (max-width: 880px) {
  .hero, .action-panel, .pair-panel, .summary-grid { grid-template-columns: 1fr; }
  .hero { gap: 2rem; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .context-note { text-align: left; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .selector-wrap { width: 100%; grid-template-columns: auto 1fr; }
  .history-item { grid-template-columns: 1fr 1fr; }
  .history-state { justify-self: start; }
}

@media (max-width: 580px) {
  .topbar { align-items: flex-start; }
  .top-actions { align-items: flex-end; flex-direction: column; }
  .brand small { display: none; }
  .shell { margin-top: .6rem; }
  .hero { min-height: 18rem; }
  .fact-grid, .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-label { min-height: auto; }
  .history-item { grid-template-columns: 1fr; gap: .25rem; }
  .input-action { grid-template-columns: 1fr; }
  footer { flex-direction: column; }
  footer span[aria-hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
