/* 도씨 앱 공통 틀 — 고객·관리자 화면이 같이 쓴다. 색은 /css/tokens.css
   배치: IoT Device Monitoring Dashboard 키트(Figma 7iQe6OLWBxA5jMml0ZitkI) — 그라디언트 바탕 위 사이드바 +
   둥근 본문 판, 요약 카드, 상태 도넛, 남색 머리줄 표, 단색 심각도 칩. 키트의 진홍색은 도씨 파랑으로 바꿨다.
   부품: Untitled UI(dSgbJDMMllCFGYKTqloJY2) — 단추 3287:427299/427323, 입력칸 3531:402962, 모달, 배지, 툴팁.
   글자: Pretendard 하나만 쓴다(사용자 취향: 글꼴 섞지 않기, 고정폭 글꼴 금지). 휴대폰에서는 아래 탭 막대(IOT application 키트)로 바뀐다. */

:root {
  --frame: linear-gradient(135deg, #1e2f62 0%, #1849a9 100%);
  --canvas: #eef0f4;
  --card: #ffffff;
  --card-line: #e5e7eb;
  --heading: #1e2f62;
  --nav-ink: rgba(255, 255, 255, .92);
  --font-num: var(--font);   /* 숫자도 같은 글꼴. 칸 맞춤은 tabular-nums 로 */
  --sidebar-w: 232px;
  --ok: #27ae60;
  --warn: #64748b;   /* 주의: 회청색. 빨강(--crit)은 진짜 위험에만 */
  --crit: #dc1500;
  --low: #f2c94c;
  --offline: #8a94a6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --frame: #050506;   /* 어두운 화면은 파랑 없이 무채색 (사용자 취향) */
    --canvas: #0e0e10;
    --card: #17181b;
    --card-line: #2a2c31;
    --heading: #e8eefc;
    --ok: #4cc38a;
    --warn: #7c8aa0;
    --crit: #ff5a47;
    --low: #f2d06b;
    --offline: #7c8698;
  }
}
:root[data-theme="dark"] {
  --frame: #050506;   /* 어두운 화면은 파랑 없이 무채색 (사용자 취향) */
  --canvas: #0e0e10;
  --card: #17181b;
  --card-line: #2a2c31;
  --heading: #e8eefc;
  --ok: #4cc38a;
  --warn: #7c8aa0;
  --crit: #ff5a47;
  --low: #f2d06b;
  --offline: #7c8698;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html:has(body.app) { background: #1e2f62; }
:root[data-theme="dark"]:has(body.app) { background: #050506; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]):has(body.app) { background: #050506; } }
body.app {
  margin: 0;
  min-height: 100vh;
  background: var(--frame) fixed;
  color: var(--text-primary);
  font: 400 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--text-brand); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ===== 아이콘: Untitled UI SVG 를 글자색으로 칠한다 (/icons/*.svg) ===== */
.icon {
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  background: currentColor;
  -webkit-mask: var(--i) center / contain no-repeat;
  mask: var(--i) center / contain no-repeat;
}

/* ===== 사이드바 ===== */
.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 28px 0 20px 16px;
  color: var(--nav-ink);
  overflow-y: auto;
}
.app-logo { display: block; padding: 0 12px 36px; }
.app-logo img { height: 30px; width: auto; display: block; }
.app-nav { display: flex; flex-direction: column; gap: 6px; }
.app-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 16px;
  border-radius: 14px 0 0 14px;
  color: var(--nav-ink);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  transition: background-color 120ms;
}
.app-nav a:hover { background: rgba(255, 255, 255, .08); }
.app-nav a .badge-count {
  margin-left: auto;
  margin-right: 8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--crit);
  color: #fff;
  font: 700 12px/22px var(--font-num);
  text-align: center;
}
/* 선택된 메뉴는 본문 판과 이어진 탭 모양 (키트) */
.app-nav a[aria-current="page"] {
  background: var(--canvas);
  color: var(--heading);
}
.app-nav a[aria-current="page"]::before,
.app-nav a[aria-current="page"]::after {
  content: '';
  position: absolute;
  right: 0;
  width: 16px;
  height: 16px;
  pointer-events: none;
}
.app-nav a[aria-current="page"]::before { top: -16px; background: radial-gradient(circle at 0 0, transparent 16px, var(--canvas) 16.5px); }
.app-nav a[aria-current="page"]::after { bottom: -16px; background: radial-gradient(circle at 0 100%, transparent 16px, var(--canvas) 16.5px); }
.app-side-foot { margin-top: auto; padding: 24px 16px 0 12px; }
.app-install { display: flex; align-items: center; gap: 12px; width: calc(100% + 12px); height: 48px; margin: 0 0 20px -12px; padding: 0 16px; border: 0; border-radius: 8px; background: none; color: var(--nav-ink); font: 600 15px var(--font); text-align: left; cursor: pointer; }
.app-install:hover { background: rgba(255, 255, 255, .1); }
.app-install[hidden] { display: none; }
.app-install .icon { width: 20px; height: 20px; }
.app-help { color: #fff; }
.app-help strong { display: block; font-size: 18px; font-weight: 600; }
.app-help span { display: block; margin: 2px 0 12px; font-size: 13px; color: rgba(255, 255, 255, .7); }
.app-help a {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 8px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

/* ===== 본문 판 ===== */
.app-main {
  margin-left: var(--sidebar-w);
  padding: 16px 16px 16px 0;
  min-height: 100vh;
}
.app-canvas {
  min-height: calc(100vh - 32px);
  padding: 28px 32px 40px;
  border-radius: 20px;
  background: var(--canvas);
}
.app-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.app-head-text { min-width: 0; }
.app-greet { margin: 0 0 2px; font-size: 15px; color: var(--text-quaternary); }
.app-title {
  margin: 0;
  font-size: 26px;
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--heading);
}
.app-head-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* 사용자 메뉴 */
.user-menu { position: relative; }
.user-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.user-btn:hover { background: var(--bg-tertiary); }
.avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-100);
  color: var(--brand-700);
}
.avatar .icon { width: 20px; height: 20px; }
.user-btn .who { display: flex; flex-direction: column; line-height: 1.3; }
.user-btn .who b { font-size: 14px; color: var(--text-primary); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn .who small { font-size: 12px; color: var(--text-quaternary); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--border-secondary);
  border-radius: 12px;
  background: var(--bg-primary);
  box-shadow: var(--shadow-lg);
}
.menu a, .menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
}
.menu a:hover, .menu button:hover { background: var(--bg-tertiary); }
.menu hr { margin: 6px 0; border: 0; border-top: 1px solid var(--border-secondary); }

