/* ============================================================
   기계설비 도면 체크리스트 — 스타일
   설계 원칙: 고대비 / 16px 이상 대형 폰트 / 색상+텍스트 병행 표기
   ============================================================ */

:root {
  --c-bg:        #eef1f6;
  --c-surface:   #ffffff;
  --c-line:      #c9d2e0;
  --c-line-soft: #e3e9f2;

  --c-text:      #16202e;
  --c-text-mid:  #4a586b;
  --c-text-dim:  #6b7a8f;

  --c-primary:   #14477d;
  --c-primary-d: #0d3159;
  --c-primary-l: #e7effa;

  --c-pass:      #16794b;
  --c-pass-bg:   #e4f5ec;
  --c-fail:      #b3261e;
  --c-fail-bg:   #fdeceb;
  --c-na:        #5a6675;
  --c-na-bg:     #eef1f5;
  --c-pending:   #7b8794;

  --c-issue:     #9a4a00;
  --c-issue-bg:  #fff3e0;
  --c-issue-row: #fff8ec;
  --c-fail-row:  #fff4f3;

  --radius:  10px;
  --radius-s: 7px;
  --shadow:  0 2px 10px rgba(20, 35, 60, .10);

  --fs-base: 16px;

  /* 테이블 헤더 실제 높이 — app.js가 측정해 덮어쓴다 (긴 행의 버튼 고정에 사용) */
  --thead-h: 46px;
}

* { box-sizing: border-box; }

html { font-size: var(--fs-base); }

/* 앱 셸 레이아웃 — 페이지 자체는 스크롤하지 않고,
   표 영역만 스크롤한다. 헤더·대시보드·툴바·표 헤더가 항상 보인다. */
body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
}

/* ── 접근성: 포커스 링 ─────────────────────────────── */
:focus-visible {
  outline: 3px solid #2f7fd4;
  outline-offset: 2px;
}

/* ============================================================
   상단 헤더
   ============================================================ */
.app-header {
  flex: 0 0 auto;
  z-index: 60;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  padding: 12px 20px;
  background: linear-gradient(180deg, #17518d 0%, #123f70 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(10, 30, 60, .28);
}

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

.brand-mark {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: rgba(255,255,255,.16);
  border: 1.5px solid rgba(255,255,255,.34);
  font-weight: 800; letter-spacing: .5px;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.32rem;
  font-weight: 800;
  letter-spacing: -.4px;
}
.project-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: auto;
}

.field { display: flex; flex-direction: column; gap: 3px; }
.field > span {
  font-size: .76rem;
  font-weight: 700;
  color: rgba(255,255,255,.85);
  letter-spacing: .2px;
}
.field input {
  min-width: 160px;
  padding: 8px 11px;
  border: 1.5px solid rgba(255,255,255,.35);
  border-radius: var(--radius-s);
  background: rgba(255,255,255,.96);
  color: var(--c-text);
  font-size: .96rem;
}
.field input::placeholder { color: #97a3b2; }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 15px;
  min-height: 44px;
  border: 1.5px solid rgba(255,255,255,.4);
  border-radius: var(--radius-s);
  background: rgba(255,255,255,.14);
  color: #fff;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .13s, transform .08s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,.26); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.28); font-weight: 600; }

/* ============================================================
   대시보드
   ============================================================ */
.dashboard {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  padding: 14px 20px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-line);
}

.stat {
  flex: 1 1 118px;
  min-width: 108px;
  padding: 9px 13px;
  border: 1.5px solid var(--c-line-soft);
  border-left-width: 5px;
  border-radius: var(--radius-s);
  background: #fbfcfe;
}
.stat-label { display: block; font-size: .8rem; font-weight: 700; color: var(--c-text-mid); }
.stat-value { display: block; font-size: 1.6rem; font-weight: 800; line-height: 1.2; }

