/* 멸종위기종 서식지 분석 — 청록 헤더, 차분한 바탕, 지도 중심 */
:root {
  --bg: #f2f5f4; --surface: #ffffff; --surface-2: #f6f8f8; --border: #dfe6e5; --border-strong: #c5d1cf;
  --text: #1b2a2a; --text-2: #48595a; --muted: #6f7f80; --primary: #0b7285; --primary-hover: #095c6b; --link: #0b6475;
  --header: #0f3a3f; --row-hover: #f1f6f6; --shadow: 0 1px 2px rgba(20, 40, 25, .06), 0 2px 8px rgba(20, 40, 25, .06);
  --radius: 10px; --font: "Noto Sans KR", -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-family: var(--font); color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101718; --surface: #182122; --surface-2: #1f2a2b; --border: #2b3839; --border-strong: #3a4a4b;
    --text: #e2eaea; --text-2: #b1c0c0; --muted: #8d9d9e; --primary: #1098ad; --primary-hover: #15aabf; --link: #66d9e8;
    --header: #0a2427; --row-hover: #1d2829; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101718; --surface: #182122; --surface-2: #1f2a2b; --border: #2b3839; --border-strong: #3a4a4b;
  --text: #e2eaea; --text-2: #b1c0c0; --muted: #8d9d9e; --primary: #1098ad; --primary-hover: #15aabf; --link: #66d9e8;
  --header: #0a2427; --row-hover: #1d2829; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; display: flex; flex-direction: column; }
a { color: var(--link); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--header); color: #fff; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand svg { width: 30px; height: 30px; color: #3bc9db; flex: none; }
.brand strong { display: block; font-size: 16px; }
.brand small { display: block; font-size: 11px; color: rgba(255, 255, 255, .7); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { color: rgba(255, 255, 255, .85); text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 500; }
.tab:hover { background: rgba(255, 255, 255, .1); }
.tab.active { background: rgba(255, 255, 255, .16); color: #fff; }

main { flex: 1; min-height: 0; display: flex; }
.view { display: none; flex: 1; min-width: 0; }
.view.active { display: flex; }
#view-map.active { min-height: 0; }
.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; overflow: auto; }
.page.narrow { max-width: 820px; }
#view-about { overflow: auto; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h3 { margin: 0 0 10px; font-size: 15px; }

.input { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 10px; font: inherit; min-width: 0; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 8px; padding: 7px 12px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-light { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-light:hover { background: var(--surface-2); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.link { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; font: inherit; text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--text-2); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 14px 0; box-shadow: var(--shadow); }
.plain { margin: 0; padding-left: 18px; line-height: 1.7; }

/* 지도 공통 */
.search-results { border: 1px solid var(--border); border-radius: 8px; max-height: 280px; overflow: auto; }
.search-results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 10px; cursor: pointer; font: inherit; }
.search-results button:hover { background: var(--row-hover); }
.search-results small { display: block; color: var(--muted); }
.search-results .kind { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; margin-left: 4px; white-space: nowrap; }
.tiles-muted { filter: saturate(.55) brightness(1.04); }
.leaflet-popup-content { font-family: var(--font); font-size: 13px; margin: 12px 14px; min-width: 200px; }
.leaflet-container { font-family: var(--font); }

/* 목록·표 */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; cursor: pointer; user-select: none; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--row-hover); }
.table td.wrap { white-space: normal; min-width: 200px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.pager { display: flex; gap: 6px; justify-content: center; align-items: center; margin-top: 12px; flex-wrap: wrap; }

/* 사업지 분석 */
#view-impact.active { min-height: 0; }
.an-side { width: 360px; flex: none; background: var(--surface); border-right: 1px solid var(--border); overflow: auto; display: flex; flex-direction: column; }
.an-step { padding: 12px 14px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.an-step h3 { display: flex; align-items: center; gap: 8px; margin: 0; }
.an-step h3 .link-row { margin-left: auto; font-weight: 400; }
.an-step .num { width: 20px; height: 20px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 12px; display: inline-grid; place-items: center; flex: none; }
.an-go { position: sticky; bottom: 0; margin-top: auto; background: var(--surface); border-top: 1px solid var(--border); border-bottom: 0; z-index: 2; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.wide { width: 100%; justify-content: center; }
.nowrap { white-space: nowrap; }
.pad { padding: 8px 10px; margin: 0; }
.seg { display: flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-right: 1px solid var(--border); background: var(--surface); color: var(--text-2); padding: 7px 2px; font: inherit; font-size: 12.5px; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface-2); }
.seg button.on { background: var(--primary); color: #fff; }
.an-pane { display: grid; gap: 8px; }
.an-pane[hidden] { display: none; }
.an-pane p { margin: 0; line-height: 1.55; }
textarea.input { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.btn-light.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn:disabled { opacity: .55; cursor: default; }
.draw-bar { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.drop { display: grid; gap: 4px; justify-items: center; text-align: center; padding: 18px 10px; border: 2px dashed var(--border-strong); border-radius: 10px; cursor: pointer; background: var(--surface-2); }
.drop:hover, .drop.over { border-color: var(--primary); background: var(--row-hover); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.an-site { border: 1px solid var(--border); border-left: 4px solid #f59f00; border-radius: 8px; padding: 8px 10px; background: var(--surface-2); display: grid; gap: 4px; font-size: 13px; }
.an-site[hidden] { display: none; }
.an-site-head { display: flex; justify-content: space-between; align-items: center; }
.an-site select { margin-left: 4px; max-width: 220px; padding: 4px 6px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
#an-radius { width: 90px; }
.an-types { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.an-types .layer-group-title { grid-column: 1 / -1; margin: 6px 0 2px; }
.an-types label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 0; cursor: pointer; }
.an-types .swatch { width: 11px; height: 11px; border-radius: 2px; flex: none; border: 1px solid rgba(0, 0, 0, .2); }
.progress { display: grid; gap: 4px; }
.progress[hidden] { display: none; }
.progress .bar { height: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.an-main { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; }
.an-map-wrap { position: relative; height: 58vh; min-height: 340px; flex: none; }
#an-map { position: absolute; inset: 0; background: #dfe7e2; }
#an-map.drawing { cursor: crosshair; }
.an-result { padding: 16px; width: 100%; max-width: 1280px; }
.an-result h2 { font-size: 18px; margin: 0 0 4px; }
.an-result h3 { margin: 18px 0 8px; }
.an-rows-wrap { max-height: 560px; }
.an-empty p { margin: 4px 0; line-height: 1.6; }
.an-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 12px 0; }
.an-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.an-card b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.an-card span { color: var(--muted); font-size: 12px; }
.an-card.warn { border-color: #f08c00; }
.an-card.warn b { color: #e8590c; }
.an-dl { display: grid; gap: 10px; }
.check { display: inline-flex; align-items: center; gap: 5px; margin-right: 10px; cursor: pointer; }
.check select { padding: 4px 6px; }
.note { background: rgba(255, 146, 43, .12); color: #d9480f; border: 1px solid rgba(255, 146, 43, .45); border-radius: 8px; padding: 8px 12px; }
.an-sum tbody tr { cursor: default; }
.hit { color: #e8590c; }
.rel { font-size: 12px; white-space: nowrap; }
.rel-hit { color: #fff; background: #e8590c; border-radius: 999px; padding: 1px 8px; }
.table tr.sel { background: var(--row-hover); box-shadow: inset 3px 0 0 var(--primary); }
.pop-dist { font-weight: 700; color: #c2255c; margin-bottom: 6px; }
.leaflet-tooltip.dist-tip { background: #c2255c; color: #fff; border: 0; font-weight: 700; font-family: var(--font); box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.leaflet-tooltip.dist-tip::before { display: none; }

.inapp-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #fff3bf; color: #5c3c00; font-size: 13px; }
.inapp-bar[hidden] { display: none; }
.inapp-bar span { flex: 1; }
.inapp-bar .icon-btn { color: #5c3c00; font-size: 15px; }
.dl-sheet .btn { flex: 1; justify-content: center; }
.dl-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 2100; padding: 12px; display: flex; justify-content: center; }
.dl-sheet-body { width: 100%; max-width: 520px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: 0 -2px 18px rgba(0, 0, 0, .18); display: grid; gap: 10px; }
.dl-sheet-body .small { word-break: break-all; }
.dl-sheet-note { margin: 0; color: var(--text-2); line-height: 1.5; }
.dl-sheet .btn-primary { flex: 1; justify-content: center; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2a20; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 2000; box-shadow: var(--shadow); }
.only-mobile { display: none; }

@media (max-width: 760px) {
  .only-mobile { display: inline-flex; }
  .brand small { display: none; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .tab { padding: 6px 9px; }
  #view-impact.active { flex-direction: column; overflow: auto; }
  .an-side { width: auto; border-right: 0; overflow: visible; }
  .an-main { overflow: visible; }
  .an-go { position: static; }
  .an-map-wrap { height: 60vh; }
  .an-result { padding: 14px 16px; }
}

/* 종 정보 */
#view-species.active { min-height: 0; }
.sp-side { width: 330px; flex: none; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.sp-filter { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.sp-filter .row select { flex: 1; }
.sp-count { padding: 6px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.sp-list { flex: 1; overflow: auto; min-height: 0; }
.sp-item { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; cursor: pointer; font: inherit; text-decoration: none; }
.sp-item:hover { background: var(--row-hover); }
.sp-item.on { background: var(--row-hover); box-shadow: inset 3px 0 0 var(--primary); }
.sp-item img, .sp-item .noimg { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface-2); }
.sp-item b { font-weight: 600; }
.sp-item small { display: block; color: var(--muted); font-size: 11.5px; font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-main { flex: 1; min-width: 0; overflow: auto; }
.sp-detail { max-width: 1180px; margin: 0 auto; padding: 18px 16px 48px; }
.sp-empty { padding: 40px 24px; max-width: 640px; line-height: 1.7; }
.sp-head { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: start; }
.sp-photo { width: 150px; height: 150px; border-radius: var(--radius); object-fit: cover; background: var(--surface-2); display: block; }
.sp-photo-cap { font-size: 10.5px; color: var(--muted); margin-top: 4px; line-height: 1.35; word-break: break-all; }
.sp-head h1 { margin: 0 0 2px; }
.sp-sci { font-style: italic; color: var(--text-2); margin-bottom: 8px; }
.badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge.en1 { background: #c92a2a; color: #fff; border-color: #c92a2a; }
.badge.en2 { background: #e8590c; color: #fff; border-color: #e8590c; }
.badge.nm { background: #5f3dc4; color: #fff; border-color: #5f3dc4; }
.badge.absent { background: #495057; color: #fff; border-color: #495057; }
.sp-links { margin-top: 10px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.sp-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; margin-top: 16px; }
.sp-map-wrap { position: relative; height: 520px; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.sp-map { position: absolute; inset: 0; background: #dfe7e2; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; }
.facts dt { color: var(--muted); white-space: nowrap; }
.facts dd { margin: 0; line-height: 1.55; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.tag.warn { border-color: rgba(232, 89, 12, .45); color: #d9480f; background: rgba(255, 146, 43, .1); }
.bars { display: grid; gap: 5px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 40px; gap: 8px; align-items: center; font-size: 12.5px; }
.bar-row .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.bar-row .track i { display: block; height: 100%; background: var(--primary); }
.bar-row .v { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.measures { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.measures li { display: grid; grid-template-columns: 52px 1fr; gap: 10px; line-height: 1.55; }
.measures .stage { font-size: 11.5px; font-weight: 700; border-radius: 6px; text-align: center; padding: 2px 0; height: fit-content; color: #fff; }
.stage.s-avoid { background: #1971c2; } .stage.s-min { background: #0b7285; } .stage.s-comp { background: #5f3dc4; } .stage.s-mon { background: #495057; }
.legend { position: absolute; z-index: 500; right: 10px; bottom: 26px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); display: grid; gap: 3px; }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(0, 0, 0, .15); }
.legend .rec { width: 10px; height: 10px; border: 2px solid #d6336c; background: transparent; }
.map-toggles { position: absolute; z-index: 500; left: 10px; bottom: 26px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: var(--shadow); display: grid; gap: 2px; }
.grade { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 1px 9px; white-space: nowrap; color: #fff; }
.g-high { background: #c92a2a; } .g-mid { background: #e8590c; } .g-low { background: #868e96; }
.method { font-size: 11px; color: var(--muted); }
.im-detail { margin-top: 16px; }
.im-detail .panel { margin: 0 0 12px; }
.im-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.im-sp-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.cover-bar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; border: 1px solid var(--border); margin: 6px 0 4px; }
.cover-bar i { display: block; height: 100%; }
.cover-key { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.cover-key i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.about h2 { font-size: 17px; margin: 22px 0 8px; }
.about p, .about li { line-height: 1.7; }
.sp-back { display: none; }

@media (max-width: 980px) {
  .sp-grid { grid-template-columns: 1fr; }
  .im-cols { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  #view-species.active { flex-direction: column; }
  .sp-side { width: auto; border-right: 0; flex: 1; }
  #view-species.detail .sp-side { display: none; }
  #view-species:not(.detail) .sp-main { display: none; }
  .sp-back { display: inline-flex; margin-bottom: 10px; }
  .sp-head { grid-template-columns: 96px 1fr; gap: 12px; }
  .sp-photo { width: 96px; height: 96px; }
  .sp-map-wrap { height: 62vh; }
  .sp-detail { padding: 14px 16px 40px; }
}
