/* ── Design tokens：商务 · 科技 · 效率 ── */
:root {
  --bg-base: #080a0f;
  --bg-elevated: #0f1219;
  --bg-surface: #141820;
  --bg-hover: #1a1f2a;
  --bg-inset: #0c0e14;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.14);

  --text-primary: #eceff4;
  --text-secondary: #8b93a1;
  --text-tertiary: #5a6270;
  --text-muted: #454c58;

  --accent: #3b82f6;
  --accent-dim: rgba(59, 130, 246, 0.12);
  --accent-border: rgba(59, 130, 246, 0.35);

  --success: #22a06b;
  --success-dim: rgba(34, 160, 107, 0.12);
  --warning: #c9971a;
  --warning-dim: rgba(201, 151, 26, 0.12);
  --danger: #d14343;
  --danger-dim: rgba(209, 67, 67, 0.12);

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --font-sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "Cascadia Code", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --shadow-panel: 0 1px 0 var(--border-subtle) inset;
  --transition: 0.15s ease;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── 顶栏 ── */
.app-header {
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.toolbar-primary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  height: 52px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, #1e3a5f 0%, #0f172a 100%);
  border: 1px solid var(--accent-border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-mark svg {
  width: 14px;
  height: 14px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-text h1 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.brand-text .brand-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 400;
  letter-spacing: 0.04em;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition), box-shadow var(--transition);
}

.status-dot.active {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-dim);
}

.primary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-secondary {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 0 24px;
  height: 40px;
  background: var(--bg-inset);
  font-size: 12px;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-label {
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.field-inline input[type="text"],
.field-inline select {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
}

.field-inline input[type="text"]:focus,
.field-inline select:focus {
  border-color: var(--accent-border);
}

.field-inline input[type="text"] { width: 148px; }
.field-inline select { min-width: 92px; cursor: pointer; }

.tool-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.tool-nav a {
  color: var(--text-tertiary);
  text-decoration: none;
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  letter-spacing: 0.02em;
  transition: color var(--transition), background var(--transition);
}

.tool-nav a:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

/* ── 按钮 ── */
button {
  font-family: inherit;
  padding: 0 14px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.btn-start {
  background: var(--accent);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.08);
}
.btn-start:hover:not(:disabled) { filter: brightness(1.08); }
.btn-start:disabled {
  background: var(--bg-surface);
  color: var(--text-muted);
  border-color: var(--border-subtle);
  cursor: not-allowed;
}

.btn-stop {
  background: transparent;
  color: var(--danger);
  border-color: rgba(209, 67, 67, 0.35);
}
.btn-stop:hover:not(:disabled) {
  background: var(--danger-dim);
}
.btn-stop:disabled {
  color: var(--text-muted);
  border-color: var(--border-subtle);
  cursor: not-allowed;
}

.btn-export {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-default);
}
.btn-export:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-agent {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent-border);
  min-width: 118px;
}
.btn-agent:hover:not(:disabled) {
  background: var(--accent-dim);
}
.btn-agent:disabled {
  color: var(--text-muted);
  border-color: var(--border-subtle);
  cursor: not-allowed;
}
.btn-agent.is-success {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(34, 160, 107, 0.35);
}
.btn-agent.is-error {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(209, 67, 67, 0.35);
}

.btn-auto-agent-toggle {
  background: transparent;
  color: var(--text-tertiary);
  border-color: var(--border-subtle);
  min-width: 72px;
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-auto-agent-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}
.btn-auto-agent-toggle.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
}
.btn-auto-agent-toggle .toggle-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition), box-shadow var(--transition);
}
.btn-auto-agent-toggle.active .toggle-dot {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-dim);
}

