:root {
  --bg: #0f1419;
  --panel: #1a2029;
  --panel-2: #232b36;
  --line: #2e3947;
  --text: #e8edf2;
  --muted: #8b98a8;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --ok: #2ea043;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .room { color: var(--muted); font-size: 13px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 13px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.badge.ok { color: var(--ok); border-color: rgba(46,160,67,.4); }
.badge.off { color: var(--danger); border-color: rgba(248,81,73,.4); }

button {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); padding: 10px 16px;
  transition: background .12s, border-color .12s;
}
button:hover { background: #2b3543; }
button.primary { background: var(--accent-2); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------- 약사 화면 */
.pharm-wrap { display: grid; grid-template-columns: 280px 1fr; gap: 16px; padding: 16px; height: calc(100vh - 53px); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; overflow: auto; }
.panel h2 { font-size: 14px; color: var(--muted); margin: 0 0 12px; text-transform: uppercase; letter-spacing: .04em; }

.product-row { display: flex; gap: 8px; margin-bottom: 8px; }
.product-row input { flex: 1; }
input[type=text] {
  font: inherit; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 10px 12px;
}
.product-list { list-style: none; padding: 0; margin: 0; }
.product-list li { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: var(--panel-2); }

.mic-area { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 8px 0 20px; }
.mic-btn {
  width: 120px; height: 120px; border-radius: 50%; font-size: 44px;
  display: grid; place-items: center; border: 2px solid var(--line); background: var(--panel-2);
}
.mic-btn.on { background: var(--danger); border-color: var(--danger); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(248,81,73,.5);} 50%{ box-shadow: 0 0 0 16px rgba(248,81,73,0);} }
.interim { min-height: 28px; color: var(--muted); font-size: 18px; text-align: center; }
.interim.live { color: var(--text); }

.log { list-style: none; padding: 0; margin: 0; }
.log li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--panel-2); }
.log .ko { color: var(--muted); font-size: 14px; }
.log .tr { font-size: 16px; margin-top: 4px; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ------------------------------------------------- 고객 화면 */
.customer-body { display: flex; flex-direction: column; height: 100vh; }
.flag-grid {
  flex: 1; display: grid; align-content: start; overflow: auto;
  /* 모바일 기본 2열 → 폭에 따라 열 수 증가 (아래 미디어쿼리) */
  grid-template-columns: repeat(2, 1fr);
  gap: 10px; padding: 12px;
}
@media (min-width: 460px)  { .flag-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 16px; } }
@media (min-width: 720px)  { .flag-grid { grid-template-columns: repeat(4, 1fr); gap: 14px; padding: 22px; } }
@media (min-width: 1000px) { .flag-grid { grid-template-columns: repeat(5, 1fr); gap: 16px; padding: 28px; } }
@media (min-width: 1300px) { .flag-grid { grid-template-columns: repeat(6, 1fr); } }
.flag-card {
  position: relative; aspect-ratio: 4 / 3; overflow: hidden;
  border-radius: 18px; background: var(--panel);
  border: 1px solid var(--line); cursor: pointer;
  transition: transform .1s, border-color .1s, box-shadow .1s;
}
.flag-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 8px 24px rgba(0,0,0,.28); }
.flag-card:active { transform: translateY(0); }
/* 국기 배경 (인라인 --flag 변수로 각 카드 이미지 지정) */
.flag-card .flag-img {
  position: absolute; inset: 0;
  background-image: var(--flag);
  background-size: cover; background-position: center;
}
/* 하단 라벨 — 국기 위 가독성 위해 그라데이션 오버레이 */
.flag-card .flag-label {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; gap: 1px;
  padding: clamp(18px, 6vw, 28px) 8px clamp(7px, 2vw, 12px);
  text-align: center; color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,.78) 0%, rgba(0,0,0,.5) 45%, rgba(0,0,0,0) 100%);
  text-shadow: 0 1px 3px rgba(0,0,0,.9);
}
.flag-card .native {
  font-size: clamp(14px, 3.6vw, 22px); font-weight: 700; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.flag-card .ko { font-size: clamp(11px, 2.6vw, 14px); opacity: .9; }
.flag-prompt { text-align: center; padding: 28px 16px 4px; font-size: 26px; }
.flag-prompt small { display: block; color: var(--muted); font-size: 16px; margin-top: 6px; }

.output-view { flex: 1; display: none; flex-direction: column; padding: 0; }
.output-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.output-header .who { display: flex; align-items: center; gap: 12px; font-size: 22px; }
.output-header .who .flag { font-size: 40px; }
.output-lines { flex: 1; overflow: auto; padding: 24px 32px; display: flex; flex-direction: column; gap: 18px; }
.out-line { border-left: 4px solid var(--accent); padding: 12px 20px; background: var(--panel); border-radius: 0 14px 14px 0; }
.out-line .product { font-size: 15px; color: var(--accent); margin-bottom: 6px; }
.out-line .translated { font-size: 30px; line-height: 1.4; font-weight: 500; }
.out-line .original { font-size: 16px; color: var(--muted); margin-top: 8px; }
.out-line.rtl .translated { direction: rtl; text-align: right; }
.out-line.pending .translated { color: var(--muted); font-style: italic; }
.output-footer { display: flex; gap: 12px; justify-content: center; padding: 16px; border-top: 1px solid var(--line); background: var(--panel); }
.waiting { color: var(--muted); font-size: 20px; text-align: center; margin: auto; padding: 40px; }

.notice { font-size: 12px; color: var(--muted); padding: 6px 20px; }

/* ------------------------------------------------- 채팅형 대화 로그 (양쪽 공통) */
.chat { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.bubble { max-width: 78%; padding: 12px 16px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel-2); }
.bubble.them { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { align-self: flex-end; background: var(--accent-2); border-color: var(--accent); border-bottom-right-radius: 4px; color: #fff; }
.bubble .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.bubble.me .who { color: rgba(255,255,255,.8); }
.bubble .prod { font-size: 12px; color: var(--accent); margin-bottom: 4px; }
.bubble.me .prod { color: #cfe3ff; }
.bubble .big { font-size: 18px; line-height: 1.45; }
.bubble .small { font-size: 13px; color: var(--muted); margin-top: 6px; }
.bubble.me .small { color: rgba(255,255,255,.8); }
.bubble.pending .big { font-style: italic; color: var(--muted); }
.bubble.rtl .big { direction: rtl; text-align: right; }

/* 고객 화면은 크게 */
.customer-body .bubble { max-width: 84%; }
.customer-body .bubble .big { font-size: 28px; }
.customer-body .bubble .small { font-size: 15px; }

/* 입력바 */
.input-bar { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel); align-items: center; }
.input-bar input { flex: 1; }
.mic-btn-sm { width: 46px; height: 46px; border-radius: 50%; font-size: 20px; padding: 0; flex: none; }
.mic-btn-sm.on { background: var(--danger); border-color: var(--danger); }
/* 자동 음성감지(🎧) — 대기(초록 펄스) / 발화 캡처 중(빨강 펄스) */
#vadBtn.on { background: #2ea043; border-color: #2ea043; animation: pulse-green 1.8s infinite; }
#vadBtn.on.rec { background: var(--danger); border-color: var(--danger); animation: pulse 1s infinite; }
#vadBtn:disabled { opacity: .45; }
@keyframes pulse-green { 0%,100% { box-shadow: 0 0 0 0 rgba(46,160,67,.5);} 50%{ box-shadow: 0 0 0 14px rgba(46,160,67,0);} }
