/* ============================================================
   동김제농협 스마트 HACCP — 허브 화면
   문서센터 · 기록양식 목록 · MDR 등록대장 · 열람 화면.

   콘솔(index.html)이 "오늘 뭘 써야 하나"에 답한다면 허브는
   "그 문서가 어디 있나"에 답한다. 성격은 다르지만 같은 사람이
   같은 태블릿에서 쓰므로 팔레트·터치 타깃·카드 형태를 공유한다.

   팔레트와 페이지 셸(.ck-header/.ck-main/.ck-card)은 dkj-tokens.css.
   이 파일은 허브 전용 컴포넌트만 담는다.

   주의 — 목록 DOM은 docs-center.js / records-center.js / mdr-register.js 가
   문자열로 만든다. 아래 선택자(.doc-row, .cat-status, .status-pill 등)는
   그 JS가 내보내는 클래스명이므로 이름을 바꾸면 스타일이 끊긴다.
/* ---------- 헤더 공통 및 브랜드 로고 크기 고정 ---------- */
.site-header,
.ck-header {
  background: var(--nh-green, #009a44) !important;
  color: #fff !important;
  padding: 0 24px;
  height: 72px;
  display: flex;
  align-items: center;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-sizing: border-box;
}

.site-header .brand,
.ck-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: #fff !important;
  text-decoration: none;
}

.site-header .brand img,
.site-header img,
.brand img,
.ck-wordmark-symbol,
img.brand-logo {
  width: 32px !important;
  height: 32px !important;
  max-width: 32px !important;
  max-height: 32px !important;
  flex: 0 0 32px !important;
  object-fit: contain;
}

/* ---------- 헤더 안 메가메뉴 (dkj-nav.js) ---------- */

.gnb {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
  margin-left: 12px;
  min-width: 0;
  flex: 1 1 auto;
  overflow: visible !important;
}

.gnb-static,
.gnb-trigger,
.gnb-item {
  flex: 0 0 auto;
}

.gnb-static,
.gnb-trigger {
  display: inline-flex;
  align-items: center;
  height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.gnb-static:hover,
.gnb-trigger:hover { background: rgba(255, 255, 255, .16); }

.gnb-static.active,
.gnb-item.active .gnb-trigger {
  background: #fff;
  color: var(--nh-green-dark);
  font-weight: 800;
}

.gnb-trigger::after {
  content: "▾";
  margin-left: 6px;
  font-size: 11px;
  opacity: .8;
}

.gnb-item { position: relative; height: 100%; display: flex; align-items: center; overflow: visible !important; }

.mega-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 580px;
  max-width: calc(100vw - 24px);
  /* 항목이 많은 메뉴(선행요건관리)는 800px 세로에서 아래가 잘린다 — 스크롤로 처리 */
  max-height: calc(100vh - 92px);
  overflow-y: auto;
  padding: 18px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: 0 16px 36px rgba(5, 67, 31, .22);
  z-index: 9999;
}

/* 마우스 이동 시 닫히지 않도록 투명 연결 브릿지 영역 생성 */
.mega-menu::before {
  content: "";
  position: absolute;
  top: -18px;
  left: 0;
  right: 0;
  height: 18px;
  display: block;
}

.gnb-item.open .mega-menu,
.gnb-item:hover .mega-menu,
.gnb-item:focus-within .mega-menu { display: block !important; }

/* 오른쪽 끝 메뉴는 왼쪽 기준으로 펼치면 화면 밖으로 잘린다(1280 태블릿에서 실측).
   뒤쪽 두 개만 오른쪽 기준으로 뒤집는다. */
.gnb-item:nth-last-of-type(-n+2) .mega-menu {
  left: auto;
  right: 0;
}

.mega-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.mega-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--nh-green-dark);
  letter-spacing: .02em;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 2px solid var(--nh-green-50);
}

.mega-col a {
  display: block;
  padding: 9px 10px;
  border-radius: var(--r-s);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.35;
}

.mega-col a:hover { background: var(--nh-green-50); color: var(--nh-green-dark); }