.btn-ghost {
  height: 28px;
  padding: 0 10px;
  background: transparent;
  color: var(--text-tertiary);
  border-color: var(--border-subtle);
  font-size: 11px;
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

/* ── 主布局 ── */
.main {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
  gap: 1px;
  background: var(--border-subtle);
}

.transcript-column,
.segment-panel,
.sidebar {
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.transcript-column { flex: 1.2; min-width: 0; }
.segment-panel { flex: 0.85; min-width: 300px; border-left: none; }
.sidebar { flex: 0 0 248px; border-left: none; }

.panel-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-panel);
}

.panel-head .panel-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-head .panel-meta {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.panel-head.transcript-toolbar {
  justify-content: flex-start;
  flex-wrap: wrap;
  height: auto;
  min-height: 40px;
  padding-top: 7px;
  padding-bottom: 7px;
  gap: 8px 10px;
}

.panel-head.transcript-toolbar .panel-title {
  margin-right: 2px;
}

.panel-head.transcript-toolbar .hint {
  flex: 1;
  min-width: 80px;
}

/* 批量编辑展开时独占一行，避免「应用/取消」被挤扁 */
.batch-bar {
  display: none;
  align-items: center;
  gap: 8px;
  flex: 1 1 100%;
  width: 100%;
  min-width: 0;
}

.batch-bar.visible {
  display: flex;
}

.panel-head.transcript-toolbar:has(.batch-bar.visible) .hint {
  display: none;
}

.batch-bar input[type="text"] {
  height: 26px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 11px;
  flex: 1;
  min-width: 88px;
  max-width: 160px;
  outline: none;
}

.batch-bar .sel-count {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}

.batch-bar button {
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 48px;
  padding: 0 12px;
}

#btnBatchApply {
  height: 26px;
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
}
#btnBatchClear {
  height: 26px;
  background: transparent;
  color: var(--text-tertiary);
  border-color: var(--border-subtle);
}

.transcript-toolbar > button {
  height: 26px;
  padding: 0 10px;
  font-size: 11px;
  background: transparent;
  color: var(--text-tertiary);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
  white-space: nowrap;
}
.transcript-toolbar > button:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}
.transcript-toolbar > button.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
}

.transcript-toolbar .hint {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transcript-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.transcript-area::-webkit-scrollbar,
.segment-scroll::-webkit-scrollbar,
.sidebar #speakerList::-webkit-scrollbar {
  width: 6px;
}
.transcript-area::-webkit-scrollbar-thumb,
.segment-scroll::-webkit-scrollbar-thumb,
.sidebar #speakerList::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

.sidebar #speakerList {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

/* ── 转录消息 ── */
.msg {
  position: relative;
  margin-bottom: 2px;
  padding: 10px 12px 10px 14px;
  border-radius: var(--radius-md);
  background: transparent;
  border-left: 2px solid var(--speaker-accent, transparent);
  animation: msgIn 0.12s ease;
}

.msg.speaker-unknown {
  border-left-color: var(--text-muted);
}

.msg .speaker {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: 0.01em;
  color: var(--speaker-text, var(--text-secondary));
}

.msg.speaker-unknown .speaker {
  color: var(--text-tertiary);
}

.msg .speaker span {
  font-weight: 400;
  color: var(--text-muted) !important;
  margin-left: 8px !important;
  font-family: var(--font-mono);
  font-size: 10px;
}

.msg:hover { background: var(--bg-elevated); }

@keyframes msgIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.msg .text {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-primary);
}

.msg.interim {
  opacity: 0.55;
  background: var(--bg-elevated);
}

.empty-state,
.panel-empty,
.segment-empty-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 32px 20px;
  text-align: center;
  line-height: 1.6;
}

.empty-state { height: 100%; }

.segment-empty-hint::before {
  content: "";
  width: 32px;
  height: 32px;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border-default);
  opacity: 0.6;
}

