:root {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #171717;
  --surface-2: #1f1f1f;
  --surface-3: #252525;
  --hover: #303030;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: rgba(255, 255, 255, 0.9);
  --muted: rgba(255, 255, 255, 0.52);
  --muted-strong: rgba(255, 255, 255, 0.68);
  --accent: #ff8a00;
  --ok: #6fd17f;
  --warn: #eeb35d;
  --error: #ff6b70;
  --rail-width: 360px;
  --header-height: 58px;
  --radius: 8px;
  --font-ui: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font-ui);
  letter-spacing: 0;
}

body.rail-collapsed {
  --rail-width: 0px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
  background: var(--bg);
}

.db-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(270px, 0.62fr) minmax(520px, 1fr);
  gap: 16px;
  align-items: center;
  min-height: var(--header-height);
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(23, 23, 23, 0.96);
  backdrop-filter: blur(14px);
}

.db-title-block,
.db-toolbar,
.rail-actions,
.reader-head,
.reader-head-main,
.reader-actions,
.agent-filters,
.tag-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.db-title-block {
  min-width: 0;
}

.db-title-block h1,
.mobile-header h1 {
  overflow: hidden;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.db-title-block p,
.mobile-header p,
.rail-head p,
.report-subtitle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.meta-sep,
.report-subtitle-sep {
  color: rgba(255, 255, 255, 0.26);
}

.status-text.is-ok,
.source-text.is-ok {
  color: var(--ok);
}

.status-text.is-warn,
.status-text.is-loading {
  color: var(--warn);
}

.status-text.is-error {
  color: var(--error);
}

.source-text.is-muted {
  color: var(--muted);
}

.db-toolbar {
  justify-content: end;
  min-width: 0;
}

.search-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: min(360px, 36vw);
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.search-field i {
  color: var(--muted);
  font-size: 13px;
}

.search-field input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 13px;
}

.search-field input::placeholder {
  color: rgba(255, 255, 255, 0.38);
}

.agent-filters {
  flex-wrap: nowrap;
  max-width: min(470px, 34vw);
  overflow-x: auto;
  scrollbar-width: none;
}

.agent-filters::-webkit-scrollbar {
  display: none;
}

.chip {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted-strong);
  font-size: 12px;
  white-space: nowrap;
}

.chip:hover,
.chip.is-active {
  background: var(--surface-3);
  color: var(--text);
}

.chip.is-active {
  border-color: var(--line-strong);
}

.icon-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
}

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

.secondary-button {
  gap: 7px;
  padding: 0 10px;
  font-size: 12px;
}

.icon-button:hover,
.secondary-button:hover,
.mobile-dock button:hover {
  border-color: var(--line-strong);
  background: var(--hover);
}

.mobile-header,
.mobile-dock,
.mobile-only {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  min-height: calc(100vh - var(--header-height));
  transition: grid-template-columns 180ms ease;
}

.thread-rail {
  position: sticky;
  top: var(--header-height);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  height: calc(100vh - var(--header-height));
  min-width: 0;
  padding: 12px 10px 12px 12px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface);
  transition: opacity 180ms ease, transform 180ms ease, padding 180ms ease, border-color 180ms ease;
}

body.rail-collapsed .thread-rail {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-18px);
  padding-left: 0;
  padding-right: 0;
  border-color: transparent;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 8px;
}

.rail-head h2 {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
}

