@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=IBM+Plex+Sans+KR:wght@400;500;600;700&display=swap");

/* =============================================================================
 * styles.css — 기계설비 범례 검색기
 * 색/간격은 :root 토큰만 바꾸면 전체 테마가 바뀝니다.
 * ========================================================================== */

:root {
  --bg:        #f4f6f8;
  --surface:   #ffffff;
  --surface-2: #eef1f5;
  --ink:       #16202c;
  --ink-2:     #5a6a7a;
  --ink-3:     #93a1b0;
  --line:      #d7dee6;
  --line-2:    #c2cbd6;
  --accent:    #0b6fd4;
  --accent-bg: #e5f0fd;
  --accent-ink:#ffffff;
  --hit:       #ff8a00;
  --hit-bg:    #fff4e3;
  --star:      #f5a623;
  --nav:       #2c4a7d;   /* 상단 바 */
  --nav-badge: #1d3560;   /* 로고 배지 */
  --nav-edge:  #1b3157;   /* 바 아래 경계 */
  --radius:    12px;
  --shadow:    0 1px 2px rgba(16,32,48,.06), 0 6px 20px rgba(16,32,48,.06);
  /* IBM Plex — 기술문서용으로 설계된 서체. 도면 주기(annotation)의 결을 그대로 씁니다.
     오프라인이면 시스템 한글 서체로 자연스럽게 폴백됩니다. */
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "D2Coding", monospace;
  --sans: "IBM Plex Sans KR", "Pretendard", -apple-system, BlinkMacSystemFont,
          "Segoe UI", "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", Roboto, sans-serif;
}

/* 다크 팔레트 — 명시적 선택(data-theme="dark")과 시스템 설정 양쪽에 적용.
   앱 초기화 시 JS 가 data-theme 을 확정하지만, 첫 페인트 깜빡임을 막기 위해
   prefers-color-scheme 블록을 함께 둡니다. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --nav:       #1e3459;
    --nav-badge: #142642;
    --nav-edge:  #0d1c33;
    --bg:        #0e1319;
    --surface:   #161d26;
    --surface-2: #1e2732;
    --ink:       #e6edf5;
    --ink-2:     #9fb0c2;
    --ink-3:     #6b7d8f;
    --line:      #29333f;
    --line-2:    #3a4757;
    --accent:    #4d9dff;
    --accent-bg: #16283f;
    --accent-ink:#08111c;
    --hit:       #ffa53d;
    --hit-bg:    #2e2314;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

:root[data-theme="dark"] {
  --nav:       #1e3459;
  --nav-badge: #142642;
  --nav-edge:  #0d1c33;
  --bg:        #0e1319;
  --surface:   #161d26;
  --surface-2: #1e2732;
  --ink:       #e6edf5;
  --ink-2:     #9fb0c2;
  --ink-3:     #6b7d8f;
  --line:      #29333f;
  --line-2:    #3a4757;
  --accent:    #4d9dff;
  --accent-bg: #16283f;
  --accent-ink:#08111c;
  --hit:       #ffa53d;
  --hit-bg:    #2e2314;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

/* ── 헤더 ─────────────────────────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1360px; margin: 0 auto; padding: 12px 20px 0; }

/* 상단 네이비 바 — 로고 배지 + 제목 + 동작 버튼.
   버튼 색은 흰색 알파로 얹어 라이트/다크 어느 쪽에서도 같은 결을 냅니다. */