/* ===== Untitled UI 단추 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 14px;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 1px 2px #0000000d, inset 0 0 0 1px #0000002e, inset 0 -2px 0 0 #0000000d;
  transition: background-color 120ms;
}
.btn > span:not(.icon) { padding: 0 2px; }
.btn:hover { background: var(--bg-secondary); }
.btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { border: 2px solid rgba(255, 255, 255, .12); background: var(--brand-600); color: #fff; }
.btn.primary:hover { background: var(--brand-700); }
.btn.danger { border: 2px solid rgba(255, 255, 255, .12); background: var(--error-fg); color: #fff; }
.btn.danger:hover { filter: brightness(.92); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--text-tertiary); }
.btn.ghost:hover { background: var(--bg-tertiary); }
.btn.sm { padding: 8px 12px; }
.btn.icon-only { padding: 10px; }
.btn.sm.icon-only { padding: 8px; }

/* ===== Untitled UI 입력칸 ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-size: 14px; line-height: 20px; font-weight: 500; color: var(--text-secondary); }
.field .hint { font-size: 14px; line-height: 20px; color: var(--text-tertiary); }
.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 24px;
  box-shadow: 0 1px 2px #0000000d;
}
.input.sm, .select.sm { min-height: 40px; font-size: 14px; line-height: 20px; }
.input::placeholder, .textarea::placeholder { color: var(--text-placeholder); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 4px rgba(46, 144, 250, .24); }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-quaternary); }
.input-icon .input { padding-left: 40px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text-secondary); }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand-600); }
/* 켜고 끄기 */
.switch { position: relative; display: inline-flex; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { width: 100%; height: 100%; border-radius: 10px; background: var(--bg-tertiary); box-shadow: inset 0 0 0 1px var(--border-primary); transition: background-color 120ms; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #0000001a; transition: transform 120ms; }
.switch input:checked + span { background: var(--brand-600); box-shadow: none; }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ===== 카드 ===== */
.grid { display: grid; gap: 20px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  position: relative;
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--card-line);
  border-radius: 14px;
  background: var(--card);
}
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.card-title { margin: 0; font-size: 16px; font-weight: 700; color: var(--text-secondary); }
.card-sub { margin: 0; font-size: 13px; color: var(--text-quaternary); }
.card-head .spacer, .spacer { flex: 1; }

/* 요약 카드 — 제목 + 큰 숫자 + 물결 그래프 */
.stat { overflow: hidden; padding-bottom: 0; }
.stat .card-title { font-size: 15px; }
.stat-value { margin: 6px 0 0; font: 700 34px/1.15 var(--font-num); color: var(--heading); letter-spacing: -.01em; }
.stat-value small { font-size: 16px; font-weight: 600; color: var(--text-quaternary); margin-left: 2px; }
.stat-note { margin: 4px 0 0; font-size: 13px; color: var(--text-quaternary); }
.stat-spark { display: block; width: calc(100% + 40px); height: 64px; margin: 8px -20px 0; }
.stat.flat { padding-bottom: 20px; }

/* 상태 도넛 */
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; flex: 1; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.legend i { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.legend b { margin-left: auto; font: 700 14px var(--font-num); }

/* ===== 상태 글자 =====
   채운 칩·알약 배지는 쓰지 않는다 (사용자: "AI 같아 보인다"). 상태는 글자 색과 작은 점으로만 보이고,
   정상은 되도록 따로 표시하지 않는다(문제가 있을 때만 눈에 띄게).
   .chip = 굵은 상태 글자(고온·저온·끊김), .badge = 작은 점 + 글자(온라인·구독 중·확인됨) */
.chip { display: inline-flex; align-items: center; font-size: 13px; font-weight: 700; white-space: nowrap; color: var(--text-tertiary); }
.chip.ok { color: var(--success-fg); }
.chip.warn { color: var(--warning-fg); }
.chip.crit { color: var(--error-fg); }
.chip.cold { color: var(--text-brand); }
.chip.low { color: var(--text-secondary); }
.chip.off { color: var(--text-quaternary); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; line-height: 18px; font-weight: 600; white-space: nowrap; color: var(--text-tertiary); }
.badge.ok { color: var(--text-secondary); }
.badge.warn { color: var(--warning-fg); }
.badge.crit { color: var(--error-fg); }
.badge.brand { color: var(--text-brand); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-quaternary); }
.badge.ok .dot { background: var(--ok); }
.badge.crit .dot { background: var(--crit); }
.badge.brand .dot { background: var(--brand-500); }
.badge.warn .dot { background: var(--warn); }

/* ===== 표 (키트: 남색 머리줄 + 흰 본문) ===== */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.toolbar .input-icon { width: 280px; max-width: 100%; }
.table-wrap { border-radius: 14px; overflow: hidden; border: 1px solid var(--card-line); background: var(--card); }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }   /* collapse 는 크롬에서 머리줄 칸 사이에 틈이 보인다 */
/* 칸 경계가 소수점 픽셀이면 크롬이 칸 사이에 1px 틈을 남긴다 → 오른쪽으로 1px 같은 색을 덧칠해 덮는다 */
.table thead { background: var(--heading); }
.table thead th {
  background: var(--heading);
  box-shadow: 1px 0 0 var(--heading);
  padding: 16px 20px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  word-break: keep-all;
}
:root[data-theme="dark"] .table thead, :root[data-theme="dark"] .table thead th { background: #1f2a4d; box-shadow: 1px 0 0 #1f2a4d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .table thead, :root:not([data-theme="light"]) .table thead th { background: #1f2a4d; box-shadow: 1px 0 0 #1f2a4d; } }
.table td {
  padding: 14px 20px;
  border-top: 1px solid var(--card-line);
  font-size: 14px;
  color: var(--text-secondary);
  vertical-align: middle;
  overflow-wrap: anywhere;   /* 긴 이메일·코드도 줄을 바꿔 가로 스크롤이 생기지 않게 */
}
.table tbody tr:first-child td { border-top: 0; }
.table tbody tr:hover td { background: var(--bg-secondary); }
.table .strong { color: var(--text-primary); font-weight: 600; }
.table .muted { color: var(--text-quaternary); font-size: 13px; }
.table .right { text-align: right; }
.table .center { text-align: center; }
.row-icon {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
}
.row-icon.crit { background: var(--error-bg); color: var(--crit); }
.row-icon.warn { background: var(--warning-bg); color: var(--warn); }
.row-icon.ok { background: var(--success-bg); color: var(--ok); }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--card-line); font-size: 13px; color: var(--text-tertiary); }