.thread-list {
  display: grid;
  gap: 2px;
  align-content: start;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.thread-item {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 10px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.thread-item:hover,
.thread-item.is-selected {
  background: var(--surface-3);
}

.thread-item.is-selected {
  border-color: var(--line-strong);
}

.thread-item-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.thread-title {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-agent,
.thread-foot {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.thread-agent {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-time {
  flex: 0 0 auto;
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
}

.thread-excerpt {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.thread-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.reading-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: calc(100vh - var(--header-height));
  background: var(--bg);
}

.reader-head {
  position: sticky;
  top: var(--header-height);
  z-index: 6;
  justify-content: space-between;
  min-height: 58px;
  padding: 9px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 13, 13, 0.96);
  backdrop-filter: blur(14px);
}

.reader-head-main {
  min-width: 0;
}

.reader-heading {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.report-title {
  overflow: hidden;
  max-width: 76vw;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-subtitle {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.drawer-open-button {
  display: none;
}

.report-page {
  min-height: 0;
  background: var(--bg);
}

.placeholder-block,
.loading-state,
.empty-state {
  margin: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.placeholder-grid,
.empty-state,
.loading-state {
  display: grid;
  gap: 10px;
}

.placeholder-label,
.empty-kicker {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.placeholder-copy,
.empty-state p {
  max-width: 56ch;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.5;
}

.empty-state h3 {
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
}

.report-content {
  display: grid;
  gap: 0;
  min-height: 100%;
}

.report-details {
  margin: 0;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.report-details summary {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.report-details p {
  margin-top: 8px;
  max-width: 86ch;
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.45;
}

.tag-row {
  flex-wrap: wrap;
  margin-top: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted-strong);
  font-size: 12px;
}

.document-surface {
  width: min(100%, 980px);
  padding: 28px 28px 54px;
}

.report-body {
  color: rgba(255, 255, 255, 0.86);
  font-size: 15px;
  line-height: 1.62;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.2em 0 0.48em;
  color: var(--text);
  font-weight: 600;
  line-height: 1.18;
}

.markdown-body h1 {
  font-size: 24px;
}

.markdown-body h2 {
  font-size: 20px;
}

.markdown-body h3 {
  font-size: 17px;
}

.markdown-body h4 {
  font-size: 15px;
}

.markdown-body p,
.markdown-body li,
.markdown-body blockquote {
  font-size: 15px;
  line-height: 1.62;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body pre,
.markdown-body blockquote,
.markdown-body table {
  margin: 0 0 1em;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.35rem;
}

.markdown-body li + li {
  margin-top: 0.28em;
}

.markdown-body code {
  padding: 0.12em 0.32em;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.markdown-body pre {
  padding: 12px 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #101010;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
}

.markdown-body pre code.hljs,
.json-box-pre code.hljs {
  display: block;
  background: transparent;
}

.markdown-body .hljs,
.json-box .hljs {
  background: transparent;
}

.json-box {
  margin: 0 0 1em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}

.json-box-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.json-box-pre {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--surface-2);
  white-space: pre;
}

.json-box-pre code {
  display: block;
  font-size: 13px;
  line-height: 1.55;
}

.markdown-body blockquote {
  padding-left: 12px;
  border-left: 3px solid var(--line-strong);
  color: var(--muted-strong);
}

.markdown-body table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  border-spacing: 0;
}

.markdown-body th,
.markdown-body td {
  padding: 9px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.markdown-body hr {
  margin: 1.3em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.markdown-body a {
  color: #ffbd72;
}

.markdown-body a:hover {
  color: #ffd6a3;
}

.is-hidden {
  display: none !important;
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 18;
  background: rgba(0, 0, 0, 0.52);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

body.rail-mobile-open .drawer-scrim {
  opacity: 1;
  pointer-events: auto;
}

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  animation: shimmer 1.3s infinite;
}

.skeleton-line {
  height: 14px;
}

.skeleton-line.short {
  width: 42%;
}

.skeleton-line.medium {
  width: 68%;
}

.skeleton-card {
  height: 62px;
}

.skeleton-paragraph {
  height: 120px;
}

.skeleton-paragraph.tall {
  height: 180px;
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}

@media (max-width: 1120px) {
  :root {
    --header-height: 56px;
  }

  .db-header {
    display: none;
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: var(--header-height);
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(23, 23, 23, 0.96);
    backdrop-filter: blur(14px);
  }

  .mobile-header > div {
    min-width: 0;
    text-align: center;
  }

  .workspace {
    display: block;
    min-height: calc(100vh - var(--header-height));
    padding-bottom: 68px;
  }

  .thread-rail {
    position: fixed;
    inset: auto 8px 8px;
    z-index: 20;
    width: auto;
    height: min(78vh, 680px);
    padding: 14px 10px 12px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 14px 14px 10px 10px;
    background: var(--surface);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.55);
    transform: translateY(calc(100% + 18px));
    opacity: 0;
    pointer-events: none;
  }

  .thread-rail::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    width: 44px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    transform: translateX(-50%);
  }

  body.rail-mobile-open .thread-rail {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  body.rail-collapsed .thread-rail {
    padding: 14px 10px 12px 12px;
    border-color: var(--line-strong);
  }

  .mobile-only {
    display: inline-flex;
  }

  .drawer-open-button {
    display: inline-flex;
  }

  .reading-pane {
    min-height: calc(100vh - var(--header-height));
  }

  .reader-head {
    top: var(--header-height);
    min-height: 56px;
    padding: 8px 12px;
  }

  .reader-actions {
    display: none;
  }

  .report-title {
    max-width: calc(100vw - 96px);
  }

  .document-surface {
    width: 100%;
    padding: 20px 16px 42px;
  }

  .mobile-dock {
    position: fixed;
    right: 10px;
    bottom: 10px;
    left: 10px;
    z-index: 12;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(31, 31, 31, 0.96);
    backdrop-filter: blur(14px);
  }

  .mobile-dock button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-size: 12px;
  }
}

@media (max-width: 720px) {
  .reader-head {
    align-items: center;
  }

  .report-subtitle {
    font-size: 11px;
  }

  .report-details {
    padding: 10px 12px;
  }

  .markdown-body h1 {
    font-size: 22px;
  }

  .markdown-body h2 {
    font-size: 18px;
  }

  .markdown-body p,
  .markdown-body li,
  .markdown-body blockquote,
  .report-body {
    font-size: 14px;
  }
}