.navbar {
  background: var(--nav);
  border-bottom: 1px solid var(--nav-edge);
  color: #fff;
}
.navbar-in {
  max-width: 1360px; margin: 0 auto; padding: 9px 20px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.navbar .spacer { flex: 1 1 auto; }

.logo {
  flex: none; width: 38px; height: 38px; border-radius: 10px;
  background: var(--nav-badge); border: 1.5px solid rgba(255, 255, 255, .45);
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 600; font-size: 14px; letter-spacing: .04em;
}

.navbar h1 {
  margin: 0; color: #fff; font-weight: 700; line-height: 1.25;
  font-size: clamp(18px, 1.9vw, 23px); letter-spacing: -.02em;
}

.navacts { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.navbtn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 13px; border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .36);
  background: rgba(255, 255, 255, .10); color: #fff;
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.navbtn:hover { background: rgba(255, 255, 255, .21); border-color: rgba(255, 255, 255, .62); }
.navbtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.navbtn .ic { font-size: 14px; line-height: 1; }
.navbtn.icon { width: 36px; padding: 0; justify-content: center; font-size: 15px; }
/* 즐겨찾기 필터가 켜진 상태 */
.navbtn.on { background: #fff; border-color: #fff; color: var(--nav); }
.navbtn.on:hover { background: #fff; }

.iconbtn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  display: inline-grid; place-items: center; color: var(--ink-2);
  background: var(--surface); font-size: 15px; transition: .15s;
}
.iconbtn:hover { border-color: var(--line-2); color: var(--ink); }
.iconbtn.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

/* ── 검색바 ───────────────────────────────────────────────────────────── */
.searchrow { display: flex; gap: 10px; align-items: center; margin: 12px 0; }
.searchrow .search { flex: 1 1 auto; }

.search {
  flex: 1 1 auto; position: relative;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 11px; padding: 0 12px; height: 46px;
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.search svg { flex: none; color: var(--ink-3); }
.search input {
  flex: 1 1 auto; border: none; outline: none; background: none;
  font-size: 15.5px; min-width: 0;
}
.search input::placeholder { color: var(--ink-3); }
.search .clear { color: var(--ink-3); font-size: 18px; padding: 0 4px; line-height: 1; }
.search .clear:hover { color: var(--ink); }
.search kbd {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  border: 1px solid var(--line); border-radius: 5px; padding: 2px 6px;
}

/* ── 탭 ───────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 9px 14px 11px; font-size: 14px; font-weight: 600;
  color: var(--ink-2); border-bottom: 2.5px solid transparent; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; transition: .15s;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab .n {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  background: var(--surface-2); border-radius: 20px; padding: 1px 7px;
}
.tab[aria-selected="true"] .n { background: var(--accent-bg); color: var(--accent); }

/* ── 본문 ─────────────────────────────────────────────────────────────── */
main { max-width: 1360px; margin: 0 auto; padding: 18px 20px 80px; }

.statusbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 13px; color: var(--ink-2); margin-bottom: 12px; min-height: 24px;
}
.statusbar b { color: var(--ink); font-variant-numeric: tabular-nums; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent-bg); color: var(--accent);
  border-radius: 20px; padding: 2px 10px; font-size: 12px; font-weight: 600;
}
.chip button { color: inherit; opacity: .7; font-size: 13px; line-height: 1; }
.chip button:hover { opacity: 1; }

.grouphead {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 700; color: var(--ink-2);
  margin: 22px 0 10px; letter-spacing: .02em;
}
.grouphead-line { flex: 1 1 auto; height: 1px; background: var(--line); }
.groupsub { font-family: var(--mono); font-weight: 400; color: var(--ink-3); font-size: 11.5px; }

/* ── 카드 그리드 ──────────────────────────────────────────────────────── */
.grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
}