/* 빈 상태 */
.empty { padding: 48px 20px; text-align: center; color: var(--text-quaternary); }
.empty .icon { width: 40px; height: 40px; margin-bottom: 12px; color: var(--text-placeholder); }
.empty p { margin: 0 0 16px; }

/* ===== 모달 (Untitled UI: 16px 모서리, 24px 여백) ===== */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 13, 18, .6);
  backdrop-filter: blur(4px);
}
.modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 24px;
  border-radius: 16px;
  background: var(--bg-primary);
  box-shadow: 0 20px 24px -4px #00000014, 0 8px 8px -4px #00000008;
}
.modal.wide { max-width: 720px; }
.modal h2 { margin: 0 0 4px; font-size: 18px; line-height: 28px; font-weight: 600; color: var(--text-primary); }
.modal .modal-desc { margin: 0 0 20px; font-size: 14px; color: var(--text-tertiary); }
.modal-body { display: grid; gap: 16px; }
.add-steps { margin: 0; padding-left: 22px; display: grid; gap: 10px; font-size: 15px; line-height: 1.5; color: var(--text-primary); }
.modal-actions { display: flex; gap: 12px; margin-top: 24px; }
.modal-actions .btn { flex: 1; }

/* 알림 띠 (IOT application 키트: 연결됨/오류) */
.toast-stack { position: fixed; z-index: 60; right: 20px; bottom: 20px; display: grid; gap: 8px; }
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--ok);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}
.toast.error { background: var(--crit); }
.toast.info { background: var(--heading); }

