:root {
  --bg: #0b0d12;
  --bg-2: #11141b;
  --card: #161a23;
  --card-2: #1c212c;
  --line: #252b38;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --faint: #5d6579;
  --accent: #7c8cff;
  --pg-a: #4d8dff;
  --pg-b: #22c27a;
  --warn: #f5b13d;
  --bad: #ff6b6b;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Hiragino Sans", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.55 var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(77, 141, 255, .10), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(34, 194, 122, .08), transparent 60%),
    var(--bg);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 상단 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 18, .7);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--pg-a), var(--pg-b));
  color: #fff; font-weight: 700; font-size: 18px;
}
h1 { font-size: 16px; margin: 0; letter-spacing: -.01em; }
.sub { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.conn {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 12px; white-space: nowrap;
}
.conn .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--pg-b); box-shadow: 0 0 0 0 rgba(34, 194, 122, .6); animation: pulse 2s infinite; }
.conn.down .pulse { background: var(--warn); animation: none; }
.conn.down { color: var(--warn); border-color: rgba(245, 177, 61, .4); }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(34, 194, 122, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 194, 122, 0); } }

/* ---------- 레이아웃 ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* ---------- 메시지 ---------- */
.messages { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 20px 20px 8px; scroll-behavior: smooth; }
.msg { display: flex; gap: 10px; margin: 0 0 14px; animation: rise .25s ease-out; max-width: 760px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: #fff;
  background: var(--c, #555);
}
.bubble-wrap { min-width: 0; }
.head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 12px; flex-wrap: wrap; }
.who { font-weight: 650; color: var(--text); font-size: 13px; }
.time { color: var(--faint); font-variant-numeric: tabular-nums; }

.bubble {
  display: inline-block;
  padding: 9px 13px;
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  white-space: pre-wrap; word-break: break-word;
}

/* 일본어 번역: 한국어 말풍선 아래에 작게 */
.translation {
  margin: 5px 0 0 2px;
  padding-left: 9px;
  border-left: 2px solid var(--line);
  font-size: 12.5px; line-height: 1.5; color: var(--muted);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", var(--font);
  white-space: pre-wrap; word-break: break-word;
}
.translation::before { content: "JA"; margin-right: 6px; font: 600 9.5px/1 var(--mono); color: var(--faint); vertical-align: 1px; }
.msg.mine .translation { border-left: 0; border-right: 2px solid var(--line); padding: 0 9px 0 0; margin-right: 2px; }

.route {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 0 8px; border-radius: 999px;
  font: 11px/1.6 var(--mono); color: var(--muted);
  background: var(--bg-2); border: 1px solid var(--line);
}
.route .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--db, var(--faint)); }
.route .arrow { color: var(--faint); }
.tick { margin-left: 6px; font-size: 11px; color: var(--muted); }
.tick.seen { color: var(--pg-b); }

/* 내 메시지 */
.msg.mine { margin-left: auto; flex-direction: row-reverse; }
.msg.mine .bubble-wrap { text-align: right; }
.msg.mine .head { justify-content: flex-end; }
.msg.mine .bubble {
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  background: linear-gradient(135deg, rgba(124, 140, 255, .22), rgba(124, 140, 255, .12));
  border-color: rgba(124, 140, 255, .35);
  text-align: left;
}
.msg.pending { opacity: .55; }
.msg.pending .bubble { border-style: dashed; }

/* 이전 구분선: DB나 앱 환경이 바뀐 지점 */
.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0; color: var(--muted); font-size: 12px;
  list-style: none;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.divider .tag {
  padding: 4px 12px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--line);
  font-weight: 600; color: var(--text);
}
.divider.db .tag { border-color: rgba(34, 194, 122, .5); box-shadow: 0 0 24px rgba(34, 194, 122, .15); }
.divider .tag b { font-family: var(--mono); font-weight: 600; }

.notice { text-align: center; color: var(--warn); font-size: 12px; margin: 8px 0; list-style: none; }

/* ---------- 입력창 ---------- */
.composer {
  display: flex; gap: 8px; align-items: center;
  margin: 8px 20px 16px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
}
.composer input {
  font: inherit; color: var(--text); background: transparent; border: 0; outline: none;
  padding: 8px 10px; min-width: 0;
}
.composer .name { width: 110px; border-right: 1px solid var(--line); color: var(--muted); }
.composer .body { flex: 1; }
.send {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 0; border-radius: 12px; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, var(--accent), #5b6cff);
}
.send:active { transform: scale(.96); }

/* ---------- 오른쪽 패널 ---------- */
.panel { border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; background: rgba(17, 20, 27, .6); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 13px; margin: 0 0 12px; display: flex; justify-content: space-between; align-items: baseline; }
.hint { font-size: 11px; color: var(--faint); font-weight: 400; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.kpi { background: var(--bg-2); border-radius: 10px; padding: 8px 6px; text-align: center; }
.kpi .num { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .label { font-size: 11px; color: var(--muted); }

.rows { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; margin: 0 0 10px; font-size: 12px; }
.rows dt { color: var(--muted); }
.rows dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.ghost {
  width: 100%; padding: 8px; border-radius: 10px; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--card-2); border: 1px solid var(--line);
}
.ghost:hover { border-color: var(--accent); }
.result { margin: 8px 0 0; font-size: 13px; min-height: 1em; }
.result.ok { color: var(--pg-b); }
.result.bad { color: var(--bad); }

.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--bg-2); margin-bottom: 10px; }
.bar span { height: 100%; transition: width .4s ease; }
.legend { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.legend .sw { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.legend .k { font-family: var(--mono); }
.legend .v { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 모바일 (QR로 접속한 심사위원) ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .panel { display: none; }
  .sub { display: none; }
  .messages { padding: 14px 12px 6px; }
  .composer { margin: 6px 10px 10px; }
  .composer .name { width: 72px; }
}
