/* ==========================================================================
   Engineering Notes — knowledge base, search, article
   ========================================================================== */
.kb-page {
  padding-top: 32px;
}

.kb-layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: clamp(28px, 3.4vw, 44px);
  width: 100%;
  max-width: var(--kb-max);
  margin: 0 auto;
  padding: 0 var(--gutter);
  align-items: start;
}

/* Sidebar --------------------------------------------------------------- */
.kb-sidebar {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  align-self: start;
  padding-right: 22px;
  border-right: 1px solid var(--line);
}

.kb-nav-title {
  margin-bottom: 7px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.kb-nav {
  margin-bottom: 22px;
}

.kb-nav a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  text-decoration: none;
  overflow-wrap: anywhere;
  transition: color var(--dur) var(--ease);
}

.kb-nav a:hover {
  color: var(--ink);
}

.kb-nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--yellow);
  padding-left: 9px;
}

.kb-nav .n {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9.5px;
}

.kb-mobile {
  display: none;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.kb-mobile summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 10px 14px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.kb-mobile summary::-webkit-details-marker {
  display: none;
}

.kb-mobile summary::after {
  content: "+";
  font-family: var(--mono);
  color: var(--purple);
}

.kb-mobile[open] summary::after {
  content: "−";
}

.kb-mobile .kb-nav {
  margin: 0;
  padding: 0 14px 14px;
}

.kb-mobile .kb-nav-title {
  margin-top: 12px;
}

/* Head ------------------------------------------------------------------ */
.kb-main {
  min-width: 0;
}

.kb-head {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-strong);
}

.kb-head h1 {
  max-width: 26ch;
  font-size: clamp(2rem, 3.4vw, 2.9rem);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.kb-count {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12.5px;
}

.kb-search {
  display: grid;
  gap: 5px;
  margin-top: 18px;
}

.kb-search label {
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}

.search-control {
  position: relative;
}

.search-control input {
  width: 100%;
  height: 44px;
  padding: 0 42px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  transition: border-color var(--dur) var(--ease);
}

.search-control input:hover {
  border-color: var(--faint);
}

.search-control input:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-soft);
}

.search-control input::placeholder {
  color: var(--faint);
}

.search-clear {
  position: absolute;
  top: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--faint);
  font-size: 15px;
  cursor: pointer;
}

.search-clear:hover {
  color: var(--ink);
  background: var(--warm);
}

.search-hint {
  color: var(--faint);
  font-size: 11px;
  line-height: 1.6;
}

/* Filter ---------------------------------------------------------------- */
.kb-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.filter-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  white-space: nowrap;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
  text-decoration: none;
}

.filter-link:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.filter-link[aria-current="true"] {
  border-color: var(--line-strong);
  background: var(--yellow);
  color: #020a0f;
}

.filter-link .n {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9.5px;
}

.filter-link[aria-current="true"] .n {
  color: #020a0f;
}

/* List ------------------------------------------------------------------ */
.kb-list {
  margin-top: 0;
}

.doc-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 24px;
  align-items: start;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}

.doc-body {
  min-width: 0;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 6px;
  font-size: 11px;
}

.doc-meta .cat {
  color: var(--purple);
  font-weight: 700;
}

.doc-meta time {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9.5px;
}

.doc-title {
  color: var(--ink);
  font-size: clamp(1.1rem, 1.8vw, 1.3rem);
  font-weight: 700;
  line-height: 1.42;
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
  transition: color var(--dur) var(--ease);
}

.doc-card:hover .doc-title {
  color: var(--purple);
}

.doc-summary {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.doc-cover {
  width: 220px;
}

.doc-cover .cover {
  min-height: 136px;
  padding: 13px;
  gap: 10px;
}

.doc-cover .cover-title {
  font-size: 16px;
  line-height: 1.3;
}

.doc-cover .cover-cat,
.doc-cover .cover-no {
  font-size: 8.5px;
}

.doc-cover .cover-keys {
  padding-top: 6px;
  font-size: 8.5px;
}

.doc-cover .cover-ghost {
  font-size: 64px;
  bottom: -14px;
}

/* Pagination ------------------------------------------------------------ */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10.5px;
  text-decoration: none;
}

.page-link:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.page-link[aria-current="page"] {
  border-color: var(--line-strong);
  background: var(--yellow);
  color: #020a0f;
}

/* Empty ----------------------------------------------------------------- */
.kb-empty {
  margin-top: 20px;
  padding: 40px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--warm);
  text-align: center;
}

