/* 공통 레이아웃 헬퍼 — Basecoat(CDN) 위에 얹는 프로젝트 로컬 클래스.
   인라인 Tailwind 유틸을 쓰지 않으므로 레이아웃은 모두 여기서 정의한다. */

:root {
  --rx-gap: 1rem;
  --rx-maxw: 1200px;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", "Malgun Gothic", sans-serif;
  background: var(--background, #fff);
  color: var(--foreground, #0a0a0a);
}

/* 상단바 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--rx-gap);
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border, #e5e5e5);
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; }
.topbar nav { display: flex; gap: 0.75rem; align-items: center; }

/* 컨테이너 */
.container {
  max-width: var(--rx-maxw);
  margin: 0 auto;
  padding: 1.25rem;
}
.container-wide { max-width: none; }

/* 스택 / 행 */
.stack { display: flex; flex-direction: column; gap: var(--rx-gap); }
.stack-sm { display: flex; flex-direction: column; gap: 0.5rem; }
.row { display: flex; gap: var(--rx-gap); align-items: center; flex-wrap: wrap; }
.row-sm { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: var(--rx-gap); align-items: center; justify-content: space-between; }
.grow { flex: 1 1 auto; }

/* Basecoat 카드 footer 간격 보강 */
.card > footer { gap: 0.5rem; }

/* 테이블 가로 스크롤 래퍼 */
.table-wrap { overflow-x: auto; width: 100%; }
/* 목록 테이블은 컨테이너 전체 폭 사용 */
.table > table { width: 100%; }

/* 다이얼로그 중앙정렬 + 폭 */
dialog { position: fixed; inset: 0; margin: auto; border: none; border-radius: 0.5rem; padding: 0; max-width: 480px; width: 92%; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog > div { padding: 1.25rem; }
dialog header { margin-bottom: 0.75rem; }
dialog footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

/* 보조 텍스트 / 상태 */
.muted { color: var(--muted-foreground, #737373); font-size: 0.875rem; }
.spacer { height: 1rem; }

/* 알림 영역(토스트 대용) */
#notices {
  position: fixed; top: 1rem; right: 1rem; z-index: 1000;
  display: flex; flex-direction: column; gap: 0.5rem; max-width: 380px;
}
#notices .alert { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12); }

/* 인증 페이지 가운데 */
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem; }

/* 상태 뱃지 색 */
.status-draft { opacity: 0.8; }

/* Jspreadsheet 컨테이너.
   프로젝트 폼: FitActiveSheet 가 내부(jss_content) 폭을 셀에 맞춰 FREEZE 스크롤.
   관리자 baseform(메뉴 없음): 내부 폭 보정이 없으므로 바깥 가로 스크롤로 폴백. */
.sheet-host { width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; }
.sheet-host .jss_worksheet { font-size: 0.85rem; }
/* 워크시트 탭 추가([+]) 버튼 숨김 — 시트 구조는 고정 */
.jtabs-add { display: none !important; }
/* 네이티브 워크시트 탭바 숨김 — 커스텀 2-depth 메뉴를 쓰는 시트영역에 한정.
   (메뉴 없는 관리자 baseform 은 네이티브 탭을 그대로 사용) */
.sheet-area .jtabs-headers { display: none !important; }
/* tableOverflow 스크롤 컨테이너가 카드 폭을 넘지 않도록 클램프 */
.sheet-host .jtabs, .sheet-host .jtabs-content, .sheet-host .jss_container { max-width: 100%; }

/* 2-depth 시트 메뉴 */
.sheet-menu { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.75rem; }
.menu-group { position: relative; }
.menu-btn.active { background: var(--primary, #0a0a0a); color: var(--primary-foreground, #fff); }
.menu-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 50; min-width: 200px;
  background: var(--popover, #fff); color: var(--popover-foreground, #0a0a0a);
  border: 1px solid var(--border, #e5e5e5); border-radius: 0.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); padding: 0.25rem;
  display: flex; flex-direction: column;
}
.menu-dropdown[hidden] { display: none; }
.menu-item {
  text-align: left; background: transparent; border: none; padding: 0.4rem 0.6rem;
  border-radius: 0.375rem; cursor: pointer; font: inherit; color: inherit;
}
.menu-item:hover { background: var(--accent, #f5f5f5); }
.menu-item.active { font-weight: 600; }
.menu-btn.has-issue::after, .menu-item.has-issue::after {
  content: "●"; color: #dc2626; margin-left: 0.4rem; font-size: 0.7em; vertical-align: middle;
}
.sheet-current { margin-left: 0.25rem; font-weight: 600; }
.sheet-actions { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }
.sheet-search {
  height: 2.25rem; width: 180px; padding: 0 0.6rem; font: inherit; color: inherit;
  border: 1px solid var(--border, #e5e5e5); border-radius: var(--radius, 0.5rem);
  background-color: var(--background, #fff);
}
.sheet-search:focus-visible { outline: 2px solid var(--ring, #94a3b8); outline-offset: 1px; }

/* 시트 영역 레이아웃 — 테이블 + 보조패널 배치 */
.sheet-area.layout-none { display: block; }
.sheet-area.layout-h { display: grid; grid-template-columns: 3fr 1fr; gap: 1rem; align-items: start; }
.sheet-area.layout-v { display: flex; flex-direction: column; gap: 1rem; }
.aux-panel { min-width: 0; }
.aux-panel[hidden] { display: none; }

/* 보조패널 공통 컨트롤 */
.panel-controls { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.panel-controls .ctl { display: flex; flex-direction: column; gap: 0.25rem; }
.panel-controls label { font-size: 0.75rem; color: var(--muted-foreground, #737373); }
.ctl-hint { font-size: 0.72rem; color: var(--muted-foreground, #737373); font-weight: 600; margin-left: 0.35rem; }
.ctl-note { font-size: 0.68rem; color: var(--muted-foreground, #737373); margin-top: 0.15rem; }

/* 기간선택(시작일~종료일 + 전체 버튼) */
.period-range { display: flex; align-items: center; gap: 0.4rem; }
.panel-controls input[type="date"] {
  height: 2.25rem; padding: 0 0.5rem; font: inherit; color: inherit;
  border: 1px solid var(--border, #e5e5e5); border-radius: var(--radius, 0.5rem);
  background-color: var(--background, #fff);
}
.period-range .btn-outline { height: 2.25rem; }

/* 네이티브 select — Basecoat 에는 .input 정의가 없어 직접 스타일(화살표 포함) */
.panel-controls select, .gen-form select, select.input {
  appearance: none; -webkit-appearance: none;
  height: 2.25rem; padding: 0 1.75rem 0 0.6rem;
  border: 1px solid var(--border, #e5e5e5); border-radius: var(--radius, 0.5rem);
  background-color: var(--background, #fff); color: inherit; font: inherit; cursor: pointer;
  background-repeat: no-repeat; background-position: right 0.55rem center; background-size: 0.85rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
.panel-controls select:focus-visible, .gen-form select:focus-visible, select.input:focus-visible {
  outline: 2px solid var(--ring, #94a3b8); outline-offset: 1px;
}

/* 지역필터 체크박스 — Basecoat 자동 스타일이 레이어 충돌로 미적용되어 직접 스타일 */
.area-filter { display: flex; flex-wrap: wrap; gap: 0.4rem; max-height: 6rem; overflow: auto; }
.area-filter label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: inherit; }
.area-filter input[type="checkbox"], .capacity-checks-list input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 1rem; height: 1rem; margin: 0; cursor: pointer;
  border: 1px solid var(--border, #d4d4d4); border-radius: 0.25rem;
  background: var(--background, #fff); position: relative; flex: 0 0 auto;
}
.area-filter input[type="checkbox"]:checked, .capacity-checks-list input[type="checkbox"]:checked {
  background: var(--primary, #0a0a0a); border-color: var(--primary, #0a0a0a);
}
.area-filter input[type="checkbox"]:checked::after, .capacity-checks-list input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.demand-chart { width: 100%; height: 300px; margin-top: 0.5rem; }

/* 보조패널 차트 컨테이너 — 카테고리별 높이 */
.cast-chart { width: 100%; height: 300px; margin-top: 0.5rem; }
.step-chart { width: 100%; height: 320px; margin-top: 0.5rem; }
.cal-chart { width: 100%; height: 200px; }
/* 스케줄러 최근실행 요약/원인 셀 — 길어도 셀 안에서 줄바꿈(화면 밖 넘침 방지) */
.run-summary { max-width: 36rem; white-space: normal; word-break: break-word; overflow-wrap: anywhere; }
.heatmap-chart { width: 100%; height: 360px; margin-top: 0.5rem; }

/* 가용용량 패널 — | 체크박스(세로 스크롤) | 차트 | */
.capacity-split { display: grid; grid-template-columns: 200px 1fr; gap: 1rem; align-items: start; }
.capacity-split .step-chart { margin-top: 0; }
.capacity-checks { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.capacity-checks-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.capacity-checks-head span { font-size: 0.75rem; color: var(--muted-foreground, #737373); }
.capacity-checks-list {
  display: flex; flex-direction: column; gap: 0.3rem;
  max-height: 300px; overflow-y: auto; padding-right: 0.25rem;
}
.capacity-checks-list label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: inherit; }

/* 결과 GEN 탭 — 좌측 패널을 차트 높이에 맞춰 고정하고, 체크목록만 내부 스크롤한다
   (목록이 길어져도 차트 아래로 영역이 늘어나지 않도록). */
#gen-chart-host .capacity-checks { height: 320px; }
#gen-chart-host .capacity-checks-list { flex: 1; min-height: 0; max-height: none; }

/* 발전기 폼 패널 */
.gen-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 0.75rem; }
.gen-form .ctl { display: flex; flex-direction: column; gap: 0.2rem; }
.gen-form label { font-size: 0.72rem; color: var(--muted-foreground, #737373); }
.gen-form .ctl.full { grid-column: 1 / -1; }
.gen-form .input { font-size: 0.85rem; }
.gen-form-foot { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }

/* 결과 페이지 — 진행추적 + SMP/GEN 탭 */
.progress-row { display: flex; align-items: center; gap: 0.75rem; }
.progress-row #phase-label { flex: 0 0 auto; min-width: 9rem; }
.progress-row #prog-pct { flex: 0 0 auto; min-width: 3rem; text-align: right; }
/* Basecoat progress 디자인(track + fill) — CDN 번들엔 Tailwind 유틸이 없어 토큰으로 재현 */
.progress-track {
  flex: 1 1 auto; position: relative; height: 0.5rem; overflow: hidden;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--primary, #0a0a0a) 20%, transparent);
}
.progress-fill {
  height: 100%; width: 0%;
  background: var(--primary, #0a0a0a); transition: width 0.2s ease;
}
/* 폼 라벨 — select 위 설명문이 제목처럼 커 보이지 않도록 작게 */
.field-label { font-size: 0.78rem; font-weight: 500; color: var(--muted-foreground, #737373); }
/* 경고 — 접이식 영역에 전체 표시(발생 날짜 포함) */
.warn-box { margin-top: 0.75rem; border: 1px solid var(--border, #e5e5e5); border-radius: var(--radius, 0.5rem); }
.warn-box > summary { cursor: pointer; padding: 0.5rem 0.75rem; font-size: 0.85rem; font-weight: 500; color: var(--destructive, #dc2626); }
.warn-list { display: flex; flex-direction: column; gap: 0.3rem; padding: 0 0.75rem 0.75rem; }
.warn-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; }
.warn-when { flex: 0 0 auto; min-width: 5rem; }
.warn-msg { flex: 1 1 auto; min-width: 0; }
.result-chart { width: 100%; height: 320px; }
.result-table { width: 100%; }
