/* ── 디자인 토큰 ─────────────────────────────────────── */
:root {
  /* 색상 — RGB 채널이 단일 진실원천. 이름색은 채널에서 합성하고, Tailwind 설정
     (base.html)도 같은 채널을 rgb(var(--x-rgb)/<alpha-value>) 로 참조 → 한 곳만 고치면 전체 반영.
     채널 형태라 Tailwind 투명도 수식어(bg-danger/10 등)도 그대로 동작한다. */
  --bg-rgb: 247 248 251;
  --surface-rgb: 255 255 255;
  --surface2-rgb: 240 242 247;
  --border-rgb: 227 230 240;
  --text-rgb: 25 27 41;
  --text2-rgb: 107 113 133;
  --accent-rgb: 109 94 240;
  --red-rgb: 232 64 74;
  --green-rgb: 31 157 87;
  --peak-rgb: 224 131 5;
  --valley-rgb: 31 116 208;
  --orange-rgb: 226 84 26;
  /* 이름색 (채널 합성 — 기존 var(--accent) 등 사용처 전부 동일 값 유지) */
  --bg: rgb(var(--bg-rgb));
  --surface: rgb(var(--surface-rgb));
  --surface2: rgb(var(--surface2-rgb));
  --border: rgb(var(--border-rgb));
  --text: rgb(var(--text-rgb));
  --text2: rgb(var(--text2-rgb));
  --accent: rgb(var(--accent-rgb));
  --accent-weak: rgb(var(--accent-rgb) / .12);
  --red: rgb(var(--red-rgb));
  --green: rgb(var(--green-rgb));
  --peak: rgb(var(--peak-rgb));
  --valley: rgb(var(--valley-rgb));
  --orange: rgb(var(--orange-rgb));
  /* 별칭 */
  --danger: var(--red);
  --ok: var(--green);
  /* 그림자 / 라운드 */
  --shadow-card: 0 1px 2px rgba(20,22,40,.04), 0 4px 12px rgba(20,22,40,.06);
  --shadow-pop: 0 8px 30px rgba(20,22,40,.12);
  --radius-card: 14px;
  --radius-btn: 10px;
  --radius-chip: 8px;
  /* 모바일 하단바 높이(햄버거 서랍 방식 → 0) + 아이폰 홈 인디케이터 safe area.
     기존 하단 여백 계산식(calc(Npx + var(--tabbar-h)))이 전부 이 값을 더해 쓰므로
     여기 한 곳만 고치면 필터시트·FAB·스크리너 하단여백이 전부 자동으로 안전해진다. */
  --tabbar-h: env(safe-area-inset-bottom, 0px);
}

/* ── 리셋 + 기본 ─────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font-family: 'Pretendard', -apple-system, sans-serif; }

/* ── 스크롤바 ─────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #c4c9db, #b0b6cc);
  border-radius: 8px;
  border: 2px solid var(--bg);
  transition: background .15s;
}
::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, #9fa5bf, var(--accent)); }
::-webkit-scrollbar-corner { background: transparent; }
.sidebar ::-webkit-scrollbar-thumb,
.modal   ::-webkit-scrollbar-thumb { border-color: var(--surface); }

/* ── 배지 ────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.badge.success   { background: rgba(47,158,68,.12);   color: var(--green); }
.badge.fail      { background: rgba(224,49,49,.12);    color: var(--red); }
.badge.info      { background: var(--accent-weak);     color: var(--accent); }
.badge.valley    { background: rgba(25,113,194,.12);   color: var(--valley); }
.badge.neutral   { background: rgba(100,105,126,.12);  color: var(--text2); }
.badge.tentative { background: rgba(217,119,10,.08);   color: var(--peak); border: 1px dashed var(--peak); padding: 1px 5px; }
.badge.confirmed { background: rgba(47,158,68,.10);    color: var(--green); }

/* ── 공용 컴포넌트 ───────────────────────────────────── */
.empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text2); font-size: 15px; flex-direction: column; gap: 8px;
}

.loading {
  display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(255,255,255,.95); border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  padding: 30px 50px; border-radius: 12px; z-index: 999;
  font-size: 16px; color: var(--text); text-align: center;
}
.loading.show { display: block; }

/* 공통 인라인 로딩 스피너 — 작전실/실험실 등 백엔드 계산 페이지 공용(중복 인라인 CSS 통합) */
.spin { display:inline-block; width:14px; height:14px; border:2px solid var(--border);
  border-top-color: var(--accent, #60a5fa); border-radius:50%;
  animation: spin .7s linear infinite; vertical-align:-2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1000; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; max-width: 700px; width: 90%; max-height: 80vh; overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
}
.modal h3 { font-size: 16px; margin-bottom: 16px; color: var(--peak); }
.modal table { width: 100%; border-collapse: collapse; font-size: 12px; font-family: monospace; }
.modal th { text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--border); color: var(--text2); font-size: 11px; position: sticky; top: 0; background: var(--surface); }
.modal td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.modal tr.label-row { background: var(--surface2); }
.modal .lbl { font-weight: 700; color: var(--peak); font-size: 10px; }
.modal .pos { color: var(--green); }
.modal .neg { color: var(--red); }
.modal .close-btn { position: absolute; top: 12px; right: 16px; background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; }
.modal-wrap { position: relative; }