.kb-empty h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.kb-empty p {
  max-width: 46ch;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.kb-empty .btn-ghost {
  margin-top: 16px;
}

/* Search results -------------------------------------------------------- */
.search-view {
  padding-top: 18px;
}

.search-view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-strong);
}

.search-view-head h2 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.search-view-head .search-scope {
  color: var(--faint);
  font-size: 11.5px;
}

.search-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.search-meta strong {
  color: var(--ink);
  font-weight: 600;
}

.search-results {
  margin-top: 4px;
}

.search-empty {
  margin-top: 24px;
  padding: 40px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--warm);
  text-align: center;
}

.search-empty h3 {
  font-size: 17px;
  font-weight: 700;
}

.search-empty p {
  max-width: 48ch;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.search-empty .btn-ghost {
  margin-top: 16px;
}

.search-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.search-page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10.5px;
  cursor: pointer;
}

.search-page:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.search-page[aria-current="true"] {
  border-color: var(--line-strong);
  background: var(--yellow);
  color: #020a0f;
}

/* Article --------------------------------------------------------------- */
.article-page {
  padding-top: 32px;
}

.article-shell {
  display: grid;
  grid-template-columns: minmax(0, var(--article-max)) 220px;
  gap: clamp(32px, 5vw, 56px);
  justify-content: center;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 var(--gutter);
  align-items: start;
}

.article-main {
  min-width: 0;
}

.article-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 22px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.article-back:hover {
  color: var(--ink);
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin-bottom: 12px;
  font-size: 11.5px;
}

.article-meta .cat {
  color: var(--purple);
  font-weight: 700;
}

.article-meta time {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
}

.article-title {
  max-width: 24ch;
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.article-byline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
}

.article-byline strong {
  color: var(--ink);
  font-weight: 600;
}

.article-sample {
  display: inline-flex;
  align-items: center;
  height: 19px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.03em;
}

.article-toc {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 48px);
  overflow-y: auto;
}

.article-toc-title {
  margin-bottom: 8px;
  color: var(--purple);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.article-toc ol {
  border-top: 1px solid var(--line-strong);
}

.article-toc li {
  border-bottom: 1px solid var(--line);
}

.toc-link {
  display: flex;
  gap: 7px;
  padding: 8px 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.toc-link:hover {
  color: var(--ink);
}

.toc-link.is-active {
  color: var(--purple);
  font-weight: 600;
}

.toc-link.level-3 {
  padding-left: 16px;
  font-size: 11px;
}

.toc-link.level-4 {
  padding-left: 28px;
  font-size: 10.5px;
}

.toc-link .toc-n {
  flex: none;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
  padding-top: 2px;
}

.toc-mobile {
  display: none;
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.toc-mobile summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.toc-mobile summary::-webkit-details-marker {
  display: none;
}

.toc-mobile summary::after {
  content: "+";
  font-family: var(--mono);
  color: var(--purple);
}

.toc-mobile[open] summary::after {
  content: "−";
}

.toc-mobile .toc-list {
  padding: 0 14px 14px;
}

.toc-mobile ol {
  border-top: 1px solid var(--line);
}

/* Article body ---------------------------------------------------------- */
.article-body {
  margin-top: 30px;
  font-size: 17px;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.article-body h2,
.article-body h3,
.article-body h4 {
  scroll-margin-top: calc(var(--header-h) + 20px);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.article-body h2 {
  margin: 44px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 1.5rem;
  line-height: 1.35;
}

.article-body h3 {
  margin: 30px 0 10px;
  font-size: 1.2rem;
  line-height: 1.4;
}

.article-body h4 {
  margin: 24px 0 8px;
  font-size: 1.05rem;
  line-height: 1.4;
}

.article-body p {
  margin: 0 0 18px;
}

.article-body strong {
  font-weight: 700;
}

.article-body em {
  font-style: italic;
}

.article-body a {
  color: var(--purple);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.article-body ul,
.article-body ol {
  display: grid;
  gap: 7px;
  margin: 0 0 18px;
  padding-left: 20px;
}

.article-body ul {
  list-style: disc;
}

.article-body ol {
  list-style: decimal;
}

.article-body li {
  padding-left: 2px;
}

.article-body li > ul,
.article-body li > ol {
  margin-top: 7px;
  margin-bottom: 0;
}

.article-body code {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--warm);
  font-family: var(--mono);
  font-size: 0.84em;
}

.code-block {
  margin: 24px 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-text);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--code-muted);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.04em;
}

.code-block pre {
  margin: 0;
  padding: 15px 17px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
}

.code-block code {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: inherit;
  white-space: pre;
}

.article-body blockquote {
  margin: 26px 0;
  padding: 18px 0;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: -0.02em;
}

.callout {
  margin: 24px 0;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--warm);
}

.callout-label {
  margin-bottom: 4px;
  color: var(--purple);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.callout p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.table-wrap {
  margin: 24px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.table-wrap table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table-wrap caption {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--faint);
  font-size: 10.5px;
  text-align: left;
}

.table-wrap th,
.table-wrap td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.6;
}

.table-wrap thead th {
  background: var(--warm);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

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

.fold {
  margin: 22px 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.fold summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

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

.fold summary::after {
  content: "+";
  font-family: var(--mono);
  color: var(--purple);
}

.fold[open] summary::after {
  content: "−";
}

.fold-body {
  padding-top: 10px;
}

.fold-body p {
  color: var(--muted);
  font-size: 13.5px;
}

.task-list {
  display: grid;
  gap: 7px;
  margin: 0 0 18px;
  padding-left: 0;
  list-style: none;
}

.article-body .task-list {
  padding-left: 0;
  list-style: none;
}

.task-item {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  font-size: 15px;
  line-height: 1.65;
}

.task-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-top: 0.32em;
  border: 1px solid var(--line-strong);
  border-radius: 1px;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1;
  color: var(--ink);
}

.task-box.is-checked {
  background: var(--yellow);
  border-color: var(--line-strong);
}

.image-block {
  margin: 26px 0;
}

.image-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  padding: 24px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--warm);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-align: center;
}

.image-block figcaption {
  margin-top: 7px;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.6;
}

.attachment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 13px;
  text-decoration: none;
}

