:root {
  color-scheme: light;
  --ink: #101b33;
  --muted: #58647a;
  --paper: #f5f7fb;
  --surface: #ffffff;
  --rule: #d9deea;
  --nav: #101d37;
  --nav-muted: #aebbd1;
  --action: #2457d6;
  --action-hover: #1747be;
  --success: #147a52;
  --success-soft: #e8f6ef;
  --warning: #9b5b08;
  --warning-soft: #fff3dc;
  --danger: #b4233a;
  --danger-soft: #fdecef;
  --focus: #6e9cff;
  --radius: 14px;
  --shadow: 0 12px 32px rgba(16, 29, 55, 0.08);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

button, input, select { font: inherit; }

button, a, input, select { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: 10;
  transform: translateY(-160%);
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.skip-link:focus { transform: translateY(0); }

.app-shell { min-height: 100vh; }

.rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: 252px;
  display: flex;
  flex-direction: column;
  padding: 28px 20px 22px;
  background: var(--nav);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 40px;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: #3e77f1;
  box-shadow: 0 7px 16px rgba(14, 39, 91, 0.42);
  font-weight: 800;
}

nav { display: grid; gap: 7px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--nav-muted);
  text-decoration: none;
  transition: background-color 180ms ease-out, color 180ms ease-out;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item-active { background: rgba(100, 145, 235, .2); color: #fff; }

.rail-note {
  margin-top: auto;
  display: grid;
  gap: 5px;
  padding: 16px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: var(--radius);
  color: var(--nav-muted);
  font-size: 13px;
}

.rail-note strong { color: #fff; font-size: 15px; }
.rail-note-label { text-transform: uppercase; letter-spacing: .08em; font-size: 11px; }

.workspace {
  min-height: 100vh;
  margin-left: 252px;
  padding: 48px clamp(28px, 5vw, 72px) 30px;
}

.page-header,
.section-heading,
.access-strip,
.status-band,
.jobs-heading,
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.page-header { margin-bottom: 30px; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 9px; font-size: 34px; line-height: 1.12; letter-spacing: -0.03em; }
h2 { margin-bottom: 6px; font-size: 18px; line-height: 1.25; letter-spacing: -0.02em; }
p { margin-bottom: 0; color: var(--muted); max-width: 72ch; }

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  color: var(--muted);
  font-weight: 650;
}

.connection-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9099aa;
}

.connection-state.connected .connection-dot { background: var(--success); }

.access-strip {
  padding: 18px 20px;
  border-radius: var(--radius);
  background: #e9eef9;
  margin-bottom: 20px;
}

.access-strip h2 { font-size: 15px; }
.access-strip p { font-size: 13px; }
.access-form, .job-form { display: flex; align-items: end; gap: 10px; }
.access-form label, .job-form label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

input, select {
  height: 42px;
  border: 1px solid #bcc6d8;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

input::placeholder { color: #6a7488; }
input:hover, select:hover { border-color: #8f9db5; }
input:disabled, select:disabled { background: #e9edf4; color: #737d8e; cursor: not-allowed; }
#token { width: min(320px, 30vw); }
#requested-range { width: 218px; }

.button {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 700;
  transition: background-color 180ms ease-out, transform 150ms ease-out, box-shadow 180ms ease-out;
}

.button:active { transform: translateY(1px); }
.button-primary { background: var(--action); color: #fff; box-shadow: 0 7px 18px rgba(36, 87, 214, .2); }
.button-primary:hover { background: var(--action-hover); }
.button-quiet { background: #e5eaf3; color: #26334b; }
.button-quiet:hover { background: #d9e0ec; }
.button:disabled { background: #dce1ea; color: #7d8798; box-shadow: none; cursor: not-allowed; transform: none; }

.message {
  margin-bottom: 20px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: #7e1729;
}

.status-band {
  min-height: 174px;
  padding: 28px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-summary { display: flex; align-items: flex-start; gap: 16px; min-width: 300px; }
.status-signal { flex: none; width: 17px; height: 17px; margin-top: 26px; border-radius: 50%; background: #9099aa; }
.status-summary h2 { margin-bottom: 7px; font-size: 28px; }
.label { color: var(--muted); font-size: 13px; }
.status-ready .status-signal { background: var(--success); }
.status-degraded .status-signal { background: var(--warning); }
.status-error .status-signal { background: var(--danger); }

.status-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 18px 32px;
  margin: 0;
  min-width: min(430px, 46%);
}

.status-facts div { border-bottom: 1px solid var(--rule); padding-bottom: 9px; }
.status-facts dt { color: var(--muted); font-size: 12px; }
.status-facts dd { margin: 3px 0 0; font-weight: 750; font-variant-numeric: tabular-nums; }

.loading-skeleton { display: grid; gap: 10px; margin-top: 26px; }
.loading-skeleton span { height: 13px; border-radius: 6px; background: #e2e7f0; }
.loading-skeleton span:nth-child(2) { width: 82%; }
.loading-skeleton span:nth-child(3) { width: 64%; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 22px;
  margin-top: 26px;
}

.ledger, .alerts, .jobs {
  min-width: 0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.ledger, .jobs { padding: 24px; }
.alerts { padding: 24px 20px; }
.section-heading { align-items: start; margin-bottom: 20px; }
.section-heading p { font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 0 12px 10px; color: var(--muted); text-align: left; font-weight: 650; border-bottom: 1px solid var(--rule); white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid #e8ebf1; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.empty-row td { height: 84px; color: var(--muted); text-align: center; vertical-align: middle; }
.run-id { max-width: 150px; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, "Cascadia Mono", monospace; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 999px;
  padding: 2px 9px;
  background: #e9edf3;
  color: #3f4c62;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: #0c6240; }
.badge-warning { background: var(--warning-soft); color: #794404; }
.badge-danger { background: var(--danger-soft); color: #8c1b2f; }

.alerts-list { display: grid; gap: 10px; list-style: none; margin: 0; padding: 0; }
.alert-item { padding: 12px; border: 1px solid var(--rule); border-radius: 12px; }
.alert-item strong, .alert-item span { display: block; }
.alert-item span { margin-top: 3px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.empty-state { color: var(--muted); font-size: 13px; }

.jobs { margin-top: 22px; }
.jobs-heading { align-items: flex-end; }
.job-form { flex-wrap: wrap; justify-content: flex-end; }
.job-receipt { margin: 0 0 18px; padding: 12px 14px; border-radius: 10px; background: #edf3ff; color: #173d92; overflow-wrap: anywhere; }

footer { padding: 26px 4px 0; color: var(--muted); font-size: 12px; }

@media (max-width: 1020px) {
  .rail { position: static; width: auto; min-height: auto; flex-direction: row; align-items: center; gap: 20px; padding: 15px 20px; }
  .brand { margin: 0 auto 0 0; }
  .rail nav { display: flex; }
  .rail-note { display: none; }
  .workspace { margin-left: 0; padding-top: 32px; }
  .content-grid { grid-template-columns: 1fr; }
  .status-band { align-items: flex-start; }
  .status-facts { min-width: 48%; }
}

@media (max-width: 760px) {
  .rail { align-items: flex-start; flex-wrap: wrap; overflow: visible; }
  .brand { width: 100%; min-width: 0; }
  .rail nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; min-width: 0; }
  .nav-item { justify-content: center; padding: 0 7px; font-size: 12px; }
  .nav-item svg { display: none; }
  .workspace { padding: 26px 16px 22px; }
  .page-header, .access-strip, .status-band, .jobs-heading { align-items: stretch; flex-direction: column; }
  .page-header { gap: 14px; }
  .access-form, .job-form { align-items: stretch; flex-direction: column; }
  #token, #requested-range, .access-form .button, .job-form .button, .job-form select { width: 100%; }
  .status-facts { grid-template-columns: 1fr 1fr; min-width: 0; width: 100%; }
  .status-summary { min-width: 0; }
  .status-summary h2 { font-size: 24px; }
  h1 { font-size: 29px; }
  .ledger, .jobs { padding: 20px 16px; }
  .alerts { padding: 20px 16px; }
  footer { align-items: flex-start; flex-direction: column; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