/* 알림 상자 */
.notice { display: flex; gap: 12px; padding: 14px 16px; border-radius: 12px; border: 1px solid; font-size: 14px; }
.notice.warn { background: var(--warning-bg); border-color: color-mix(in srgb, var(--warning-fg) 30%, transparent); color: var(--warning-fg); }
.notice.crit { background: var(--error-bg); border-color: color-mix(in srgb, var(--error-fg) 30%, transparent); color: var(--error-fg); }
.notice.info { background: var(--brand-50); border-color: var(--brand-200); color: var(--brand-800); }
:root[data-theme="dark"] .notice.info { background: rgba(46, 144, 250, .12); border-color: rgba(46, 144, 250, .3); color: var(--brand-200); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .notice.info { background: rgba(46, 144, 250, .12); border-color: rgba(46, 144, 250, .3); color: var(--brand-200); } }

/* 탭 (Untitled UI 버튼 그룹) */
.tabs { display: inline-flex; border: 1px solid var(--border-primary); border-radius: 8px; overflow: hidden; box-shadow: 0 1px 2px #0000000d; }
.tabs button { padding: 8px 16px; border: 0; border-left: 1px solid var(--border-primary); background: var(--bg-primary); color: var(--text-secondary); font-size: 14px; font-weight: 600; cursor: pointer; }
.tabs button:first-child { border-left: 0; }
.tabs button[aria-pressed="true"] { background: var(--bg-tertiary); color: var(--text-primary); }

.skeleton { border-radius: 8px; background: linear-gradient(90deg, var(--bg-tertiary), var(--bg-secondary), var(--bg-tertiary)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ===== 휴대폰 탭 막대 ===== */
.app-tabbar { display: none; }
.app-topbar { display: none; }

@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  body.app { background: var(--canvas); padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .app-sidebar { display: none; }
  .app-main { margin: 0; padding: 0; }
  .app-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 20;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    background: var(--frame);
    color: #fff;
  }
  .app-topbar img { height: 24px; }
  .app-topbar .user-btn .who { display: none; }
  .app-topbar .avatar { width: 34px; height: 34px; font-size: 14px; }
  .app-canvas { min-height: 0; padding: 20px 16px 28px; border-radius: 0; }
  .app-head { margin-bottom: 16px; flex-wrap: wrap; }
  .app-head-actions { margin-left: 0; width: 100%; }
  .app-head-actions .btn { flex: 1; }
  .span-2-m { grid-column: 1 / -1; }
  .app-head .user-menu { display: none; }
  .app-title { font-size: 22px; }
  .grid { gap: 12px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 16px; border-radius: 16px; }
  .stat-spark { width: calc(100% + 32px); margin: 8px -16px 0; height: 48px; }
  .stat-value { font-size: 26px; }
  .app-tabbar {
    display: flex;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 20;
    padding: 6px 4px env(safe-area-inset-bottom);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-secondary);
  }
  .app-tabbar a, .app-tabbar button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 52px;
    padding: 4px 0;
    border: 0;
    background: none;
    color: var(--text-quaternary);
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
  }
  .app-tabbar .icon { width: 24px; height: 24px; }
  .app-tabbar [aria-current="page"] { color: var(--brand-600); }
  .btn, .input, .select { min-height: 44px; }
  .table thead th, .table td { padding: 12px 14px; }
  .toast-stack { left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  .menu.sheet { position: fixed; inset: auto 8px calc(72px + env(safe-area-inset-bottom)) 8px; top: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media print {
  body.app { background: #fff; }
  .app-sidebar, .app-topbar, .app-tabbar, .app-head-actions, .toolbar { display: none !important; }
  .app-main { margin: 0; padding: 0; }
  .app-canvas { padding: 0; background: #fff; }
}

/* ===== 대시보드: 기기 카드 + 센서 타일 (IOT application 키트의 기기 타일) ===== */
.stat-icon { position: absolute; right: 16px; bottom: 14px; width: 56px; height: 56px; color: var(--text-primary); opacity: .08; }
.stat-value.crit { color: var(--crit); }
/* 온도 그래프 (tempchart.js): 대시보드 방 창·알림 펼치기 */
.tc { position: relative; height: 240px; }
.tc-note { display: flex; height: 100%; align-items: center; justify-content: center; margin: 0; font-size: 14px; color: var(--text-tertiary); }
.room-top { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 16px; margin-bottom: 8px; }
.room-top .modal-desc { margin-bottom: 0; }
/* 기기 모습 (box3d.js): 화면 폭을 다 쓰는 DOSSI BOX, 아래에 방 카드, 박스에서 카드로 가는 가는 선 */
.box3d { position: relative; margin-top: 4px; padding: 20px 24px 32px; border-radius: 24px;
  background: linear-gradient(180deg, #d9dfe9 0%, #e6eaf1 55%, #eff2f6 100%); }   /* 박스가 걸린 옅은 회청색 벽 */
.box3d-tabs { display: flex; justify-content: center; gap: 6px; margin: 0 auto 4px; }
.box3d-tabs[hidden] { display: none; }
.box3d-tabs button { padding: 8px 16px; border: 1px solid transparent; border-radius: 999px; background: none; color: var(--text-tertiary); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.box3d-tabs button[aria-pressed="true"] { border-color: var(--border-primary, #d5d7da); background: var(--bg-primary, #fff); color: var(--text-primary); box-shadow: 0 1px 2px rgba(16, 24, 40, .06); }
.box3d-stage { position: relative; display: flex; flex-direction: column; align-items: center; gap: 44px; }
.box3d-view { width: 100%; height: clamp(440px, 56vh, 640px); cursor: grab; }
.box3d-view:active { cursor: grabbing; }
.box3d-view canvas { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.box3d-wires { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.wire { fill: none; stroke: #a3acba; stroke-width: 1.25; opacity: .8; }
.wire.dot { fill: #fff; stroke-width: 1.5; opacity: 1; }
.wire.out { stroke: #d92d20; opacity: .55; }
.wire.out.dot { opacity: 1; }
.wire.off { stroke-dasharray: 3 5; opacity: .45; }
.box3d-rooms { position: relative; display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; width: 100%; }
.room { flex: 0 1 300px; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name state" "temp range"; align-items: end; row-gap: 8px; padding: 18px 20px;
  border: 1px solid var(--border-secondary, #e9eaeb); border-radius: 16px; background: var(--bg-primary, #fff); box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 12px 28px -18px rgba(16, 24, 40, .2); }
.room { font: inherit; color: inherit; text-align: left; cursor: pointer; transition: transform .2s ease, box-shadow .2s ease; }
.room:hover { transform: translateY(-2px); box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 18px 34px -18px rgba(16, 24, 40, .28); }
.room:focus-visible { outline: 2px solid var(--brand-600, #2563eb); outline-offset: 2px; }
.room p { margin: 0; }
.room-name { grid-area: name; font-size: 15px; font-weight: 600; color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-temp { grid-area: temp; line-height: 1; color: var(--text-primary); }
.room-temp b { font-size: 44px; font-weight: 700; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.room-temp small { margin-left: 2px; font-size: 16px; color: var(--text-tertiary); }
.room-state { grid-area: state; justify-self: end; display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: #2f7d5b; }
.room-state i { width: 14px; height: 14px; background: currentColor; -webkit-mask: url(/icons/check.svg) center / contain no-repeat; mask: url(/icons/check.svg) center / contain no-repeat; }
.room-range { grid-area: range; justify-self: end; font-size: 12px; color: var(--text-tertiary); }
.room.out { border-color: rgba(217, 45, 32, .4); }
.room.out .room-state, .room.out .room-temp b { color: var(--error-fg); }
.room.out .room-state i { -webkit-mask-image: url(/icons/alert-triangle.svg); mask-image: url(/icons/alert-triangle.svg); }
.room.off .room-state { color: var(--text-tertiary); }
.room.off .room-state i { display: none; }
.box3d-caption { margin: 10px 0 0; text-align: center; font-size: 13px; color: var(--error-fg); }
/* 고르기 모드 (설정 → 일지): 누르면 박스에서 방으로 파란 선이 그어지고 체크가 그려진다 */
.wire.pickline { stroke-dasharray: 3 5; opacity: .5; }
.wire-link { fill: none; stroke: var(--brand-600); stroke-width: 2.25; stroke-linecap: round; stroke-dasharray: 1 1; stroke-dashoffset: 1; transition: stroke-dashoffset .55s cubic-bezier(.2, .7, .2, 1); }
.wire-link.on { stroke-dashoffset: 0; }
.room.pick { grid-template-columns: 1fr auto; grid-template-areas: "name check" "sub check"; align-items: center; row-gap: 4px; }
.room.pick:not(.on) { opacity: .72; }
.room.pick.on { border-color: color-mix(in srgb, var(--brand-600) 45%, transparent); }
.room.pick .room-name { font-size: 17px; color: var(--text-primary); }
.room-sub { grid-area: sub; margin: 0; font-size: 13px; color: var(--text-tertiary); }
.room.pick.on .room-sub { color: var(--brand-600); font-weight: 600; }
.room-check { grid-area: check; width: 40px; height: 40px; }
.room-check circle { fill: transparent; stroke: var(--border-primary, #d4d4d4); stroke-width: 2; transition: fill .25s .35s, stroke .25s .35s; }
.room-check path { fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.room.pick.on .room-check circle { fill: var(--brand-600); stroke: var(--brand-600); }
.room.pick.on .room-check path { stroke-dashoffset: 0; transition: stroke-dashoffset .3s .5s ease-out; }
.room.pick.on .room-check { animation: pick-pop .45s .45s ease-out; }
@keyframes pick-pop { 40% { transform: scale(1.15); } 100% { transform: scale(1); } }
:root[data-theme="dark"] .box3d { background: linear-gradient(180deg, #1c212b 0%, #161a22 100%); }
:root[data-theme="dark"] .room:not(.out):not(.off) .room-state { color: #7fd1a8; }   /* 벗어남·끊김 색은 그대로 */
:root[data-theme="dark"] .wire.dot { fill: #1f232b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .box3d { background: linear-gradient(180deg, #1c212b 0%, #161a22 100%); }
  :root:not([data-theme="light"]) .room:not(.out):not(.off) .room-state { color: #7fd1a8; }
  :root:not([data-theme="light"]) .wire.dot { fill: #1f232b; }
}
@media (max-width: 719px) {
  .box3d { padding: 14px 12px 18px; border-radius: 18px; }
  .box3d-stage { gap: 28px; }
  .box3d-view { height: 290px; }
  .box3d-rooms { gap: 10px; }
  .room { flex: 1 1 140px; grid-template-columns: 1fr; grid-template-areas: "name" "temp" "state" "range"; padding: 14px 16px; }
  .room-state, .room-range { justify-self: start; }
  .room-temp b { font-size: 30px; }
}

.devices { display: grid; gap: 20px; margin-top: 20px; }
.devices[hidden] { display: none; }
.device-card { padding: 0; overflow: hidden; }
.device-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 18px 20px; border-bottom: 1px solid var(--card-line); }
.device-name { margin: 0; font-size: 18px; font-weight: 700; color: var(--text-primary); }
.device-serial { font: 500 12px var(--font-num); color: var(--text-quaternary); }
.device-meta { flex-basis: 100%; margin: 0; font-size: 13px; color: var(--text-quaternary); }
.device-head .badges { display: flex; gap: 6px; margin-left: auto; }
.sensor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; padding: 16px 20px 20px; }
.sensor-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--card-line);
  border-radius: 14px;
  background: var(--bg-secondary);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms, box-shadow 120ms;
}
.sensor-tile:hover { border-color: var(--brand-300); box-shadow: 0 4px 12px rgba(21, 112, 239, .08); }
.sensor-tile:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.sensor-tile.alert { border-color: color-mix(in srgb, var(--crit) 55%, transparent); background: color-mix(in srgb, var(--crit) 6%, var(--bg-secondary)); }
.sensor-tile.offline { opacity: .6; }
.sensor-tile.dragging { opacity: .4; }
.sensor-tile.drag-over { border-color: var(--brand-500); border-style: dashed; }
.tile-top { display: flex; align-items: center; gap: 8px; }
.tile-name { flex: 1; min-width: 0; font-weight: 700; font-size: 14px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-temp { font: 700 40px/1 var(--font-num); letter-spacing: -.02em; color: var(--text-primary); }
.tile-temp small { font-size: 18px; font-weight: 600; margin-left: 2px; color: var(--text-quaternary); }
.sensor-tile.alert .tile-temp { color: var(--crit); }
/* 범위 눈금: 가는 선 위 정상 범위는 조금 진한 회색, 현재 온도는 세로 눈금 하나 */
.range { position: relative; height: 4px; margin: 6px 0; border-radius: 2px; background: var(--bg-tertiary); }
.range .zone { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--border-primary); }
.range .mark { position: absolute; top: 50%; width: 2px; height: 14px; margin-left: -1px; border-radius: 1px; background: var(--text-primary); transform: translateY(-50%); transition: left 600ms ease; }
.sensor-tile.alert .range .mark { background: var(--crit); }
.tile-range { display: flex; justify-content: space-between; font: 600 12px var(--font-num); color: var(--text-quaternary); }
.tile-foot { font-size: 12px; color: var(--text-quaternary); }
.sensor-wait { grid-column: 1 / -1; padding: 28px; text-align: center; color: var(--text-quaternary); }
/* 기준 온도계로 맞추기 */
.calib-now { margin: 0; font-size: 14px; color: var(--text-secondary); }
.calib-now b { font-weight: 700; color: var(--text-primary); }
.calib-row { display: flex; gap: 8px; }
.calib-row .input { flex: 1; min-width: 0; }
.link-btn { border: 0; background: none; padding: 0; color: var(--text-brand); font: inherit; font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
/* 프리셋: 글자 단추 한 줄 ("빠른 입력  냉동실 · 냉장실 · 지육실") */
.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; font-size: 14px; color: var(--text-tertiary); }
.preset-row button { border: 0; background: none; padding: 4px 0; color: var(--text-brand); font: 600 14px var(--font); cursor: pointer; }
.preset-row button:hover { text-decoration: underline; text-underline-offset: 3px; }
.preset-row button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { margin: 0; font-size: 14px; color: var(--error-fg); }
@media (max-width: 860px) {
  /* 요약 3개는 한 줄에 작게, 도넛은 아래 한 줄 */
  .dash-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dash-stats .span-2-m { grid-column: 1 / -1; }
  .dash-stats .stat { padding: 12px; }
  .dash-stats .stat .card-title { font-size: 13px; }
  .dash-stats .stat-value { font-size: 22px; }
  .dash-stats .stat-note { font-size: 11px; line-height: 1.35; }
  .dash-stats .stat-icon { display: none; }
  .sensor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 10px; }
  .sensor-tile { padding: 12px; gap: 8px; }
  .tile-temp { font-size: 30px; }
  .device-head { padding: 14px 16px; }
  .stat-icon { width: 40px; height: 40px; }
}

/* ===== 관리자 "고객 화면으로 보기" 띠 ===== */
.viewas-bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 45;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--brand-700);
  color: #fff;
  font-size: 14px;
}
.viewas-bar .icon { width: 18px; height: 18px; }
.viewas-bar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewas-bar .btn { flex: none; min-height: 34px; border-color: transparent; }
body.app.viewas { padding-top: 48px; }
body.app.viewas .app-sidebar { top: 48px; }
@media (max-width: 860px) {
  body.app.viewas .app-topbar { top: 48px; }
  .viewas-bar { justify-content: space-between; font-size: 13px; }
}

/* 기다릴 때 도는 고리 (Figma Loading Spinner 키트의 'Loading 3': 꼬리가 옅어지는 3/4 원). 색은 글자색을 따른다 */
.spinner {
  display: inline-block;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 25%, currentColor);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
  animation: spinner-turn .9s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spinner-turn { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
