/* 뉴모피즘 — 배경과 같은 색 면에 빛(좌상)·그림자(우하)를 줘서 튀어나오거나(raised) 눌린(inset) 느낌.
   색은 상태(정상·끊김·가동)에만, 배지는 단색 바탕 + 흰 글씨. */
:root {
  color-scheme: light;
  --bg: #e9edf2;
  --text: #2b3440;
  --muted: #7b8794;
  --faint: #a3adb8;
  --light: #ffffff;
  --dark: #c3cad4;
  --line: #dde2e8;
  --hover: #e3e8ee;
  --ok: #16a34a;
  --on: #2563eb;
  --bad: #dc2626;
  /* 그래프 선 색 — 6자리 hex 만 (detail.js 가 뒤에 투명도를 붙여 면을 칠함) */
  --c-h2s: #ea580c; /* 황화수소 여과전 주황 — 표·상세 글자색도 같음 */
  --c-rear: #16a34a; /* 여과후 초록 */
  --c-temp: #e03131; /* 온도 빨강 — 여과전 주황과 구분 */
  --c-hum: #2563eb;
  /* 고장 유형 색 — 색약 구분 검증한 3색 (dataviz 기본 1~3번), 미분류는 회색 */
  --f-stop: #2a78d6;
  --f-degrade: #eb6834;
  --f-damage: #1baf7a;
  --f-none: #a3adb8;
  /* 자동 등록 유형 (모터 · LED · 센서 · 네트워크) · 점검 탭 구분 (A/S · 정기점검 · 기타) — 점검 탭은 고장 탭과 따로 보여서 색을 다시 씀 */
  --f-motor: #7c4dd6;
  --f-led: #d4a017;
  --f-sensor: #0e9fbd;
  --f-network: #d6336c;
  --f-as: #2a78d6;
  --f-inspection: #1baf7a;
  --f-etc: #eb6834;

  --raised: 8px 8px 18px var(--dark), -8px -8px 18px var(--light);
  --raised-sm: 4px 4px 10px var(--dark), -4px -4px 10px var(--light);
  --inset: inset 4px 4px 9px var(--dark), inset -4px -4px 9px var(--light);
  --radius: 22px;
}

