/* ============================================================
   构音障碍即时字幕（千问版）— 双视图样式
   视图1: body.home → 后台管理面板
   视图2: body.subtitle → 全屏字幕识别
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "HarmonyOS Sans SC", sans-serif;
  background: #0f1220; color: #e0e3ec;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: #1a1d2e; border-bottom: 1px solid #2a2e42;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 24px; }
.brand h1 { font-size: 16px; font-weight: 600; }
.brand .sub { font-size: 12px; color: #888; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ---- Status Pill ---- */
.status-pill {
  padding: 3px 12px; border-radius: 12px; font-size: 12px; font-weight: 600;
}
.st-idle { background: #2a2e42; color: #888; }
.st-processing { background: #3a3520; color: #f0c040; animation: pulse 1.2s infinite; }
.st-listening { background: #1a3a1a; color: #4caf50; }
.st-error { background: #3a1a1a; color: #f44336; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ---- Error Banner ---- */
.error-banner {
  padding: 10px 16px; background: #3a1a1a; color: #f44336; font-size: 13px;
  border-bottom: 1px solid #5a2a2a; text-align: center;
}

/* ---- Buttons ---- */
.btn {
  padding: 6px 14px; border: 1px solid #3a3e58; border-radius: 6px;
  background: #1a1d2e; color: #ccc; font-size: 13px;
}
.btn:hover { background: #2a2e42; }
.btn.primary { background: #2a4a7a; border-color: #3a5a9a; color: #fff; }
.btn.primary:hover { background: #3a5a9a; }
.btn.warn { background: #5a3a1a; border-color: #7a5a2a; color: #f0c040; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: #f44336; }
.btn.big { padding: 14px 48px; font-size: 18px; border-radius: 10px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============================================================ */
/* 视图 1: 首页 — 后台管理面板 */
/* ============================================================ */
.home-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px; padding: 14px; overflow-y: auto; flex: 1;
}

.card {
  background: #1a1d2e; border: 1px solid #2a2e42; border-radius: 10px;
  overflow: hidden;
}
.card h2 { padding: 10px 14px; font-size: 14px; border-bottom: 1px solid #2a2e42; }
.card-body { padding: 10px 14px; }
.card-body label { display: block; font-size: 12px; color: #888; margin-top: 8px; }
.card-body label:first-child { margin-top: 0; }
.card-body input, .card-body select, .card-body textarea {
  width: 100%; padding: 6px 10px; margin-top: 2px; border-radius: 6px;
  border: 1px solid #3a3e58; background: #0f1220; color: #e0e3ec; font-size: 13px;
}
.card-body .btn { margin-top: 8px; }
.check-label { display: flex !important; align-items: center; gap: 6px; font-size: 13px !important; color: #ccc !important; }
.check-label input[type="checkbox"] { width: auto; margin: 0; }

.engine-select-row { margin-top: 12px; padding-top: 8px; border-top: 1px solid #2a2e42; }
.engine-select-row label { margin-top: 0 !important; }

.stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; font-size: 13px; border-bottom: 1px solid #1a1d2e;
}
.stat-row:last-child { border: none; }
.chk { color: #888; }
.chk.ok { color: #4caf50; }
.chk.err { color: #f44336; }

/* Card range slider */
.card-body input[type="range"] { padding: 0; border: none; background: transparent; }

/* ---- CTA ---- */
.home-cta {
  text-align: center; padding: 20px 14px 14px; flex-shrink: 0;
}

/* ---- Log & Diag ---- */
.logbar { background: #111; border-top: 1px solid #2a2e42; flex-shrink: 0; max-height: 120px; overflow-y: auto; }
.log-head { padding: 4px 14px; font-size: 11px; color: #666; border-bottom: 1px solid #1a1d2e; }
.log { padding: 4px 14px; font-size: 11px; color: #888; font-family: monospace; }
.log-line { padding: 1px 0; }
.diag-toggle { position: fixed; bottom: 6px; right: 6px; z-index: 99; opacity: 0.5; }
.diag-panel { padding: 10px; background: #111; font-size: 11px; color: #888; display: none; }
.diag-panel:not([hidden]) { display: block; }
.diag-panel .k { color: #6af; }
.diag-panel .err { color: #f66; }
.report-area { margin-top: 8px; padding: 8px; background: #0f1220; border-radius: 6px; font-size: 12px; }
.session-list { margin-top: 8px; font-size: 12px; }
.session-list div { padding: 4px 8px; border-bottom: 1px solid #2a2e42; cursor: pointer; }

/* ============================================================ */
/* 视图 2: 字幕识别界面 */
/* ============================================================ */
body.subtitle #view-home { display: none; }
body:not(.subtitle) #view-subtitle { display: none; }
body.subtitle #view-subtitle { display: flex; flex-direction: column; height: 100%; }

.sub-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px; background: rgba(15,18,32,0.7); flex-shrink: 0;
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
}

.admin-gear {
  background: none; border: none; color: #888; font-size: 18px;
  cursor: pointer; padding: 2px 6px; opacity: 0.5;
}
.admin-gear:hover { opacity: 1; color: #ccc; }

/* 全屏字幕 — 从上到下自动排序，新句追加底部 */
.subtitle-stage-full {
  flex: 1; display: flex; flex-direction: column;
  padding: 60px 28px 20px; overflow-y: auto;
  font-size: var(--subtitle-font-size, 56px);
  background: #0a0c14; color: #fff;
  text-align: left; direction: ltr;
}

/* 历史行（最多 display:maxLines 条，灰色） */
.subtitle-history .subtitle-line {
  padding: 8px 0; line-height: 1.35; word-break: break-word;
  opacity: 0.48; color: #999;
  border-bottom: 1px solid #151825;
}

/* 最新行 — 当前句子，高亮 */
.subtitle-latest {
  padding: 12px 0; line-height: 1.35; word-break: break-word;
  font-weight: 500; border-bottom: 2px solid #3a5a9a;
}
.subtitle-latest .subtitle-final { color: #fff; }
.subtitle-latest .subtitle-partial {
  color: #88ccff; font-style: italic; opacity: 0.85;
}
.subtitle-latest .subtitle-partial:empty { display: none; }
.subtitle-latest .subtitle-partial.visible::after {
  content: '|'; animation: blink 0.8s infinite; margin-left: 2px; color: #4caf50;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.subtitle-stage-full .subtitle-placeholder {
  color: #444; font-size: 24px; margin-top: 40px;
}

/* 底部控制栏 */
.sub-controls {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px 16px; background: #1a1d2e; border-top: 1px solid #2a2e42;
  flex-shrink: 0; flex-wrap: wrap;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}
.sub-controls .btn { font-size: 14px; padding: 8px 20px; }
.mic-meter-inline { display: flex; align-items: center; gap: 6px; }
.mic-meter {
  width: 100px; height: 6px; background: #2a2e42; border-radius: 3px; overflow: hidden;
}
.mic-meter-bar {
  height: 100%; background: #4caf50; transition: width 80ms linear; width: 0;
}
.mic-hint { font-size: 11px; color: #888; }

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .home-grid { grid-template-columns: 1fr; padding: 8px; gap: 8px; }
  .home-cta .btn.big { width: 100%; padding: 12px; font-size: 16px; }
  .sub-controls { gap: 6px; padding: 8px 10px; }
  .sub-controls .btn { padding: 8px 14px; font-size: 13px; }
  .topbar .sub { display: none; }
  .brand h1 { font-size: 13px; }
  .topbar { padding: 6px 10px; }
}

@media (max-width: 480px) {
  .home-grid { gap: 6px; padding: 6px; }
}