/* ── 사이드바·드로어 공통 네비 (데스크톱/모바일 통일) ──── */
.app-sidebar .nav-link,
.drawer .nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-btn);
  color: var(--text2); font-size: 14px; font-weight: 600;
  text-decoration: none; transition: background .15s, color .15s;
}
.app-sidebar .nav-link:hover,
.drawer .nav-link:hover { background: var(--surface2); color: var(--text); }
.app-sidebar .nav-link.on,
.drawer .nav-link.on { background: var(--accent-weak); color: var(--accent); }
.drawer .nav-link:active { background: var(--surface2); }
.nav-ico { font-size: 20px; line-height: 1; flex-shrink: 0; }

/* ── 실험실 펼침 그룹(<details>) ── */
.nav-group { display: block; }
.nav-group > summary.nav-link { list-style: none; cursor: pointer; width: 100%; }
.nav-group > summary.nav-link::-webkit-details-marker { display: none; }
.nav-caret { margin-left: auto; font-size: 18px; opacity: .6; transition: transform .15s; }
.nav-group[open] .nav-caret { transform: rotate(180deg); }
.nav-sub { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.app-sidebar .nav-sub-link,
.drawer .nav-sub-link { padding-left: 34px; font-size: 13px; }

/* ── 모바일: 헤더 패딩 (햄버거 40px 자리 확보) ───────── */
@media (max-width: 1024px) {
  .app-header {
    padding-left: calc(52px + env(safe-area-inset-left)) !important;
    padding-top: env(safe-area-inset-top) !important;
    min-height: 56px; align-items: center;
  }
}

/* ── 햄버거 버튼 ─────────────────────────────────────── */
.drawer-toggle { display: none; }
@media (max-width: 1024px) {
  .drawer-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; z-index: 8600;
    top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left));
    width: 40px; height: 40px; padding: 0;
    background: transparent; border: none; border-radius: 9px;
    color: var(--text); font-size: 23px; line-height: 1; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .drawer-toggle:active { background: var(--surface2); }
}

/* ── 좌측 서랍 + 백드롭 ──────────────────────────────── */
.drawer-backdrop { display: none; position: fixed; inset: 0; z-index: 8700; background: rgba(0,0,0,.4); }
.drawer-backdrop.open { display: block; animation: drawer-fade .2s ease; }
@keyframes drawer-fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 8800;
  width: 76%; max-width: 300px;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  box-shadow: 2px 0 24px rgba(0,0,0,.18);
  transform: translateX(-100%); transition: transform .26s cubic-bezier(.4,0,.2,1);
  /* 아이폰 노치·홈 인디케이터 safe area — 헤드/푸터가 눌리지 않도록 안쪽 여백으로 밀어냄 */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 16px 14px 12px;
}
.drawer-head a { color: var(--text); text-decoration: none; }
.drawer-close { background: none; border: none; font-size: 18px; color: var(--text2); cursor: pointer; padding: 4px; flex-shrink: 0; }

/* ── iOS Safari 입력 자동 확대 방지 ──────────────────── */
@supports (-webkit-touch-callout: none) {
  input, select, textarea { font-size: max(16px, 1em) !important; }
}

/* ── PWA 설치 버튼 (사이드바/드로어에 JS 주입) ─────────── */
.pwa-install-btn {
  width: 100%; border: none; background: none; cursor: pointer; font: inherit;
}
/* 사이드바·드로어 공통: .nav-link 스타일 위에 강조색만 */
.app-sidebar .pwa-install-btn,
.drawer .pwa-install-btn { color: var(--accent); }
.app-sidebar .pwa-install-btn { margin-bottom: 4px; }
.app-sidebar .pwa-install-btn:hover,
.drawer .pwa-install-btn:active { background: var(--accent-weak); color: var(--accent); }

/* 알림 토글 버튼: 버튼 기본 모양만 제거 — 형태·폰트·색은 .nav-link 가 관장(형제 링크와 동일) */
.app-sidebar .js-lp-toggle,
.drawer .js-lp-toggle {
  width: 100%; background: none; border: none; cursor: pointer; font-family: inherit;
}

/* ── iOS '홈 화면에 추가' 안내 팝업 ───────────────────── */
.pwa-ios-tip {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 9500; width: calc(100% - 32px); max-width: 320px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-pop);
  padding: 16px 18px; font-size: 14px; line-height: 1.6; color: var(--text);
}
.pwa-ios-tip b { color: var(--accent); }
.pwa-ios-tip .x {
  position: absolute; top: 8px; right: 12px; border: none; background: none;
  font-size: 18px; color: var(--text2); cursor: pointer; line-height: 1;
}
