:root {
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --primary-dark: #065f46;
  --blue-700: #1d4ed8;
  --blue-600: #2563eb;
  --blue-50: #eff6ff;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08);
  --transition: all 0.18s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  background-color: #f1f5f9;
  color: var(--slate-800);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ================= 상단 헤더 ================= */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--slate-200);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

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

.brand-badge {
  background: var(--primary);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--slate-900);
  letter-spacing: -0.4px;
}

.sub-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 3px 9px;
  border-radius: 20px;
  margin-left: 6px;
}

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

.sync-info-text {
  font-size: 0.8rem;
  color: var(--slate-500);
  font-weight: 500;
}

.btn-sync-compact {
  background: var(--slate-50);
  color: var(--slate-700);
  border: 1px solid var(--slate-300);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: var(--transition);
}

.btn-sync-compact:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary);
}

/* ================= 메인 컨테이너 & 카드 ================= */
.main-container {
  max-width: 1320px;
  margin: 1.25rem auto;
  padding: 0 1.5rem;
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--slate-200);
  box-shadow: var(--shadow-md);
}

/* ================= 상단 2단계 컨트롤 패널 ================= */
.control-panel {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.25rem;
  align-items: end;
}

@media (max-width: 900px) {
  .control-grid {
    grid-template-columns: 1fr;
  }
}

.control-step {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.step-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--slate-800);
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-badge {
  background: var(--primary);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.step-badge.secondary {
  background: var(--slate-700);
}

.text-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--slate-300);
  background: #ffffff;
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--slate-900);
  transition: var(--transition);
}

.facility-select {
  font-weight: 700;
  cursor: pointer;
  background-color: #f8fafc;
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.14);
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.btn-clear-search {
  position: absolute;
  right: 10px;
  background: var(--slate-200);
  color: var(--slate-700);
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-clear-search:hover {
  background: var(--slate-300);
}

/* 2단계 세부 점검부위 칩 바 */
.subfilter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--slate-200);
  flex-wrap: wrap;
}

.subfilter-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--slate-700);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tax-filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

.tax-chip {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  color: var(--slate-700);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: var(--transition);
}

.tax-chip:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: var(--primary-light);
}

.tax-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* ================= 결과 상단 바 & 2-탭 네비게이션 ================= */
.result-section {
  overflow: hidden;
}

.result-top-bar {
  padding: 1.15rem 1.5rem;
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.facility-main-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--slate-900);
}

.facility-gosi-sub {
  font-size: 0.82rem;
  color: var(--slate-600);
  margin-top: 2px;
  font-weight: 500;
}

.view-tabs {
  display: flex;
  gap: 8px;
  background: var(--slate-200);
  padding: 4px;
  border-radius: 10px;
}

.view-tab-btn {
  border: none;
  background: transparent;
  color: var(--slate-700);
  font-size: 0.88rem;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
}

.view-tab-btn.active {
  background: #ffffff;
  color: var(--slate-900);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tab-count-pill {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 0.75rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 12px;
}

.tab-panel {
  padding: 1.5rem;
}

/* ================= 탭 1: 현장 지적사례 카드 ================= */
.case-cards-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.case-card {
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.case-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.case-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.source-pill {
  background: var(--slate-800);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.source-file-text {
  font-size: 0.78rem;
  color: var(--slate-500);
  font-weight: 500;
}

.case-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--slate-900);
}

.defect-badge {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.25);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 6px;
  white-space: nowrap;
}

/* 사진 영역 */
.case-photo-section {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.photo-section-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--slate-700);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.photo-hint {
  font-weight: 400;
  color: var(--slate-500);
  font-size: 0.74rem;
}

.case-images-gallery {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.photo-thumb-wrap {
  flex-shrink: 0;
  width: 210px;
  height: 150px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--slate-300);
  background: #000;
}

.photo-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.photo-thumb-wrap img:hover {
  transform: scale(1.04);
}

/* 지적사항 및 개선조치 그리드 */
.case-content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 768px) {
  .case-content-grid {
    grid-template-columns: 1fr;
  }
}

.box-defect,
.box-solution {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--slate-200);
}

.box-defect {
  background: #fffafa;
  border-color: #fecaca;
}

