/* 엑셀 조건 필터 수식 만들기(#3143) */
:root {
  --font: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, Menlo, "D2Coding", "Noto Sans Mono CJK KR", "Noto Sans KR", monospace;
  --bg: #f2f6fb;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #16202b;
  --sub: #55636f;
  --line: #d7e0ea;
  --accent: #1f5fae;
  --accent-soft: #e6eef8;
  --accent-ink: #ffffff;
  /* 상태색: 선(굵은 막대)·글자·배경 세 가지로 보인다(색만으로 구분하지 않게 글자도 붙임) */
  --green: #1d7a46;
  --green-bg: #eef8f1;
  --blue: #1f5fae;
  --blue-bg: #eef4fb;
  --red: #b3261e;
  --red-bg: #fdf0ef;
  --out-bg: #e6eaef;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  font-size: 16px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

::selection { background: #cfe0f5; color: var(--ink); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; overflow-wrap: anywhere; word-break: break-all; }

.site-header {
  padding: 24px 16px 8px;
  max-width: 1100px;
  margin: 0 auto;
}
.site-header .brand { margin: 0 0 4px; font-weight: 700; color: var(--accent); font-size: 0.9rem; }
.site-header h1 { margin: 0 0 8px; font-size: clamp(1.4rem, 4vw, 1.9rem); }
.site-header .lead { margin: 0; color: var(--sub); max-width: 70ch; }

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}
.result-col { display: grid; gap: 20px; min-width: 0; align-content: start; }

.form-panel, .out-panel, .preview-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.form-panel h2, .out-panel h2, .preview-panel h2 { margin: 0 0 12px; font-size: 1.1rem; }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 16px;
  padding: 12px;
  min-width: 0;
}
legend { font-weight: 700; padding: 0 6px; }
.legend-sub { font-weight: 600; color: var(--sub); font-size: 0.85rem; margin-left: 4px; }

