/* ===== DB분석 탭 — v3 ===== */

.erp-tab-content.active[data-tab="dbsearch"] { display: flex !important; height: calc(100vh - 105px); width: 100%; }
.erp-tab-content.active[data-tab="dbsearch"] #erp-dbsearch-body { width: 100%; height: 100%; }

.dbs-wrap { display: flex; width: 100%; height: 100%; font-family: '맑은 고딕','Malgun Gothic','Segoe UI',sans-serif; }

/* 좌: 결과 (70%) */
.dbs-result { flex: 7; display: flex; flex-direction: column; border-right: 2px solid #1F497D; background: #e8ecf0; overflow: hidden; }
.dbs-result-header { flex-shrink: 0; padding: 8px 16px; background: #1F497D; color: #fff; font-size: 12px; font-weight: 700; display: flex; justify-content: space-between; }
.dbs-result-scroll { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 24px; }

/* A4 가로 — 화면 맞춤, 넘치면 다음 페이지로 */
.dbs-page {
  width: min(calc(100% - 30px), calc((100vh - 160px) * 1.414));
  aspect-ratio: 297 / 210;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 2px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 20px 24px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.dbs-page-num { position: absolute; bottom: 8mm; right: 15mm; font-size: 10px; color: #94a3b8; }
.dbs-page-footer { position: absolute; bottom: 8mm; left: 15mm; font-size: 9px; color: #b0b8c4; }
.dbs-page-q { background: #dbe8f8; border-left: 4px solid #1F497D; padding: 6px 10px; margin-bottom: 8px; border-radius: 0 4px 4px 0; }
.dbs-page-q-row1 { font-size: 11px; font-weight: 700; color: #1F497D; display: flex; align-items: center; gap: 6px; }
.dbs-page-q-row2 { font-size: 12px; font-weight: 600; color: #475569; margin-top: 4px; padding-top: 4px; border-top: 1px solid rgba(31,73,125,0.15); }
.dbs-page-q .dbs-q-label { background: #1F497D; color: #fff; padding: 2px 8px; border-radius: 3px; font-size: 10px; font-weight: 800; flex-shrink: 0; }
.dbs-page-a { font-size: 10px; line-height: 1.5; color: #1a1a1a; font-weight: 500; }
.dbs-page-a p { margin: 3px 0; }
.dbs-page-a strong { color: #1F497D; font-weight: 800; }
.dbs-page-a strong.dbs-warn { color: #c62828; background: #fff5f5; padding: 1px 4px; border-radius: 2px; }
.dbs-page-a ul, .dbs-page-a ol { margin: 3px 0 3px 16px; }
.dbs-page-a li { margin-bottom: 1px; }
.dbs-page-a code { background: #f1f5f9; padding: 1px 4px; border-radius: 3px; font-size: 9px; color: #334155; }
.dbs-page-a pre { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 4px; padding: 6px 10px; overflow-x: auto; font-size: 9px; margin: 4px 0; }
.dbs-page-a h2 { font-size: 12px; color: #1F497D; background: #dbe8f8; border-left: 4px solid #1F497D; padding: 4px 10px; border-radius: 4px; margin: 8px 0 5px; font-weight: 800; }
.dbs-page-a h3 { font-size: 11px; color: #2E75B6; margin: 6px 0 4px; padding-bottom: 3px; border-bottom: 1px solid #e2e8f0; font-weight: 700; }

/* 테이블 */
.dbs-sql-table { width: 100%; border-collapse: collapse; font-size: 9px; border-top: 2px solid #1F497D; margin: 4px 0; }
.dbs-sql-table th { background: #1F497D; color: #fff; padding: 4px 6px; text-align: center; font-weight: 800; font-size: 9px; border-bottom: 1px solid #1F497D; }
.dbs-sql-table td { padding: 3px 6px; border-bottom: 1px solid #e2e8f0; color: #1a1a1a; font-weight: 500; }
.dbs-sql-table tr:nth-child(even) td { background: #fafbfc; }
.dbs-sql-table tr:hover td { background: #f0f4f8; }

/* 우: 분석 패널 (30%) */
.dbs-chat { flex: 3; min-width: 280px; display: flex; flex-direction: column; background: #f0f3f7; overflow: hidden; border-left: 1px solid #cbd5e1; }
.dbs-chat-header { flex-shrink: 0; padding: 10px 14px; background: linear-gradient(135deg, #1F497D, #2E75B6); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: 0.5px; }
.dbs-chat-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }

/* 섹션 레이블 */
.dbs-section-label { font-size: 10px; font-weight: 800; color: #1F497D; letter-spacing: 0.5px; margin-top: 2px; padding-bottom: 3px; border-bottom: 1px solid #1F497D; }

/* 탭 선택 목록 */
.dbs-tab-list { display: flex; flex-direction: column; gap: 3px; margin: 4px 0; }
.dbs-tab-item { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 11px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.dbs-tab-item:hover { border-color: #2E75B6; background: #f0f4ff; box-shadow: 0 2px 6px rgba(31,73,125,0.12); transform: translateY(-1px); }
.dbs-tab-item:has(input:checked) { border-color: #1F497D; background: #dbe8f8; box-shadow: 0 2px 6px rgba(31,73,125,0.15); }
.dbs-tab-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: #1F497D; cursor: pointer; }

/* 모델 선택 */
.dbs-model-bar { display: flex; gap: 4px; margin: 4px 0; }
.dbs-model-btn { flex: 1; padding: 5px 0; background: #fff; border: 1px solid #e2e8f0; border-radius: 4px; font-size: 10px; font-weight: 600; color: #64748b; cursor: pointer; text-align: center; transition: all 0.15s; }
.dbs-model-btn:hover { border-color: #2E75B6; color: #2E75B6; }
.dbs-model-btn.active { background: #1F497D; border-color: #1F497D; color: #fff; box-shadow: 0 2px 4px rgba(31,73,125,0.3); }

/* 추가 지시 */
.dbs-extra { width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 11px; font-family: inherit; resize: vertical; outline: none; background: #fff; box-shadow: inset 0 1px 2px rgba(0,0,0,0.06); min-height: 44px; box-sizing: border-box; }
.dbs-extra:focus { border-color: #1F497D; box-shadow: 0 0 0 3px rgba(31,73,125,0.1); }
.dbs-extra::placeholder { color: #94a3b8; font-size: 11px; }
.dbs-extra-copy { position: absolute; right: 6px; bottom: 6px; background: #e2e8f0; border: none; border-radius: 4px; padding: 3px 6px; font-size: 12px; cursor: pointer; opacity: 0.6; transition: opacity 0.2s; }
.dbs-extra-copy:hover { opacity: 1; }

/* 분석 버튼 */
.dbs-analyze-btn { width: 100%; padding: 8px; background: linear-gradient(135deg, #1F497D, #2E75B6); color: #fff; border: none; border-radius: 6px; font-size: 12px; font-weight: 700; cursor: pointer; margin-top: 6px; transition: all 0.2s; box-shadow: 0 2px 6px rgba(31,73,125,0.3); }
.dbs-analyze-btn:hover { background: linear-gradient(135deg, #163a64, #1F497D); box-shadow: 0 4px 12px rgba(31,73,125,0.4); transform: translateY(-1px); }
.dbs-analyze-btn:active { transform: translateY(0); }
.dbs-analyze-btn:disabled { background: #94a3b8; box-shadow: none; cursor: not-allowed; transform: none; }

/* 상태 */
.dbs-status { margin-top: 4px; padding: 6px 8px; background: #fff; border-radius: 4px; border: 1px solid #e2e8f0; min-height: 16px; font-size: 10px; }

/* 로딩 */
.dbs-loading { display: flex; align-items: center; gap: 8px; padding: 10px; color: #64748b; font-size: 12px; }
.dbs-spinner { width: 16px; height: 16px; border: 2px solid #e2e8f0; border-top-color: #1F497D; border-radius: 50%; animation: dbs-spin 0.8s linear infinite; }
@keyframes dbs-spin { to { transform: rotate(360deg); } }

/* 빈 상태 */
.dbs-empty { color: #94a3b8; font-size: 13px; text-align: center; padding: 40px 20px; }

/* 설치 가이드 */
.dbs-guide { max-width: 700px; margin: 20px auto; padding: 0 20px; }
.dbs-guide h2 { font-size: 18px; color: #1F497D; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid #1F497D; }
.dbs-guide h3 { font-size: 15px; color: #2E75B6; margin: 24px 0 12px; }
.dbs-step { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 14px 18px; margin-bottom: 12px; display: flex; gap: 14px; align-items: flex-start; }
.dbs-step-num { width: 28px; height: 28px; background: #1F497D; color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; flex-shrink: 0; }
.dbs-step-body { flex: 1; font-size: 13px; line-height: 1.7; }
.dbs-step-body .dbs-cmd { display: flex; align-items: center; gap: 8px; margin-top: 6px; background: #1e293b; color: #e2e8f0; padding: 8px 12px; border-radius: 4px; font-family: 'Consolas',monospace; font-size: 12px; }
.dbs-step-body .dbs-cmd code { flex: 1; background: none; color: inherit; padding: 0; }
.dbs-copy-btn { background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); color: #fff; font-size: 10px; padding: 2px 8px; border-radius: 3px; cursor: pointer; }
.dbs-copy-btn:hover { background: rgba(255,255,255,0.25); }
.dbs-copy-btn.copied { background: #2e7d32; border-color: #2e7d32; }
.dbs-easy { background: #f0f4f8; border: 1px solid #cbd5e1; border-radius: 8px; padding: 16px 18px; margin-top: 16px; }
.dbs-easy-title { font-size: 14px; font-weight: 700; color: #1F497D; margin-bottom: 10px; }
.dbs-easy-desc { font-size: 12px; color: #475569; margin-bottom: 10px; }
.dbs-easy-prompt { background: #fff; border: 1px solid #e2e8f0; border-radius: 4px; padding: 12px; font-size: 12px; line-height: 1.7; white-space: pre-wrap; max-height: 200px; overflow-y: auto; }
.dbs-easy-copy { margin-top: 8px; background: #1F497D; color: #fff; border: none; padding: 8px 16px; border-radius: 4px; font-size: 12px; font-weight: 700; cursor: pointer; }

/* 인쇄 버튼 (헤더) */
.dbs-print-btn { background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.4); color: #fff; font-size: 11px; padding: 3px 10px; border-radius: 4px; cursor: pointer; margin-left: 8px; }
.dbs-print-btn:hover { background: rgba(255,255,255,0.3); }

/* 페이지별 인쇄 버튼 */
.dbs-page-print { float: right; background: #1F497D; color: #fff; border: 1px solid rgba(255,255,255,0.3); font-size: 10px; padding: 2px 8px; border-radius: 3px; cursor: pointer; }
.dbs-page-print:hover { background: #163a64; }

/* 인쇄 — 선택된 그룹만, 페이지당 A4 가로 1장 */
@media print {
  @page { size: A4 landscape; margin: 8mm 10mm; }

  /* 컨테이너 높이 제한 해제 (dbsearch 탭만) */
  body.dbs-printing .dbs-wrap,
  body.dbs-printing .dbs-result,
  body.dbs-printing .dbs-result-scroll,
  body.dbs-printing .erp-tab-content[data-tab="dbsearch"],
  body.dbs-printing #erp-dbsearch-body { height: auto !important; overflow: visible !important; display: block !important; }

  /* 불필요 요소 숨김 (다른 탭 포함) */
  body.dbs-printing #sidebar,
  body.dbs-printing #menu-toggle,
  body.dbs-printing .erp-sticky,
  body.dbs-printing .erp-tab-bar,
  body.dbs-printing .dbs-chat,
  body.dbs-printing .dbs-result-header,
  body.dbs-printing .dbs-page-print,
  body.dbs-printing .dbs-page:not(.dbs-print-target) { display: none !important; }

  /* DB분석 외 탭 완전 숨김 — ID 셀렉터로 특이도 최대화 */
  body.dbs-printing #page-erp .erp-tab-content[data-tab="flow"],
  body.dbs-printing #page-erp .erp-tab-content[data-tab="team"],
  body.dbs-printing #page-erp .erp-tab-content[data-tab="quality"],
  body.dbs-printing #page-erp .erp-tab-content[data-tab="hours"],
  body.dbs-printing #page-erp .erp-tab-content[data-tab="equip"],
  body.dbs-printing #page-erp .erp-tab-content[data-tab="bom"],
  body.dbs-printing #page-erp .erp-tab-content[data-tab="ref"],
  body.dbs-printing #page-erp .erp-tab-content[data-tab="drawing"],
  body.dbs-printing #page-erp .erp-tab-content[data-tab="production"] {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
  }

  /* 대상 페이지 — 화면 제약 해제, A4에 맞게 */
  body.dbs-printing .dbs-print-target {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: auto !important;
    max-width: none !important;
    box-shadow: none !important;
    border: none !important;
    padding: 5mm 8mm !important;
    overflow: visible !important;
    page-break-after: always;
  }

  /* 테이블/제목 잘림 방지 */
  .dbs-sql-table { page-break-inside: avoid; }
  .dbs-page-a h2, .dbs-page-a h3 { page-break-after: avoid; }

  /* 색상 유지 */
  .dbs-page-q, .dbs-page-q-row1, .dbs-page-q-row2,
  .dbs-sql-table th, .dbs-page-a h2, strong.dbs-warn {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