.stat-total  { border-left-color: var(--c-primary); }
.stat-done   { border-left-color: #2f7fd4; }
.stat-pass   { border-left-color: var(--c-pass);  background: var(--c-pass-bg); }
.stat-pass   .stat-value { color: var(--c-pass); }
.stat-fail   { border-left-color: var(--c-fail);  background: var(--c-fail-bg); }
.stat-fail   .stat-value { color: var(--c-fail); }
.stat-na     { border-left-color: var(--c-na);    background: var(--c-na-bg); }
.stat-issue  { border-left-color: var(--c-issue); background: var(--c-issue-bg); }
.stat-issue  .stat-value { color: var(--c-issue); }

.progress-wrap { flex: 2 1 260px; min-width: 220px; display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 0 4px; }
.progress-head { display: flex; justify-content: space-between; font-size: .86rem; font-weight: 700; color: var(--c-text-mid); }
.progress-head strong { color: var(--c-primary); font-size: 1.05rem; }
.progress-bar { height: 14px; border-radius: 999px; background: #dfe6f0; overflow: hidden; border: 1px solid var(--c-line); }
.progress-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #2f7fd4, #16794b); transition: width .25s ease; }

/* ============================================================
   레이아웃
   ============================================================ */
.layout {
  flex: 1 1 auto;
  min-height: 0;              /* 자식이 부모를 밀어내지 않도록 */
  display: flex;
  align-items: stretch;
  gap: 0;
  overflow: hidden;
}

/* ── 사이드바 ─────────────────────────────────────── */
.sidebar {
  flex: 0 0 258px;
  min-height: 0;
  background: var(--c-surface);
  border-right: 1px solid var(--c-line);
  overflow: hidden;
}
.sidebar-inner {
  height: 100%;
  overflow-y: auto;
  padding: 16px 12px 24px;
}

.sidebar-title {
  margin: 0 0 10px 6px;
  font-size: .84rem;
  font-weight: 800;
  letter-spacing: .6px;
  color: var(--c-text-dim);
}

.cat-nav { display: flex; flex-direction: column; gap: 4px; }

.cat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 11px 12px;
  min-height: 46px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  text-align: left;
  font-size: 1rem;
  font-weight: 700;
  color: var(--c-text);
  cursor: pointer;
}
.cat-btn:hover { background: #f2f6fc; }
.cat-btn.is-active { background: var(--c-primary-l); border-color: #a9c6e8; color: var(--c-primary-d); }

.cat-btn .cat-name { flex: 1; }
.cat-btn .cat-count {
  font-size: .8rem;
  font-weight: 800;
  color: var(--c-text-dim);
  background: #eef2f8;
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.cat-btn.is-active .cat-count { background: #fff; color: var(--c-primary); }
.cat-btn .cat-flag {
  font-size: .78rem; font-weight: 800; color: #fff;
  background: var(--c-fail); border-radius: 999px; padding: 2px 8px;
}

.dwg-list { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 8px 12px; padding-left: 8px; border-left: 2px solid var(--c-line-soft); }
.dwg-btn {
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  font-size: .9rem;
  color: var(--c-text-mid);
  cursor: pointer;
}
.dwg-btn:hover { background: #f2f6fc; color: var(--c-text); }
.dwg-btn.is-active { background: #dbe8f8; color: var(--c-primary-d); font-weight: 700; }

/* ── 메인 ─────────────────────────────────────────── */
.main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 20px;
}

.toolbar {
  flex: 0 0 auto;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-box { position: relative; flex: 1 1 300px; min-width: 220px; display: flex; align-items: center; }
.search-icon { position: absolute; left: 12px; font-size: 1rem; pointer-events: none; }
.search-box input {
  width: 100%;
  padding: 11px 38px 11px 38px;
  min-height: 46px;
  border: 1.5px solid var(--c-line);
  border-radius: var(--radius-s);
  background: #fbfcfe;
}
.search-clear {
  position: absolute; right: 8px;
  width: 30px; height: 30px;
  border: 0; border-radius: 50%;
  background: #e6ebf3; color: var(--c-text-mid);
  cursor: pointer; font-size: .9rem;
}

.filter-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 9px 15px;
  min-height: 44px;
  border: 1.5px solid var(--c-line);
  border-radius: 999px;
  background: #fff;
  font-size: .93rem;
  font-weight: 700;
  color: var(--c-text-mid);
  cursor: pointer;
}
.chip:hover { border-color: #9db6d6; color: var(--c-text); }
.chip.is-active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }

.select-field { display: flex; align-items: center; gap: 7px; font-size: .88rem; font-weight: 700; color: var(--c-text-mid); }
.select-field select {
  padding: 10px 12px;
  min-height: 44px;
  border: 1.5px solid var(--c-line);
  border-radius: var(--radius-s);
  background: #fff;
  font-weight: 600;
}

.result-count { margin-left: auto; font-size: .9rem; font-weight: 700; color: var(--c-text-dim); white-space: nowrap; }

/* ============================================================
   체크리스트 테이블
   ============================================================ */
/* 표 영역만 스크롤한다. 이 요소가 스크롤 컨테이너이므로
   thead 의 sticky 기준점도 이 요소의 상단(top:0)이 된다. */
.table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.check-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1120px; }

.check-table thead th {
  position: sticky;
  top: 0;                       /* 스크롤 컨테이너(.table-scroll) 상단에 고정 */
  z-index: 30;
  padding: 12px 10px;
  background: #dce6f4;
  border-bottom: 2px solid #a9bfdc;
  font-size: .9rem;
  font-weight: 800;
  color: var(--c-primary-d);
  text-align: left;
  white-space: nowrap;
}
.check-table thead th:first-child { border-top-left-radius: var(--radius); }
.check-table thead th:last-child  { border-top-right-radius: var(--radius); }

.col-no      { width: 78px; }
.col-cat     { width: 96px; }
.col-dwg     { width: 122px; }
.col-item    { width: 138px; }
.col-content { min-width: 320px; }
.col-stage   { width: 68px; text-align: center !important; }
.col-status  { width: 198px; }
.col-issue   { width: 82px; text-align: center !important; }
.col-comment { width: 226px; }

.check-table tbody td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--c-line-soft);
  vertical-align: top;
  font-size: .95rem;
}

.check-table tbody tr:nth-child(even) { background: #fafbfd; }
.check-table tbody tr:hover { background: #f2f7fd; }

.check-table tbody tr.row-fail  { background: var(--c-fail-row); }
.check-table tbody tr.row-fail:hover { background: #ffeceb; }
.check-table tbody tr.row-issue { background: var(--c-issue-row); box-shadow: inset 5px 0 0 var(--c-issue); }
.check-table tbody tr.row-issue:hover { background: #fff2dd; }
.check-table tbody tr.row-fail.row-issue { background: #fff0ea; box-shadow: inset 5px 0 0 var(--c-fail); }

.cell-id { font-family: Consolas, "Courier New", monospace; font-size: .84rem; font-weight: 700; color: var(--c-text-dim); }
.cell-cat { font-weight: 700; color: var(--c-primary-d); white-space: nowrap; }
.cell-item { font-weight: 700; }
.cell-content { white-space: pre-wrap; line-height: 1.62; word-break: keep-all; }
.cell-std {
  display: inline-block;
  margin-top: 7px;
  padding: 3px 9px;
  border-radius: 5px;
  background: #eaf0f9;
  border: 1px solid #c6d6ea;
  font-size: .8rem;
  font-weight: 700;
  color: var(--c-primary);
}

.stage-badge {
  display: inline-block;
  min-width: 38px;
  white-space: nowrap;
  padding: 3px 7px;
  border-radius: 5px;
  font-size: .78rem;
  font-weight: 800;
  text-align: center;
  background: #e8edf5;
  color: var(--c-text-mid);
  border: 1px solid var(--c-line);
}
.stage-SD { background: #e6f0ff; color: #14477d; border-color: #b6cdec; }
.stage-DD { background: #eaf6ec; color: #16794b; border-color: #b7dcc5; }
.stage-CD { background: #fdeee2; color: #9a4a00; border-color: #eccbaa; }

/* 검토내용이 30줄에 달하는 항목(예: 기계실 유지관리 공간)에서도
   판정·문제·의견 입력칸이 화면 밖으로 밀려나지 않도록 셀 안에서 고정한다. */
.sticky-cell { position: sticky; top: calc(var(--thead-h) + 8px); }

/* ── 판정 세그먼트 ─────────────────────────────────── */
.status-group { display: flex; gap: 4px; }

.status-btn {
  flex: 1;
  padding: 8px 4px;
  min-height: 42px;
  border: 1.5px solid var(--c-line);
  border-radius: 6px;
  background: #fff;
  font-size: .85rem;
  font-weight: 800;
  color: var(--c-text-mid);
  cursor: pointer;
  white-space: nowrap;
}
.status-btn:hover { border-color: #9db6d6; }

.status-btn[aria-pressed="true"][data-status="pass"] { background: var(--c-pass); border-color: var(--c-pass); color: #fff; }
.status-btn[aria-pressed="true"][data-status="fail"] { background: var(--c-fail); border-color: var(--c-fail); color: #fff; }
.status-btn[aria-pressed="true"][data-status="na"]   { background: var(--c-na);   border-color: var(--c-na);   color: #fff; }

/* ── 문제 토글 ─────────────────────────────────────── */
.issue-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  padding: 8px 4px;
  min-height: 42px;
  border: 1.5px solid var(--c-line);
  border-radius: 6px;
  background: #fff;
  font-size: .84rem;
  font-weight: 800;
  color: var(--c-text-mid);
  cursor: pointer;
  white-space: nowrap;
}
.issue-toggle[aria-pressed="true"] { background: var(--c-issue); border-color: var(--c-issue); color: #fff; }

/* ── 코멘트 ────────────────────────────────────────── */
.comment-input {
  width: 100%;
  min-height: 64px;
  padding: 9px 10px;
  border: 1.5px solid var(--c-line);
  border-radius: 6px;
  background: #fff;
  resize: vertical;
  line-height: 1.5;
  font-size: .93rem;
}
.comment-input:focus { border-color: #2f7fd4; background: #fbfdff; }
.comment-input::placeholder { color: #a3aebc; }

.empty-state { padding: 60px 20px; text-align: center; font-size: 1.05rem; color: var(--c-text-dim); }

/* ── 토스트 ────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  z-index: 200;
  padding: 13px 22px;
  border-radius: 999px;
  background: rgba(18, 32, 50, .94);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 22px rgba(0,0,0,.3);
}

/* ============================================================
   리포트(PDF/인쇄) 컨테이너 — 화면에서는 숨김
   ============================================================ */
.report-root { display: none; }

.report-page { width: 100%; padding: 6mm; background: #fff; color: #16202e; font-size: 10pt; }
.report-title { margin: 0 0 4mm; font-size: 17pt; font-weight: 800; text-align: center; color: #123f70; letter-spacing: -.5px; }
.report-meta { width: 100%; border-collapse: collapse; margin-bottom: 4mm; font-size: 9.5pt; }
.report-meta td { border: 1px solid #9db1cc; padding: 4px 8px; }
.report-meta .k { background: #e4ecf7; font-weight: 800; width: 68px; white-space: nowrap; }

.report-summary { display: flex; gap: 5px; margin-bottom: 4mm; }
.report-summary div { flex: 1; border: 1px solid #9db1cc; border-radius: 4px; padding: 4px 6px; text-align: center; font-size: 8.5pt; }
.report-summary strong { display: block; font-size: 13pt; }

.report-table { width: 100%; border-collapse: collapse; font-size: 8.6pt; table-layout: fixed; }
.report-table th, .report-table td { border: 1px solid #9db1cc; padding: 4px 5px; vertical-align: top; word-break: break-word; }
.report-table thead th { background: #dce6f4; color: #0d3159; font-weight: 800; text-align: center; }
.report-table tbody tr { page-break-inside: avoid; break-inside: avoid; }
.report-table .r-content { white-space: pre-wrap; line-height: 1.45; }
.report-table .r-center { text-align: center; }
.report-table tr.r-fail  { background: #fdeceb; }
.report-table tr.r-issue { background: #fff5e4; }
.report-badge { font-weight: 800; }
.report-badge.pass { color: #16794b; }
.report-badge.fail { color: #b3261e; }
.report-badge.na   { color: #5a6675; }
.report-badge.pending { color: #7b8794; }
.report-foot { margin-top: 5mm; font-size: 8.5pt; color: #4a586b; text-align: right; }

/* ============================================================
   반응형
   ============================================================ */
@media (max-width: 1180px) {
  .project-fields { margin-left: 0; width: 100%; }
  .field input { min-width: 140px; }
}

/* 태블릿·모바일에서는 앱 셸을 풀고 일반 문서 스크롤로 되돌린다 */
@media (max-width: 900px) {
  body { height: auto; overflow: visible; display: block; }
  .layout { display: block; overflow: visible; }
  .sidebar { width: 100%; border-right: 0; border-bottom: 1px solid var(--c-line); overflow: visible; }
  .sidebar-inner { height: auto; max-height: 260px; }
  .main { display: block; overflow: visible; padding: 14px 12px 50px; }
  .table-scroll { max-height: none; overflow-x: auto; }
  .check-table thead th { position: static; }
  .sticky-cell { position: static; }
}

/* ============================================================
   인쇄
   ============================================================ */
@media print {
  @page { size: A4 landscape; margin: 8mm; }

  /* 앱 셸(높이 100vh · overflow hidden)을 풀어야 전체 페이지가 인쇄된다 */
  html, body { height: auto !important; overflow: visible !important; display: block !important; background: #fff; }

  .app-header,
  .dashboard,
  .sidebar,
  .toolbar,
  .toast,
  .table-scroll { display: none !important; }

  .layout { display: block; }
  .main { padding: 0; }

  .report-root { display: block !important; }
  .report-page { padding: 0; }
}