.mega-foot {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.mega-foot a {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: var(--r-s);
  background: var(--nh-green-50);
  color: var(--nh-green-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.mega-backdrop {
  display: none;
  position: fixed;
  inset: 72px 0 0;
  background: rgba(5, 67, 31, .18);
  z-index: 35;
}

.mega-backdrop.show { display: block; }

/* 햄버거 — 좁은 화면에서만 노출 */
.menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .1);
  cursor: pointer;
  padding: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
}

/* ---------- 화면 머리말 (구 docs-hero 대체) ---------- */

/* 그라데이션 배너를 걷어내고 콘솔과 같은 섹션 머리말을 쓴다.
   현황은 장식이 아니라 숫자로만 말한다. */
.hub-head {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 16px;
}

.hub-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--nh-green-ink);
}

.hub-head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.5;
}

.hub-head-main { min-width: 260px; }

.docs-status-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.done {
  background: var(--st-done-bg);
  border-color: var(--st-done-line);
  color: var(--st-done);
}

.status-pill.wip {
  background: var(--st-todo-bg);
  border-color: var(--st-todo-line);
  color: var(--st-todo);
}

/* ---------- 레이아웃 ---------- */

.hub-layout {
  display: grid;
  grid-template-columns: 264px 1fr;
  gap: 16px;
  align-items: start;
}

/* ---------- 카테고리 사이드바 ---------- */

.docs-sidebar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 108px);
  overflow-y: auto;
}

.docs-sidebar button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--r-m);
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  line-height: 1.3;
}

.docs-sidebar button > span:first-child { flex: 1; min-width: 0; }

.docs-sidebar button:hover {
  background: var(--nh-green-50);
  color: var(--nh-green-dark);
}

.docs-sidebar button.active {
  background: var(--nh-green);
  border-color: var(--nh-green);
  color: #fff;
}

.docs-sidebar button.active small { opacity: .9 !important; }

.cat-status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  background: var(--st-off-bg);
  color: var(--st-off);
}

.cat-status.done { background: var(--st-done-bg); color: var(--st-done); }
.cat-status.wip { background: var(--st-todo-bg); color: var(--st-todo); }

.docs-sidebar button.active .cat-status {
  background: rgba(255, 255, 255, .22);
  color: #fff;
}

/* ---------- 목록 영역 ---------- */

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

#categoryHead h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--nh-green-ink);
}

/* JS가 인라인 색으로 회색 설명문을 넣는다 — 토큰 색으로 덮어쓴다 */
#categoryHead p {
  color: var(--ink-3) !important;
  font-size: 13px !important;
  line-height: 1.5;
}

.docs-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 10px;
}

.docs-search,
.docs-filter {
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px;
}

.docs-search {
  flex: 1;
  min-width: 220px;
}

.docs-search:focus,
.docs-filter:focus {
  outline: 2px solid var(--nh-green);
  outline-offset: -1px;
}

.docs-filter { min-width: 150px; font-weight: 600; cursor: pointer; }

.docs-count {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
}

.doc-row:hover { border-color: var(--nh-green); }

.doc-row-main { flex: 1; min-width: 240px; }

.doc-row-main h3 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
}

.doc-code {
  display: inline-block;
  padding: 2px 8px;
  margin-right: 4px;
  border-radius: var(--r-s);
  background: var(--nh-green-50);
  color: var(--nh-green-dark);
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: -.01em;
}

.doc-rev {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-3);
}

.doc-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.doc-tag {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--st-off-bg);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
}

.doc-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge.type {
  background: var(--nh-green-50);
  color: var(--nh-green-dark);
}

/* 문서관리대장의 '완료'와는 다른 축 — 시스템에 정본 원문이 올라와 있는지 */
.badge.pdf-ok {
  background: #e0f2fe;
  color: #075985;
}

.badge.pdf-none {
  background: #fef3c7;
  color: #92400e;
}

.docs-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-3);
  font-size: 14px;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--r-l);
}

/* ---------- 열람 화면 (doc-viewer / record-viewer) ---------- */

.viewer-top {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
}

.viewer-top .container {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.viewer-meta { flex: 1; min-width: 260px; }

.viewer-meta h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.35;
  color: var(--nh-green-ink);
}

.viewer-meta p {
  margin: 6px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--ink-3);
  font-weight: 600;
}

.viewer-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.viewer-body { padding: 20px 24px 48px; }

.viewer-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.viewer-tab {
  height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  background: var(--card);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
}

.viewer-tab:hover { border-color: var(--nh-green); color: var(--nh-green-dark); }