/* 다크 — 같은 뉴모피즘을 어두운 면으로 (빛은 면보다 살짝 밝게, 그림자는 더 어둡게).
   파랑·빨강·그래프 선은 어두운 바탕에서 보이게 한 단계 밝게, 갈색은 묻혀서 황토색으로 */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #262a30;
  --text: #e3e8ee;
  --muted: #9aa4b0;
  --faint: #6b7581;
  --light: #30353d;
  --dark: #1a1d21;
  --line: #343a42;
  --hover: #2c3037;
  --on: #3b82f6;
  --bad: #ef4444;
  --c-h2s: #f97316;
  --c-rear: #22c55e;
  --c-temp: #f04848;
  --c-hum: #3b82f6;
  --f-stop: #3987e5;
  --f-degrade: #d95926;
  --f-damage: #199e70;
  --f-none: #6b7581;
  --f-motor: #9b74ec;
  --f-led: #e0b43a;
  --f-sensor: #35bcd8;
  --f-network: #e8598a;
  --f-as: #3987e5;
  --f-inspection: #199e70;
  --f-etc: #d95926;
}
:root[data-theme="dark"] .dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
/* 눌린 홈 모양 태그(수위계·버전)는 어두운 면에선 거의 안 보여서 단색 회색 바탕으로 */
:root[data-theme="dark"] .tag { background: #3a414b; color: #d5dbe3; box-shadow: none; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* 스크롤바 자리를 늘 비워 둠 — 긴 페이지(스크롤바 있음)↔짧은 페이지를 오갈 때 헤더·내용이 옆으로 밀리지 않게.
   지도 화면은 스크롤이 없어 비운 자리가 빈 띠로 보이므로 안 비우고, 헤더만 스크롤바 폭(--sbw, app.js)만큼 안쪽으로 */
html { scrollbar-gutter: stable; }
html:has(body.view-map) { scrollbar-gutter: auto; }
@media (min-width: 861px) {
  body.view-map .top { padding-right: calc(40px + var(--sbw, 0px)); }
}
@media (min-width: 1200px) {
  body.view-map .brand { left: calc(50% - var(--sbw, 0px) / 2); }
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Pretendard", system-ui, -apple-system, "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── 상단 ─────────────────────────────── */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 40px; /* 위아래 같게 — 제목·버튼이 헤더 띠 위아래 가운데 */
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-logo { flex: none; width: 36px; height: 36px; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
/* 가람환경기술 로고 (헤더 왼쪽, PC만) — 다크면 글씨 흰 로고 */
.top-logo { display: block; flex: none; }
.top-logo img { display: block; width: 258px; height: auto; }
.top-logo .dark, :root[data-theme="dark"] .top-logo .light { display: none; }
:root[data-theme="dark"] .top-logo .dark { display: block; }
@media (min-width: 861px) {
  .brand .brand-logo { display: none; } /* 로고가 왼쪽에 있으니 제목 옆 작은 아이콘은 뺌 */
}
/* 넓은 화면: 제목은 헤더 한가운데 — 좁으면 로고·버튼과 겹쳐서 로고 옆에 */
@media (min-width: 1200px) {
  .top { position: relative; }
  .brand { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
}
.top-actions, .who { display: flex; align-items: center; gap: 14px; }

/* 종 버튼 알림 — 안 읽은 모터 이상 알림이 있으면 오른쪽 위 빨간 점, 누르면 아래로 목록 */
.alert-box { position: relative; }
.alert-btn { position: relative; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: var(--bg); color: var(--muted); cursor: pointer; box-shadow: var(--raised-sm); transition: color 0.15s ease, box-shadow 0.15s ease; }
.alert-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.alert-btn:hover { color: var(--text); }
.alert-btn[aria-expanded="true"] { color: var(--on); box-shadow: var(--inset); }
.alert-btn:focus-visible { outline: 2px solid var(--on); outline-offset: 3px; }
/* 종 위 안 읽은 알림 개수 — 빨간 동그라미 숫자 (99 넘으면 99+) */
.alert-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bad);
  box-shadow: 0 0 0 2px var(--bg);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.alerts {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 40;
  width: min(360px, calc(100vw - 32px));
  max-height: 420px;
  overflow-y: auto;
  padding: 14px 8px 10px;
  border-radius: 18px;
  background: var(--bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.alerts-head { margin: 0 10px 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.alerts-list { margin: 0; padding: 0; list-style: none; }
.alerts-list li + li { border-top: 1px solid var(--line); }
.alerts-list a { display: flex; flex-direction: column; gap: 5px; padding: 11px 10px; border-radius: 12px; color: var(--text); text-decoration: none; }
.alerts-list a:hover { background: var(--hover); }
.alerts-list a:focus-visible { outline: 2px solid var(--on); outline-offset: -2px; }
.alert-name { display: flex; align-items: flex-start; gap: 8px; font-size: 15px; font-weight: 700; word-break: keep-all; }
.alert-name .badge { flex: none; margin-top: 1px; }
.alert-time { color: var(--muted); font-size: 13px; }
.alert-time:empty { display: none; }
.alerts-empty { padding: 10px; color: var(--muted); font-size: 14px; }

/* 다크 모드 토글 — 눌린 홈 안에서 튀어나온 동그라미가 해(라이트)·달(다크) 아래로 미끄러지고, 그 아이콘만 색이 들어옴.
   모양은 aria-pressed 가 아니라 data-theme 기준 (첫 화면에서 동그라미가 미끄러지는 애니메이션이 안 보이게) */
.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 72px;
  height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--bg);
  box-shadow: var(--inset);
  cursor: pointer;
}
.theme-toggle::before {
  content: '';
  position: absolute;
  top: 5px;
  left: 5px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 3px 3px 7px var(--dark), -3px -3px 7px var(--light);
  transition: transform 0.25s ease;
}
.theme-toggle svg {
  position: relative;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--faint);
  transform: scale(0.85);
  transition: color 0.25s ease, fill 0.25s ease, transform 0.25s ease;
}
.theme-toggle .sun { color: #f59e0b; fill: currentColor; transform: none; }
.theme-toggle:hover .moon { color: var(--muted); }
.theme-toggle:focus-visible { outline: 2px solid var(--on); outline-offset: 3px; }
:root[data-theme="dark"] .theme-toggle::before { transform: translateX(34px); }
:root[data-theme="dark"] .theme-toggle .sun { color: var(--faint); fill: none; transform: scale(0.85); }
:root[data-theme="dark"] .theme-toggle .moon { color: #fcd34d; fill: currentColor; transform: none; }
:root[data-theme="dark"] .theme-toggle:hover .sun { color: var(--muted); }

.chip {
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--inset);
  color: var(--muted);
  font-weight: 600;
}

main { padding: 20px 40px 48px; }

/* ── 왼쪽 메뉴 (모바일은 아래 탭) — 고른 메뉴는 파란 바탕 + 흰 글씨 ── */
/* 공용 헤더가 맨 위를 가로로 채우고, 메뉴는 그 바로 아래부터 (로고는 헤더에 있어서 메뉴엔 없음) */
.nav {
  position: fixed;
  top: calc(var(--top-h, 70px) + 4px);
  bottom: 20px;
  left: 20px;
  z-index: 25; /* 모니터링에서 위에 붙는 헤더(바탕색, z 20)보다 위 — 메뉴 위쪽 그림자가 화면마다 똑같이 보이게 */
  width: 84px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 8px;
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--raised);
}
.nav:not([hidden]) ~ main { margin-left: 96px; }
.nav:not([hidden]) ~ .top { padding-left: 136px; } /* 헤더 제목(로고)은 아래 내용 시작선(메뉴 96 + 여백 40)에, 오른쪽 버튼은 내용 오른쪽 끝(40)에 */
.nav-logo { display: none; justify-content: center; padding: 2px 0 8px; }
.nav-logo img { width: 52px; height: 52px; border-radius: 14px; } /* 앱 아이콘이 흰 바탕이라 앱 타일처럼 모서리만 둥글게 */
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px;
  border-radius: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease;
}
.nav-item svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { color: var(--text); }
.nav-item.active { background: var(--on); color: #fff; box-shadow: var(--raised-sm); }
.nav-item:focus-visible { outline: 2px solid var(--on); outline-offset: 2px; }

/* ── 공통 ─────────────────────────────── */
.panel { background: var(--bg); border-radius: var(--radius); box-shadow: var(--raised); }

.btn {
  border: 0;
  border-radius: 14px;
  padding: 9px 18px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--raised-sm);
  transition: box-shadow 0.15s ease, color 0.15s ease;
}
.btn:hover { color: var(--on); }
.btn:active { box-shadow: var(--inset); }
.btn:focus-visible, .name-btn:focus-visible, input:focus-visible { outline: 2px solid var(--on); outline-offset: 3px; }
.btn.primary { padding: 13px; font-size: 15px; }

input {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  box-shadow: var(--inset);
}

.msg { margin: 0; min-height: 1.5em; color: var(--bad); font-weight: 600; }

/* ── 로그인 ───────────────────────────── */
.login { display: flex; justify-content: center; padding-top: 16vh; }
.login form {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 36px 32px 30px;
}
.login h2 { margin: 0; font-size: 20px; font-weight: 800; }
.login .msg:empty { display: none; } /* 오류 문구가 없으면 버튼 아래 빈 줄을 접음 */
.login label { display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; }
.login .btn.primary { margin-top: 18px; }

/* 아이디 저장·자동 로그인 체크 — 눌린 네모, 체크하면 파란 바탕 + 흰 체크 */
.login-opts { display: flex; flex-wrap: wrap; gap: 10px 24px; }
.login label.check { flex-direction: row; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check .box {
  position: relative;
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  box-shadow: var(--inset);
  transition: background 0.15s ease;
}
.check input:checked + .box { background: var(--on); box-shadow: none; }
.check input:checked + .box::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 3px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.check input:focus-visible + .box { outline: 2px solid var(--on); outline-offset: 3px; }

/* ── 요약 타일 ────────────────────────── */
.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
  margin-bottom: 18px;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 24px;
  border-radius: var(--radius);
  box-shadow: var(--raised);
}
.tile .label { color: var(--muted); font-size: 13px; font-weight: 600; word-break: keep-all; } /* 좁으면 단어 단위로 접힘 */
.detail-tiles .tile .label { min-height: 3.1em; } /* 좁은 화면에서 이름이 두 줄로 접혀도 값 줄이 칸마다 같은 높이 */
.tile b { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile b.ok { color: var(--ok); }
.tile b.bad { color: var(--bad); }
.tile .state.ok { color: var(--c-rear); }   /* 상세 "네트워크 / 기기상태" 칸 */
.tile .state.bad { color: var(--bad); }
.tile .state.on { color: var(--on); }
.tile .tile-line { display: block; } /* 상세 두 줄 칸 — 한 줄에 값 하나 */
.tile b.time { font-size: 22px; padding-top: 6px; }

/* ── 검색 ─────────────────────────────── */
.search {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 160px)) minmax(180px, 1fr) repeat(2, minmax(100px, 130px)) auto;
  align-items: end;
  gap: 16px;
  padding: 20px 24px;
  margin-bottom: 18px;
}
.search label { display: flex; flex-direction: column; gap: 8px; min-width: 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.search input { width: 100%; }
.search .btn.primary { padding: 12px 28px; font-size: 14px; }

select {
  width: 100%;
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 12px 36px 12px 16px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%237b8794' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center / 11px;
  color: var(--text);
  font: inherit;
  box-shadow: var(--inset);
  cursor: pointer;
}
select:disabled { color: var(--faint); cursor: default; }
select:focus-visible { outline: 2px solid var(--on); outline-offset: 3px; }

.result-line { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 4px 10px; padding-top: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.result-line .updated { margin-left: auto; font-weight: 500; }
#site-add { margin-left: auto; }
#site-add + .updated, #site-bulk + .updated { margin-left: 4px; }
/* 표시 개수 10·20·30 — 로그인 체크박스 모양을 하나만 고르는 라디오로 */
.page-size { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.page-size .check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; user-select: none; }
.page-size .check .box { box-shadow: inset 0 0 0 1.5px var(--muted), var(--inset); } /* 안 고른 칸도 보이게 테두리 (고르면 파랑으로 덮임) */

/* ── 현장 표 ──────────────────────────── */
.table-panel { padding: 10px 14px; overflow-x: auto; }
.sites { width: 100%; border-collapse: collapse; font-size: 15px; }
/* 현장명만 왼쪽, 나머지 칸은 머리글·값 모두 가운데 — 칸 사이 여백이 고르게 보이도록 */
.sites th, .sites td { padding: 16px 12px; text-align: center; white-space: nowrap; }
.sites th.name, .sites td.name { text-align: left; }
.sites th.name { width: 26%; padding-left: 18px; }
.sites td.name { padding-left: 18px; }
.sites th {
  color: var(--muted); /* 값(진함) > 머리글 > 미적용(.na, 흐림) */
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-bottom: 2px solid var(--line);
}
.sites td { border-bottom: 1px solid var(--line); }
.sites th .th-line { display: block; margin-top: 2px; } /* 두 줄 머리글의 아랫줄 */
.sites th .rd { color: var(--on); }                     /* 원격접속 No — 값(원격 주소 링크)과 같은 파랑 */
.h2s-pre { color: var(--c-h2s); }
.h2s-post { color: var(--c-rear); }
.na { color: var(--faint); font-weight: 500; }           /* '미적용' — 진짜 값보다 흐리게 (dom.js dimNotApplied) */

/* 헤더 정렬 버튼 */
.sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}
.sort:hover, .sites th.sorted, .ops-table th.sorted { color: var(--text); }
.sort:focus-visible { outline: 2px solid var(--on); outline-offset: 3px; border-radius: 4px; }
.sort .arrow { font-size: 9px; color: var(--on); }
.sites tbody tr:last-child td { border-bottom: 0; }
.sites tbody tr { transition: background 0.15s ease; }
.sites tbody tr:hover { background: var(--hover); }
.sites .num { font-variant-numeric: tabular-nums; }
.sites .mono { color: var(--muted); font-variant-numeric: tabular-nums; }
.sites td.num { font-weight: 600; }

.badge {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.badge.ok { background: var(--ok); }
.badge.on { background: var(--on); }
.badge.bad { background: var(--bad); }
.badge.run { background: var(--c-h2s); } /* 현장 지도 목록의 저감중 */

.sites tbody tr { cursor: pointer; }
.sites tbody td.serial { cursor: text; } /* 시리얼 칸은 상세로 안 넘어감 (app.js) — 긁어서 복사 */
.site-link { color: var(--text); font-weight: 700; text-decoration: none; }
.site-link:hover { color: var(--on); }
.site-link.empty { color: var(--faint); font-weight: 500; }
.sites td.name .addr { display: block; margin-top: 3px; margin-left: 22px; color: var(--faint); font-size: 13px; } /* 점 너비만큼 들여 현장명과 줄 맞춤 */
/* 현장명 앞 네트워크 점 — 정상 초록(여과후와 같은 색) · 끊김 빨강. 점은 이름 첫 줄 가운데 */
.name-row { display: flex; align-items: flex-start; gap: 12px; }
.net-dot { flex: none; width: 10px; height: 10px; margin-top: calc((1.55em - 10px) / 2); border-radius: 50%; }
.net-dot.ok { background: var(--c-rear); }
.net-dot.bad { background: var(--bad); }
/* 수동 등록(받은 데이터 없음) — 끊김(빨강)과 구분해 회색 */
.net-dot.none, .badge.none { background: var(--faint); }
.mk.none { color: var(--faint); }
.tile .state.none { color: var(--muted); }
.sites .badge { padding: 4px 12px; font-size: 13px; }
.rd-link { color: var(--on); font-weight: 600; text-decoration: none; font-variant-numeric: tabular-nums; }
.rd-link:hover { text-decoration: underline; }

.pager { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 24px; }
.btn.page { min-width: 42px; padding: 9px 12px; font-variant-numeric: tabular-nums; }
.btn.page.current { box-shadow: var(--inset); color: var(--on); }


/* ── 상세 ─────────────────────────────── */
a.btn { display: inline-block; text-decoration: none; }
.btn:disabled { color: var(--faint); cursor: default; box-shadow: var(--inset); }

.detail-head { display: flex; align-items: center; gap: 20px; margin-bottom: 24px; }
.detail-title { flex: 1; min-width: 0; }
.detail-title h2 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.detail-title h2.empty { color: var(--faint); font-weight: 600; }
.detail-title p { margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.detail-title .addr { color: var(--muted); }
.detail-title .addr.empty { color: var(--faint); }

/* ── 현장 설정 창 ─────────────────────── */
.dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--raised);
}
.dialog::backdrop { background: rgba(43, 52, 64, 0.28); }
.dialog form { display: flex; flex-direction: column; gap: 14px; padding: 28px 28px 22px; }
.dialog h2 { margin: 0; font-size: 19px; font-weight: 800; }
.dialog .hint { margin: -8px 0 2px; color: var(--muted); font-size: 13px; }
.dialog .hint, .dialog .msg { word-break: keep-all; }
.dialog label { display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; }
.dialog-actions .danger { margin-right: auto; color: var(--bad); } /* 삭제는 왼쪽 끝 */
.region-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.dialog .btn.primary { padding: 10px 26px; font-size: 14px; }

/* 스위치 (수위계·현장 설정) — 그림자 없이 평평하게 (입체 그림자가 다크에서 번져 보여서), 손잡이는 살짝 튕김 */
:root { --track-off: #d3d9e1; }
:root[data-theme="dark"] { --track-off: #3a414b; }
.dialog label.switch { flex-direction: row; align-items: center; gap: 12px; color: var(--text); font-size: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--track-off);
  transition: background 0.25s ease;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}
:root[data-theme="dark"] .switch input:not(:checked) + .track::after { background: #aeb7c2; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--on); outline-offset: 3px; }

.btn.mini { padding: 6px 14px; border-radius: 11px; font-size: 13px; }
.tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  box-shadow: var(--inset);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  vertical-align: 2px;
}

.detail-tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.detail-tiles .tile b { font-size: 22px; }
.detail-tiles .tile b.time { font-size: 16px; padding-top: 6px; }
.tile b.on { color: var(--on); }

.chart-panel { padding: 26px 28px 24px; }
/* 상세 아래쪽 패널(위치·이슈 히스토리) 사이 여백 */
.map-panel, .issue-panel { margin-top: 36px; }
.detail-tiles { margin-bottom: 30px; }
.chart-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
/* 왼쪽: 실시간·평균값 탭 + (실시간) 날짜 칩 / (평균값) 요일·시간대별 탭 */
.chart-left { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
/* 오른쪽: 그래프 항목 탭 */
.chart-right { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
/* 날짜 칩 — 그래프 탭과 같은 모양 (눌린 홈 안에서 고른 날만 튀어나옴) */
.days { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 6px; border-radius: 18px; box-shadow: var(--inset); }
.tab.day { padding: 8px 12px; font-variant-numeric: tabular-nums; }
.tab.day.active { color: var(--on); }
/* 그래프 탭 — 눌린 홈 안에서 고른 탭만 튀어나옴 */
.tabs { display: inline-flex; gap: 6px; padding: 6px; border-radius: 18px; box-shadow: var(--inset); }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: 0;
  border-radius: 13px;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  white-space: nowrap; /* 좁은 화면에서도 글자가 세로로 쪼개지지 않게 */
  cursor: pointer;
  transition: box-shadow 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); box-shadow: var(--raised-sm); }
.tab:focus-visible { outline: 2px solid var(--on); outline-offset: 2px; }
.tab .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); }
.tab.active .dot.h2s { background: var(--c-h2s); }
.tab.active .dot.temp { background: var(--c-temp); }
.tab.active .dot.hum { background: var(--c-hum); }

.chart-sub { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px; margin-bottom: 8px; }
.readout { flex: 1; min-width: 220px; margin: 0; min-height: 1.5em; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; margin: 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; }
.sites td.name .addr .tag:first-child { margin-left: 0; }
/* 기기상태 뱃지 — 정상 가동중 초록(여과후와 같은 색) · 모터 이상 빨강 */
.sites td.name .tag.dev.ok { background: var(--c-rear); color: #fff; box-shadow: none; }
.sites td.name .tag.dev.bad { background: var(--bad); color: #fff; box-shadow: none; }
.sites td.name .tag.dev.none { background: var(--faint); color: #fff; box-shadow: none; } /* 수동 등록 */
.sites td .sub { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; font-weight: 500; }
.sites td .rear, .sites td .line { display: block; margin-top: 2px; }
.chart { width: 100%; min-height: 360px; }
.chart-panel .msg:empty { display: none; }

/* 원격 명령 버튼 — 지금 모드는 눌린 모양 */
.ctl-box { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.ctl-row { display: flex; align-items: center; gap: 16px; }
.ctl { display: flex; gap: 10px; }
.ctl-btn { min-width: 64px; }
.ctl-btn.active { box-shadow: var(--inset); color: var(--on); }
.ctl-btn.active[data-cmd="stop"] { color: var(--bad); }
.ctl-msg { margin: 0; min-height: 1.2em; color: var(--muted); font-size: 12px; text-align: right; }

.map-panel { padding: 24px 28px 28px; }
.map-panel h3 { margin: 0; font-size: 15px; font-weight: 800; }
/* 위치 칸: 왼쪽 지도 · 오른쪽 현장 사진 (좁은 화면은 위아래) — 두 제목줄 높이를 맞춰 지도·사진 칸 윗선이 같게 */
.loc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.loc-head { display: flex; align-items: center; justify-content: space-between; min-height: 32px; margin-bottom: 14px; }
/* 현장 사진 한 장 — 지도와 같은 높이로 칸을 꽉 채움 */
.photo-box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 380px;
  overflow: hidden;
  border-radius: 16px;
  box-shadow: var(--inset);
}
/* 사진은 칸 높이에 맞춤 — 가로가 넘치면 양옆을 똑같이 자르고, 모자라면 양옆이 여백 */
.photo-box a { position: absolute; inset: 0; display: flex; justify-content: center; overflow: hidden; }
.photo-box img { display: block; flex: none; width: auto; max-width: none; height: 100%; }
.photo-empty { margin: 0; color: var(--faint); font-size: 14px; }
.photo-del {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.photo-del:hover { background: var(--bad); }
@media (max-width: 1100px) {
  .loc-grid { grid-template-columns: minmax(0, 1fr); }
}
.site-map { height: 380px; border-radius: 16px; overflow: hidden; box-shadow: var(--inset); }
.map-panel .msg:empty { display: none; }

/* ── 이슈 히스토리 (상세, 지도 아래) ── */
.issue-panel { padding: 24px 28px 28px; }
.issue-panel h3 { margin: 0 0 14px; font-size: 15px; font-weight: 800; }
.issue-counts { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 18px; }
.issue-counts .tile { padding: 14px 20px; }
.issue-counts .tile b { font-size: 22px; }
/* 건수 칸 = 구분 고르는 버튼 — 고른 칸은 눌린 모양 + 파란 이름 */
.issue-counts button.tile { border: 0; background: var(--bg); color: inherit; font: inherit; text-align: left; cursor: pointer; transition: box-shadow 0.2s ease; }
.issue-counts button.tile[aria-pressed="true"] { box-shadow: var(--inset); }
.issue-counts button.tile[aria-pressed="true"] .label { color: var(--on); }
.issue-counts button.tile:focus-visible { outline: 2px solid var(--on); outline-offset: 2px; }
/* 고장 유형 칸은 구분이 고장이력일 때만 보여서 flex 로 (칸이 빠져도 나머지가 자리를 채움) */
.issue-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.issue-form label { display: flex; flex-direction: column; gap: 8px; flex: 0 0 160px; min-width: 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.issue-form label.grow { flex: 1 1 240px; }
.issues td.kind .sub { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }
.issue-form input { width: 100%; }
.issue-form .btn.primary { padding: 12px 26px; font-size: 14px; }
.issue-panel .msg { margin-top: 8px; }
.issue-panel .msg:empty { display: none; }
.issues { width: 100%; margin-top: 14px; border-collapse: collapse; font-size: 15px; }
.issues th, .issues td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: center; }
.issues th { color: var(--faint); font-size: 13px; font-weight: 700; border-bottom-width: 2px; }
.issues th:first-child { width: 140px; }
.issues th:nth-child(2) { width: 120px; }
.issues th.act { width: 90px; }
.issues th.act.wide { width: 150px; } /* 이슈 히스토리: 수정 · 삭제 두 버튼 */
.issues td.act .btn + .btn { margin-left: 6px; }
.issues tr.editing td { background: var(--hover); } /* 고치는 중인 기록 */
.issues th.author { width: 120px; }
.issues td.author { white-space: nowrap; }
.issues .content { text-align: left; word-break: keep-all; overflow-wrap: anywhere; }
.issues td.date { font-variant-numeric: tabular-nums; }
.issues td.date, .issues td.kind { white-space: nowrap; }
.issues tbody tr:last-child td { border-bottom: 0; }
.issues .empty td { color: var(--muted); }

/* ── 고장 통계 ── 유형 색은 --f-* (검증한 3색 + 미분류 회색), 글자는 늘 글자색 */
.stats-panel { margin-bottom: 20px; padding: 20px 24px 24px; }
.stats-panel h3 { margin: 0 0 14px; font-size: 15px; font-weight: 800; }
.stats-scroll { overflow-x: auto; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
.stats-table thead th { color: var(--faint); font-size: 13px; font-weight: 700; border-bottom-width: 2px; }
.stats-table tbody th { font-weight: 600; text-align: left; }
.stats-table th.kind { width: 140px; text-align: left; padding-left: 16px; }
.stats-table tr.total th, .stats-table tr.total td, .stats-table .sum { font-weight: 800; }
.stats-table tbody tr:last-child th, .stats-table tbody tr:last-child td { border-bottom: 0; }
.sw { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 3px; vertical-align: 0; }
.st-list th.name, .st-list td.name { text-align: left; padding-left: 16px; }
.st-list .empty td { color: var(--muted); }
.st-list td.date { color: var(--muted); }

/* 통계 표(왼쪽)·그래프(오른쪽) 반반, 좁은 화면은 위아래 — 그래프 칸 안은 막대 위, 도넛·범례 아래 */
/* ── 운영 통계 (ops.js) ── */
.ops-search { grid-template-columns: repeat(3, minmax(110px, 160px)) minmax(180px, 1fr); } /* 시/도 · 시/군 · 시/군/구 · 검색어 (모니터링처럼) */
.ops-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.ops-head h3 { margin: 0; }
.ops-actions { display: flex; align-items: center; gap: 10px; }
.ops-table th.name, .ops-table td.name { padding-left: 16px; text-align: left; }
.ops-table .th-line, .ops-table .line { display: block; }
.ops-table td.name .addr { display: block; margin-top: 2px; color: var(--faint); font-size: 13px; }
.ops-table tr.empty td { padding: 28px; color: var(--faint); }
@media (max-width: 1100px) {
  .ops-search { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ops-search .q { grid-column: 1 / -1; }
}
/* 폰 화면에서만 운영 통계를 현장 카드로 — 인쇄(PDF)는 A4 폭이 860px 보다 좁아도 표 그대로 나오게 screen 으로 한정 */
@media screen and (max-width: 860px) {
  .ops-table, .ops-table tbody, .ops-table tr, .ops-table td { display: block; width: 100%; }
  .ops-table thead { display: none; }
  .ops-table tbody tr:not(.empty) { margin-bottom: 14px; padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--raised); }
  .ops-table td { display: grid; grid-template-columns: 116px 1fr; gap: 2px 12px; padding: 5px 0; border-bottom: 0; text-align: right; white-space: nowrap; }
  .ops-table td::before { content: attr(data-label); color: var(--faint); font-size: 12px; font-weight: 700; text-align: left; }
  .ops-table td .line { grid-column: 2; }
  .ops-table td.name { display: block; margin-bottom: 4px; padding: 0 0 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: normal; }
  .ops-table td.name::before { content: none; }
}
/* PDF(인쇄) — 운영 통계만 흰 바탕에 표 전부 (ops.js 가 인쇄 직전에 페이지 없이 다시 그림) */
@media print {
  :root, :root[data-theme="dark"] { --bg: #fff; --text: #111; --muted: #555; --faint: #888; --line: #ccc; }
  .nav, .top, #ops-search, .ops-actions, .pager, #ops-msg { display: none !important; }
  body { background: #fff; }
  main { padding: 0 !important; margin: 0 !important; }
  .panel, .tile { box-shadow: none !important; border: 1px solid #ccc; }
  .stats-scroll { overflow: visible; }
  .ops-table { font-size: 11px; }
  .ops-table thead th, .ops-table td.name .addr { font-size: 10px; } /* 지역 줄이 현장명보다 크지 않게 */
  .ops-table thead { display: table-header-group; } /* 여러 장이면 장마다 머리글 */
  .ops-table tr { break-inside: avoid; }
}
@page { size: A4; margin: 12mm; }

.stats-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.stats-row .stats-panel { margin-bottom: 0; }
@media (max-width: 1100px) {
  .stats-row { grid-template-columns: minmax(0, 1fr); }
}
.stats-chart-panel { position: relative; }
.stats-charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.stats-charts .stats-share { justify-content: center; }
.stats-columns { min-width: 0; }
.stats-columns svg, #stats-donut svg { display: block; }
.stats-share { display: flex; align-items: center; gap: 24px; }
.stats-legend { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.stats-legend li { display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.stats-legend .name { min-width: 64px; font-weight: 700; }
.stats-legend .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.stats-empty { margin: 4px 0 0; color: var(--muted); }
.stats-panel svg .grid { stroke: var(--line); stroke-width: 1; }
.stats-panel svg .axis { stroke: var(--faint); stroke-width: 1; }
.stats-panel svg .tick { fill: var(--muted); font: 600 12px Pretendard, system-ui, sans-serif; }
.stats-panel svg .val { fill: var(--text); font: 800 13px Pretendard, system-ui, sans-serif; }
.stats-panel svg .donut-num { fill: var(--text); font: 800 22px Pretendard, system-ui, sans-serif; }
.stats-panel svg .hit { fill: transparent; cursor: default; }
.stats-panel svg .seg { stroke: var(--bg); stroke-width: 2; } /* 조각 사이 2px 틈 */
.stats-panel svg .ring { fill: none; }
.f-stop { background: var(--f-stop); fill: var(--f-stop); stroke: var(--f-stop); }
.f-degrade { background: var(--f-degrade); fill: var(--f-degrade); stroke: var(--f-degrade); }
.f-damage { background: var(--f-damage); fill: var(--f-damage); stroke: var(--f-damage); }
.f-none { background: var(--f-none); fill: var(--f-none); stroke: var(--f-none); }
.f-motor { background: var(--f-motor); fill: var(--f-motor); stroke: var(--f-motor); }
.f-led { background: var(--f-led); fill: var(--f-led); stroke: var(--f-led); }
.f-sensor { background: var(--f-sensor); fill: var(--f-sensor); stroke: var(--f-sensor); }
.f-network { background: var(--f-network); fill: var(--f-network); stroke: var(--f-network); }
.f-as { background: var(--f-as); fill: var(--f-as); stroke: var(--f-as); }
.f-inspection { background: var(--f-inspection); fill: var(--f-inspection); stroke: var(--f-inspection); }
.f-etc { background: var(--f-etc); fill: var(--f-etc); stroke: var(--f-etc); }
.stats-panel svg rect[class^="f-"],
.stats-panel svg path[class^="f-"] { stroke: none; }
.stats-tip {
  position: absolute;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  pointer-events: none;
  white-space: nowrap;
}
.stats-tip[hidden] { display: none; }
.stats-tip .tip-row { display: flex; align-items: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart .u-over { touch-action: pan-y; }
.chart .u-over.zoomed { cursor: grab; }
.chart .u-over.panning { cursor: grabbing; }
/* 그래프 커서 말풍선 (chartTip.js) — 커서를 따라 그래프 위쪽에 그 자리 값 */
.chart-tip {
  position: absolute;
  top: 4px;
  left: 0;
  z-index: 2;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
.chart-tip[hidden] { display: none; }
.chart-tip .tip-value { font-weight: 600; } /* 선 색으로 칠한 값 (여과전 · 여과후) */

/* ── 현장 지도 ─────────────────────────── */
/* 지도는 메뉴 오른쪽 화면 전체, 검색칸·검색 결과는 그 위 왼쪽에 카드로 (모바일은 아래 @media 에서 위아래로 쌓음) */
.map-view { position: fixed; top: var(--top-h, 76px); right: 0; bottom: 0; left: 124px; } /* 공용 헤더 아래부터 */
.overview-map { position: absolute; inset: 0; }
/* 카카오 지도 바탕은 식당·카페 같은 장소가 그림에 박혀 있어 못 지움 → 색을 반쯤 빼서 현장 점이 눈에 띄게 */
.overview-map img[src*="/tile/"], .site-map img[src*="/tile/"] { filter: grayscale(0.55) brightness(1.03); }

.map-side {
  position: absolute;
  top: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 5;
  width: 430px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none; /* 카드 사이 빈 곳은 지도를 그대로 끌 수 있게 */
}
.map-side > * { pointer-events: auto; }
/* 상태 칩 — 지도 위에 긴 막대 하나. 점 색은 지도 핀과 같음 (저감중 주황 · 저감완료 초록 · 설비이상·네트워크 이상 빨강)
   넓은 화면은 헤더 제목 바로 아래(화면 한가운데), 좁으면 왼쪽 검색 카드 오른쪽 빈 곳 가운데 */
.map-chips {
  position: absolute;
  top: 16px;
  left: 462px;
  right: 16px; /* 검색 카드 오른쪽 빈 곳 — 그 안에서 가운데, 모자라면 막대 안에서 두 줄 */
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: fit-content;
  margin: 0 auto;
  padding: 6px 18px;
  border-radius: 24px;
  background: var(--bg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
/* 막대가 검색 카드와 안 겹칠 만큼 넓으면 제목과 같은 세로 축 — 지도 칸은 메뉴 124px 오른쪽부터 화면 끝까지라
   (폭 - 124) 의 가운데에서 62px 왼쪽 = 화면 가운데, 제목은 스크롤바 폭 절반만큼 왼쪽이라 그만큼 더 */
@media (min-width: 1700px) {
  .map-chips { left: calc(50% - 62px - var(--sbw, 0px) / 2); right: auto; margin: 0; transform: translateX(-50%); }
}
.map-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.map-chip:hover:not(:disabled) { background: var(--hover); }
.map-chip b { font-variant-numeric: tabular-nums; }
.map-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.map-chip.run .dot { background: var(--c-h2s); }
.map-chip.done .dot { background: var(--c-rear); }
.map-chip.error .dot, .map-chip.stale .dot { background: var(--bad); }
.map-chip.active { box-shadow: var(--inset); color: var(--on); }
.map-chip:disabled { cursor: default; } /* 0곳이어도 색은 그대로 (못 누르기만) */
.map-chip:focus-visible { outline: 2px solid var(--on); outline-offset: 2px; }
/* 노트북 화면(1366 등)은 막대가 한 줄에 들어가게 여백만 줄임 */
@media (max-width: 1440px) {
  .map-chips { gap: 2px; padding: 5px 10px; }
}
.map-card { border-radius: 18px; background: var(--bg); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); }
/* 6칸 격자: 첫 줄 검색어(5칸) + 초기화(1칸), 아래 줄 지역 세 칸(2칸씩) */
.map-search { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px 10px; margin: 0; padding: 16px; }
.map-search .q { grid-row: 1; grid-column: 1 / 6; }
.map-search > label:not(.q) { grid-column: span 2; }
.map-search > .map-reset { grid-row: 1; grid-column: 6; align-self: end; padding: 0 8px; }
.map-filter-toggle, .map-list-toggle { display: none; } /* 폰 전용 (아래 @media) */
.map-search select { padding: 10px 28px 10px 12px; background-position: right 10px center; font-size: 13px; }

.map-list { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 14px 8px 20px; }
.map-list-head { display: flex; justify-content: space-between; gap: 10px; margin: 0 12px 8px; color: var(--muted); font-size: 14px; font-weight: 700; }
.map-list-head b { color: var(--text); font-variant-numeric: tabular-nums; }
.map-list-head .updated { font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.map-note { margin: 8px 12px 0; color: var(--muted); font-size: 13px; }
.map-note:empty { display: none; }

/* 지도 화면에선 위 제목줄 대신 테마·사용자·로그아웃만 오른쪽 위에 띄움 */
/* 모니터링: 제목줄·검색창·표시 개수가 스크롤해도 위에 붙음 — 넓은 화면만 (폰은 검색창이 화면 절반이라 안 붙임) */
@media (min-width: 861px) {
  body.view-list .top { position: sticky; top: 0; z-index: 20; background: var(--bg); }
  body.view-list .board-head {
    position: sticky;
    top: var(--top-h, 76px);
    z-index: 19;
    margin: -20px -40px 0;
    padding: 20px 40px 18px; /* 아래 여백 — 스크롤한 표가 표시 개수 줄에 바로 붙지 않게 */
    background: var(--bg);
  }
  body.view-list .board-head .result-line { margin-bottom: 0; }
}
/* 홈·운영 통계도 제목줄이 위에 붙음, 운영 통계는 검색 묶음과 (넓은 화면) 표 머리글까지 — 모니터링과 같은 방식 */
@media screen and (min-width: 861px) {
  body.view-home .top, body.view-ops .top, body.view-config .top, body.view-detail .top { position: sticky; top: 0; z-index: 20; background: var(--bg); }
  /* 상세·현장 설정: 현장 이름 줄까지 붙음 */
  body.view-detail .detail-head, body.view-config .detail-head { position: sticky; top: var(--top-h, 76px); z-index: 19; margin: -20px -40px 24px; padding: 20px 40px 16px; background: var(--bg); }
  body.view-config .cfg-sec { scroll-margin-top: calc(var(--top-h, 76px) + var(--cfg-head-h, 110px) + 12px); } /* 고칠 값 카드로 스크롤할 때 붙은 줄에 안 가림 */
  body.view-ops .ops-sticky { position: sticky; top: var(--top-h, 76px); z-index: 19; margin: -20px -40px 0; padding: 20px 40px 18px; background: var(--bg); }
  body.view-ops .ops-sticky .search { margin-bottom: 0; }
}
@media screen and (min-width: 1200px) {
  body.view-ops .ops-panel .stats-scroll { overflow: visible; }
  body.view-ops .ops-table thead th { position: sticky; top: calc(var(--top-h, 76px) + var(--ops-h, 130px)); z-index: 2; background: var(--bg); }
}
/* 표 머리글 줄도 검색 묶음 바로 아래 붙음 — 붙으려면 표 칸이 가로 스크롤 칸이면 안 돼서, 표가 한 화면에 들어가는 넓이(1200~)에서만 */
@media (min-width: 1200px) {
  body.view-list .table-panel { overflow: visible; }
  body.view-list .sites thead th { position: sticky; top: calc(var(--top-h, 76px) + var(--board-h, 160px)); z-index: 2; background: var(--bg); }
}
.map-list-items { flex: 1 1 auto; min-height: 0; margin: 0; padding: 0 2px; overflow-y: auto; list-style: none; }
.map-list-items li + li { border-top: 1px solid var(--line); }
.map-item {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 13px 12px;
  border: 0;
  border-radius: 14px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}
.map-item:hover { background: var(--hover); }
.map-item.active { box-shadow: var(--inset); }
.map-item:focus-visible { outline: 2px solid var(--on); outline-offset: -2px; }
.map-item-body { display: flex; flex: 1 1 auto; flex-direction: column; gap: 4px; min-width: 0; }
.map-item-name { overflow: hidden; font-size: 16px; font-weight: 800; white-space: nowrap; text-overflow: ellipsis; } /* 긴 현장명은 한 줄로 … (전체 이름은 마우스를 올리면 · 누르면 팝업) */
.map-item-name.empty { color: var(--faint); font-weight: 600; }
.map-item-sub { color: var(--muted); font-size: 14px; }
.map-item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 2px; color: var(--muted); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.map-item-meta .badge { padding: 2px 10px; font-size: 13px; }
.map-list-pager { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding-top: 14px; }
.map-list-pager .btn.page { min-width: 34px; padding: 6px 9px; border-radius: 10px; font-size: 13px; }

/* 지도 위 현장 핀 + 이름표 — 핀 끝이 현장 위치, 지도는 다크 모드에서도 밝아서 이름표는 늘 흰 바탕 */
.mk { position: relative; width: 30px; height: 40px; padding: 0; border: 0; background: none; cursor: pointer; }
.pin-layer { position: absolute; left: 0; top: 0; } /* 핀 한 겹 (mapPins.js) — 버튼 아래 가운데(핀 끝)가 현장 위치 */
.pin-layer > .mk { position: absolute; transform: translate(-50%, -100%); }
.mk.ok { color: var(--ok); }
.mk.run { color: var(--c-h2s); } /* 저감중 = 여과전 주황 */
.mk.bad { color: var(--bad); }
.mk .pin { position: relative; display: block; width: 30px; height: 40px; transform-origin: 50% 100%; transition: transform 0.15s ease; }
.mk .pin svg { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45)); }
.mk .pin path { fill: currentColor; stroke: #fff; stroke-width: 2.5; }
.mk .pin circle { fill: #fff; }
/* 끊김 현장은 핀 머리에서 물결이 퍼짐 */
.mk.bad::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  animation: mk-pulse 1.6s ease-out infinite;
}
@keyframes mk-pulse {
  from { opacity: 0.45; transform: scale(0.7); }
  to { opacity: 0; transform: scale(1.9); }
}
@media (prefers-reduced-motion: reduce) {
  .mk.bad::before { animation: none; }
}
.mk .label {
  position: absolute;
  top: 100%;
  left: 50%;
  margin-top: 2px;
  padding: 1px 8px;
  border-radius: 999px;
  background: #fff;
  color: #2b3440;
  font: 700 12px/1.6 "Pretendard", system-ui, sans-serif;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transform: translateX(-50%);
}
.mk.bad .label { color: #dc2626; }
/* 넓게 볼 땐 이름표가 겹쳐서 끊김 현장만 이름 표시, 나머지는 마우스를 올리면 */
.far .mk:not(.bad) .label { display: none; } /* 현장 지도·홈 작은 지도 (mapPins.js 가 멀리 보면 .far) */
.far .mk:hover .label, .far .mk:focus-visible .label { display: block; }
.mk:hover .pin { transform: scale(1.15); }
.mk:focus-visible { outline: 2px solid var(--on); outline-offset: 2px; border-radius: 8px; }

/* 핀을 누르면 뜨는 말풍선 — 아래 여백 = 핀 높이(40px) + 틈, 꼬리가 핀 머리 위에 옴 */
.pop-wrap { padding-bottom: 48px; }
.pop {
  position: relative;
  width: 320px;
  padding: 20px 22px 20px;
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Pretendard", system-ui, sans-serif;
  white-space: normal; /* 카카오 오버레이는 줄바꿈을 막아 둬서 긴 현장명이 잘림 → 띄어쓰기에서 줄바꿈 */
  word-break: keep-all;
  overflow-wrap: anywhere;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  cursor: default;
}
.pop::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 0 0 4px 0;
  background: var(--bg);
  transform: translateX(-50%) rotate(45deg);
}
.pop-head { display: flex; align-items: flex-start; gap: 8px; }
.pop-head h3 { flex: 1; min-width: 0; margin: 0; font-size: 19px; font-weight: 800; line-height: 1.4; }
.pop-head h3.empty { color: var(--faint); font-weight: 600; }
.pop-close { padding: 0 2px; border: 0; background: none; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; }
.pop-close:hover { color: var(--text); }
.pop-sub { margin: 4px 0 14px; color: var(--muted); font-size: 14px; }
.pop-rows { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 9px 16px; margin: 0 0 18px; }
.pop-rows dt { color: var(--faint); font-size: 14px; font-weight: 700; }
.pop-rows dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.pop-rows .badge { padding: 3px 12px; font-size: 13px; }
.pop-rows .badges { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; } /* 기기상태 이상이 여럿이면 */
.pop .btn { display: block; padding: 11px; border-radius: 14px; font-size: 15px; text-align: center; }
/* 지도 핀 미리보기 (PC 마우스 올림) — 핀 바로 위: 현장명, 사진이 있으면 그 아래 */
.pin-preview {
  position: absolute;
  z-index: 25;
  width: 240px;
  overflow: hidden;
  border: 3px solid var(--bg);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, calc(-100% - 10px));
  pointer-events: none;
}
.pin-preview[hidden] { display: none; }
.pin-preview img { display: block; width: 100%; height: 160px; object-fit: cover; }
.pin-preview img[hidden] { display: none; }
.pin-preview-name { margin: 0; padding: 8px 12px; color: var(--text); font-size: 15px; font-weight: 700; line-height: 1.4; word-break: keep-all; }
.pop-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
/* 길찾기 중간 페이지 (route.html) */
.route-page { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; min-height: 80vh; color: var(--muted); font-size: 15px; font-weight: 600; text-align: center; }

@media (max-width: 1200px) {
  .detail-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* 칸이 13개라 노트북 화면(1366 등)에선 여백을 줄이고 현장명은 줄바꿈 허용 — 가로 스크롤 없이 한 화면에 */
@media (max-width: 1600px) {
  .sites th, .sites td { padding: 14px 7px; }
  .sites th.name { width: auto; padding-left: 14px; }
  .sites td.name { padding-left: 14px; white-space: normal; word-break: keep-all; min-width: 150px; }
}

/* ── 모바일: 표 → 현장별 카드 (라벨-값 2열) ── */
@media (max-width: 860px) {
  /* 공용 헤더(폰): 제목·테마·이름·로그아웃을 한 줄로 — 지도 화면에서도 지도를 덜 가리게 */
  .top { gap: 6px; padding: 10px 12px 10px 14px; }
  .top-logo { display: none; } /* 폰은 자리가 없어 작은 아이콘+제목만 */
  .brand { min-width: 0; gap: 5px; }
  .brand-logo { width: 24px; height: 24px; }
  .brand h1 { overflow: hidden; font-size: 15px; letter-spacing: -0.04em; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions, .who { flex: none; gap: 4px; }
  .top .theme-toggle { zoom: 0.75; } /* 손잡이 위치까지 통째로 줄임 */
  .top .chip { padding: 6px 8px; font-size: 12px; }
  .top #who { display: none; } /* 폰은 자리가 좁아 이름 칩은 빼고 제목이 다 보이게 */
  .top .alert-btn { width: 32px; height: 32px; }
  .top .alert-btn svg { width: 17px; height: 17px; }
  .top .alert-dot { top: -4px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px; font-size: 10px; line-height: 17px; }
  /* 알림 목록은 종 버튼 아래 오른쪽 정렬이면 폰에선 왼쪽이 화면 밖으로 → 화면 폭에 맞춰 */
  .alerts { position: fixed; top: calc(var(--top-h, 60px) + 6px); right: 12px; left: 12px; width: auto; }
  #logout { padding: 6px 8px; font-size: 12px; }
  main { padding: 16px 16px 40px; }
  .nav { top: auto; right: 12px; bottom: 12px; left: 12px; width: auto; flex-direction: row; justify-content: center; gap: 4px; padding: 6px; }
  .nav-logo { display: none; }
  /* 메뉴 4개: 아이콘 위·이름 아래 한 줄 (이름이 두 줄로 쪼개지지 않게) */
  .nav-item { flex: 1 1 0; min-width: 0; max-width: 180px; flex-direction: column; justify-content: center; gap: 3px; padding: 8px 4px; font-size: 12px; white-space: nowrap; }
  .nav-item svg { width: 20px; height: 20px; }
  .nav:not([hidden]) ~ .top, .nav:not([hidden]) ~ main { margin-left: 0; }
  .nav:not([hidden]) ~ .top { padding-right: 12px; padding-left: 14px; } /* 폰은 메뉴가 아래라 양옆 맞춤 없음 */
  .nav:not([hidden]) ~ main { padding-bottom: 100px; }
  /* 현장 지도(폰): 공용 헤더 아래를 지도로 가득 — 위에 검색 한 줄([검색][지역]) 끝까지, 그 아래 상태 막대 한 줄,
     목록은 왼쪽 아래 "목록" 버튼으로 아래에서 펼침 */
  .map-view { position: fixed; inset: var(--top-h, 60px) 0 0; }
  .overview-map { position: absolute; inset: 0 0 84px; }
  .map-side { top: 10px; right: 10px; left: 10px; bottom: auto; width: auto; gap: 8px; }
  .map-card { box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22); }
  .map-search { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; border-radius: 16px; }
  .map-search > label:not(.q) { display: none; }
  .map-search.open > label:not(.q) { display: flex; flex: 1 1 100%; flex-direction: row; align-items: center; gap: 10px; }
  .map-search.open > label:not(.q) select { flex: 1; }
  .map-search .q { order: -1; flex: 1 1 0; min-width: 0; font-size: 0; gap: 0; } /* "검색어" 글자는 숨기고 입력칸만 */
  .map-search .q input { padding: 10px 14px; font-size: 14px; }
  .map-filter-toggle { display: inline-flex; order: -1; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .map-search > .map-reset { display: none; } /* 폰: 지역 칸을 펼쳤을 때만 맨 아래 오른쪽에 */
  .map-search.open > .map-reset { display: inline-flex; margin-left: auto; padding: 0 14px; }
  .map-chips { top: 86px; right: 10px; left: 10px; flex-wrap: nowrap; justify-content: space-between; gap: 0; width: auto; margin: 0; padding: 4px 6px; overflow-x: auto; scrollbar-width: none; }
  .map-chip { gap: 4px; padding: 6px 7px; font-size: 12px; } /* 4칸이 폰 한 줄에 들어가게 */
  .map-view:has(.map-search.open) .map-chips { display: none; } /* 지역 칸을 펼치면 상태 막대는 잠깐 숨김 (겹치지 않게) */
  .map-list { position: fixed; right: 10px; bottom: 140px; left: 10px; display: none; max-height: 52vh; }
  .map-view.list-open .map-list { display: flex; }
  .map-list-toggle { position: fixed; bottom: 92px; left: 10px; z-index: 7; display: inline-flex; padding: 10px 18px; border-radius: 999px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22); }
  body.view-map main { padding: 0; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .search { grid-template-columns: 1fr 1fr; grid-auto-flow: dense; gap: 14px; padding: 16px; }
  .search .q, .search .btn.primary { grid-column: 1 / -1; }
  .tile { padding: 16px 18px; }
  .tile b { font-size: 24px; }
  .tile b.time { font-size: 18px; padding-top: 4px; }
  .issue-panel { padding: 16px; }
  .issue-form label { flex: 1 1 40%; }
  .issue-form label.grow, .issue-form .btn.primary { flex: 1 1 100%; }
  .stats-panel { padding: 16px; }
  .stats-charts { grid-template-columns: minmax(0, 1fr); }
  .stats-share { flex-wrap: wrap; justify-content: center; }
  .issues { font-size: 14px; }
  .issues th, .issues td { padding: 11px 6px; }
  .issues th:first-child, .issues th:nth-child(2) { width: auto; }
  .issues th.act { width: 64px; }

  .table-panel { padding: 0; box-shadow: none; overflow: visible; }
  .sites, .sites tbody, .sites tr, .sites td { display: block; width: 100%; }
  .sites thead { display: none; }
  .sites tbody tr {
    margin-bottom: 18px;
    padding: 14px 18px;
    border-radius: var(--radius);
    box-shadow: var(--raised);
  }
  .sites tbody tr:hover { background: none; }
  .sites td {
    display: grid;
    grid-template-columns: 96px 1fr;
    align-items: center;
    gap: 4px 12px;
    padding: 6px 0;
    border-bottom: 0;
    white-space: nowrap;
    text-align: right;
  }
  .sites td::before { content: attr(data-label); color: var(--faint); font-size: 12px; font-weight: 700; text-align: left; }
  .sites td:not(.name) > * { justify-self: end; }
  .sites td .sub, .sites td .rear, .sites td .line { grid-column: 2; margin: 0; }
  .sites td.name { display: block; padding: 2px 0 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); text-align: left; font-size: 16px; }
  .sites td.name::before { content: none; }
  .sites td.num { text-align: right; }

  .detail-head { flex-wrap: wrap; gap: 14px; }
  .detail-title { order: 3; flex-basis: 100%; }
  .ctl-box { margin-left: auto; }
  .dialog form { padding: 22px 18px 18px; }
  .region-row { grid-template-columns: 1fr; }
  .detail-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-panel { padding: 16px 12px 12px; }
  /* 날짜 칩은 한 줄로 옆으로 밀어서 (세 줄로 쌓이지 않게) — 고른 날이 보이게 detail.js 가 맞춰 줌 */
  .chart-left { width: 100%; min-width: 0; }
  .days { position: relative; width: 100%; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }

}
