/* 원격관리 콘솔 — 차분한 화면 + 잠금화면 같은 인증 코드 입력 하나만 강조 */
:root {
  --paper: #f4f6f5;
  --surface: #ffffff;
  --ink: #17212b;
  --ink-2: #4a5866;
  --ink-3: #75828e;
  --line: #d8dfdd;
  --line-2: #e8edeb;
  --jade: #0f6e5f;
  --jade-deep: #0a4c42;
  --jade-tint: #e3f1ee;
  --amber: #8f5a0c;
  --amber-tint: #fbf1df;
  --red: #b42318;
  --red-tint: #fcebe9;
  --focus: 0 0 0 3px rgba(15, 110, 95, 0.35);
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --r-sm: 6px;
  --r-md: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  word-break: keep-all;
}
h1, h2, h3 { line-height: 1.3; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0 0 12px; }
a { color: var(--jade); }
code, .num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ───── 폼 요소 ───── */
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.hint { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  min-height: 42px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, .nav a:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-color: var(--jade);
}
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--jade); vertical-align: -3px; margin: 0 6px 0 0; }
.check { display: flex; align-items: center; font-weight: 500; margin: 0; cursor: pointer; }

button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 14px;
  min-height: 38px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--ink-3); }
button.primary { background: var(--jade); border-color: var(--jade); color: #fff; }
button.primary:hover { background: var(--jade-deep); border-color: var(--jade-deep); }
button.danger { color: var(--red); }
button.danger:hover { border-color: var(--red); }
button.link { border: 0; background: none; color: var(--jade); padding: 4px 0; min-height: 0; text-decoration: underline; text-underline-offset: 3px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.wide { width: 100%; min-height: 46px; font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.notice { border-radius: var(--r-sm); padding: 10px 14px; font-size: 14px; margin-bottom: 16px; border: 1px solid transparent; }
.notice.error { background: var(--red-tint); color: var(--red); border-color: #f3c6c1; }
.notice.warn { background: var(--amber-tint); color: var(--amber); border-color: #efd9ad; }
.notice.ok { background: var(--jade-tint); color: var(--jade-deep); border-color: #bfe0d9; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

/* ───── 로그인 화면 ───── */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 5fr) 7fr;
}
.login-side {
  background: var(--jade-deep);
  color: #e6f2ef;
  padding: 56px 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.login-side h1 { font-size: 34px; color: #fff; }
.login-side .sub { color: #a9cfc6; margin-top: 8px; font-size: 16px; }
.guard { list-style: none; padding: 0; margin: 0; font-size: 14px; color: #c6e2db; }
.guard li { padding: 10px 0; border-top: 1px solid rgba(255, 255, 255, 0.12); display: flex; gap: 10px; }
.guard li::before { content: ""; width: 8px; height: 8px; margin-top: 8px; border-radius: 50%; background: #6fc3b1; flex: none; }
.login-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-box { width: 100%; max-width: 380px; }
.login-box h2 { margin-bottom: 6px; }
.login-box .lead { color: var(--ink-2); margin-bottom: 24px; }

/* 잠금화면처럼 보이는 6자리 코드 입력 */
.passcode { position: relative; display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 8px 0 20px; }
.passcode .cell {
  aspect-ratio: 4 / 5;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.12s, background 0.12s;
}
.passcode .cell.filled { background: var(--jade-tint); border-color: #9fd0c5; }
.passcode:focus-within .cell.active { border-color: var(--jade); box-shadow: var(--focus); }
.passcode input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; font-size: 16px; cursor: text;
  caret-color: transparent;
}
.passcode.shake { animation: shake 0.32s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) {
  .passcode.shake { animation: none; }
  .passcode .cell { transition: none; }
}

@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-main { align-items: flex-start; padding-top: 32px; }
  .login-side { padding: 32px 24px; }
  .login-side h1 { font-size: 26px; }
  .guard { display: none; }
}

/* ───── 앱 화면 ───── */
.topbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 0 24px; height: 58px; position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 17px; }
.brand small { font-weight: 500; color: var(--ink-3); margin-left: 8px; font-size: 13px; }
.who { font-size: 14px; color: var(--ink-2); }
.who b { color: var(--ink); }
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 58px); }
.nav { border-right: 1px solid var(--line); padding: 20px 12px; background: var(--paper); }
.nav a {
  display: block; padding: 8px 12px; border-radius: var(--r-sm); color: var(--ink-2);
  text-decoration: none; font-weight: 600; font-size: 14px; margin-bottom: 2px;
}
.nav a:hover { background: var(--line-2); color: var(--ink); }
.nav a[aria-current=page] { background: var(--jade-tint); color: var(--jade-deep); }
.nav .group { margin: 18px 12px 6px; font-size: 13px; color: var(--ink-3); font-weight: 600; }
.main { padding: 28px 32px 64px; max-width: 1120px; width: 100%; }
.main > header { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.main > header p { color: var(--ink-2); margin: 4px 0 0; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 20px; }
.panel > .head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.panel > .body { padding: 18px; }
.panel.narrow { max-width: 520px; }
.panel .desc { color: var(--ink-2); font-size: 14px; margin: 2px 0 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 13px; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 4px; }
.table-wrap { overflow-x: auto; }
.muted { color: var(--ink-3); }

.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--line-2); color: var(--ink-2); margin: 1px 4px 1px 0; }
.tag.on { background: var(--jade-tint); color: var(--jade-deep); }
.tag.warn { background: var(--amber-tint); color: var(--amber); }
.tag.bad { background: var(--red-tint); color: var(--red); }

.platform { display: inline-flex; width: 28px; height: 28px; border-radius: 8px; align-items: center; justify-content: center; background: var(--line-2); color: var(--ink-2); font-size: 12px; font-weight: 700; margin-right: 10px; flex: none; }
.platform.android { background: #e5f2e3; color: #2f6b29; }
.platform.ios { background: #e8ebf2; color: #39445e; }
.devname { display: flex; align-items: center; font-weight: 600; }

/* 권한 표 */
.matrix td, .matrix th { text-align: center; padding: 8px 10px; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }

.empty { padding: 36px 18px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; background: var(--paper); border: 1px dashed var(--line); border-radius: var(--r-sm); padding: 14px 18px; margin: 12px 0; }
.secret { font-size: 15px; font-weight: 600; letter-spacing: 0.08em; word-break: break-all; background: var(--paper); padding: 8px 10px; border-radius: var(--r-sm); }
.qr { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin: 8px 0 16px; }
.qr img { width: 180px; height: 180px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; }
.qr > div { flex: 1; min-width: 220px; }

.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 16px; max-height: 220px; overflow: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); }

dialog { border: 1px solid var(--line); border-radius: var(--r-md); padding: 0; width: min(560px, calc(100vw - 32px)); color: var(--ink); }
dialog::backdrop { background: rgba(23, 33, 43, 0.45); }
dialog .head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
dialog .body { padding: 20px; }
dialog .foot { padding: 14px 20px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--r-sm); font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); }
.toast.error { background: var(--red); }

.focus-panel { max-width: 560px; margin: 40px auto; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .nav { border-right: 0; border-bottom: 1px solid var(--line); display: flex; overflow-x: auto; padding: 8px; gap: 4px; }
  .nav .group { display: none; }
  .nav a { white-space: nowrap; margin: 0; }
  .main { padding: 20px 16px 48px; }
  .topbar { padding: 0 16px; }
  .brand small { display: none; }
}
.links { margin-top: 14px; }
dialog.wide-dialog { width: min(880px, calc(100vw - 32px)); }

/* 화면 점검 후 보정 */
.layout > *, .main { min-width: 0; }
.main:focus { outline: none; }
.passcode { max-width: 380px; }
.secret { word-break: keep-all; overflow-wrap: anywhere; }
dialog .table-wrap + .row { margin-top: 14px; }
.filters select, .filters input { width: auto; min-width: 150px; }
td b + .tag, .who b + .tag { margin-left: 6px; }
@media (max-width: 860px) {
  .layout { grid-template-rows: auto 1fr; align-content: start; }
  .main > header .spacer { display: none; }
}
@media (max-width: 600px) {
  table.devices thead { display: none; }
  table.devices tr { display: block; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
  table.devices tr:last-child { border-bottom: 0; }
  table.devices td { display: inline-block; border: 0; padding: 2px 10px 2px 0; }
  table.devices td:first-child { display: block; padding-bottom: 4px; }
  table.devices td.actions { display: flex; flex-wrap: wrap; gap: 6px; text-align: left; white-space: normal; padding-top: 8px; }
  table.devices td.actions button { margin: 0; }
}

/* 장치 상세 관리 창 */
.detail-section { margin-bottom: 18px; }
.detail-section h4 { margin: 0 0 8px; font-size: 14px; color: var(--ink-2); border-bottom: 1px solid var(--line-2); padding-bottom: 6px; }
.detail-card { border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 10px 12px; margin-bottom: 8px; }
.detail-card .row { margin-bottom: 4px; }
.detail-card .muted { margin: 2px 0 0; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid2 .field { margin-bottom: 12px; }
.logbox { background: var(--ink); color: #d6e9e4; font-size: 12px; line-height: 1.5; padding: 10px 12px; border-radius: var(--r-sm); max-height: 180px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 0; }
textarea { resize: vertical; min-height: 44px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

/* 승인 대기 기기 */
.pending-row { display: flex; align-items: flex-start; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.pending-row:last-child { border-bottom: 0; }
.pending-row .muted { margin: 2px 0 6px; font-size: 13px; }
.pending-row button { margin-top: 2px; }

/* ───────── 상태 점 / 칩 ───────── */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); vertical-align: middle; }
.dot.on { background: #1f9d55; box-shadow: 0 0 0 3px rgba(31,157,85,0.18); }
.dot.off { background: #c0392b; }

/* ───────── 원격 화면 뷰어 ───────── */
.viewer-body { margin: 0; height: 100vh; display: flex; flex-direction: column; background: #0d1117; color: #e6edf3; overflow: hidden; }
.viewer-bar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: #161b22; border-bottom: 1px solid #222a33; flex: none; }
.viewer-bar .back { color: #e6edf3; text-decoration: none; font-size: 20px; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
.viewer-bar .back:hover { background: #222a33; }
.viewer-title { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.viewer-title b { font-size: 15px; }
.viewer-sub { font-size: 12px; color: #8b949e; }
.viewer-stats { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stat-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; background: #0d1117; border: 1px solid #222a33; padding: 4px 9px; border-radius: 999px; color: #c9d1d9; }
.stat-chip b { font-weight: 600; }
.viewer-control-toggle { color: #e6edf3; font-size: 13px; gap: 6px; background: #0d1117; border: 1px solid #222a33; padding: 5px 10px; border-radius: 999px; }
.viewer-bar button { background: #21262d; color: #e6edf3; border: 1px solid #30363d; border-radius: 8px; width: 34px; height: 34px; cursor: pointer; }
.viewer-bar button:hover { background: #2d333b; }
.viewer-stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 12px; min-height: 0; }
.viewer-screen-wrap { position: relative; max-width: 100%; max-height: 100%; display: flex; }
#screen { max-width: 100%; max-height: calc(100vh - 110px); height: auto; width: auto; border-radius: 14px; background: #000; box-shadow: 0 10px 40px rgba(0,0,0,0.5); touch-action: none; cursor: crosshair; }
.viewer-screen-wrap.actual-size #screen { max-width: none; max-height: none; }
.viewer-screen-wrap.actual-size { overflow: auto; }
.viewer-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(13,17,23,0.82); border-radius: 14px; text-align: center; padding: 20px; }
.viewer-overlay p { margin: 0; color: #c9d1d9; font-size: 14px; max-width: 280px; }
.viewer-foot { flex: none; padding: 8px 14px; background: #161b22; border-top: 1px solid #222a33; font-size: 13px; }
.viewer-foot .muted { color: #8b949e; }
.spinner { width: 34px; height: 34px; border: 3px solid #30363d; border-top-color: #58a6ff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
