/**
 * MyHome 대시보드. 색은 MyWorks STYLE_GUIDE.md 의 JIO 토큰을 옮겨 쓴다.
 * 상태 색(--st-*)은 map.js 가 getComputedStyle 로 읽는다 — Cytoscape 는
 * CSS 변수를 모르기 때문이다. 라이트에서는 흰 바탕에서 읽히도록 한 단계 진하게 둔다.
 */
:root {
  --ff-base: 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont,
             'Apple SD Gothic Neo', system-ui, sans-serif;
  --primary-main: #323f53;
  --warning-main: #ff9500;
  --error-main: #e42b2e;
  --grey-900: #212121; --grey-800: #303334; --grey-700: #46494b; --grey-600: #606365;
  --grey-500: #7e8184; --grey-200: #d8dadb; --grey-100: #ebebeb; --grey-50: #f8f8f8;
  --app-bg: var(--grey-50);
  --app-header-bg: #ffffff;
  --app-card-bg: #ffffff;
  --app-text: var(--grey-900);
  --app-text-muted: var(--grey-600);
  --app-border: var(--grey-200);
  --app-border-strong: #9ca3af;
  --app-hover-bg: var(--grey-100);
  --chart-1: #1f95ec;
  --chart-8: #7e8184;
  --st-ok: #15803d;
  --st-warn: #c2410c;
  --st-off: #c2410c;
  --st-down: #dc2626;
  --st-gone: #71717a;
  --st-parent_off: #a1a1aa;
  --st-none: #94a3b8;
  --st-down-bg: #fee2e2;
}

[data-bs-theme="dark"] {
  --primary-main: #7a85ff;
  --app-bg: #121212;
  --app-header-bg: #1e1e1e;
  --app-card-bg: #1e1e1e;
  --app-text: #ffffff;
  --app-text-muted: var(--grey-200);
  --app-border: var(--grey-700);
  --app-border-strong: #64748b;
  --app-hover-bg: var(--grey-800);
  --chart-8: #9c9fa1;
  --st-ok: #4ade80;
  --st-warn: #fbbf24;
  --st-off: #fbbf24;
  --st-down: #f87171;
  --st-gone: #a1a1aa;
  --st-parent_off: #71717a;
  --st-none: #64748b;
  --st-down-bg: #450a0a;
}

* { box-sizing: border-box; }
/* ID 선택자의 display 가 UA 의 [hidden] 보다 우선해서 화면이 겹친다. 명시로 이긴다. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--app-bg); color: var(--app-text); font: 14px/1.45 var(--ff-base); }
button { font: inherit; color: inherit; }
a { color: var(--primary-main); }
.muted { color: var(--app-text-muted); font-size: 12px; }

.center { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.box { width: min(360px, 100%); display: grid; gap: 10px; background: var(--app-card-bg);
       border: 1px solid var(--app-border); border-radius: 10px; padding: 24px; }
.box h1 { margin: 0 0 6px; font-size: 20px; }
.box input, .settings input { padding: 8px 10px; border: 1px solid var(--app-border); border-radius: 6px;
                              background: var(--app-bg); color: var(--app-text); }
.box button, .settings button, .side-actions button { padding: 8px 12px; border: 0; border-radius: 6px;
                                                       background: var(--primary-main); color: #fff; cursor: pointer; }
.error { color: var(--error-main); min-height: 1em; margin: 0; }

.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px;
       background: var(--app-header-bg); border-bottom: 1px solid var(--app-border); }
.logo { font-size: 16px; }
.sites { display: flex; gap: 14px; flex-wrap: wrap; margin-right: auto; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.tabs { display: flex; gap: 4px; }
.tabs button, .icon-btn { background: none; border: 0; padding: 4px 10px; border-radius: 6px; cursor: pointer;
                          color: var(--app-text-muted); }
.tabs button.on { background: var(--app-hover-bg); color: var(--app-text); }
.alerts { background: var(--st-down-bg); color: var(--st-down); padding: 7px 16px; font-size: 13px; }
.alerts div + div { margin-top: 2px; }

/* 앱 전체를 창 높이에 맞춘 세로 flex 로 둔다. 헤더·경고·카드가 쓰고 남은 높이를
   구성도가 정확히 채운다 — 예전처럼 calc(100vh - 170px) 로 어림하면 경고 줄이
   생기거나 카드가 두 줄로 접힐 때 화면이 남거나 스크롤이 생긴다.
   dvh 는 모바일 주소창이 접히고 펴지는 것까지 따라간다. */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#app > .top, #app > .alerts, .cards { flex: none; }
