:root {
  --bg: #0f1117;
  --panel: #1a1d27;
  --panel-2: #232735;
  --line: #2e3346;
  --text: #e8eaf0;
  --muted: #9aa0b4;
  --primary: #6c8cff;
  --primary-d: #4f6fe6;
  --accent: #ffd166;
  --green: #46d39a;
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2030 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(15,17,23,.85); backdrop-filter: blur(8px); z-index: 10;
}
.brand { font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand .sub { color: var(--muted); font-size: 13px; margin-left: 4px; }
/* 로고 마크: 로고 색이 밝은 배경용이라 흰색 칩 위에 표시 */
.logo-mark { width: 30px; height: 30px; background: #fff; border-radius: 8px; padding: 3px; box-sizing: border-box; }
.top-right { display: flex; align-items: center; gap: 14px; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: #555; transition: .3s; }
.status-dot.live { background: var(--green); box-shadow: 0 0 0 4px rgba(70,211,154,.2); animation: pulse 1.5s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

main { max-width: 920px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel h2 { margin: 0 0 14px; font-size: 16px; }

.controls { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
.field.btns { flex-direction: row; gap: 10px; margin-left: auto; }
select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; min-width: 190px;
}

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 16px; font-size: 14px; cursor: pointer; transition: .15s;
}
.btn:hover:not(:disabled) { border-color: var(--primary); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-d); }
.btn.small { padding: 6px 12px; font-size: 12px; }

.live-head { display: flex; justify-content: space-between; align-items: center; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }

.subtitles {
  margin-top: 14px; height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  padding: 8px 4px; scroll-behavior: smooth;
}
.subtitles .placeholder { color: var(--muted); text-align: center; margin: auto; }
.sub-line {
  background: var(--panel-2); border-left: 3px solid var(--primary);
  border-radius: 10px; padding: 12px 14px; animation: slideIn .35s ease;
}
.sub-line .translated { font-size: 17px; line-height: 1.5; }
.sub-line .original { font-size: 12px; color: var(--muted); margin-top: 6px; }
@keyframes slideIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.interim { margin-top: 8px; min-height: 22px; color: var(--accent); font-style: italic; font-size: 14px; }

.dub-mode { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 12px; }
.dub-mode .radio { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.dub-mode .radio input { accent-color: var(--primary); }
.dub-mode .hint { color: var(--muted); font-size: 12px; }

.dub-lang-hint { background: rgba(255,209,102,.12); border: 1px solid var(--accent); color: var(--accent); border-radius: 8px; padding: 10px 12px; font-size: 13px; line-height: 1.5; margin-bottom: 14px; }
.dub-lang-hint.hidden { display: none; }

.voice-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.voice-row label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.voice-row select { flex: 1; min-width: 0; }

.action-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.btn.action { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 16px; text-align: left; }
.btn.action small { color: var(--muted); font-weight: 400; font-size: 12px; }

.dub-progress { display: flex; align-items: center; gap: 12px; margin-top: 16px; color: var(--accent); }
.dub-progress.hidden, .hidden { display: none; }
.spinner {
  width: 20px; height: 20px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.result-head h2 { margin: 0; }
.result-body { background: var(--panel-2); border-radius: 10px; padding: 18px; line-height: 1.7; white-space: pre-wrap; }
.result-body h1, .result-body h2, .result-body h3 { margin: 14px 0 8px; }
.result-body ul, .result-body ol { padding-left: 22px; }
.result-body code { background: #0e1018; padding: 1px 6px; border-radius: 5px; }

/* ===== API 키 설정 모달 ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; width: 100%; max-width: 460px; animation: slideIn .25s ease;
}
.modal-box h2 { margin: 0 0 6px; }
.modal-desc { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.modal-box .field { margin-bottom: 18px; }
.modal-box label { font-size: 14px; color: var(--text); }
.modal-box label .hint { color: var(--muted); font-size: 12px; margin-left: 6px; }
.modal-box input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px; font-size: 14px; width: 100%; margin-top: 8px;
}
.modal-box input:focus { outline: none; border-color: var(--primary); }
.getkey { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--primary); text-decoration: none; }
.getkey:hover { text-decoration: underline; }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 24px; }

/* ===== 사용자 칩 ===== */
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-chip img { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); object-fit: cover; }
.user-chip span { font-size: 13px; color: var(--text); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== 로그인/승인 오버레이 ===== */
.auth-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: radial-gradient(1000px 500px at 50% -10%, #1b2030 0%, var(--bg) 60%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-overlay.hidden { display: none; }
.auth-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 40px 36px; width: 100%; max-width: 420px; text-align: center; animation: slideIn .3s ease;
}
.auth-logo { width: 84px; height: 84px; margin: 0 auto; background: #fff; border-radius: 20px; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 20px rgba(0,0,0,.25); }
.auth-logo img { width: 64px; height: 64px; }
.auth-box h1 { margin: 14px 0 4px; font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.auth-box h1 .wm-live { color: #6c8cff; }
.auth-box h1 .wm-class { color: #aebfe0; }
.auth-box #authMsg { color: var(--muted); margin: 0 0 28px; line-height: 1.5; }
.google-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #1f1f1f; font-weight: 600; font-size: 15px;
  border-radius: 10px; padding: 12px 20px; text-decoration: none; width: 100%; box-sizing: border-box;
  transition: .15s;
}
.google-btn:hover { box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.auth-hint { color: var(--muted); font-size: 12px; margin-top: 18px; line-height: 1.5; }
.auth-box.state-pending .auth-logo,
.auth-box.state-blocked .auth-logo { font-size: 42px; }

/* ===== 관리자 콘솔 ===== */
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; text-align: center; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.table-wrap { overflow-x: auto; }
.user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.user-table th, .user-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.user-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.user-table .u-cell { display: flex; align-items: center; gap: 10px; }
.user-table .u-av { width: 32px; height: 32px; border-radius: 50%; background: var(--panel-2); object-fit: cover; }
.user-table .u-name { font-weight: 600; }
.user-table .u-email { color: var(--muted); font-size: 11px; }
.user-table .usage { font-variant-numeric: tabular-nums; color: var(--muted); }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.danger { border-color: #e5484d; color: #ff8a8d; }
.btn.danger:hover:not(:disabled) { border-color: #ff5a5e; }
.btn.xs { padding: 4px 9px; font-size: 11px; }
.muted { color: var(--muted); }
.keys-line { font-size: 11px; }

/* 스탯 카드 색상 변형 */
.stat-card.ok .stat-value { color: var(--green); }
.stat-card.warn .stat-value { color: var(--accent); }
.stat-card.accent .stat-value { color: var(--primary); }
.storage-note { margin-top: 14px; font-size: 12px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.storage-note code { background: #0e1018; padding: 1px 6px; border-radius: 4px; }

/* 공용 키 섹션 */
.ck-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ck-grid .field { display: flex; flex-direction: column; gap: 6px; }
.ck-grid label { font-size: 13px; }
.ck-grid input { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.ck-grid input:focus { outline: none; border-color: var(--primary); }
.ck-status { font-size: 12px; color: var(--muted); margin-left: 6px; }
.ck-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
@media (max-width: 720px) { .ck-grid { grid-template-columns: 1fr; } }

/* 섹션 헤더 / 뱃지 */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { margin: 0; }
.badge { background: var(--accent); color: #1a1d27; border-radius: 20px; padding: 1px 9px; font-size: 12px; font-weight: 700; margin-left: 4px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* 승인 대기 카드 */
.pending-list { display: flex; flex-direction: column; gap: 10px; }
.pending-card { display: flex; align-items: center; gap: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.pending-info { flex: 1; min-width: 0; }
.pending-actions { display: flex; gap: 8px; }

/* 14일 사용량 차트 */
.usage-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-stack { width: 70%; min-height: 2px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; background: var(--panel-2); }
.bar-col:hover .bar-stack { outline: 2px solid var(--primary); }
.seg.translate { background: #6c8cff; }
.seg.summary { background: #46d39a; }
.seg.notes { background: #ffd166; }
.seg.dub { background: #ff8a8d; }
.bar-x { font-size: 9px; color: var(--muted); margin-top: 4px; transform: rotate(-45deg); white-space: nowrap; }
.chart-legend { display: flex; gap: 16px; margin-top: 16px; font-size: 12px; color: var(--muted); }
.chart-legend i.lg { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.lg.translate { background: #6c8cff; } .lg.summary { background: #46d39a; } .lg.notes { background: #ffd166; } .lg.dub { background: #ff8a8d; }

/* 가로 막대 리스트 (언어/TOP) */
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bar-label { width: 90px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--green); border-radius: 6px; }
.bar-fill.accent { background: var(--primary); }
.bar-num { width: 36px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 테이블 도구 / 필터 칩 */
.table-tools { display: flex; gap: 8px; }
.table-tools input, .table-tools select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13px; }
.filter-chips { display: flex; gap: 8px; margin-bottom: 12px; }
.chip { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); border-radius: 20px; padding: 5px 14px; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 토스트 */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 20px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.4); z-index: 300; }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: #e5484d; color: #ff8a8d; }
.toast.hidden { display: none; }

@media (max-width: 720px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } .two-col { grid-template-columns: 1fr; } .table-tools { flex-direction: column; } }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

@media (max-width: 640px) {
  .controls { flex-direction: column; align-items: stretch; }
  .field.btns { margin-left: 0; }
  .action-grid { grid-template-columns: 1fr; }
  select { min-width: 100%; }
}