.viewer-tab.active {
  background: var(--nh-green);
  border-color: var(--nh-green);
  color: #fff;
}

.viewer-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 12px;
}

.viewer-panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 800;
  color: var(--nh-green-ink);
}

.highlight-list {
  margin: 0;
  padding-left: 20px;
  line-height: 1.75;
  font-size: 14px;
  color: var(--ink-2);
}

.viewer-excerpt {
  white-space: pre-wrap;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--ink-2);
  max-height: 460px;
  overflow-y: auto;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
}

.viewer-notice {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--r-m);
  background: var(--st-todo-bg);
  border: 1px solid var(--st-todo-line);
  color: var(--st-todo);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.6;
}

/* 확인·정상 안내 — 기본 안내(노랑)와 구분한다 */
.viewer-notice.ok {
  background: var(--st-done-bg);
  border-color: var(--st-done-line);
  color: var(--st-done);
}

.viewer-notice code {
  background: rgba(0, 0, 0, .06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.link-chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.pdf-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

.pdf-frame {
  width: 100%;
  height: 72vh;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  background: var(--bg);
}

/* ---------- 반응형 ---------- */

@media (max-width: 1180px) {
  .hub-layout { grid-template-columns: 220px 1fr; }
  .mega-menu { min-width: 420px; }
}

@media (max-width: 1024px) {
  .menu-toggle { display: flex; }

  .gnb {
    display: none;
    position: absolute;
    top: 72px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    height: auto;
    margin: 0;
    padding: 10px;
    background: var(--nh-green-dark);
    box-shadow: 0 10px 24px rgba(5, 67, 31, .25);
  }

  .gnb.open { display: flex; }
  .gnb-item { height: auto; display: block; }
  .gnb-static, .gnb-trigger { width: 100%; }

  .mega-menu {
    position: static;
    min-width: 0;
    margin-top: 6px;
    box-shadow: none;
  }
}

@media (max-width: 820px) {
  .hub-layout { grid-template-columns: 1fr; }

  .docs-sidebar {
    position: static;
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .docs-sidebar button { width: auto; min-height: 44px; }
  .viewer-body { padding: 16px 14px 40px; }
}

@media print {
  .ck-header,
  .mega-backdrop,
  .docs-sidebar,
  .docs-toolbar,
  .viewer-tabs,
  .viewer-actions,
  .pdf-toolbar { display: none !important; }

  .viewer-panel,
  .doc-row { box-shadow: none; }
}

/* ---------- 공용 메뉴 폭 보호 (2026-08) ----------
   헤더에 브랜드·메가메뉴·바로가기 버튼을 한 줄에 모두 배치하면
   14~18인치 크롬 창에서도 메뉴 항목이 브랜드 위로 밀려 겹칠 수 있다.
   브랜드/바로가기와 전체 메뉴를 독립 행으로 분리해 모든 항목의 글자 폭을 보존한다. */
@media (max-width: 1800px) {
  .ck-header {
    height: auto;
    min-height: 72px;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 16px;
  }

  .ck-brand {
    order: 1;
    flex: 0 0 auto !important;
    min-width: max-content !important;
  }

  .ck-tagline {
    display: none !important;
  }

  .ck-header-right {
    order: 2;
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    margin-left: auto;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
  }

  .gnb {
    order: 3;
    flex: 1 1 100%;
    min-width: 0;
    margin-left: 0;
    padding: 0 2px;
    overflow: visible;
  }

  .gnb-static,
  .gnb-trigger,
  .gnb-item { flex: 0 0 auto; }
}

@media (max-width: 1024px) {
  .ck-header {
    flex-wrap: nowrap;
    min-height: 64px;
    padding: 10px 14px;
  }

  .ck-brand { flex: 1 1 auto; }

  .ck-header-right {
    flex: 0 0 auto;
    width: auto;
    margin-left: auto;
  }

  .ck-header-right .ck-hbtn { display: none; }

  .gnb {
    order: initial;
    overflow: visible;
    padding: 10px;
  }
}

@media (max-width: 560px) {
  .ck-wordmark { padding-right: 9px; gap: 7px; }
  .ck-wordmark-name b { font-size: 12px; }
  .ck-wordmark-symbol { width: 27px; height: 27px; flex-basis: 27px; }
}
