.h-menu { display: contents; }

.nav-toggle {
  display: none;
  flex: 0 0 auto;
  width: 38px; height: 38px; padding: 0;
  align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--text); cursor: pointer; transition: background .15s, border-color .15s;
}
.nav-toggle:hover { background: var(--hover-surface); }
.nav-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-toggle-box { display: block; position: relative; width: 18px; height: 13px; }
.nav-toggle-box > span {
  position: absolute; left: 0; width: 100%; height: 2px; border-radius: 2px;
  background: currentColor; transition: transform .2s ease, opacity .15s ease;
}
.nav-toggle-box > span:nth-child(1) { top: 0; }
.nav-toggle-box > span:nth-child(2) { top: 50%; margin-top: -1px; }
.nav-toggle-box > span:nth-child(3) { bottom: 0; }
body.nav-open .nav-toggle-box > span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
body.nav-open .nav-toggle-box > span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle-box > span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

.nav-backdrop { display: none; }

@media (min-width: 901px) {
  .app-nav {
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    -webkit-overflow-scrolling: touch; min-width: 0; scroll-padding-inline: 12px;
  }
  .app-nav::-webkit-scrollbar { display: none; }
  .app-nav-btn { flex: 0 0 auto; }
  .logo { min-width: 0; }
  .logo #app-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .h-tools { flex: 0 0 auto; }
  .search-wrap { flex: 0 0 auto; }
}
@media (min-width: 901px) and (max-width: 1400px) {
  .app-nav-btn { padding-inline: 9px; }
  body > header { gap: 10px; padding-inline: 14px; }
}
@media (min-width: 901px) and (max-width: 1180px) {
  .search-wrap input { width: 132px; }
}
@media (min-width: 901px) and (max-width: 1040px) {
  #app-title { display: none; }
}

@media (min-width: 901px) { .search-wrap { margin-right: -6px; } }

