:root {
  --bg: #0f1419;
  --panel: #161c23;
  --panel-2: #1c242d;
  --line: #263039;
  --text: #dde5ec;
  --muted: #8b9aa8;
  --accent: #4da3ff;
  --ok: #5abe82;
  --warn: #e0a95a;
  --bad: #e06060;
  --crit: #ff4d4d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 13px/1.5 -apple-system, "Hiragino Sans", "Yu Gothic UI", "Malgun Gothic",
        "Noto Sans JP", "Noto Sans KR", "PingFang SC", "Microsoft YaHei",
        Segoe UI, sans-serif;
  overflow: hidden;
}

button {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 11px; cursor: pointer;
}
button:hover { background: #26303b; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
button.primary:hover { background: #6bb4ff; }
button.danger { color: var(--bad); border-color: #4a2a2a; }
button:disabled { opacity: .45; cursor: default; }

input, select {
  font: inherit; color: var(--text);
  background: #0d1216; border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; width: 100%;
}
input:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.field { margin-bottom: 10px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

#app { display: flex; height: 100%; }

/* ---------- 사이드바 ---------- */
#sidebar {
  width: 260px; flex: none; background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
/* 부제가 길어졌다. 한 줄에 나란히 두면 좁은 창에서 잘리므로 아래로 내린다.
   가로로 붙여 두면 언어에 따라 길이가 크게 달라져 어느 언어에선가 반드시 깨진다. */
#brand {
  padding: 14px 16px 10px; font-weight: 700; letter-spacing: .3px;
  display: flex; flex-direction: column; gap: 2px;
}
#brand small {
  font-weight: 400; color: var(--muted); font-size: 10px;
  letter-spacing: 0; line-height: 1.35;
}
#device-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }

.device {
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
  display: flex; align-items: center; gap: 9px; margin-bottom: 2px;
}
.device:hover { background: var(--panel-2); }
.device.active { background: #22303f; }
.device .name { flex: 1; min-width: 0; }
.device .name b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .name span { color: var(--muted); font-size: 11px; }
/* 장비를 고치거나 지우는 버튼. 평소에는 눈에 띄지 않다가 그 줄에 올리면
   드러난다 — 감시 화면에서 가장 자주 누르는 것은 장비 선택이지 편집이 아니다.
   다만 키보드로 옮겨 다닐 때는 항상 보여야 한다. */
.device .row-edit {
  opacity: 0; flex: none; padding: 2px 6px; font-size: 12px; line-height: 1;
  background: transparent; border-color: transparent; color: var(--muted);
}
.device:hover .row-edit,
.device .row-edit:focus-visible { opacity: 1; }
.device .row-edit:hover { color: var(--text); border-color: var(--line); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.up { background: var(--ok); }
.dot.down { background: var(--crit); box-shadow: 0 0 7px rgba(255,77,77,.7); }
.dot.unknown { background: #4a5764; }
/* 살아 있지만 하드웨어가 고장난 상태. 지도의 노드 색과 같은 값을 쓴다 —
   같은 장비를 목록과 지도가 다른 색으로 말하면 사람이 헷갈린다. */
.dot.hwcrit { background: #e0703c; box-shadow: 0 0 7px rgba(224,112,60,.6); }
.dot.hwwarn { background: var(--warn); }

#sidebar-foot { padding: 8px; border-top: 1px solid var(--line); display: flex; gap: 6px; }
#sidebar-foot button { flex: 1; }

/* ---------- 본문 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#tabs {
  display: flex; gap: 2px; padding: 8px 14px 0;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.tab {
  padding: 7px 14px; border-radius: 7px 7px 0 0; cursor: pointer;
  color: var(--muted); border: 1px solid transparent; border-bottom: none;
}
.tab.active { color: var(--text); background: var(--bg); border-color: var(--line); margin-bottom: -1px; }
.tab .badge {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 9px;
  background: var(--crit); color: #fff; font-size: 10px; font-weight: 700;
}

#views { flex: 1; overflow-y: auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; }

h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
h3 { margin: 20px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; }
.card .k { color: var(--muted); font-size: 11px; }
.card .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.card .v.bad { color: var(--bad); }
.card .v.ok { color: var(--ok); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 11px; }
tbody tr:hover { background: var(--panel); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.bar { height: 5px; background: #202a34; border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

.pill { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; }
.pill.up { background: #16311f; color: var(--ok); }
.pill.down { background: #331616; color: var(--bad); }
.pill.other { background: #2a2a16; color: var(--warn); }

.incident {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: 8px; padding: 11px 13px; margin-bottom: 8px;
}
.incident.critical { border-left-color: var(--crit); }
.incident.high { border-left-color: var(--bad); }
.incident.resolved { opacity: .55; border-left-color: var(--ok); }
.incident .head { display: flex; align-items: baseline; gap: 9px; }
.incident .head b { flex: 1; }
.incident .meta, .incident .why { color: var(--muted); font-size: 11px; margin-top: 4px; }
.incident .why { color: #b6c4d0; }
.incident ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 11px; }

.empty { color: var(--muted); padding: 28px; text-align: center; }
.hint { color: var(--muted); font-size: 11px; margin-top: 5px; }
.warnbox {
  background: #2a1f12; border: 1px solid #4a3a20; color: #e8c98a;
  border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 12px;
}

canvas { display: block; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }

#modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
#modal-back.open { display: flex; }
#modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  padding: 18px 20px; width: 460px; max-height: 88vh; overflow-y: auto;
}
#modal h3 { margin-top: 0; color: var(--text); font-size: 14px; }
#modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
#test-result { font-size: 12px; margin-top: 8px; padding: 9px; border-radius: 7px; background: #0d1216; }
#test-result.ok { color: var(--ok); }
#test-result.bad { color: var(--bad); }
.toggle { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.toggle input { width: auto; }
.toggle label { margin: 0; color: var(--text); font-size: 12px; }

/* ---------- 체험판 배너와 만료 화면 ---------- */
#banner {
  display: none; align-items: center; gap: 12px;
  padding: 8px 16px; font-size: 12px;
  background: #2a2412; border-bottom: 1px solid #4a4020; color: #e8d08a;
}
#banner.show { display: flex; }
#banner.urgent { background: #331a1a; border-bottom-color: #5a2a2a; color: #f0a0a0; }
#banner .grow { flex: 1; }
#banner button { padding: 3px 10px; font-size: 12px; }

#gate {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 14, 18, .94);
  display: none; align-items: center; justify-content: center; padding: 24px;
}
#gate.show { display: flex; }
#gate .box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px 30px; width: 540px; max-width: 100%;
}
#gate h2 { font-size: 19px; margin: 0 0 10px; }
#gate p { color: var(--muted); line-height: 1.65; margin: 0 0 18px; }
#gate .keyrow { display: flex; gap: 8px; }
#gate .keyrow input { flex: 1; font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12px; }
#gate .result { margin-top: 12px; font-size: 12px; min-height: 18px; }
#gate .result.ok { color: var(--ok); }
#gate .result.bad { color: var(--bad); }
#gate .contact { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line);
                 font-size: 12px; color: var(--muted); }

/* 탐색 대화상자는 결과 표가 들어가므로 넓게 */
#modal.wide { width: 760px; }
#modal.wide table { font-size: 12px; }
#modal.wide td { padding: 5px 7px; vertical-align: top; }
#modal textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
#sidebar-foot { flex-wrap: wrap; }
#sidebar-foot button { flex: 1 1 30%; font-size: 12px; padding: 5px 6px; }

/* ---------- 하드웨어 상태 ---------- */
.hstat { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 16px; }
.hstat .box { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; }
.hstat .box .k { color: var(--muted); font-size: 11px; }
.hstat .box .v { font-size: 22px; font-weight: 700; margin: 3px 0 6px; }
.hstat .box.warn { border-color: #4a3a20; }
.hstat .box.crit { border-color: #5a2a2a; }
.hstat .box.warn .v { color: var(--warn); }
.hstat .box.crit .v { color: var(--bad); }

.hrow { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.hrow .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hrow .val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 96px; text-align: right; }
.hrow .bar { width: 140px; flex: none; }

.pill.ok { background: #16311f; color: var(--ok); }
.pill.warn { background: #2a2416; color: var(--warn); }
.pill.crit { background: #331616; color: var(--bad); }
.pill.grey { background: #23292f; color: var(--muted); }

.unverified { color: var(--warn); font-size: 11px; }

/* ---------- 맵 ---------- */
#map-canvas { cursor: grab; }
#map-canvas:active { cursor: grabbing; }

/* ---------- 보고서 ---------- */
.spark { display: flex; align-items: flex-end; gap: 2px; height: 54px; margin-top: 6px; }
.spark i { flex: 1; background: var(--accent); border-radius: 1px 1px 0 0; min-height: 1px; opacity: .8; }

/* 형제 제품으로 건너가는 버튼 */
.detail-head { display: flex; align-items: center; gap: 12px; }
.detail-head h2 { margin: 0; }
.link-out { font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 6px;
  cursor: pointer; background: transparent; border: 1px solid currentColor; opacity: .75; }
.link-out:hover { opacity: 1; }
