:root {
  --bg: #f4f6f9; --surface: #fff; --text: #1d2733; --muted: #6b7785; --line: #dde3ea;
  --primary: #1f5fae; --primary-text: #fff; --danger: #c0392b; --warn: #e6a100; --top: #1f3a5f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.pad { padding: 16px; }
.err { color: var(--danger); min-height: 1em; }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 12px;
  border-radius: 8px; font-size: 14px; cursor: pointer; margin: 2px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 8px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; }
input, select, textarea { font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); width: 100%; }
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0; }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.card h3 { margin-top: 0; }

/* 로그인 */
.screen { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 22px; margin: 0 0 8px; }
.login-card .btn { width: 100%; margin-top: 12px; padding: 12px; }

/* 상단 */
#main { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; background: var(--top); color: #fff; padding: 0 12px;
  height: 48px; flex-shrink: 0; }
.brand { font-weight: 700; white-space: nowrap; }
#tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
#tabs button { background: none; border: 0; color: #c9d6e6; padding: 14px 10px; font-size: 15px; cursor: pointer;
  white-space: nowrap; border-bottom: 3px solid transparent; }
#tabs button.active { color: #fff; border-bottom-color: #7fb3ff; }
.user { font-size: 13px; white-space: nowrap; }
.view { display: none; flex: 1; overflow: auto; position: relative; }
.view.active { display: block; }
#view-map.active { display: block; overflow: hidden; }
#map { position: absolute; inset: 0; }