.field { margin-bottom: 14px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field-row { display: grid; grid-template-columns: 1fr; gap: 0 12px; }

label, .label { display: block; font-weight: 600; margin: 0 0 6px; font-size: 0.95rem; }

input[type="text"],
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--ink);
  font: inherit;
  caret-color: var(--accent);
}
select { padding-right: 8px; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--red); box-shadow: inset 4px 0 0 var(--red); }
::placeholder { color: #6b7783; opacity: 1; }

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible,
pre:focus-visible,
.ex-scroll:focus-visible,
.chip input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.help-text { margin: 6px 0 10px; font-size: 0.85rem; color: var(--sub); }
fieldset > .help-text:last-child { margin-bottom: 0; }

/* 입력 오류: 빨강 왼쪽 굵은 막대 + 옅은 빨강 바탕 + 굵은 글자 */
.field-error {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-left: 6px solid var(--red);
  border-radius: 0 8px 8px 0;
  background: var(--red-bg);
  color: #6f1712;
  font-size: 0.88rem;
  font-weight: 600;
}
.field-error:empty { display: none; }
.field-error p { margin: 0; }
.field-error p + p { margin-top: 4px; }

/* ---- 범위 ---- */
.range-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.range-grid .field { margin-bottom: 12px; }
.range-grid input { text-transform: uppercase; font-family: var(--mono); }
.range-text { margin: 2px 0 0; font-size: 0.9rem; color: var(--sub); }
.range-text code { font-size: 0.95rem; color: var(--ink); font-weight: 700; }

/* ---- 열 이름표 ---- */
.colmap { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.colmap-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.colmap-row input.col-letter-in { text-transform: uppercase; font-family: var(--mono); text-align: center; }

/* ---- 조건 줄 ---- */
.conds { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 10px; }
.cond { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; background: var(--surface-2); }
.cond-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.cond-no { font-weight: 700; font-size: 0.92rem; }
.cond-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.cond-grid .field { margin-bottom: 10px; }
.cond-grid .field:last-child { margin-bottom: 0; }
.cond-grid .f-value, .cond-grid .f-value2 { grid-column: 1 / -1; }
.cond-grid .field[hidden] { display: none; }
.cond label { font-size: 0.85rem; margin-bottom: 4px; }

/* 칩(라디오) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { margin: 0; position: relative; cursor: pointer; font-weight: 600; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.95rem;
  transition: background-color 0.15s ease-out, border-color 0.15s ease-out, color 0.15s ease-out;
}
.chip:hover span { border-color: #9fb6d1; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
#sortOrderField[hidden] { display: none; }
/* 「빈 행 빼기」 스위치(체크 상자, 44px 터치) */
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; margin: 0; cursor: pointer; font-weight: 600; }
.switch input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }
.switch input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.privacy-note { margin: 14px 0 0; font-size: 0.85rem; color: var(--sub); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 4px; }
.btn {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s ease-out, transform 0.1s ease-out, background-color 0.15s ease-out;
}
.btn-main { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:hover { filter: brightness(0.96); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; transform: none; }
.btn-del { min-height: 44px; min-width: 44px; padding: 6px 12px; font-size: 0.85rem; border-radius: 999px; }
.btn-add { border-style: dashed; color: var(--accent); }
/* 좁은 화면(≤1279px)은 결과가 입력 아래라 바로 내려가는 링크. 두 칸 화면에서는 숨김 */
.to-result {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 6px;
  color: var(--accent);
  font-weight: 700;
  text-underline-offset: 3px;
}

/* ---- 수식 상자 ---- */
.form-state {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-left: 6px solid var(--red);
  border-radius: 0 8px 8px 0;
  background: var(--red-bg);
  color: #6f1712;
  font-weight: 600;
  font-size: 0.92rem;
}
.form-state[hidden] { display: none; }
.out { margin: 0; padding: 14px 0 16px; border-top: 1px solid var(--line); }
.out:first-of-type { border-top: 0; padding-top: 0; }
.out h3 { margin: 0 0 8px; font-size: 1rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.ver { font-size: 0.82rem; font-weight: 600; color: var(--sub); }
.formula {
  margin: 0;
  padding: 12px 14px;
  min-height: 3.2em;
  border: 1px solid var(--line);
  border-top: 4px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}
/* 정상 수식: 초록 위선 */
.formula.ok { border-top: 4px solid var(--green); }
/* 입력 오류로 수식이 없을 때: 회색 위선·안내 글(고정폭 아님) */
.formula.off { border-top: 4px solid var(--line); color: var(--sub); font-family: var(--font); font-size: 0.9rem; }
.copy-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 10px; }
.copy-msg { font-size: 0.9rem; font-weight: 700; color: var(--green); }
.copy-msg.warn { color: var(--blue); }
.copy-msg:empty { display: none; }
/* 시트 OR 안내: 파랑 왼쪽 막대 */
.note-or {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-left: 6px solid var(--blue);
  border-radius: 0 8px 8px 0;
  background: var(--blue-bg);
  color: #173c66;
  font-size: 0.9rem;
}
.note-or[hidden] { display: none; }
/* 빈 행 가드 안내(r2 H2): 파랑 왼쪽 막대 — 수식 상자 아래 */
.note-guard {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-left: 6px solid var(--blue);
  border-radius: 0 8px 8px 0;
  background: var(--blue-bg);
  color: #173c66;
  font-size: 0.9rem;
}
.note-guard[hidden] { display: none; }
/* 조건 안내 줄(FIND·날짜 열·빈 행): 파랑 왼쪽 막대 목록 */
.out-notes {
  list-style: none;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-left: 6px solid var(--blue);
  border-radius: 0 8px 8px 0;
  background: var(--blue-bg);
  color: #173c66;
  font-size: 0.9rem;
}
.out-notes[hidden] { display: none; }
.out-notes li + li { margin-top: 6px; }
.helper-steps { margin: 12px 0 0; padding-left: 1.4em; }
.helper-steps li { margin-bottom: 6px; max-width: 70ch; }
.out .help-text { margin: 0 0 8px; }
.out .helper-steps + .help-text { margin: 8px 0 0; }

/* ---- 예시 표 ---- */
.ex-count { margin: 0 0 10px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ex-count:empty { display: none; }
.ex-notice {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-left: 6px solid var(--blue);
  border-radius: 0 8px 8px 0;
  background: var(--blue-bg);
  color: #173c66;
  font-size: 0.9rem;
}
.ex-notice[hidden] { display: none; }
.ex-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 100%;
}
.ex-table { width: 100%; min-width: 500px; border-collapse: collapse; font-size: 0.92rem; }
.ex-table th, .ex-table td { padding: 9px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
.ex-table tbody tr:last-child th, .ex-table tbody tr:last-child td { border-bottom: 0; }
.ex-table thead th { background: var(--surface-2); font-weight: 700; font-size: 0.85rem; }
.ex-table .c-num { text-align: right; font-variant-numeric: tabular-nums; }
.col-letter { display: inline-block; min-width: 1.4em; margin-right: 6px; color: var(--sub); font-family: var(--mono); font-weight: 600; }
.ex-table .c-state { width: 4.5em; }
.ex-table tr.is-in td:first-child { box-shadow: inset 4px 0 0 var(--green); color: var(--green); font-weight: 700; }
/* 걸러진 행: 회색 배경 + 「빠짐」 글자(흐리게·취소선 아님) */
.ex-table tr.is-out td, .ex-table tr.is-out th { background: var(--out-bg); color: #46525d; }
.ex-table.is-off tbody td { color: #46525d; }
/* 범위 끝 빈 행(r2 H2): 점선 위선으로 데이터 행과 구분 */
.ex-table tr.is-blank td { border-top: 1px dashed #9fb6d1; color: #5b6772; }

/* ---- 도움말 ---- */
.help {
  max-width: 1100px;
  margin: 8px auto 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.help h2 { margin-top: 0; font-size: 1.1rem; }
.help h3 { font-size: 1rem; margin: 28px 0 10px; }
.help p { max-width: 75ch; }
.steps { padding-left: 1.4em; margin: 0; }
.steps li { margin-bottom: 10px; max-width: 75ch; }
.steps strong { display: block; }
.help-list { padding-left: 1.2em; margin: 0; }
.help-list li { margin-bottom: 8px; max-width: 75ch; }
.help-list strong { margin-right: 6px; }
.help details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.help summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.help details p { margin: 8px 0 0; color: var(--sub); }
.sources { list-style: none; margin: 0; padding: 0; }
.sources a { color: var(--accent); display: inline-flex; align-items: center; min-height: 44px; text-underline-offset: 3px; }
.asof { margin: 12px 0 0; font-size: 0.85rem; color: var(--sub); }
.related { margin: 16px 0 0; }
.related a { color: var(--accent); display: inline-flex; align-items: center; min-height: 44px; text-underline-offset: 3px; }

/* ---- 바닥글 ---- */
.site-footer {
  max-width: 1100px;
  margin: 24px auto 0;
  padding: 16px;
  color: var(--sub);
  font-size: 0.85rem;
}
.site-footer .footer-brand { font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.footer-links { list-style: none; padding: 0; display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.footer-links a { color: var(--accent); display: inline-flex; align-items: center; min-height: 44px; }

/* 본문 바로가기·터치 반응·제목 줄바꿈 (형제와 같음) */
.skip { position: absolute; left: 8px; top: -60px; z-index: 10; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none; }
.skip:focus-visible { top: 8px; }
button, a, summary, .chip, select { touch-action: manipulation; -webkit-tap-highlight-color: rgba(31, 95, 174, 0.15); }
h1, h2, h3 { text-wrap: balance; }
#result, #preview { scroll-margin-top: 12px; }

/* ---- 좁은 화면(갤럭시 Z 폴드5 접힘 약 360px · 펼침 약 1,100px 포함): 1279px 까지 한 칸(입력 → 수식 → 예시 표) ---- */
@media (max-width: 1279px) {
  .layout { grid-template-columns: 1fr; }
}
@media (min-width: 560px) {
  .range-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .field-row { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 720px) {
  .cond-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1.2fr); }
  .cond-grid .field { margin-bottom: 0; }
  .cond-grid .f-value { grid-column: auto; }
  .cond-grid .f-value2 { grid-column: auto; }
  .cond-grid .f-value.wide { grid-column: span 2; }
}
/* 1280px 이상에서만 입력·결과를 나란히 */
@media (min-width: 1280px) {
  .to-result { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; max-width: 1240px; }
  .cond-grid { grid-template-columns: 1fr 1fr; }
  .cond-grid .field { margin-bottom: 10px; }
  .cond-grid .f-value, .cond-grid .f-value2 { grid-column: auto; }
  .cond-grid .f-value.wide { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  .chip span, .btn { transition: none; }
}