.msg.selectable { cursor: pointer; padding-left: 36px; }
.msg.selected {
  background: var(--accent-dim);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

.msg .msg-check {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── 讨论片段 ── */
.segment-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.segment-card {
  margin-bottom: 8px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition);
}

.segment-card:hover { border-color: var(--border-default); }

.segment-card.is-updated {
  border-color: var(--accent-border);
  animation: segPulse 0.6s ease;
}

@keyframes segPulse {
  0% { box-shadow: 0 0 0 0 var(--accent-dim); }
  50% { box-shadow: 0 0 0 4px var(--accent-dim); }
  100% { box-shadow: none; }
}

.segment-card .seg-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.segment-card .seg-index {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.segment-card .seg-topic {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.segment-card .seg-time {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 10px;
}

.segment-card .seg-summary {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.segment-card .seg-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 8px;
  margin-bottom: 6px;
}

.segment-card .seg-list {
  font-size: 12px;
  color: var(--text-secondary);
  padding-left: 0;
  margin: 0;
  list-style: none;
}

.segment-card .seg-list li {
  position: relative;
  padding-left: 12px;
  margin-bottom: 4px;
  line-height: 1.5;
}

.segment-card .seg-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
}

.segment-card .seg-list.questions li::before {
  background: var(--warning);
}

.segment-card .seg-list.questions li {
  color: var(--text-secondary);
}

/* ── 说话人侧栏 ── */
.speaker-card {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.speaker-card:hover { background: var(--bg-elevated); }

.speaker-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  opacity: 0.92;
}

.speaker-detail { flex: 1; min-width: 0; }
.speaker-detail .guest-label {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.speaker-detail .real-name {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
  margin-top: 2px;
}
.speaker-detail .match-info {
  font-size: 10px;
  margin-top: 4px;
  letter-spacing: 0.02em;
}
.match-info.matched { color: var(--success); }
.match-info.searching { color: var(--warning); }
.match-info.not-found { color: var(--danger); }

.speaker-edit-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  width: 100%;
}

.speaker-edit-row input {
  flex: 1;
  height: 28px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 11px;
  outline: none;
}

.speaker-edit-row input:focus {
  border-color: var(--accent-border);
}

.btn-inline {
  height: 28px;
  padding: 0 10px;
  background: transparent;
  color: var(--text-tertiary);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
}

.btn-primary-inline {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
}

/* ── Toast ── */
.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid rgba(209, 67, 67, 0.4);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  font-size: 12px;
  display: none;
  z-index: 100;
  max-width: min(480px, 90vw);
}

@media (max-width: 960px) {
  .toolbar-primary { flex-wrap: wrap; height: auto; padding: 12px 16px; }
  .primary-actions { width: 100%; justify-content: flex-end; }
  .toolbar-secondary { height: auto; padding: 10px 16px; }
  .sidebar { display: none; }
  .segment-panel { min-width: 240px; }
}

/* 飞书授权面板 */
.auth-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
#gmwsGroupSelect {
  height: 32px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  font-size: 13px;
  cursor: pointer;
}

.auth-overlay > * {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 340px; width: 100%;
  text-align: center;
}
.auth-overlay #qrCodeContainer svg {
  background: #fff; border-radius: 8px; padding: 12px;
  max-width: 280px; max-height: 280px;
  display: block; margin: 0 auto;
}

/* 登录状态栏 */
.login-status {
  position: relative;
  font-size: 13px;
}
.login-name {
  color: #68c8b4;
  white-space: nowrap;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s ease;
}
.login-status:hover .login-name {
  opacity: 0.6;
}
.login-label {
  color: #94a3b8;
  white-space: nowrap;
}
.login-label.logged-in {
  color: #68c8b4;
}
.login-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 8px;
  min-width: 80px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
  z-index: 100;
}
.login-status:hover .login-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.btn-switch-user {
  background: transparent;
  border: 1px solid #4a7fd4;
  color: #6b9ae8;
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
  white-space: nowrap;
  box-sizing: border-box;
}
.btn-switch-user:hover {
  background: #2d4a7a;
}

/* 登录选项按钮 */
.login-option-btn {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: #e2e8f0;
  padding: 12px 16px;
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  box-sizing: border-box;
  text-align: center;
}
