:root {
  --bg: #14161a;
  --surface: #1e2127;
  --surface-raised: #262a32;
  --border: #30353e;
  --text: #e8eaed;
  --text-muted: #9aa1ac;
  --accent: #3b82f6;
  --accent-hover: #2f6fe0;
  --danger: #dc4c4c;
  --danger-hover: #c23c3c;
  --error: #ff8a8a;
  --success: #6fcf97;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;

  /* 한글은 낱말 중간에서 줄을 바꾸지 않는다(띄어쓰기에서만). 띄어쓰기 없는 긴 글자(주소 등)는 넘치지 않게 끊는다. */
  word-break: keep-all;
  overflow-wrap: break-word;
}

/* hidden 속성이 display 지정보다 항상 우선하게 한다. */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── 버튼·입력 ─────────────────────────────── */

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  border-color: var(--text-muted);
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

button.danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}

input:disabled {
  opacity: 0.6;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--text-muted);
}

.field small {
  font-size: 12px;
  opacity: 0.8;
  margin-left: 4px;
}

.message {
  margin: 0;
  color: var(--error);
  font-size: 14px;
}

.message.success {
  color: var(--success);
}

/* ── 카드(가운데 놓이는 폼) ─────────────────── */

.center {
  flex: 1;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card h1,
.card h2,
.card h3 {
  margin: 0;
  letter-spacing: -0.01em;
}

.card h1 {
  font-size: 22px;
}

.card h2 {
  font-size: 18px;
}

.card h3 {
  font-size: 15px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.lead {
  margin: 0;
  color: var(--text-muted);
}

.card > .primary {
  padding: 10px 14px;
  font-size: 16px;
}

.code-input {
  font: 600 28px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.06em;
  text-align: center;
  padding: 12px 8px;
}

.code-input::placeholder {
  color: #4a505b;
}

.waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.waiting p {
  margin: 0;
}

/* ── 위쪽 막대 ─────────────────────────────── */

.toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow-x: auto;
}

.brand {
  font-weight: 700;
}

.nav {
  display: flex;
  gap: 6px;
}

.nav button,
#nav-password {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.nav button.active,
#nav-password.active {
  background: var(--surface-raised);
  color: var(--text);
}

.status,
.stats {
  color: var(--text-muted);
  font-size: 13px;
}

.stats {
  font-variant-numeric: tabular-nums;
}

.spacer {
  flex: 1;
}

/* ── 로그인 뒤 화면 ─────────────────────────── */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.app .center {
  min-height: 0;
}

.admin {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px;
}

