:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --border: #e3e6ee;
  --text: #171a23;
  --muted: #646b7d;
  --faint: #9aa1b2;
  --accent: #4f5bea;
  --accent-ink: #ffffff;
  --accent-soft: #eceefe;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 6px 20px rgba(20, 24, 40, .05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a22;
    --surface-2: #1d212b;
    --border: #2a2f3b;
    --text: #e8eaf0;
    --muted: #9aa2b5;
    --faint: #6b7385;
    --accent: #7b84ff;
    --accent-ink: #0f1117;
    --accent-soft: #23264a;
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --danger-soft: #3a1d22;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Pretendard", "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.mono { font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace; font-size: .93em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- 로그인 화면 ---------- */
.center {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px 26px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 40px; height: 40px; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: 13px; color: var(--muted); }
.auth-card h1 { font-size: 19px; margin: 26px 0 4px; }
.auth-card p.lead { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.auth-foot {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 폼 ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field > small { display: block; margin-top: 5px; color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=password], select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.inline { width: auto; min-width: 200px; height: 34px; font-size: 14px; }
.error { color: var(--danger); font-size: 13.5px; min-height: 20px; margin: 4px 0 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { opacity: .92; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; height: 42px; }

.checks { display: grid; gap: 8px; }
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }

/* ---------- 앱 화면 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-in {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar .brand img { width: 30px; height: 30px; }
.topbar .brand-name { font-size: 17px; }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge.warn { color: var(--warn); }

.tabs { max-width: 1080px; margin: 0 auto; padding: 0 20px; display: flex; gap: 4px; }
.tab {
  border: 0;
  background: none;
  padding: 10px 14px 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.card + .card { margin-top: 16px; }
.grid .card + .card { margin-top: 0; }

.exit-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip b { font-weight: 600; }

.steps { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.steps li { margin: 4px 0; }
.steps b { color: var(--text); }

.list { display: grid; gap: 10px; }
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.row .main { flex: 1; min-width: 180px; }
.row .title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row .sub { font-size: 13px; color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.empty { padding: 26px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 0 10px 10px; white-space: nowrap; }
td { padding: 11px 10px; border-top: 1px solid var(--border); vertical-align: middle; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
.table-wrap { overflow-x: auto; }

.exit-card { display: flex; flex-direction: column; gap: 6px; border-top: 4px solid var(--c); }
.exit-card .ip { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }

/* ---------- 대화상자 / 알림 ---------- */
dialog {
  width: min(480px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 12, 20, .45); }
.dlg-head { padding: 20px 22px 4px; font-size: 17px; font-weight: 700; }
.dlg-body { padding: 12px 22px 4px; }
.dlg-body p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 20px; }
.qr { display: flex; justify-content: center; padding: 14px; background: #fff; border-radius: 12px; margin-bottom: 12px; }
.qr img { width: 240px; height: 240px; image-rendering: pixelated; }
textarea.conf {
  width: 100%;
  height: 150px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 10px;
  font: 12px/1.5 "Cascadia Mono", Consolas, monospace;
  color: var(--text);
}

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; }
.toast {
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  animation: rise .18s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .topbar-in { padding: 10px 16px; gap: 10px; }
  .user-chip .name { display: none; }
  .tabs { padding: 0 8px; overflow-x: auto; }
  main { padding: 18px 16px 48px; }
  .hide-sm { display: none; }
  select.inline { min-width: 0; width: 100%; }
}
