:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #8a93a3;
  --line: #e4e8ef;
  --nav: #101828;
  --nav-ink: #c6cdd9;
  --nav-active: #1d2a44;
  --brand: #3b5bdb;
  --brand-ink: #ffffff;
  --danger: #d6336c;
  --danger-bg: #fdecf2;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --gray-bg: #eceff4;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.hidden { display: none !important; }

/* ── 앱 틀 ─────────────────────────────── */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--nav);
  color: var(--nav-ink);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; letter-spacing: -0.2px; }
.brand small { display: block; color: var(--ink-3); font-weight: 400; font-size: 12px; margin-top: 2px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: var(--nav-ink);
  padding: 9px 12px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav a:hover { background: var(--nav-active); text-decoration: none; color: #fff; }
.nav a.on { background: var(--brand); color: #fff; }
.nav .group { color: #6b7691; font-size: 11px; padding: 14px 12px 4px; text-transform: none; }
.side .foot { margin-top: auto; font-size: 12px; color: #6b7691; padding: 10px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.top .title { font-size: 16px; font-weight: 700; }
.top .right { display: flex; align-items: center; gap: 14px; color: var(--ink-2); font-size: 13px; }
.env { background: var(--gray-bg); border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--ink-2); }
.content { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }

/* ── 공통 부품 ─────────────────────────── */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover:not(:disabled) { background: #f6f8fb; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { background: #3050c4; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #bd2a5f; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 0; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.input, select.input, textarea.input {
  border: 1px solid #cdd3de;
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
textarea.input { resize: vertical; min-height: 84px; width: 100%; }
.hint { font-size: 12px; color: var(--ink-3); }
.hint.bad { color: var(--danger); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.panel > h2, .panel .panel-head {
  font-size: 14px;
  font-weight: 700;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-body { padding: 16px 18px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row.center { align-items: center; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; letter-spacing: -0.3px; }

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--gray-bg);
  color: var(--ink-2);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: #e3e9ff; color: #2f48b0; }
.badge.dark { background: #2b3445; color: #fff; }

/* ── 표 ───────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left;
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 600;
  background: #f8fafc;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #fafbfd; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl td.wrap { max-width: 360px; white-space: pre-wrap; word-break: break-word; }
.state { padding: 44px 20px; text-align: center; color: var(--ink-3); }
.state.error { color: var(--danger); }
.state .btn { margin-top: 12px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 13px; }
.pager .btns { display: flex; gap: 6px; align-items: center; }

/* ── 대시보드 ─────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--ink-2); font-size: 12px; font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; margin-top: 4px; }
.kpi .value.small { font-size: 20px; margin: 10px 0 0; }
.kpi .sub { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.kpi.alert { border-color: #f3b4cb; background: #fff8fb; }
.kpi.alert .value { color: var(--danger); }
.bar { height: 10px; border-radius: 6px; background: var(--gray-bg); overflow: hidden; display: flex; margin-top: 10px; }
.bar > span { display: block; height: 100%; }
.bar .m { background: #4c6ef5; }
.bar .f { background: #e64980; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; }
.dl dt { color: var(--ink-2); font-size: 12px; font-weight: 600; padding-top: 1px; }
.dl dd { margin: 0; min-width: 0; word-break: break-word; }

/* ── 사진·대화 ───────────────────────── */
.photos { display: flex; gap: 10px; flex-wrap: wrap; }
.photos img { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--gray-bg); }
.text-block { white-space: pre-wrap; word-break: break-word; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.chat { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; }
.msg { max-width: 70%; }
.msg .who { font-size: 12px; color: var(--ink-3); margin-bottom: 2px; }
.msg .bubble { white-space: pre-wrap; word-break: break-word; padding: 8px 12px; border-radius: 12px; background: #eef1f6; }
.msg.b { align-self: flex-end; text-align: right; }
.msg.b .bubble { background: #e3e9ff; text-align: left; }
.raw-tag { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; }

/* ── 대화상자 ─────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.dialog { background: #fff; border-radius: 14px; width: 480px; max-width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); }
.dialog .d-head { padding: 18px 22px 6px; font-size: 16px; font-weight: 700; }
.dialog .d-body { padding: 8px 22px 6px; display: flex; flex-direction: column; gap: 12px; }
.dialog .d-foot { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }
.dialog .target { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.dialog .err { color: var(--danger); font-size: 13px; }
.choice { display: flex; gap: 8px; }
.choice .btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.toast {
  position: fixed; right: 24px; bottom: 24px; background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 360px;
}

/* ── 로그인 ───────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login { width: 400px; max-width: 100%; padding: 30px 30px 26px; }
.login h1 { font-size: 20px; margin-bottom: 4px; }
.login .sub { color: var(--ink-2); margin-bottom: 18px; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.login .note { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; font-size: 13px; }
.login .errmsg { color: var(--danger); font-size: 13px; min-height: 18px; }
.qr { display: flex; justify-content: center; }
.qr img { width: 180px; height: 180px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.secret { font-family: ui-monospace, Menlo, monospace; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; word-break: break-all; font-size: 12px; user-select: all; }
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; color: var(--ink-3); }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
