:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #eef4f5;
  --line: #d8e1e3;
  --line-strong: #b9c8cc;
  --text: #172126;
  --muted: #5f6f76;
  --faint: #839199;
  --teal: #0f766e;
  --teal-dark: #0b5f59;
  --blue: #1d4f91;
  --amber: #9a6100;
  --red: #b42318;
  --green: #137333;
  --shadow: 0 18px 45px rgba(23, 33, 38, 0.12);
  --radius: 8px;
  --sidebar: 252px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

body.drawer-locked {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

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

:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.32);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 20;
  background: var(--text);
  color: #fff;
  padding: 10px 12px;
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 12px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #112226;
  color: #f6fbfb;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #fff;
  border: 1px solid rgba(15, 118, 110, 0.18);
  overflow: hidden;
}

.brand-logo,
.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 42px;
  max-height: 42px;
  object-fit: contain;
  transform: scale(1.36);
}

.login-brand .brand-logo,
.login-brand .brand-mark img {
  max-width: 56px;
  max-height: 56px;
}

.brand strong,
.brand > div span {
  display: block;
}

.brand > div span {
  color: #a7bcbe;
  font-size: 12px;
}

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

.nav-item {
  width: 100%;
  border: 0;
  color: #dce9ea;
  background: transparent;
  text-align: left;
  padding: 10px 11px;
  border-radius: 7px;
}

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

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

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--faint);
}

.dot.ok {
  background: #43d17d;
}

.dot.error {
  background: #ff7d72;
}

.workspace {
  min-width: 0;
}

.topbar {
  min-height: 82px;
  background: rgba(244, 247, 248, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 28px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.token-entry {
  width: min(330px, 34vw);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), transparent 35%),
    var(--bg);
}

.login-shell {
  width: min(440px, calc(100vw - 28px));
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.login-brand .brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(23, 33, 38, 0.1);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form .button {
  width: 100%;
  justify-content: center;
}

.login-message {
  min-height: 20px;
  color: var(--muted);
  font-weight: 700;
}

.login-message.error {
  color: var(--red);
}

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

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

h2 {
  font-size: 19px;
  line-height: 1.2;
}

h3 {
  font-size: 15px;
}

.eyebrow {
  color: var(--teal);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.content {
  padding: 22px 28px 40px;
  display: grid;
  gap: 18px;
}

.panel,
.form-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 9px 10px;
  min-height: 38px;
}

textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.button,
.link-button,
.icon-button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  min-height: 38px;
  padding: 8px 11px;
  font-weight: 700;
}

.button:hover,
.icon-button:hover {
  border-color: var(--teal);
}

.button.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.button.primary:hover {
  background: var(--teal-dark);
}

.link-button {
  border: 0;
  padding: 0;
  min-height: auto;
  color: var(--blue);
  background: transparent;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.status-pill,
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.status-pill.neutral,
.chip.neutral {
  color: var(--muted);
  background: var(--surface-2);
}

.status-pill.ok {
  color: var(--green);
  background: #e8f5ec;
}

.status-pill.error {
  color: var(--red);
  background: #ffebe8;
}

.chip.green {
  color: var(--green);
  background: #e8f5ec;
}

.chip.amber {
  color: var(--amber);
  background: #fff4dc;
}

.chip.red {
  color: var(--red);
  background: #ffebe8;
}

.chip.blue {
  color: var(--blue);
  background: #e8f0fb;
}

.view {
  display: none;
}

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

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 27px;
  line-height: 1;
}

.two-column {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.panel,
.form-panel {
  padding: 14px;
}

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

.compact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px;
  background: var(--surface-2);
  border-radius: 7px;
}

.muted {
  color: var(--muted);
}

.toolbar,
.form-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 160px 110px auto;
  gap: 12px;
  align-items: end;
}

.form-grid {
  border: 0;
  padding: 0;
  grid-template-columns: 1fr 180px;
  align-items: start;
}

.segmented-field {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 6px;
}

.segmented-field legend {
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.segmented-control {
  min-height: 38px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-2);
}

