/* 아키리토 디자인 v2 — 건축 모형 + 크림슨 (토큰은 디자인 캔버스 그대로) */
:root {
  --ar-bg: #F3F2EF; --ar-surface: #FFFFFF; --ar-surface-2: #FAF9F7; --ar-press: #ECEAE6;
  --ar-text: #111111; --ar-text-2: #4D5157; --ar-text-3: #7A7D83; --ar-body: #2B2D31;
  --ar-line: #E2E0DB; --ar-line-strong: #CFCCC6;
  --ar-accent: #B3263A; --ar-accent-press: #8C1C2D; --ar-accent-tint: #F8E9EB;
  --ar-primary: #111111; --ar-primary-press: #2B2D31;
  --ar-disabled-bg: #E6E4E0; --ar-disabled-fg: #8C8F95;
  --ar-warn: #B45309; --ar-warn-tint: #FDF3E7; --ar-warn-ink: #8A3F06;
  --ar-d0: #B9BBBE; --ar-d0-line: #6E7177;
  --ar-hatch: repeating-linear-gradient(135deg, #B9BBBE 0 2px, #D3D5D7 2px 4px);
  --ar-r-1: 10px; --ar-r-btn: 8px; --ar-r-sheet: 14px;
  --ar-sh-1: 0 1px 2px rgba(17,17,17,.06);
  --ar-sh-2: 0 1px 2px rgba(17,17,17,.08), 0 12px 32px rgba(17,17,17,.12);
  --ar-sh-fab: 0 1px 2px rgba(17,17,17,.1), 0 6px 16px rgba(17,17,17,.1);
  --ar-ls-label: .3em;
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  letter-spacing: -0.01em;
  font-weight: 500;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #E9E9E7; color: var(--ar-text); }
.leaflet-container { font-family: inherit; background: #E9E9E7; }
/* 일반 배경지도는 채도만 살짝 낮춤 (위성은 제외) */
.tile-gray { filter: saturate(.55) brightness(1.03); }
#map { position: absolute; inset: 0; }
#map.selecting { cursor: crosshair; touch-action: none; }
#map.drawing { cursor: crosshair; }
:focus-visible { outline: 2px solid var(--ar-accent); outline-offset: 2px; }

/* ── 툴바 ─────────────────────────────────── */
.toolbar {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); left: calc(60px + env(safe-area-inset-left)); z-index: 1000;
  background: var(--ar-surface); border-radius: var(--ar-r-1); box-shadow: var(--ar-sh-2);
  padding: 14px 16px; width: min(660px, calc(100vw - 160px));
}
.title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.title .logo { display: block; flex: none; }
.title strong { font-size: 20px; font-weight: 800; letter-spacing: -.04em; }
.title .subtitle { font-size: 14px; color: var(--ar-text-2); }
.mlink { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 600; color: var(--ar-accent); text-decoration: none; white-space: nowrap; }
.mlink:hover { color: var(--ar-accent-press); }
.badge { font-size: 12px; font-weight: 600; background: var(--ar-warn-tint); color: var(--ar-warn-ink); padding: 2px 6px; border-radius: var(--ar-r-1); }
.search-row { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.search-row .buttons { flex: none; }
.search { position: relative; display: flex; gap: 6px; flex: 1; min-width: 0; }
.search input {
  flex: 1; min-width: 0; height: 44px; font: inherit; font-size: 14px; padding: 0 14px; border: 0; border-radius: var(--ar-r-btn);
  background: var(--ar-surface-2); box-shadow: inset 0 0 0 1px var(--ar-line-strong); color: var(--ar-text);
}
.search input:focus { outline: 0; background: #fff; box-shadow: inset 0 0 0 1px var(--ar-accent), 0 0 0 3px rgba(179,38,58,.18); }
.search .btn { height: 44px; }
.place-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 10; list-style: none; margin: 0; padding: 4px 0;
  background: var(--ar-surface); border-radius: var(--ar-r-1); box-shadow: var(--ar-sh-2); max-height: 300px; overflow-y: auto;
}
.place-results li { padding: 9px 14px; cursor: pointer; font-size: 14px; }
.place-results li:hover, .place-results li.active { background: var(--ar-press); }
.place-results small { display: block; color: var(--ar-text-2); font-size: 13px; }
.place-results .msg { color: var(--ar-text-2); cursor: default; }
.buttons { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.status { margin-top: 10px; font-size: 13.5px; color: var(--ar-body); min-height: 1.2em; line-height: 1.5; }
.status.error { color: var(--ar-warn-ink); }
.status.error::before {
  content: ""; display: inline-block; width: 13px; height: 13px; margin-right: 6px; vertical-align: -2px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1.5L15 14H1z' fill='none' stroke='%23B45309' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M8 6v4M8 11.6v.4' stroke='%23B45309' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat center / contain;
}

/* ── 버튼: 주 = 검정, 보조 = 흰 바탕 + 선, 선택 = 크림슨 ── */
.btn {
  font: inherit; font-size: 14.5px; font-weight: 600; height: 40px; padding: 0 14px; border-radius: var(--ar-r-btn); cursor: pointer;
  border: 0; background: var(--ar-surface); box-shadow: inset 0 0 0 1px var(--ar-line-strong); color: var(--ar-text); white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--ar-surface-2); box-shadow: inset 0 0 0 1px #B9B6AF; }
.btn:active:not(:disabled) { background: var(--ar-press); }
.btn.active { background: var(--ar-accent-tint); box-shadow: inset 0 0 0 1.5px var(--ar-accent); color: var(--ar-accent-press); }
.btn.primary { background: var(--ar-primary); color: #fff; box-shadow: none; }
.btn.primary:hover:not(:disabled) { background: var(--ar-primary-press); box-shadow: none; }
.btn.ghost { box-shadow: none; color: var(--ar-body); background: transparent; }
.btn:disabled { background: var(--ar-disabled-bg); color: var(--ar-disabled-fg); box-shadow: none; cursor: not-allowed; }
.btn.ghost:disabled { background: transparent; }
.btn.loading { position: relative; color: transparent; }
.btn.loading::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px;
  border: 2px solid #fff; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0;
  border: 0; background: none; cursor: pointer; color: var(--ar-text); border-radius: var(--ar-r-btn);
}
.icon-btn:hover { background: var(--ar-press); }

/* ── 결과 패널 ─────────────────────────────── */
.panel {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 1000; width: 380px;
  background: var(--ar-surface); border-radius: var(--ar-r-1); box-shadow: var(--ar-sh-2);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.panel h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.03em; }

.metric-tabs { display: grid; grid-template-columns: repeat(4, 1fr); margin: 6px 20px 0; box-shadow: inset 0 -1px 0 var(--ar-line); }
.metric-tabs button {
  border-radius: var(--ar-r-btn) var(--ar-r-btn) 0 0; font: inherit; font-weight: 600; height: 48px; padding: 0; border: 0; background: transparent; color: var(--ar-text-2); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 15px; font-weight: 600;
}
.metric-tabs button small { font-size: 10px; font-weight: 600; letter-spacing: .22em; color: var(--ar-text-2); }
.metric-tabs button:hover { background: var(--ar-press); }
.metric-tabs button.on { color: var(--ar-text); font-weight: 800; box-shadow: inset 0 -2.5px 0 var(--ar-accent); }

.stats { border-radius: var(--ar-r-btn); overflow: hidden; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 14px 20px 10px; background: var(--ar-line); box-shadow: 0 0 0 1px var(--ar-line); }
.stat { background: var(--ar-surface); padding: 9px 12px; display: flex; flex-direction: column-reverse; gap: 2px; }
.stat b { display: block; font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--ar-text-2); }
.stat.total { grid-column: 1 / -1; background: var(--ar-bg); padding: 14px 16px; flex-direction: column; gap: 4px; margin-bottom: 1px; }
.stat.total span { color: var(--ar-body); font-weight: 600; font-size: 14px; }
.stat.total b { font-size: 30px; font-weight: 800; letter-spacing: -.04em; color: var(--ar-text); }
.stat.total small { display: block; font-size: 12px; color: var(--ar-text-2); line-height: 1.5; }

.histogram { padding: 4px 20px 10px; }
.hrow { display: grid; grid-template-columns: 84px 1fr 34px; align-items: center; gap: 8px; font-size: 13.5px; margin: 4px 0; cursor: pointer; user-select: none; font-variant-numeric: tabular-nums; }
.hrow:hover span:first-child { color: var(--ar-accent); }
.hrow.off { opacity: .35; }
.hbar { height: 12px; min-width: 2px; }
.hbar.na, .legend i.na, .list .far.na { background: var(--ar-hatch); }
.hcount { text-align: right; color: var(--ar-text-2); }

.list-tools { display: flex; align-items: center; gap: 8px; padding: 12px 20px 8px; border-top: 1px solid var(--ar-line); }
.list-tools::before { content: "BUILDINGS"; font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--ar-text-2); }
.list-tools input { flex: 1; min-width: 0; }
.list-tools input, .list-tools select {
  font: inherit; font-size: 14px; height: 34px; padding: 0 8px; border: 0; border-radius: var(--ar-r-btn);
  background: var(--ar-surface-2); box-shadow: inset 0 0 0 1px var(--ar-line-strong); color: var(--ar-text);
}

.list { list-style: none; margin: 0; padding: 0 20px; overflow-y: auto; flex: 1; }
.list li { border-radius: 6px; display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 6px 0; box-shadow: inset 0 -1px 0 var(--ar-line); cursor: pointer; }
.list li:hover { background: var(--ar-press); }
.list li.note { cursor: default; min-height: 40px; }
.list .far { flex: none; order: 2; margin-left: auto; min-width: 64px; text-align: center; font-weight: 800; font-size: 14px; padding: 3px 6px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.list .far.na { color: #111; }
.list .meta { min-width: 0; flex: 1; }
.list .meta div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; font-weight: 600; }
.list .meta small { color: var(--ar-text-2); font-size: 14px; }

.panel footer { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--ar-line); }
.note { font-size: 12px; color: var(--ar-text-2); line-height: 1.5; }

/* ── 지도 숫자 라벨: 단계색 각진 태그 + 흰 테두리 ── */
.far-label {
  background: var(--c); color: var(--t); border-radius: 5px;
  box-shadow: inset 0 0 0 1px var(--l), 0 0 0 1.5px #fff, 0 1px 4px rgba(17,17,17,.28);
  padding: 0 6px; font-size: 12.5px; line-height: 20px; font-weight: 800; white-space: nowrap;
  transform: translate(-50%, -50%); width: max-content; pointer-events: none; font-variant-numeric: tabular-nums;
}
.far-label.na { --c: #fff; --t: #3A3D42; --l: #8C8F95; font-weight: 600; }
.far-label.pending { --c: #fff; --t: #8C8F95; --l: #CFCCC6; font-weight: 600; }

/* ── 범례 ── */
.legend { background: var(--ar-surface); padding: 14px 16px 16px; border-radius: var(--ar-r-1); box-shadow: var(--ar-sh-2); font-size: 14px; min-width: 200px; font-variant-numeric: tabular-nums; }
.legend .lg-h { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.legend .lg-h b { font-size: 14px; font-weight: 800; }
.legend .lg-h small { font-size: 11px; font-weight: 600; letter-spacing: .25em; color: var(--ar-text-2); }
.legend .lg { display: flex; align-items: center; gap: 10px; line-height: 22px; }
.legend i { display: block; width: 16px; height: 12px; flex: none; }
.label-toggle-unused {
  display: block; width: 100%; margin-top: 10px; font: inherit; font-size: 13.5px; font-weight: 600; height: 34px;
  border: 0; border-radius: var(--ar-r-btn); background: var(--ar-surface); box-shadow: inset 0 0 0 1px var(--ar-line-strong); color: var(--ar-text); cursor: pointer;
}
.label-toggle-unused:hover { background: var(--ar-press); }

/* ── 지도 컨트롤 ── */
.leaflet-bar, .leaflet-control-layers { border: 0 !important; border-radius: var(--ar-r-1) !important; box-shadow: var(--ar-sh-fab) !important; }
.leaflet-bar a { color: var(--ar-text) !important; border-radius: 0 !important; }
.leaflet-control-attribution { font-size: 11px; background: rgba(255,255,255,.75) !important; }

/* ── 건물 팝업 ── */
.leaflet-popup-content-wrapper { border-radius: var(--ar-r-1); box-shadow: 0 1px 2px rgba(17,17,17,.1), 0 14px 34px rgba(17,17,17,.16); }
.leaflet-popup-content { margin: 14px 16px 12px; }
.popup h3 { margin: 0 0 4px; font-size: 16px; font-weight: 800; letter-spacing: -.02em; }
.popup .big { font-size: 24px; font-weight: 800; letter-spacing: -.03em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.popup table { border-collapse: collapse; font-size: 13.5px; }
.popup td { padding: 3px 10px 3px 0; vertical-align: top; box-shadow: inset 0 -1px 0 var(--ar-line); }
.popup td:first-child { color: var(--ar-text-2); white-space: nowrap; }
.popup .src { font-size: 12px; color: var(--ar-text-2); margin-bottom: 6px; }
.popup a { color: var(--ar-accent); }

@media (max-width: 720px) {
  .toolbar { left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top)); width: auto; padding: 12px; }
  .title { gap: 8px; margin-bottom: 10px; }
  .title strong { font-size: 18px; white-space: nowrap; }
  .title .subtitle { display: none; }
  .buttons .btn { flex: 1 1 auto; padding: 0 10px; }
  .legend { min-width: 0; padding: 10px 12px; font-size: 12px; }
  .legend .lg { line-height: 18px; }

  .leaflet-control-zoom { display: none; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 48vh; border-radius: var(--ar-r-sheet) var(--ar-r-sheet) 0 0; padding-bottom: env(safe-area-inset-bottom); }
}

/* ── 설정 창 ─────────────────────────────── */
.settings { border: 0; border-radius: var(--ar-r-1); box-shadow: var(--ar-sh-2); padding: 24px; width: min(460px, calc(100vw - 32px)); color: var(--ar-text); background: var(--ar-surface); }
.settings::backdrop { background: rgba(17, 17, 17, .4); }
.settings h2 { margin: 0 0 4px; font-size: 22px; font-weight: 800; letter-spacing: -.035em; }
.set-sec { border-top: 1px solid var(--ar-line); margin-top: 16px; padding-top: 14px; }
.set-sec h3 { margin: 0 0 8px; font-size: 14px; font-weight: 700; color: var(--ar-text-2); }
.account { display: grid; gap: 8px; font-size: 14px; }
.account .who { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.account img { width: 28px; height: 28px; border-radius: 50%; }
.account .quota { color: var(--ar-text); }
.account .muted { color: var(--ar-text-2); font-size: 13.5px; }
.account .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.account a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.site-links { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14.5px; }
.site-links a { color: var(--ar-body); text-decoration: none; }
.site-links a:hover { color: var(--ar-accent); text-decoration: underline; }
.settings label { display: block; font-size: 14px; font-weight: 600; margin-top: 12px; }
.settings label a { font-size: 13px; font-weight: 600; color: var(--ar-accent); margin-left: 4px; }
.settings label small { color: var(--ar-text-2); font-weight: 500; }
.settings input {
  display: block; width: 100%; margin-top: 6px; font: inherit; font-size: 14px; height: 44px; padding: 0 12px; border: 0; border-radius: var(--ar-r-btn);
  background: var(--ar-surface-2); box-shadow: inset 0 0 0 1px var(--ar-line-strong); color: var(--ar-text);
}
.settings input:focus { outline: 0; background: #fff; box-shadow: inset 0 0 0 1px var(--ar-accent), 0 0 0 3px rgba(179,38,58,.18); }
.settings .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
#settingsBtn { margin-left: auto; }

/* ── 오른쪽 위 둥근 버튼 (휴대폰 화면과 같은 배치) ── */
.fabs { position: absolute; z-index: 1000; top: calc(16px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 10px; transition: right .2s; }
.panel:not([hidden]) ~ .fabs { right: calc(16px + 380px + 12px + env(safe-area-inset-right)); }
.fab {
  width: 56px; height: 56px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--ar-surface); color: var(--ar-text); box-shadow: var(--ar-sh-fab);
}
.fab span { font-size: 10.5px; font-weight: 700; line-height: 1.1; }
.fab:hover { background: var(--ar-press); }
.fab.active { background: var(--ar-primary); color: #fff; }
.fab.active:hover { background: var(--ar-primary-press); }
.fab .ic-label { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 19px; padding: 0 3px; border: 1.6px solid currentColor; border-radius: 4px; font-size: 13px; font-weight: 800; line-height: 1; }
@media (max-width: 720px) {
  .search-row { flex-wrap: wrap; }
  .search-row .buttons { flex: 1 1 100%; }
  .fabs { top: auto; bottom: calc(50vh + 12px); right: 12px; }
  .panel:not([hidden]) ~ .fabs { right: 12px; }
}
