:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f0f2f5;
  --ink: #171a21;
  --muted: #68707d;
  --line: #dfe3e8;
  --accent: #263f72;
  --accent-soft: #eaf0fb;
  --ok: #2d6a4f;
  --ok-soft: #e8f5ee;
  --warn: #8a5a08;
  --warn-soft: #fff4d7;
  --danger: #9b2c2c;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 12px 35px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input { font: inherit; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #111827;
  color: #d8deea;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  padding: 2px 8px 24px;
}
.brand:hover { text-decoration: none; }
.brand strong { display: block; font-size: 20px; letter-spacing: .01em; }
.brand small { display: block; color: #8f9bb0; font-size: 11px; margin-top: 1px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: #eef3ff;
  color: #1e376a;
  font-weight: 800;
  font-size: 19px;
}

.nav { display: grid; gap: 4px; }
.nav a {
  color: #b8c0cf;
  padding: 9px 11px;
  border-radius: 9px;
  font-weight: 600;
}
.nav a:hover, .nav a.active {
  background: #202a3c;
  color: #fff;
  text-decoration: none;
}

.sidebar-note {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 8px 0;
  border-top: 1px solid #2b3445;
  color: #9da8ba;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #6b7280;
}
.status-dot.ok { background: #57b987; }
.status-dot.warn { background: #d1a34b; }

.main { min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 13px 28px;
  background: rgba(245, 246, 248, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(223, 227, 232, .9);
}

.global-search {
  width: min(720px, 100%);
  display: flex;
  gap: 8px;
}
.global-search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 13px;
  outline: none;
}
.global-search input:focus {
  border-color: #8799bc;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.global-search button {
  border: 0;
  border-radius: 10px;
  padding: 10px 15px;
  color: white;
  background: var(--accent);
  cursor: pointer;
}
.topbar-meta { margin-left: auto; white-space: nowrap; }

.view {
  width: min(1220px, calc(100% - 56px));
  margin: 0 auto;
  padding: 38px 0 70px;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
}
.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 4vw, 44px); line-height: 1.12; letter-spacing: -.025em; }
h2 { font-size: 21px; }
h3 { font-size: 16px; }
.lede { max-width: 760px; color: var(--muted); font-size: 17px; }
.muted { color: var(--muted); }

.hero-grid, .card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.hero-grid { margin-bottom: 30px; }

.action-card, .card, .search-result, .edge-card, .fragment-card, .source-panel, .trace-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.action-card {
  min-height: 145px;
  color: var(--ink);
  padding: 18px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: start;
}
.action-card:hover { text-decoration: none; border-color: #b9c5d9; transform: translateY(-1px); }
.action-card h3 { margin: 2px 0 6px; font-size: 17px; }
.action-card p { color: var(--muted); margin: 0; font-size: 13px; }
.action-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}
.action-arrow { color: var(--accent); font-size: 18px; }

.card { padding: 18px; color: var(--ink); }
.card:hover { text-decoration: none; border-color: #b9c5d9; }
.card h3 { margin: 14px 0 7px; }
.card-topline, .card-footer, .fragment-meta, .result-actions, .meta-strip, .section-title, .query-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.card-footer {
  justify-content: space-between;
  padding-top: 12px;
  margin-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: #4f5968;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .01em;
}
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.section-block { margin-top: 28px; }
.section-title { justify-content: space-between; margin: 26px 0 14px; }
.section-title h2 { margin: 0; }

.notice {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 16px 18px;
  margin: 18px 0 28px;
  background: var(--surface);
}
.notice p:last-child { margin-bottom: 0; }
.notice.warn { background: var(--warn-soft); border-color: #ead8a6; }
.notice.danger { background: var(--danger-soft); border-color: #efcaca; }
.notice.neutral { background: var(--surface); }

.empty-state {
  text-align: center;
  padding: 46px 22px;
  border: 1px dashed #cbd2dc;
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255,255,255,.45);
}
.empty-state h3 { color: var(--ink); margin: 6px 0 5px; }
.empty-state p { max-width: 620px; margin: 0 auto; }
.empty-symbol { font-size: 26px; color: #8b96a6; }

.meta-strip {
  margin: -8px 0 22px;
  padding: 10px 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.meta-strip a { margin-left: auto; }

.document-index {
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 16px;
}
.document-index summary { cursor: pointer; font-weight: 750; }
.document-index ol { margin-bottom: 0; color: var(--muted); }

.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 20px;
  align-items: start;
}
.fragment-stream { display: grid; gap: 12px; }
.fragment-card { padding: 18px 20px; }
.fragment-meta { margin-bottom: 13px; }
.id-link { margin-left: auto; font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.source-text {
  white-space: pre-wrap;
  color: #2a2e36;
  line-height: 1.72;
  margin-bottom: 0;
}
.source-text.large { font-size: 17px; line-height: 1.8; }
.reader-inspector {
  position: sticky;
  top: 92px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.source-panel, .trace-panel { padding: 24px; margin-bottom: 16px; }
.detail-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.detail-row span { overflow-wrap: anywhere; color: var(--muted); }

.search-results, .edge-list { display: grid; gap: 12px; }
.search-result, .edge-card { padding: 18px 20px; }
.search-result h3 { margin: 12px 0 8px; }
.excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 7;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-actions { margin-top: 14px; }
.result-actions a {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
}
.query-line { margin: -10px 0 18px; color: var(--muted); }

.loading-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.skeleton {
  height: 16px;
  width: 65%;
  margin: 13px 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #eceff3, #f6f7f9, #eceff3);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
.skeleton.wide { width: 88%; height: 28px; }
.skeleton.short { width: 38%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 7px 10px;
}
.mobile-only { display: none; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-102%);
    width: 250px;
    transition: transform .18s ease;
    box-shadow: 20px 0 50px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-block; }
  .topbar { padding: 11px 16px; }
  .topbar-meta { display: none; }
  .view { width: min(100% - 30px, 920px); padding-top: 28px; }
  .hero-grid, .card-grid { grid-template-columns: 1fr 1fr; }
  .reader-layout { grid-template-columns: 1fr; }
  .reader-inspector { position: static; }
}

@media (max-width: 640px) {
  .global-search button { display: none; }
  .hero-grid, .card-grid { grid-template-columns: 1fr; }
  .page-heading { display: block; }
  h1 { font-size: 30px; }
  .detail-row { grid-template-columns: 1fr; gap: 2px; }
  .meta-strip a { margin-left: 0; }
  .fragment-card, .search-result, .edge-card, .source-panel, .trace-panel { padding: 16px; }
}