.segment {
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
  padding: 6px 8px;
}

.segment:hover {
  color: var(--text);
}

.segment.active {
  background: #fff;
  color: var(--teal-dark);
  box-shadow: 0 1px 3px rgba(23, 33, 38, 0.14);
}

.wide {
  grid-column: 1 / -1;
}

.hidden {
  display: none !important;
}

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

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

th {
  color: var(--muted);
  background: #f9fbfb;
  font-size: 12px;
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

.row-title {
  font-weight: 800;
}

.row-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  word-break: break-word;
}

.action-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.danger {
  color: var(--red);
  border-color: #efb4ad;
}

.empty-state,
.error-state,
.loading-state {
  padding: 22px;
  text-align: center;
  color: var(--muted);
}

.error-state {
  color: var(--red);
}

.drawer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
}

.drawer.open {
  pointer-events: auto;
  opacity: 1;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 19, 22, 0.45);
}

.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  width: min(760px, calc(100vw - 24px));
  min-width: 0;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(24px);
  transition: transform 180ms ease;
}

.drawer.open .drawer-panel {
  transform: translateX(0);
}

.drawer-header {
  flex: 0 0 auto;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-tabs {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  max-width: 100%;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable;
  touch-action: pan-x;
}

.drawer-tab {
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 7px;
  padding: 7px 10px;
  white-space: nowrap;
  font-weight: 750;
}

.drawer-tab.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px;
  display: grid;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  align-content: start;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.detail-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  /* overflow: hidden; */
}

.detail-section h3 {
  padding: 10px 12px;
  background: #f9fbfb;
  border-bottom: 1px solid var(--line);
}

.section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 22px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.collection-empty {
  padding: 14px;
}

.record-list {
  display: grid;
  gap: 12px;
  padding: 12px;
  min-width: 0;
}

.record-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.record-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: #fbfcfc;
  border-bottom: 1px solid var(--line);
}

.record-title {
  font-weight: 800;
  color: var(--text);
  word-break: break-word;
}

.record-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

.record-grid {
  display: grid;
  grid-template-columns: minmax(130px, 0.35fr) minmax(0, 1fr);
}

.record-grid dt,
.record-grid dd {
  min-width: 0;
  margin: 0;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  word-break: break-word;
}

.record-grid dt {
  color: var(--muted);
  background: #fcfdfd;
  font-weight: 750;
}

.record-grid dd {
  color: var(--text);
}

.nested-json summary {
  cursor: pointer;
  color: var(--teal-dark);
  font-weight: 750;
}

.nested-json pre {
  max-height: 260px;
  margin: 8px 0 0;
  padding: 10px;
  overflow: auto;
  border-radius: 7px;
  background: #f5f8f8;
  color: #0f2530;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.kv-grid {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
}

.kv-grid dt,
.kv-grid dd {
  margin: 0;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  word-break: break-word;
}

.kv-grid dt {
  color: var(--muted);
  font-weight: 750;
  background: #fcfdfd;
}

.json-block {
  margin: 0;
  padding: 12px;
  max-height: 440px;
  overflow: auto;
  color: #0f2530;
  background: #f5f8f8;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: grid;
  gap: 8px;
}

.toast {
  width: min(360px, calc(100vw - 36px));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 11px 12px;
  background: #102226;
  color: #fff;
  font-weight: 700;
}

.toast.error {
  background: var(--red);
}

.toast.success {
  background: var(--green);
}

.mobile-tabs {
  display: none;
}

@media (max-width: 1040px) {
  .two-column,
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .token-entry {
    width: min(420px, 100%);
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    position: static;
    padding: 14px;
  }

  .mobile-tabs {
    display: block;
    min-width: 160px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .token-entry,
  .mobile-tabs,
  .status-pill {
    grid-column: 1 / -1;
    width: 100%;
  }

  .content {
    padding: 14px;
  }

  .stats-grid,
  .two-column,
  .toolbar,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .section-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .drawer-panel {
    width: 100%;
  }

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