:root {
  --doc-primary: #002fa7;
  --doc-primary-soft: rgba(0, 47, 167, .07);
  --doc-text: #1f2329;
  --doc-muted: #667085;
  --doc-border: #e5e6eb;
  --doc-bg: #fff;
  --doc-sub: #f7f8fa;
}

.document-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 24px;
}

.document-card {
  display: flex;
  min-width: 0;
  min-height: 220px;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--doc-border);
  border-radius: 8px;
  background: var(--doc-bg);
  color: var(--doc-text);
  text-decoration: none;
  transition: border-color .18s, transform .18s, box-shadow .18s;
}
.document-card:hover { border-color: var(--doc-primary); transform: translateY(-2px); box-shadow: 0 10px 28px rgba(15, 23, 42, .07); }
.document-card h3 { margin: 10px 0; font-size: 20px; line-height: 1.45; overflow-wrap: anywhere; }
.document-card p { flex: 1; color: var(--doc-muted); line-height: 1.75; overflow-wrap: anywhere; }
.document-card__type, .document-card__meta { display: flex; justify-content: space-between; gap: 12px; color: var(--doc-muted); font-size: 12px; }
.document-card__meta { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--doc-border); }
.document-card__type { font-family: var(--font-mono); letter-spacing: .04em; }

.document-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.document-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--doc-border);
  border-radius: 4px;
  background: var(--doc-bg);
  color: var(--doc-muted);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
}
.document-tag--exclusive, .document-tag--scarce {
  min-height: 30px;
  padding: 4px 11px;
  border-color: #c58b16;
  background: #fff8df;
  color: #815600;
  font-size: 13px;
  font-weight: 650;
  box-shadow: inset 0 0 0 1px rgba(197, 139, 22, .08);
}
.document-tag--ai_assisted { border-color: #a9b5ff; background: #f1f0ff; color: #4e45a5; }
.document-tag--formerly_paid { border-color: #c99a73; background: #fbf3ed; color: #805437; }
.document-tag--private { border-color: #adb5bd; background: #f1f3f5; color: #495057; }
.document-tag--special { border-color: #65bcb2; background: #eaf9f6; color: #166c64; }

.document-filters { display: grid; grid-template-columns: minmax(180px, 1fr) 180px 180px auto; gap: 14px; align-items: end; margin-bottom: 20px; }
.document-pagination { justify-content: center; margin-top: 28px; }

.document-detail { max-width: 1180px; margin: 0 auto; padding: 0 24px 72px; color: var(--doc-muted); }
.document-breadcrumb { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 54px; font-size: 12px; }
.document-breadcrumb a:hover { color: var(--doc-primary); }
.document-detail__layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 48px; align-items: start; }
.document-detail__main { min-width: 0; }
.document-hero { padding-top: 10px; }
.document-hero h1 { margin: 10px 0 0; color: var(--doc-text); font-size: clamp(28px, 4vw, 40px); line-height: 1.35; letter-spacing: -.02em; overflow-wrap: anywhere; }
.document-deck { margin-top: 14px; font-size: 17px; line-height: 1.8; }
.article-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 9px 12px; margin-top: 18px; color: var(--doc-muted); font-size: 12px; }
.author { display: inline-flex; align-items: center; gap: 8px; color: var(--doc-text); }
.avatar { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: var(--doc-sub); color: var(--doc-muted); }
.version-chip { padding: 2px 7px; border: 1px solid var(--doc-border); border-radius: 3px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.document-notice { margin-top: 18px; padding: 10px 12px; border-left: 3px solid var(--doc-primary); background: var(--doc-primary-soft); color: var(--doc-text); }
.section { margin-top: 36px; }
.section h2 { margin-bottom: 14px; color: var(--doc-text); font-size: 20px; }
.document-summary p, .document-rights p { line-height: 1.9; }
.document-rights a { color: var(--doc-primary); }

.document-access-card { position: sticky; top: 84px; padding: 20px; border: 1px solid var(--doc-border); border-radius: 8px; background: var(--doc-sub); }
.document-access-card h2 { color: var(--doc-text); font-size: 16px; }
.document-access-card p { margin: 10px 0 16px; line-height: 1.7; font-size: 13px; }
.document-access-card form { display: grid; gap: 12px; margin-top: 16px; }
.document-access-card .btn { width: 100%; }
.document-price { color: #815600; font-size: 18px; font-weight: 650; }
.document-access-card .side-link { display: inline-block; margin-top: 20px; color: var(--doc-primary); }

.document-carousel { margin: 28px 0 0; border: 1px solid var(--doc-border); border-radius: 8px; overflow: hidden; background: var(--doc-bg); }
.document-carousel__frame { position: relative; aspect-ratio: 16 / 9; max-height: 420px; background: var(--doc-sub); }
.document-slide { display: block; width: 100%; height: 100%; object-fit: contain; }
.document-slide[hidden] { display: none; }
.document-carousel__bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; border-top: 1px solid var(--doc-border); color: var(--doc-muted); font-size: 12px; }
.document-carousel__controls { display: flex; gap: 8px; }

.document-ai { margin-top: 36px; padding-top: 24px; border-top: 1px solid var(--doc-border); }
.document-ai textarea { width: 100%; min-height: 120px; padding: 12px; border: 1px solid var(--doc-border); border-radius: 6px; resize: vertical; font: inherit; line-height: 1.7; }
.document-ai__cost { color: var(--doc-muted); font-size: 12px; }
.document-ai__answer { margin-top: 18px; padding: 16px; border: 1px solid var(--doc-border); border-radius: 6px; background: var(--doc-sub); color: var(--doc-text); line-height: 1.8; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Reader: adapted from devynhub-newv without placeholder content or fake controls. */
.document-reader { --read-size: 16px; color: var(--doc-muted); }
.reader-header { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--doc-border); background: var(--doc-bg); }
.reader-header__inner { max-width: 1120px; min-height: 58px; margin: auto; padding: 0 24px; display: flex; align-items: center; gap: 20px; }
.reader-brand { color: var(--doc-primary); font-weight: 650; text-decoration: none; }
.reader-crumb { display: flex; min-width: 0; gap: 8px; font-size: 12px; overflow: hidden; white-space: nowrap; }
.reader-crumb span:last-child { overflow: hidden; text-overflow: ellipsis; }
.reader-tools { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.tool-btn { min-height: 36px; padding: 0 9px; border: 0; border-radius: 4px; background: transparent; color: var(--doc-muted); }
.tool-btn:hover { background: var(--doc-sub); color: var(--doc-primary); }
.font-pct { min-width: 44px; text-align: center; font-size: 11px; }
.read-progress { height: 2px; }
.read-progress span { display: block; width: 0; height: 100%; background: var(--doc-primary); }
.reader-layout { max-width: 1120px; margin: auto; padding: 0 24px 72px; display: flex; gap: 56px; align-items: flex-start; }
.toc-panel { flex: 0 0 216px; width: 216px; padding-top: 40px; }
.toc-inner { position: sticky; top: 86px; }
.toc-head { display: flex; justify-content: space-between; padding-bottom: 12px; border-bottom: 1px solid var(--doc-border); }
.toc-head h2 { color: var(--doc-text); font-size: 14px; }
.toc-head span { font-size: 11px; }
.toc-nav { padding-top: 8px; }
.toc-link { display: flex; gap: 10px; padding: 9px 8px; border-radius: 4px; color: var(--doc-muted); font-size: 13px; line-height: 1.5; text-decoration: none; }
.toc-link:hover, .toc-link.is-active { background: var(--doc-primary-soft); color: var(--doc-primary); }
.toc-num { min-width: 18px; font-family: var(--font-mono); font-size: 10px; }
.toc-back { display: inline-block; margin-top: 18px; color: var(--doc-muted); font-size: 12px; }
.article { flex: 1; min-width: 0; max-width: 760px; padding-top: 40px; }
.article-head h1 { margin: 10px 0; color: var(--doc-text); font-size: clamp(28px, 4vw, 38px); line-height: 1.4; overflow-wrap: anywhere; }
.article-deck { font-size: 16px; line-height: 1.8; }
.article-body { margin-top: 34px; color: var(--doc-text); font-size: var(--read-size); line-height: 1.95; }
.article-body h1, .article-body h2, .article-body h3, .article-body h4 { margin: 38px 0 14px; color: var(--doc-text); line-height: 1.5; scroll-margin-top: 80px; }
.article-body h1:first-child, .article-body h2:first-child { margin-top: 0; }
.article-body h1 { font-size: 30px; }
.article-body h2 { font-size: 24px; }
.article-body h3 { font-size: 20px; }
.article-body p { margin: 0 0 20px; }
.article-body ul, .article-body ol { margin: 0 0 22px; padding-left: 26px; }
.article-body li { margin-bottom: 8px; }
.article-body a { color: var(--doc-primary); text-decoration: underline; text-underline-offset: 3px; }
.article-body img { display: block; max-width: 100%; height: auto; margin: 24px auto; border-radius: 6px; }
.article-body pre { overflow: auto; padding: 16px; border: 1px solid var(--doc-border); border-radius: 6px; background: var(--doc-sub); font-size: 13px; line-height: 1.75; }
.article-body code { font-family: var(--font-mono); }
.article-body p code { padding: 2px 5px; border-radius: 3px; background: var(--doc-sub); }
.article-body blockquote { margin: 24px 0; padding: 12px 16px; border-left: 3px solid var(--doc-primary); background: var(--doc-sub); }
.article-body hr { margin: 32px 0; border: 0; border-top: 1px solid var(--doc-border); }
.article-footer { margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--doc-border); font-size: 12px; }
.article-footer a { color: var(--doc-primary); }
.reader-gate { padding: 32px; border: 1px solid var(--doc-border); border-radius: 8px; background: var(--doc-sub); }
.reader-gate h2 { color: var(--doc-text); }
.reader-gate p { margin: 12px 0 20px; }
.reader-layout.toc-hidden { gap: 0; }
.reader-layout.toc-hidden .toc-panel { display: none; }
.document-reader[data-theme="dark"] { --doc-bg: #111315; --doc-sub: #191c1f; --doc-text: #e7e9eb; --doc-muted: #a9b0b8; --doc-border: #34383d; --doc-primary: #8cabff; --doc-primary-soft: rgba(140, 171, 255, .12); background: var(--doc-bg); }
.document-reader[data-theme="dark"] .document-tag { background: var(--doc-sub); }

.document-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 5px;
  background: #1f2329;
  color: #fff;
  font-size: 13px;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

/* Admin editor */
.document-editor-panel { margin-top: 24px; }
.document-editor { display: grid; gap: 16px; }
.document-body-editor { min-height: 340px; font-family: var(--font-mono); line-height: 1.65; }
.document-label-picker { display: flex; flex-wrap: wrap; gap: 12px; padding: 16px; border: 1px solid var(--doc-border); border-radius: 8px; }
.document-label-picker legend { padding: 0 8px; color: var(--doc-text); font-size: 13px; }
.document-label-picker label { display: inline-flex; align-items: center; gap: 6px; }
.document-switch-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.document-switch-grid label, .check-field { display: flex; align-items: center; gap: 8px; color: var(--doc-muted); }
.document-image-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.document-image-card { padding: 12px; border: 1px solid var(--doc-border); border-radius: 6px; }
.document-image-card img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.document-image-card p { overflow-wrap: anywhere; }
.document-revision-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--doc-border); }

@media (max-width: 1050px) {
  .document-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .document-detail__layout { grid-template-columns: minmax(0, 1fr); }
  .document-access-card { position: static; margin-top: 28px; }
  .toc-panel { display: none; }
  .reader-layout { max-width: 800px; }
  .document-switch-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .document-grid, .document-image-list { grid-template-columns: 1fr; }
  .document-card { min-height: 0; }
  .document-filters { grid-template-columns: 1fr; }
  .document-detail { padding: 0 16px 48px; }
  .document-deck { font-size: 15px; }
  .reader-header__inner { padding: 0 12px; gap: 10px; }
  .reader-crumb { display: none; }
  .reader-tools { gap: 0; }
  .tool-btn { padding: 0 7px; font-size: 12px; }
  .reader-layout { padding: 0 16px 48px; }
  .article { padding-top: 26px; }
  .article-body { line-height: 1.9; }
  .document-carousel__bar { align-items: flex-start; flex-direction: column; }
  .hero-actions { display: grid; grid-template-columns: 1fr; }
  .hero-actions .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .document-card, .document-slide { transition: none; }
}