.box-solution {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.box-label {
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 6px;
  display: block;
}

.box-defect .box-label {
  color: var(--danger);
}

.box-solution .box-label {
  color: var(--primary-dark);
}

.box-text {
  font-size: 0.88rem;
  color: var(--slate-800);
  line-height: 1.65;
  white-space: pre-line;
}

/* 상단 공식 별표 PDF 바로 열기 & 서식 토글 버튼 */
.statutory-quick-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-open-pdf-main {
  background: var(--primary);
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 700;
  padding: 9px 15px;
  border-radius: 8px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
  transition: var(--transition);
}

.btn-open-pdf-main:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-toggle-forms {
  background: #ffffff;
  color: var(--slate-800);
  border: 1px solid var(--slate-300);
  font-size: 0.84rem;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-toggle-forms:hover,
.btn-toggle-forms.active {
  background: var(--blue-50);
  color: var(--blue-700);
  border-color: #93c5fd;
}

/* 사례 하단 법정 기준 PDF 바로 열기 바 */
.statutory-link-bar {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.statutory-link-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.84rem;
  color: var(--slate-800);
}

.statutory-tag {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--blue-700);
  background: var(--blue-50);
  padding: 2px 7px;
  border-radius: 4px;
}

.btn-law-pdf {
  background: var(--blue-600);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 6px;
  text-decoration: none;
  white-space: nowrap;
  transition: var(--transition);
}

.btn-law-pdf:hover {
  background: var(--blue-700);
}

.statutory-criteria-pair {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
}

@media (max-width: 768px) {
  .statutory-criteria-pair {
    grid-template-columns: 1fr;
  }
}

.stat-col {
  background: #ffffff;
  border: 1px solid var(--slate-200);
  border-radius: 6px;
  padding: 8px 10px;
}

.stat-col-label {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--slate-600);
  display: block;
  margin-bottom: 3px;
}

.stat-col-text {
  font-size: 0.82rem;
  color: var(--slate-800);
  line-height: 1.55;
  white-space: pre-line;
}

/* ================= 탭 2: 공식 별표·별지 서식 다운로드 & 법정 기준 표 ================= */
.official-forms-box {
  background: #f8fafc;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.forms-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
  font-size: 0.92rem;
  color: #1e3a8a;
}

.forms-sub {
  font-size: 0.78rem;
  color: var(--slate-500);
  margin-left: 8px;
  font-weight: 500;
}

.forms-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 900px) {
  .forms-grid {
    grid-template-columns: 1fr;
  }
}

.forms-col {
  background: #ffffff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.forms-col-title {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--slate-700);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--slate-100);
}

.forms-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 190px;
  overflow-y: auto;
}

.form-dl-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.form-dl-item:hover {
  background: var(--slate-50);
}

.form-dl-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.form-no-badge {
  background: #e0e7ff;
  color: #3730a3;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.form-name-text {
  color: var(--slate-800);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-dl-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.dl-btn {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 4px;
  text-decoration: none;
}

.dl-btn.pdf {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.dl-btn.pdf:hover {
  background: #dc2626;
  color: #ffffff;
}

.dl-btn.hwp {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
}

.dl-btn.hwp:hover {
  background: #0284c7;
  color: #ffffff;
}

/* 법정 기준 표 */
.criteria-table-wrap {
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.criteria-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.criteria-table thead tr {
  background: var(--slate-100);
  border-bottom: 2px solid var(--slate-300);
  text-align: left;
}

.criteria-table th {
  padding: 11px 14px;
  font-weight: 800;
  color: var(--slate-800);
}

.criteria-table tbody tr {
  border-bottom: 1px solid var(--slate-200);
}

.criteria-table tbody tr:hover {
  background: #f8fafc;
}

.criteria-table td {
  padding: 12px 14px;
  vertical-align: top;
}

.criteria-cat-cell {
  background: #fcfcfd;
  border-right: 1px solid var(--slate-100);
}

.annex-pill {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  background: #e0e7ff;
  color: #3730a3;
  padding: 1px 6px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.subcat-title {
  font-weight: 800;
  color: var(--slate-900);
  font-size: 0.88rem;
}

.itemno-text {
  font-size: 0.78rem;
  color: var(--primary-dark);
  font-weight: 700;
  margin-top: 2px;
}

.majorcat-text {
  font-size: 0.72rem;
  color: var(--slate-500);
  margin-top: 3px;
}

.criteria-tech-cell {
  font-weight: 600;
  color: var(--slate-900);
  line-height: 1.6;
  white-space: pre-line;
  border-right: 1px solid var(--slate-100);
}

.criteria-detail-cell {
  color: var(--slate-700);
  line-height: 1.65;
  white-space: pre-line;
}

/* 검색 하이라이트 */
mark.search-hit {
  background: #fde047;
  color: #713f12;
  font-weight: 700;
  padding: 0 2px;
  border-radius: 3px;
}

/* 빈 상태 및 로딩 스피너 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--slate-500);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--slate-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.app-footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.8rem;
  color: var(--slate-500);
  border-top: 1px solid var(--slate-200);
  background: #ffffff;
}
