/* ============================================================
 * 主题变量：白底（light，默认） / 深色（dark）
 * 切换方式：<html data-theme="light|dark">，由 app.js 控制
 * ============================================================ */

:root,
html[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --header-bg: #ffffff;
  --border: #d8dee9;
  --border-strong: #c3ccda;
  --text: #1f2937;
  --text-dim: #64748b;
  --text-strong: #0f172a;
  --accent: #1d4ed8;
  --btn-bg: #eef2f7;
  --btn-bg-hover: #e2e8f0;
  --btn-text: #1f2937;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-border: #3b82f6;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-border: #ef4444;
  --ok: #15803d;
  --warn: #b45309;
  --err: #b91c1c;
  --info: #1d4ed8;
  --hexdim: #94a3b8;
  --log-bg: #f8fafc;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-modal: 0 20px 50px rgba(15, 23, 42, .25);
  --rec-accent: #b45309;
  --rt-accent: #b91c1c;
  --dev-accent: #15803d;
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #0f172a;
  --header-bg: #1e293b;
  --border: #334155;
  --border-strong: #475569;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-strong: #f8fafc;
  --accent: #93c5fd;
  --btn-bg: #334155;
  --btn-bg-hover: #475569;
  --btn-text: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-border: #3b82f6;
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --danger-border: #ef4444;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --info: #93c5fd;
  --hexdim: #64748b;
  --log-bg: #0b1220;
  --shadow: none;
  --shadow-modal: 0 20px 50px rgba(0, 0, 0, .6);
  --rec-accent: #fbbf24;
  --rt-accent: #f87171;
  --dev-accent: #4ade80;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background .2s, color .2s;
}

header {
  background: var(--header-bg);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

header h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-strong);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.theme-btn { white-space: nowrap; }

.conn-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, .6);
}

.dot.online {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, .6);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 16px;
  color: var(--accent);
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--btn-text);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}

.btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary { background: var(--primary); border-color: var(--primary-border); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn.danger { background: var(--danger); border-color: var(--danger-border); color: #fff; }
.btn.danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn.rec { background: var(--danger); border-color: var(--danger-border); color: #fff; font-weight: 600; }
.btn.rec:hover:not(:disabled) { background: var(--danger-hover); }

.btn.small { padding: 4px 10px; font-size: 12px; }

select {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}

.device-info {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--dev-accent);
  margin-top: 10px;
  word-break: break-all;
}

.mtu-info {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.info-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.info-item label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.info-item span {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-strong);
  word-break: break-all;
}

.rec-state {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--rec-accent);
  min-height: 42px;
}

.rt-info {
  font-size: 14px;
  color: var(--rt-accent);
}

.rt-stats {
  font-size: 13px;
  color: var(--text-dim);
}

.file-meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* 表格横向滚动容器：窄屏时表格可滑动，不会撑破卡片 */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.file-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

/* 文件名列可换行，其余列不挤压 */
.file-table th:nth-child(1), .file-table td:nth-child(1) { width: 40px; }
.file-table th:nth-child(4), .file-table td:nth-child(4) { white-space: nowrap; }

.file-table th, .file-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.file-table th {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12px;
}

.file-table .fname { color: var(--accent); word-break: break-all; }
.file-table .empty { text-align: center; color: var(--text-dim); padding: 20px; }
.file-table tr:hover td { background: var(--surface-2); }
.file-table td.ops { white-space: nowrap; }
.file-table td.ops .btn { margin: 2px 4px 2px 0; }
.file-table td { vertical-align: middle; }

.progress {
  height: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: 10px 0;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #22c55e);
  transition: width .2s;
}

.log {
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  max-height: 300px;
  overflow-y: auto;
}

.log-line { padding: 2px 0; word-break: break-all; }
.log-line.ok { color: var(--ok); }
.log-line.warn { color: var(--warn); }
.log-line.err { color: var(--err); }
.log-line.info { color: var(--info); }
.log-line.hex { color: var(--hexdim); }
.log-time { color: var(--text-dim); margin-right: 6px; }
.dim { color: var(--hexdim); }

.chk {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---- 实时录音状态条 ---- */
.rt-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}

.rt-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  flex: 0 0 auto;
}

.rt-dot.live {
  background: #e5484d;
  animation: rtPulse 1.2s ease-in-out infinite;
}

.rt-dot.paused { background: #f5a524; animation: none; }

@keyframes rtPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.55); }
  50% { opacity: 0.65; box-shadow: 0 0 0 6px rgba(229, 72, 77, 0); }
}

.rt-bar .rt-info { flex: 1 1 auto; min-width: 160px; }
.rt-bar .rt-stats { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---- 转写设置 / API Key 输入 ---- */

/* ---- 二次确认弹窗 ---- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-mask[hidden] { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-modal);
}

.modal h3 {
  font-size: 17px;
  color: var(--text-strong);
  margin-bottom: 12px;
}

.modal-msg {
  font-size: 14px;
  color: var(--text);
  word-break: break-all;
  margin-bottom: 8px;
}

.modal-detail {
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* 中等屏幕：标题与状态分两行，避免挤压重叠 */
@media (max-width: 860px) {
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
  }
  .header-right { width: 100%; justify-content: space-between; }
  header h1 { font-size: 17px; line-height: 1.3; }
  main { padding: 16px; }
}

/* 窄屏：按钮占满整行，表格允许横向滚动 */
@media (max-width: 600px) {
  .row { flex-direction: column; align-items: stretch; }
  .row .btn { width: 100%; }
  /* 表格内与状态条内的小按钮保持自适应宽度，不要撑满 */
  .file-table .btn, .rt-bar .btn, .modal-actions .btn, .btn.small { width: auto; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
  .info-grid { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 16px 14px; }
}