.card {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 13px 11px;
  transition: transform .22s cubic-bezier(.2,.8,.3,1), box-shadow .22s, border-color .15s;
  cursor: pointer; text-align: left; width: 100%;
  display: flex; flex-direction: column; gap: 9px;
}
.card:hover { border-color: var(--line-2); box-shadow: var(--shadow); transform: translateY(-1px); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 검색 적중 카드 : 확대 + 강조 */
.card.hit {
  border-color: var(--hit); box-shadow: 0 0 0 3px var(--hit-bg), var(--shadow);
  transform: scale(1.045); z-index: 2;
}
[data-theme="dark"] .card.hit { box-shadow: 0 0 0 3px var(--hit-bg), var(--shadow); }
@keyframes pop { 0% { transform: scale(1); } 55% { transform: scale(1.09); } 100% { transform: scale(1.045); } }
.card.pop { animation: pop .45s cubic-bezier(.2,.9,.3,1); }

.symbox {
  background: var(--surface-2); border-radius: 8px; height: 62px;
  display: grid; place-items: center; padding: 6px 10px; overflow: hidden;
}
.card.hit .symbox { background: var(--hit-bg); }

/* 기호 SVG.
   .pdf  = 원본 도면에서 그대로 가져온 도형. fill/stroke 가 path 속성에 들어 있고
           검정은 currentColor 로 치환돼 있으므로 CSS 로 덮어쓰지 않는다.
   .badge = 원본에 기호가 없는 항목의 약어 대체 표시. */
svg.sym { display: block; width: 100%; height: 100%; color: var(--ink); margin: auto; }
svg.sym.pdf text { font-family: var(--sans); }
/* 원본 도면 크기(--w/--h, 단위 pt)의 4배까지만 확대한다. 기호가 '-' 하나뿐인 항목이
   카드를 가득 채우지 않도록. 상세 보기에서는 조금 더 크게 허용. */
svg.sym.pdf { max-width: calc(var(--w, 160) * 4px); max-height: calc(var(--h, 40) * 4px); }
.detail-sym svg.sym.pdf { max-width: calc(var(--w, 160) * 8px); max-height: calc(var(--h, 40) * 8px); }
svg.sym.badge rect { fill: none; stroke: var(--line-2); stroke-dasharray: 4 4; }
svg.sym.badge text { fill: var(--ink-3); stroke: none; font-family: var(--mono); font-weight: 600; }

.names { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ko { font-size: 14.5px; font-weight: 650; letter-spacing: -.01em; line-height: 1.35; }
.en { font-size: 12px; color: var(--ink-2); line-height: 1.35; word-break: break-word; }

.meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.abbr {
  font-family: var(--mono); font-size: 11.5px; font-weight: 700;
  background: var(--accent-bg); color: var(--accent);
  border-radius: 5px; padding: 2px 7px; letter-spacing: .01em;
}
.abbr.none { background: var(--surface-2); color: var(--ink-3); font-weight: 400; }
.note { font-size: 11.5px; color: var(--ink-3); }
.note::before { content: "※ "; }

.star {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px;
  border-radius: 7px; display: grid; place-items: center;
  color: var(--ink-3); font-size: 14px; opacity: 0; transition: .15s;
}
.card:hover .star, .star.on { opacity: 1; }
.star:hover { background: var(--surface-2); color: var(--star); }
.star.on { color: var(--star); }

mark { background: var(--hit-bg); color: inherit; border-radius: 3px; padding: 0 1px; box-shadow: inset 0 -.45em 0 var(--hit-bg); }
[data-theme="dark"] mark { background: #4a3a1a; }

/* ── 빈 상태 ──────────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 70px 20px; color: var(--ink-3); }
.empty .big { font-size: 34px; margin-bottom: 10px; }
.empty h3 { color: var(--ink-2); font-size: 15px; margin: 0 0 6px; }
.empty p { margin: 0; font-size: 13px; }

/* ── 부속류 표기 규칙 배너 ────────────────────────────────────────────── */
.rulebox {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 13px 16px; margin-bottom: 16px; font-size: 13px; color: var(--ink-2);
}
.rulebox h4 { margin: 0 0 7px; font-size: 13px; color: var(--ink); }
.rulebox p { margin: 0 0 4px; line-height: 1.55; }
/* 이음 종류 그림 — 원본 시트 상단의 도해를 통째로 사용 */
.joints {
  background: var(--surface-2); border-radius: 8px; padding: 12px 16px; margin-top: 12px;
  overflow-x: auto;
}
.joints svg.sym { height: 78px; min-width: 460px; }

/* ── 모달 공통 ────────────────────────────────────────────────────────── */
.scrim {
  position: fixed; inset: 0; z-index: 100; background: rgba(10,18,28,.5);
  backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  width: min(620px, 100%); max-height: 90vh; overflow: auto;
  border: 1px solid var(--line); animation: rise .2s cubic-bezier(.2,.8,.3,1);
}
@keyframes rise { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.modal.wide { width: min(880px, 100%); }
.modal-head {
  display: flex; align-items: center; gap: 10px; padding: 15px 18px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 15.5px; font-weight: 700; flex: 1 1 auto; }
.modal-body { padding: 18px; }

/* 상세 보기 */
.detail-sym {
  background: var(--surface-2); border-radius: 12px; padding: 22px;
  display: grid; place-items: center; margin-bottom: 18px;
}
.detail-sym svg.sym { width: 100%; max-width: 420px; height: 110px; }
.dl { display: grid; grid-template-columns: 92px 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.dl dt, .dl dd { background: var(--surface); margin: 0; padding: 10px 13px; font-size: 13.5px; }
.dl dt { color: var(--ink-2); font-weight: 600; font-size: 12.5px; }
.dl dd { word-break: break-word; }
.dl dd.code { font-family: var(--mono); font-weight: 600; }
.detail-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 9px;
  padding: 8px 14px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); transition: .15s;
}
.btn:hover { border-color: var(--line-2); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Vision 패널 ──────────────────────────────────────────────────────── */
.drop {
  border: 2px dashed var(--line-2); border-radius: 12px; padding: 30px 20px;
  text-align: center; color: var(--ink-2); transition: .15s; cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
.drop .big { font-size: 30px; margin-bottom: 8px; }
.drop .t { font-weight: 650; font-size: 14.5px; color: var(--ink); margin-bottom: 4px; }
.drop.over .t { color: var(--accent); }
.drop .s { font-size: 12.5px; }

.preview { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.preview .thumb {
  width: 140px; height: 100px; flex: none; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; display: grid; place-items: center; overflow: hidden;
}
.preview .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview .side { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--ink-2); }

.modehint { font-size: 12.5px; color: var(--ink-3); margin: 10px 0 14px; line-height: 1.6; }
.keyrow { display: flex; gap: 8px; margin-top: 10px; }
.keyrow input {
  flex: 1 1 auto; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; background: var(--surface-2); font-family: var(--mono); font-size: 12.5px; outline: none;
}
.keyrow input:focus { border-color: var(--accent); }

.matches { display: flex; flex-direction: column; gap: 8px; }
.match {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--surface);
  transition: .15s;
}
.match:hover { border-color: var(--accent); background: var(--accent-bg); }
.match .msym { width: 100px; height: 40px; flex: none; background: var(--surface-2); border-radius: 6px; display: grid; place-items: center; padding: 3px 6px; }
.match .mtxt { flex: 1 1 auto; min-width: 0; }
.match .mko { font-size: 13.5px; font-weight: 650; }
.match .men { font-size: 11.5px; color: var(--ink-3); }
.match .mscore {
  flex: none; font-family: var(--mono); font-size: 11.5px; font-weight: 700;
  color: var(--accent); background: var(--accent-bg); border-radius: 20px; padding: 3px 9px;
}
.match .mscore.low { color: var(--ink-3); background: var(--surface-2); }

.spin { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }

.errbox { background: #fdecec; color: #a3241f; border-radius: 9px; padding: 10px 13px; font-size: 12.5px; margin-top: 10px; }
[data-theme="dark"] .errbox { background: #3a1a19; color: #ff9b95; }

/* ── 토스트 ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 20px;
  font-size: 13.5px; font-weight: 600; z-index: 200; box-shadow: var(--shadow);
  animation: toastin .25s cubic-bezier(.2,.8,.3,1);
}
@keyframes toastin { from { transform: translate(-50%, 12px); opacity: 0; } }

/* ── 반응형 ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .top-in, main { padding-left: 13px; padding-right: 13px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); gap: 8px; }
  /* 좁은 화면에서는 상단 바 버튼을 아이콘만 남겨 한 줄에 들어가게 합니다 */
  .navbar-in { gap: 9px; padding: 8px 14px; }
  .navbtn { padding: 0 10px; font-size: 0; gap: 0; }
  .navbtn .ic { font-size: 15px; }
  .navbtn.icon { font-size: 15px; }
  .logo { width: 33px; height: 33px; font-size: 12.5px; }
  .search kbd { display: none; }
  .preview { flex-direction: column; }
  .preview .thumb { width: 100%; }
  .dl { grid-template-columns: 78px 1fr; }
}

@media print {
  .top, .navbar, .star, .scrim { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
  .grid { grid-template-columns: repeat(3, 1fr); }
}