@media (max-width: 900px) {
  :root {
    --header-h: 54px;
    --subbar-h: 44px;
    --chrome-h: 98px;
    --drawer-w: min(82vw, 310px);
  }

  html { -webkit-text-size-adjust: 100%; }
  body { overflow-x: hidden; }
  body > header {
    gap: 8px;
    padding: 0 max(10px, env(safe-area-inset-left)) 0 max(8px, env(safe-area-inset-left));
  }
  .nav-toggle { display: inline-flex; }
  .logo { min-width: 0; padding: 4px 4px; gap: 7px; font-size: 13.5px; margin-right: auto; }
  .logo #app-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .logo-icon-img, .logo-icon { width: 24px; height: 24px; }
  .h-tools { gap: 6px; flex: 0 0 auto; }
  .lang-toggle button, .theme-toggle button { padding: 7px 9px; font-size: 12px; min-height: 34px; }
  .h-menu {
    display: flex; flex-direction: column; gap: 4px;
    position: fixed; top: var(--header-h); left: 0;
    width: var(--drawer-w); max-width: 100%;
    height: calc(100dvh - var(--header-h));
    padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
    background: var(--header-bg);
    border-right: 1px solid var(--border);
    box-shadow: 6px 0 26px var(--shadow);
    overflow-y: auto; overscroll-behavior: contain;
    z-index: 2;
    transform: translateX(-102%);
    transition: transform .22s ease;
  }
  body.nav-open .h-menu { transform: none; }

  .h-menu .search-wrap { order: 1; margin: 0 0 10px; }
  .h-menu .app-nav { order: 2; }
  .search-wrap input {
    width: 100%; font-size: 16px; padding: 11px 12px 11px 32px; border-radius: 8px;
  }
  .search-ico { font-size: 15px; }

  .app-nav { flex-direction: column; gap: 2px; margin-right: 0; flex-wrap: nowrap; align-items: stretch; }
  .nav-sep { width: auto; height: 0; border-left: 0; border-top: 1px solid var(--muted); margin: 6px 4px; }
  .app-nav-btn {
    width: 100%; justify-content: flex-start;
    min-height: 44px; padding: 10px 12px; font-size: 14px; border-radius: 8px;
  }
  .app-nav-btn.active { border-color: var(--accent-soft-border); }

  .nav-backdrop {
    display: block; position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(0, 0, 0, .45); z-index: 95;
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  .subbar {
    min-height: var(--subbar-h);
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    padding: 0 12px; gap: 6px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    scroll-padding-inline: 12px;
  }
  .subbar::-webkit-scrollbar { display: none; }
  .subbar > * { flex: 0 0 auto; }
  .subbar #core-chips, .subbar #skills-chips, .subbar #ref-chips,
  .subbar #tools-chips, .subbar #target-controls, .graph-dimension-tabs {
    flex-wrap: nowrap !important; gap: 6px !important;
  }
  .fb-count { margin-left: 8px; padding-right: 4px; white-space: nowrap; }
  .subbar-note { white-space: nowrap; }
  .st-tab, .fb-chip { min-height: 32px; white-space: nowrap; }

  .matrix-cols {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)) !important;
    max-width: none !important;
  }

  .content-pad { padding: 16px 14px 28px; }
  .matrix-pad { padding: 14px 12px 28px; }
  .page { padding-bottom: env(safe-area-inset-bottom); }

  .split-wrap.open .split-panel {
    border-left: none; border-top: 1px solid var(--border);
    box-shadow: 0 -6px 30px var(--shadow);
  }
  .split-panel-sticky { position: static; height: 100%; }
  .split-panel-inner {
    padding: 18px 16px calc(32px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }

  .split-wrap.open .dp-close {
    position: fixed; top: calc(var(--chrome-h) + 10px); right: 12px;
    min-height: 34px; padding: 6px 12px; font-size: 14px;
    background: var(--card); box-shadow: 0 2px 10px var(--shadow); z-index: 6;
  }
  .split-wrap.open .dp-id { padding-right: 96px; }
  .dp-title { padding-right: 76px; font-size: 18px; }
  body.panel-open { overflow: hidden; }
  input, select, textarea { font-size: 16px; }
  .contrib-input, .sop-cat-row .contrib-input { font-size: 16px; }
  .btn { min-height: 38px; padding: 8px 14px; }
  .btn-sm { min-height: 32px; padding: 6px 11px; }
  .h-btn { min-height: 34px; }
  .facet-chip { min-height: 34px; }
  .facet-chip-info { opacity: .55; width: 26px; height: 26px; }
  .table-wrap, .code-block, .sop-flow-scroll, .sv-flow-scroll {
    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  }
  #references-body table { min-width: 0; }
  #references-body th, #references-body td { width: auto !important; }
  #references-body th:nth-child(2), #references-body td:nth-child(2),
  #references-body th:nth-child(3), #references-body td:nth-child(3),
  #references-body th:nth-child(n+7), #references-body td:nth-child(n+7) { display: none; }
  #references-body th:nth-child(4), #references-body td:nth-child(4) { width: 48px !important; text-align: center; }
  #references-body th:nth-child(5), #references-body td:nth-child(5) { width: 72px !important; }
  #references-body td:nth-child(6) { white-space: nowrap; }
  #skills-body table { min-width: 0; }
  #skills-body th, #skills-body td { width: auto !important; }
  #skills-body th:nth-child(3), #skills-body td:nth-child(3) { display: none; }
  th, td { padding: 8px 10px; }
  .contrib-card { padding: 16px 14px; }
  .cw-actions, .cl-draft-actions, .cw-pick-manual { flex-wrap: wrap; }
  .sop-flow-wrap { margin: 0 -14px 14px; padding: 10px 14px; }
  .sop-meta { padding: 14px; }
  .author-graph, .reference-graph, .trend-view { padding-inline: 12px; }
  .sv-wrap { grid-template-columns: minmax(0, 1fr); }
  .sv-doc, .sv-list, .sv-paper, .sv-items { min-width: 0; }
  .sv-paper { padding: 18px 14px 22px; }
  .sv-actions { flex-wrap: wrap; }
  .sv-dl { grid-template-columns: minmax(0, 1fr); }
  .sv-title { font-size: 19px; }
  .sv-step-h { font-size: 14.5px; }
  .sv-block-h { font-size: 13.5px; }
  .sv-body, .sv-guide, .sv-guide-list li, .sv-ul { font-size: 12.5px; }
  .sv-fc-title { font-size: 12px; }
  .sv-meta, .sv-dl { font-size: 11.5px; }
  .sv-item-name { font-size: 12.5px; }
  .sop-fc-title { font-size: 13px; }
  .sop-fc-meta { font-size: 11px; }
  .sop-b-title { font-size: 13px; }
  .sop-flow-hint { font-size: 11px; }
  .sop-sec-title { font-size: 12px; }
  #view-sop input, #view-sop select, #view-sop textarea,
  #view-sopview input, #view-sopview select, #view-sopview textarea,
  #view-sop .contrib-input, #view-sop .sop-cat-row .contrib-input,
  #view-sopview .contrib-input { font-size: 14px; }

  .cw-toprow { gap: 12px; }
  .cw-tpl { flex: 1 1 100%; flex-wrap: wrap; padding-bottom: 0; }
  .cw-toprow-fields { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
  html, body { font-size: 14.5px; }
  .matrix-cols { grid-template-columns: minmax(0, 1fr) !important; max-width: none !important; }
  .content-pad { padding: 14px 12px 28px; }
  .matrix-pad { padding: 12px 10px 28px; }
  .logo #app-title { font-size: 13px; }
  .col-head { padding: 12px; }
  .dp-title { font-size: 17px; padding-right: 72px; }
  .ag-detail-metrics { grid-template-columns: 1fr 1fr; }
  .sop-meta-head { gap: 8px; }
}

@media (max-width: 360px) {
  .logo #app-title { display: none; }
  .lang-toggle button, .theme-toggle button { padding: 7px 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .h-menu, .nav-backdrop, .nav-toggle-box > span { transition: none; }
}
