:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f0f3f5;
  --text: #20252c;
  --muted: #66717f;
  --line: #d9dee5;
  --line-strong: #b7c0cc;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warn: #a35a12;
  --danger: #b42318;
  --blue: #255db4;
  --shadow: 0 10px 30px rgba(27, 35, 46, 0.08);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select {
  font: inherit;
}

a {
  color: var(--blue);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 18px;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0;
}

.brand-title {
  font-weight: 760;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-close,
.sidebar-overlay {
  display: none;
}

.field {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
}

.field input:focus,
.field select:focus,
button:focus-visible {
  outline: 2px solid rgba(15, 118, 110, 0.35);
  outline-offset: 2px;
}

.file-nav {
  margin-top: 18px;
  padding-bottom: 36px;
}

.nav-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.file-group {
  border-top: 1px solid var(--line);
}

.file-group summary {
  cursor: pointer;
  padding: 12px 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  list-style: none;
}

.file-group summary::-webkit-details-marker {
  display: none;
}

.file-group summary span {
  float: right;
  color: var(--muted);
  font-weight: 500;
}

.file-list {
  display: grid;
  gap: 4px;
  padding: 0 0 12px;
}

.file-link {
  display: grid;
  gap: 3px;
  min-height: 44px;
  border-radius: 8px;
  padding: 8px 9px;
  color: var(--text);
  text-decoration: none;
}

.file-link:hover,
.file-link.is-active {
  background: var(--surface-muted);
}

.file-link.is-active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-link-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 650;
}

.file-link-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 11px;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 18px;
  max-width: 1180px;
}

.topbar-title {
  min-width: 0;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.icon-button,
.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 8px 12px;
  text-decoration: none;
  white-space: nowrap;
}

.icon-button:hover,
.action-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

#menuButton {
  display: none;
}

.dashboard,
.reader {
  max-width: 1180px;
  margin: 0 auto;
}

.dashboard.is-hidden,
.reader.is-hidden {
  display: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 26px;
  font-weight: 780;
  line-height: 1;
}

.stat-label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.panel-body {
  padding: 6px 0;
}

.table-list {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.table-list th,
.table-list td {
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.table-list th {
  color: var(--muted);
  font-weight: 700;
}

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

.table-list a {
  overflow-wrap: anywhere;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

.table-list a:hover {
  color: var(--accent-strong);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: 3px 9px;
  font-size: 12px;
}

.badge.is-warn {
  background: #fff2df;
  color: var(--warn);
}

.badge.is-accent {
  background: #e5f4f2;
  color: var(--accent-strong);
}

.reader-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.reader-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.reader-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.document,
.compare-pane {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.document {
  padding: 28px;
}

.compare-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.compare-pane {
  min-width: 0;
  overflow: auto;
}

.compare-header {
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
  padding: 12px 16px;
  font-weight: 750;
}

.compare-body {
  padding: 20px;
}

.markdown {
  line-height: 1.82;
  font-size: 16px;
  overflow-wrap: break-word;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin: 1.45em 0 0.65em;
  line-height: 1.35;
  letter-spacing: 0;
}

.markdown h1 {
  font-size: 28px;
}

.markdown h2 {
  padding-bottom: 0.28em;
  border-bottom: 1px solid var(--line);
  font-size: 22px;
}

.markdown h3 {
  font-size: 18px;
}

.markdown p {
  margin: 0 0 1em;
}

.markdown pre {
  overflow: auto;
  max-width: 100%;
  border-radius: 8px;
  background: #20252c;
  color: #f7fafc;
  padding: 14px;
  line-height: 1.55;
}

.markdown code {
  border-radius: 5px;
  background: var(--surface-muted);
  padding: 0.12em 0.35em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

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

.markdown blockquote {
  margin: 1em 0;
  border-left: 4px solid var(--accent);
  background: #eef7f6;
  padding: 10px 14px;
  color: #23413f;
}

.markdown ul,
.markdown ol {
  padding-left: 1.35em;
  margin: 0 0 1em;
}

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

.markdown table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: auto;
  border-collapse: collapse;
  margin: 1em 0;
}

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

.markdown th {
  background: var(--surface-muted);
}

.raw-source {
  overflow: auto;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 28px;
  line-height: 1.8;
}

@media (max-width: 980px) {
  body.sidebar-open {
    overflow: hidden;
  }

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(88vw, 360px);
    max-width: calc(100vw - 34px);
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
    padding: calc(14px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    border: 0;
    background: rgba(18, 24, 33, 0.38);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
  }

  .sidebar-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-close {
    display: inline-flex;
    margin-left: auto;
  }

  .brand {
    align-items: flex-start;
  }

  .field input,
  .field select,
  .file-link,
  .icon-button,
  .action-button {
    min-height: 44px;
  }

  #menuButton {
    display: inline-flex;
  }

  .workspace {
    padding: 0 16px 18px;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 15;
    align-items: flex-start;
    padding: calc(12px + env(safe-area-inset-top)) 0 12px;
    background: rgba(246, 247, 249, 0.96);
    backdrop-filter: blur(12px);
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .compare-header {
    top: calc(70px + env(safe-area-inset-top));
  }
}

@media (max-width: 620px) {
  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px 12px;
  }

  .topbar-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  .topbar h1 {
    font-size: 20px;
    line-height: 1.25;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat {
    min-height: 78px;
    padding: 12px;
  }

  .stat-value {
    font-size: 22px;
  }

  .panel-header {
    align-items: flex-start;
    padding: 12px;
  }

  .panel-body {
    padding: 0;
  }

  .table-list,
  .table-list tbody,
  .table-list tr,
  .table-list td {
    display: block;
    width: 100%;
  }

  .table-list {
    border-collapse: separate;
  }

  .table-list thead {
    display: none;
  }

  .table-list tr {
    border-bottom: 1px solid var(--line);
    padding: 9px 12px;
  }

  .table-list tr:last-child {
    border-bottom: 0;
  }

  .table-list td {
    border-bottom: 0;
    padding: 3px 0;
    font-size: 13px;
  }

  .table-list td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
  }

  .table-list td:first-child::before {
    display: none;
  }

  .table-list .cell-text {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .reader-toolbar {
    display: grid;
    gap: 12px;
    padding: 10px;
  }

  .reader-meta,
  .reader-actions {
    width: 100%;
  }

  .reader-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reader-actions .action-button {
    width: 100%;
    min-width: 0;
  }

  .badge {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .document {
    padding: 16px;
  }

  .compare-body {
    padding: 16px;
  }

  .markdown {
    font-size: 16px;
    line-height: 1.88;
  }

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

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

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

@media (max-width: 420px) {
  .workspace {
    padding-inline: 10px;
  }

  .brand-title {
    font-size: 15px;
  }

  .brand-subtitle {
    max-width: 150px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .document,
  .compare-body {
    padding: 14px;
  }

  .markdown {
    font-size: 15px;
  }

  .raw-source {
    font-size: 12px;
  }
}