#view-map { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#view-power { flex: 1; min-height: 0; overflow: auto; }
.map-main { flex: 1; min-height: 0; display: flex; }
#cy { flex: 1; min-width: 0; min-height: 0; }
#side { flex: none; width: clamp(280px, 26vw, 420px); border-left: 1px solid var(--app-border); background: var(--app-card-bg); padding: 14px; overflow: auto; }
#side h3 { margin: 0 0 4px; font-size: 16px; }
.kv { display: grid; grid-template-columns: 80px 1fr; gap: 3px 8px; font-size: 13px; margin: 10px 0; }
.kv span:nth-child(odd) { color: var(--app-text-muted); }
.rows div { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 3px 0;
            border-bottom: 1px solid var(--app-border); }
.bar { display: flex; gap: 1px; height: 16px; margin: 6px 0 2px; }
.bar i { flex: 1; border-radius: 1px; }
.bar-legend { display: flex; justify-content: space-between; }
.s-ok { background: var(--st-ok); }
.s-warn, .s-off { background: var(--st-warn); }
.s-down { background: var(--st-down); }
.s-gone { background: var(--st-gone); }
.s-parent_off { background: var(--st-parent_off); }
.s-none { background: var(--app-border); }
.newdev { width: 100%; border-collapse: collapse; font-size: 12px; }
.newdev td { padding: 4px 2px; border-bottom: 1px solid var(--app-border); vertical-align: top; }
.newdev input, .newdev select { width: 100%; margin-bottom: 3px; background: var(--app-bg); color: var(--app-text);
                                border: 1px solid var(--app-border); border-radius: 4px; padding: 2px 4px; }
.side-actions { display: flex; gap: 4px; }
.side-actions button.secondary { background: var(--app-hover-bg); color: var(--app-text); }

.cards { display: flex; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--app-border); flex-wrap: wrap; }
.card { flex: 1; min-width: 180px; display: grid; gap: 2px; text-align: left; background: var(--app-card-bg);
        border: 1px solid var(--app-border); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.big { font-size: 20px; font-weight: 600; }

.power { padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.grid .card { cursor: default; }
.chart, .table-wrap { overflow-x: auto; }
#power-table { border-collapse: collapse; width: 100%; font-size: 13px; }
#power-table td, #power-table th { padding: 5px 8px; border-bottom: 1px solid var(--app-border); text-align: right; white-space: nowrap; }
#power-table td:nth-child(-n+2), #power-table th:nth-child(-n+2) { text-align: left; }
.est { background: var(--app-hover-bg); color: var(--st-warn); border-radius: 4px; padding: 0 5px; font-size: 11px; margin-left: 4px; }
.settings { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.settings label { display: grid; gap: 2px; font-size: 12px; color: var(--app-text-muted); }
.settings input { width: 110px; }
.uplot { color: var(--app-text); }

/* 좁은 화면에서는 구성도와 상세 패널을 위아래로 쌓는다. 둘 다 창 높이 안에
   넣으면 어느 쪽도 읽을 수 없으므로, 여기서는 페이지 스크롤을 허용한다. */
@media (max-width: 800px) {
  #app { height: auto; min-height: 100dvh; }
  #view-map, .map-main { flex: none; }
  #view-power { overflow: visible; }
  .map-main { flex-direction: column; }
  #cy { flex: none; height: 70vh; height: 70svh; min-height: 360px; }
  #side { width: auto; border-left: 0; border-top: 1px solid var(--app-border); }
  .card { min-width: 140px; }
}