.card.wide {
  max-width: 860px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.form-footer {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-weight: 500;
}

td.actions {
  text-align: right;
}

td.actions button {
  padding: 3px 10px;
  font-size: 13px;
  margin-left: 6px;
}

/* ── 고객사·기기 목록 ─────────────────────────── */

.muted {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

.caption {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

/* 고객사 하나의 묶음 */
.group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.group:first-child {
  border-top: none;
  padding-top: 0;
}

.group h3 {
  margin: 0;
  padding: 0;
  border: none;
  font-size: 15px;
}

.group-header {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.group-header input[type="text"] {
  flex: 1;
  min-width: 160px;
  font-weight: 600;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 14px;
}

.checks input,
td input[type="text"] {
  width: auto;
}

/* 상태 표시: 앞에 작은 동그라미를 붙인다 */
.dot::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--text-muted);
}

.dot.online::before {
  background: var(--success);
}

.dot.busy::before {
  background: var(--accent);
}

.dot.offline {
  color: var(--text-muted);
}

/* 방금 만든 등록 코드 */
.issued-code {
  font: 600 20px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.08em;
  padding: 6px 12px;
  border: 1px dashed var(--success);
  border-radius: 8px;
  color: var(--success);
  user-select: all;
}

/* 설치 링크: 한 줄로 길게 보여 주고 옆에 [링크 복사] 버튼을 둔다 */
.install-link {
  flex: 1;
  min-width: 220px;
  font-size: 13px;
  color: var(--text-muted);
}

a {
  color: var(--accent);
}

/* ── 설치 링크 안내 페이지(/install/…) ─────────── */

.card.install {
  max-width: 460px;
}

/* 버튼처럼 보이는 링크 */
a.button {
  display: block;
  text-align: center;
  text-decoration: none;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
}

a.button:hover {
  background: var(--accent-hover);
}

.steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

/* ── 대화 상자 ─────────────────────────────── */

.dialog {
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dialog h2 {
  margin: 0;
  font-size: 18px;
}

/* ── 세션 화면 ─────────────────────────────── */

/* 세션 중의 알림 줄(무인 접속 등록의 진행 상황 등) */
.session-notice {
  flex: none;
  margin: 0;
  padding: 8px 12px;
  font-size: 14px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
}

.session-notice.success {
  color: var(--success);
}

.session-notice.error {
  color: var(--error);
}

.session {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.screen-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

/* 캔버스 상자가 곧 보이는 화면 영역이 되도록 비율을 유지한 채 줄인다(좌표 계산이 단순해진다). */
.screen-area canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  outline: none; /* 키보드 포커스 테두리 대신 위쪽 막대의 "조작 가능" 표시로 알린다 */
}

/*
  조작할 수 있을 때: 한 손가락 동작은 페이지를 움직이지 않고 우리 코드로 온다(톡 = 클릭, 끌기 = 스크롤/끌기).
  두 손가락으로 벌리고 옮기는 것은 브라우저가 그대로 처리한다 — 작은 화면에서 상대 화면을 확대해 보는 방법이다.
*/
.screen-area canvas.controllable {
  touch-action: pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* 길게 눌렀을 때 뜨는 iOS 의 메뉴를 막는다 */
}

/* ── 터치 기기용 도구 ─────────────────────────── */

.touch-tools {
  display: flex;
  gap: 6px;
}

/* 자판이 떠 있는 동안의 [키보드] 버튼: 다시 누르면 내려간다는 것을 테두리로 알린다 */
.touch-tools button.active {
  box-shadow: 0 0 0 2px var(--text);
}

/*
  좁은 화면(휴대폰): 막대가 한 줄에 다 들어가지 않는다. 옆으로 밀어야 보이게 두면 [키보드] 버튼을 찾지 못하므로,
  덜 중요한 것(이름, 전송량, 더 좁으면 해상도까지)을 숨기고 그래도 넘치면 두 줄로 접는다.
*/
@media (max-width: 960px) {
  .session .toolbar {
    flex-wrap: wrap;
    overflow-x: visible;
    gap: 6px 8px;
    padding: 6px 8px;
  }

  .session .toolbar .brand,
  .session .toolbar .stats {
    display: none;
  }

  /* 키 줄은 한 줄에 되도록 많이 들어가게 촘촘히 놓는다(넘치는 키는 옆으로 밀어서 본다) */
  .session .key-bar {
    gap: 4px;
    padding: 6px;
  }

  .session .key-bar button {
    min-width: 36px;
    padding: 8px 6px;
  }
}

@media (max-width: 720px) {
  .session .toolbar .status {
    display: none;
  }
}

/*
  자판이 떠 있는 동안에는 상대 화면을 위쪽에 붙인다. 가운데에 두면 아래쪽 절반이 자판에 가려진다
  (iOS 는 자판이 올라와도 페이지 크기를 줄이지 않는다).
*/
.screen-area.keyboard-open {
  align-items: flex-start;
}

/* 화면 자판에 없는 키들 */
.key-bar {
  flex: none;
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.key-bar button {
  min-width: 44px;
  padding: 8px 10px;
}

/*
  화면 자판을 띄우기 위한 입력 칸. 눈에 보이지 않고 손으로 누를 수도 없지만, 포커스는 받을 수 있어야 한다
  (display: none 이면 포커스를 받지 못해 자판이 뜨지 않는다). 글자 크기 16px: 그보다 작으면 iOS 가 화면을 확대한다.
*/
.keyboard-input {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  pointer-events: none;
}

/* "조작 가능 / 보기 전용" 표시 */
.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge.on {
  border-color: var(--success);
  color: var(--success);
}