.attachment:hover {
  border-color: var(--line-strong);
}

.article-body a.attachment {
  color: var(--ink);
  text-decoration: none;
}

.attachment span {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9.5px;
}

.article-body hr {
  margin: 34px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.article-foot {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--line-strong);
}

/* Responsive ------------------------------------------------------------ */
@media (max-width: 1100px) {
  .kb-layout {
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 32px;
  }
}

@media (max-width: 1024px) {
  .article-shell {
    grid-template-columns: minmax(0, var(--article-max));
  }

  .article-toc {
    display: none;
  }

  .toc-mobile {
    display: block;
  }

  .toc-mobile .toc-link {
    min-height: 44px;
    padding: 10px 0;
  }
}

@media (max-width: 900px) {
  .kb-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .kb-sidebar {
    display: none;
  }

  .kb-mobile {
    display: block;
  }

  .kb-mobile .kb-nav a {
    min-height: 44px;
    padding: 10px 0;
  }

  .filter-link {
    flex: none;
    min-height: 44px;
  }

  .kb-filter {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .page-link,
  .search-page {
    min-width: 44px;
    height: 44px;
  }

  .search-clear {
    top: 0;
    right: 0;
    width: 44px;
    height: 44px;
  }

  .search-control input {
    padding-right: 50px;
  }

  .article-back {
    min-height: 44px;
  }
}

@media (max-width: 720px) {
  .doc-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .doc-cover {
    display: none;
  }

  .doc-title {
    font-size: 1.08rem;
  }

  .kb-filter {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .filter-link {
    flex: none;
    min-height: 44px;
  }

  .kb-mobile .kb-nav a {
    min-height: 44px;
    padding: 10px 0;
  }

  .category-menu summary {
    min-height: 40px;
  }

  .category-menu-panel a {
    min-height: 44px;
    padding: 9px;
  }

  .toc-mobile .toc-link {
    min-height: 40px;
    padding: 10px 0;
  }

  .article-page {
    padding-top: 22px;
  }

  .article-title {
    max-width: none;
    font-size: 1.9rem;
  }

  .article-body {
    font-size: 16px;
  }

  .article-body h2 {
    font-size: 1.35rem;
  }

  .article-body h3 {
    font-size: 1.1rem;
  }
}

@media (max-width: 480px) {
  .kb-head h1 {
    font-size: 1.85rem;
  }

  .page-link,
  .search-page {
    min-width: 44px;
    height: 44px;
  }

  .table-wrap table {
    min-width: 460px;
  }
}