/* 지도 오버레이 */
.map-search { position: absolute; top: 10px; left: 56px; right: 10px; max-width: 360px; z-index: 500; }
.map-search input { box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.fab-col { position: absolute; right: 12px; bottom: 90px; z-index: 500; display: flex; flex-direction: column; gap: 10px; }
.fab { width: 52px; height: 52px; border-radius: 50%; border: 0; background: #fff; font-size: 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,.3); cursor: pointer; }
.fab.primary { background: var(--primary); color: #fff; }
.legend { position: absolute; left: 10px; bottom: 24px; z-index: 500; background: rgba(255,255,255,.92);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; color: #222; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.legend i.ring { border: 2px solid var(--warn); background: #fff; }
.movebar { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 700;
  background: #fff; padding: 8px 12px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.3); font-size: 14px;
  width: max-content; max-width: calc(100% - 32px); }

/* 상세 패널: 데스크톱=오른쪽, 모바일=하단 시트 */
.panel { position: absolute; z-index: 600; background: var(--surface); overflow-y: auto;
  top: 0; right: 0; bottom: 0; width: 400px; box-shadow: -2px 0 12px rgba(0,0,0,.2); padding: 16px; }
.panel-close { position: relative; float: right; margin: -4px -4px 0 8px; border: 0; background: var(--bg); border-radius: 50%;
  width: 32px; height: 32px; font-size: 16px; cursor: pointer; z-index: 2; }
@media (max-width: 720px) {
  .panel { top: auto; left: 0; width: 100%; max-height: 62%; border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 12px rgba(0,0,0,.25); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .brand { display: none; }
  .user #userName { display: none; }
  .fab-col { bottom: 70px; }
}
.pole-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; color: #fff; margin-right: 4px; }
.badge.MV { background: #d6402b; } .badge.LV { background: #2b7bd6; }
.badge.st { background: #7a8794; } .badge.st.warn { background: var(--warn); }
.section { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.section h4 { margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 8px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0;
  border-bottom: 1px dashed var(--line); gap: 8px; }
.item:last-child { border-bottom: 0; }
.item .sub { font-size: 12px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.photos { display: flex; gap: 6px; flex-wrap: wrap; }
.photos img { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; cursor: pointer; }
.hist { font-size: 12px; color: var(--muted); padding: 4px 0; border-bottom: 1px dotted var(--line); }

/* 목록 */
.list-head { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; align-items: center;
  position: sticky; top: 0; background: var(--bg); z-index: 2; }
.list-head select, .list-head input { width: auto; flex: 1 1 140px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 12px; cursor: pointer; font-size: 14px; color: var(--text); }
.seg button.active { background: var(--primary); color: #fff; }
.table-wrap { overflow-x: auto; padding: 0 16px 16px; }
table { border-collapse: collapse; width: 100%; background: var(--surface); font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #eef2f7; position: sticky; top: 0; font-weight: 600; }
tbody tr { cursor: pointer; } tbody tr:hover { background: #f0f5fc; }

/* 현황 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat .n { font-size: 28px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.form-inline { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.form-inline input, .form-inline select { flex: 1 1 120px; width: auto; }

/* 모달/토스트 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 2000; display: flex;
  align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 14px; padding: 18px; width: 100%; max-width: 460px;
  max-height: 90vh; overflow-y: auto; }
.modal-box h3 { margin-top: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 8px; z-index: 3000; max-width: calc(100% - 32px); }
.gps-box { background: #eef5ff; border-radius: 8px; padding: 10px; font-size: 14px; margin: 8px 0; color: #1d2733; }
.gps-box b.good { color: #1a8f3c; } .gps-box b.bad { color: var(--danger); }

/* 다크 모드 */
@media (prefers-color-scheme: dark) {
  :root { --bg: #12171d; --surface: #1c232c; --text: #e6ebf1; --muted: #9aa6b4; --line: #2e3844; --top: #0f2238; }
  th { background: #232c37; } tbody tr:hover { background: #26303c; }
  .fab { background: #2a333e; color: #fff; }
  .movebar { background: #2a333e; color: #fff; }
  .gps-box { background: #1f2f44; color: #e6ebf1; }
}
@media (min-width: 721px) { #view-map.panel-open .leaflet-top.leaflet-right { right: 400px; } }
.badge.MVLV { background: #8e44ad; }
.badge.ph { background: #455a64; }
.warn-t { color: var(--warn); font-weight: 600; }
.legend i.sq { border-radius: 3px; background: #555; color: #fff; width: 12px; height: 12px; font: 700 9px/12px sans-serif; text-align: center; font-style: normal; }
.legend .ln b { display: inline-block; width: 18px; vertical-align: middle; margin-right: 4px; }
.stat-grid.sm { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.stat-grid.sm .stat { padding: 8px; } .stat-grid.sm .n { font-size: 20px; }
#statsBody h4 { margin: 12px 0 6px; }
@media (max-width: 720px) { .legend .ln { display: none; } }

/* 사진 칸 (전주 전체 / 계량기함N, 칸마다 1장) */
.photo-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photo-slot { border: 1px solid var(--line); border-radius: 8px; padding: 6px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.photo-slot .ps-head { display: flex; justify-content: space-between; align-items: center; }
.photo-slot img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: pointer; }
.photo-slot .ps-empty { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 6px;
  background: var(--bg); color: var(--muted); font-size: 12px; }
.photo-slot .sub { font-size: 11px; color: var(--muted); line-height: 1.3; }
.photo-slot .ps-act { display: flex; flex-wrap: wrap; }
.photo-slot .ps-act .btn { margin: 2px 2px 0 0; }
.photo-slot label.btn { display: inline-block; color: var(--primary-text); }
.archive { margin-top: 10px; font-size: 13px; }
.archive summary { cursor: pointer; color: var(--muted); }
.archive-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 8px; }
.archive-list figure { margin: 0; font-size: 11px; }
.archive-list img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: pointer; opacity: .85; }

/* 선택 항목 관리 */
.card.wide { grid-column: 1 / -1; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; color: var(--text); }
.opt-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.opt-card.wide { grid-column: 1 / -1; }
.opt-card h4 { margin: 0 0 8px; font-size: 15px; }
.opt-row { display: flex; align-items: center; gap: 2px; margin-bottom: 4px; }
.opt-row input { flex: 1; min-width: 0; padding: 6px 8px; }
.opt-row .opt-use { min-width: 34px; text-align: right; font-size: 12px; }
.opt-row .btn { margin: 0; padding: 4px 7px; }
.cat-row { border-top: 1px dashed var(--line); padding: 8px 0; }
.cat-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.cat-head .cat-label { font-weight: 600; flex: 1; }
.cat-row [data-sub] { padding-left: 16px; }
/* 전주번호 입력 도우미 */
.no-check { font-size: 12px; margin: -4px 0 8px; min-height: 16px; }
.no-check.good { color: #1e8449; }
.no-check.bad { color: #c0392b; }
.no-check.warn, .no-review { color: #b9770e; }
.no-review { font-size: 12px; background: #fef5e7; border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
.no-helper { margin: 0 0 8px; font-size: 13px; }
.no-helper summary { cursor: pointer; color: #555; }
label.inline { display: flex; gap: 6px; align-items: center; }
/* 변압기 연계 용량 / 저압망 */
.net-link { font-size: 13px; margin: 6px 0; }
.badge.load-warn { background: #e53935; }
.load-bar { position: relative; height: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; margin: 4px 0 8px; overflow: visible; }
.load-bar i { display: block; height: 100%; background: #43a047; border-radius: 6px; }
.load-bar.warn i { background: #e53935; }
.load-bar b { position: absolute; top: -4px; bottom: -4px; width: 2px; background: #111; }
.load-warn-t { color: #e53935; font-weight: 600; font-size: 13px; }
.stat.warn { border-color: #e53935; } .stat.warn .n { color: #e53935; }
tr.row-warn td { background: rgba(229, 57, 53, .08); }
tr.row-bad td { background: rgba(229, 57, 53, .15); color: #c62828; }
tr.row-skip td { color: var(--muted); }
.rn-mode { margin: 8px 0; }
.rn-label { font-size: 11px; font-weight: 700; color: #fff; background: #2e7d32; padding: 1px 4px; border-radius: 4px; white-space: nowrap; }
.rn-label.bad { background: #c62828; }
.tbl { font-size: 13px; }
.tbl th, .tbl td { padding: 5px 8px; }
.form-inline label.inline { flex: 0 0 auto; white-space: nowrap; margin: 0; }
.form-inline label.inline input { flex: none; width: auto; }
#batchTable td.sample { white-space: normal; font-size: 12px; min-width: 200px; }

/* 지도 필터 */
.map-filter { background: rgba(255,255,255,.95); border-radius: 6px; box-shadow: 0 1px 5px rgba(0,0,0,.35); padding: 6px 10px; font-size: 13px; }
.map-filter summary { cursor: pointer; font-weight: 600; }
.map-filter label { display: flex; align-items: center; gap: 6px; margin: 4px 0; white-space: nowrap; cursor: pointer; }
.map-filter input { width: auto; margin: 0; }
/* 라이선스 구역 이름 (구역 맨 위 꼭짓점) */
.area-label div { transform: translate(-50%, -120%); white-space: nowrap; font-size: 12px; color: #8a4b00; background: rgba(255,244,214,.92);
  border: 1px solid #f08c00; border-radius: 4px; padding: 1px 6px; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
/* 계량기함 · 계량기 */
.meter-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { border: 1px solid #c9d3de; background: #f4f7fa; border-radius: 12px; padding: 2px 8px; font-size: 12px; cursor: pointer; color: inherit; }
.chip:hover { background: #e6eef7; }
.item .col-btns { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
@media (prefers-color-scheme: dark) {
  .map-filter { background: #2a333e; color: #fff; }
  .chip { background: #2a333e; border-color: #48566a; }
}

/* 계량기함 번호 칸 · 대장 대조 */
.mb-nos-head { margin-top: 8px; }
.mb-nos { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; max-height: 320px; overflow: auto; }
.mb-no { display: grid; grid-template-columns: 26px minmax(110px, 160px) 1fr; gap: 6px; align-items: center; }
.mb-idx { color: var(--muted); font-size: 12px; text-align: right; }
.mb-st { font-size: 12px; }
.mb-in.bad, #mtNo.bad { border-color: var(--danger); }
.ok-t { color: #1a8f3c; font-weight: 600; }
.bad-t { color: var(--danger); font-weight: 600; }
.chip-warn { border-color: var(--warn); }
@media (max-width: 520px) { .mb-no { grid-template-columns: 22px 1fr; } .mb-no .mb-st { grid-column: 2; } }

/* 거리 측정 · 메모 */
.fab.on { outline: 3px solid #ff6d00; }
.ms-tip { font-weight: 700; font-size: 12px; padding: 2px 6px; }
.ms-tip.ghost { opacity: .85; font-weight: 600; }
.memo-pin { width: 26px; height: 26px; border-radius: 7px; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; font-size: 13px; position: relative; }
.memo-pin i { position: absolute; top: -8px; right: -8px; background: #c62828; color: #fff; font: 700 10px/16px sans-serif;
  min-width: 16px; height: 16px; border-radius: 8px; text-align: center; font-style: normal; padding: 0 3px; }
.badge.ok { background: #2e7d32; }
.memo-head { display: flex; align-items: center; gap: 8px; }
.memo-head h3 { margin: 0; }
.memo-body { white-space: normal; word-break: break-word; margin: 8px 0; line-height: 1.5; }
.reply { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.reply:last-child { border-bottom: 0; }
.reply .sub { font-size: 12px; color: var(--muted); }
.link.danger { color: var(--danger); font-size: 12px; }
.mp-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 6px 0; }
.mp-pick label.btn { display: inline-block; margin: 0; color: var(--text); }
.mp-prev { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.mp-th { position: relative; }
.mp-th img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; display: block; }
.mp-th button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: #222; color: #fff; font-size: 12px; cursor: pointer; }
.memo-list { padding: 0 16px 16px; display: grid; gap: 8px; }
.memo-card { display: flex; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; }
.memo-card:hover { border-color: var(--primary); }
.memo-card img, .memo-card .mc-noimg { width: 72px; height: 72px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.memo-card .mc-noimg { background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 28px; }
.mc-main { min-width: 0; flex: 1; }
.mc-main b { margin-left: 2px; }
.mc-body { margin: 4px 0; word-break: break-word; }

/* 언어 선택 · 크메르어 화면 */
.lang-sel { width: auto; padding: 4px 6px; font-size: 13px; border-radius: 6px; }
.topbar .lang-sel { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); }
.topbar .lang-sel option { color: #000; }
.login-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.login-top h1 { margin: 0 !important; }
html[lang="km"] body { font-family: "Noto Sans Khmer", "Khmer OS System", "Khmer OS", "Khmer UI", "Leelawadee UI", -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  line-height: 1.55; }
html[lang="km"] #tabs button { padding: 12px 8px; font-size: 14px; }
.i18n-tbl td { vertical-align: top; }
.i18n-tbl td.ko { min-width: 180px; max-width: 360px; white-space: normal; }
.i18n-tbl textarea.km { min-width: 220px; font-family: "Noto Sans Khmer", "Khmer OS System", "Khmer UI", "Leelawadee UI", sans-serif; font-size: 15px; line-height: 1.5; }
.i18n-tbl .sub { font-size: 11px; color: var(--muted); }
.i18n-tbl tr.i18n-none { background: #fdecea; }
.i18n-tbl tr.i18n-todo { background: #fff8e1; }
.i18n-tbl tr.i18n-ok { background: #edf7ec; }

/* 지도: 변압기 번호, 선로 정보 팝업 */
.tr-label { font-size: 11px; font-weight: 700; color: #5d4037; text-shadow: 0 0 3px #fff, 0 0 3px #fff; white-space: nowrap; }
.sp-pop { font-size: 13px; line-height: 1.45; }
.sp-row { border-top: 1px solid #eee; padding: 4px 0; }

/* 전주 정보 케이블: 회선마다 한 줄 (왼쪽 전주 ← 이 전주 → 오른쪽 전주) */
.cab-row { border-top: 1px solid var(--line, #eee); padding: 6px 0; }
.cab-c { font-size: 11px; font-weight: 700; color: #555; margin-bottom: 2px; }
.cab-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; }
.cab-side { min-width: 0; font-size: 13px; overflow-wrap: anywhere; }
.cab-grid > .cab-side:last-child { text-align: right; }
.cab-side.empty { color: #999; }
.cab-mid { font-size: 11px; color: #666; white-space: nowrap; text-align: center; }
.cab-btns { margin-top: 2px; }
.rn-do { margin: 6px 0 10px; }
.rn-do button { flex: 1; }
.pick-row { display: flex; gap: 6px; }
.pick-row input { flex: 1; min-width: 0; }
.pick-row .btn { white-space: nowrap; }
