:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2f3d;
    --text: #f5f5f7;
    --muted: #9aa3b2;
    --accent: #10a37f;
    --accent-dim: rgba(16, 163, 127, 0.15);
    --danger: #ef4444;
    --warning: #f59e0b;
    --speaking: #6366f1;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
}

.demo-page {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.demo-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(15, 17, 23, 0.95);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.demo-header a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.875rem;
}

.demo-header a:hover {
    color: var(--text);
}

.demo-title {
    font-size: 1rem;
    font-weight: 600;
}

.demo-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
    max-width: 1080px;
    width: 100%;
    margin: 0 auto;
    align-items: start;
}

@media (min-width: 960px) {
    .demo-main {
        grid-template-columns: 360px minmax(0, 1fr);
        padding: 24px;
        max-width: 1320px;
        align-items: stretch;
    }
}

.control-panel,
.summary-panel,
.transcript-final-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}

/* 人设卡片 */
.persona-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.persona-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(16, 163, 127, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.persona-name {
    font-size: 0.95rem;
    font-weight: 600;
}

.persona-desc {
    font-size: 0.76rem;
    color: var(--muted);
    margin-top: 2px;
}

/* 状态条 */
.status-bar {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
}

.status-dot.online { background: var(--accent); }
.status-dot.listening {
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
    animation: pulse 1.5s infinite;
}
.status-dot.processing { background: var(--warning); animation: pulse 1.5s infinite; }
.status-dot.speaking { background: var(--speaking); }
.status-dot.error { background: var(--danger); }
.status-dot.connecting { background: var(--warning); animation: pulse 1.5s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

#status-text {
    font-size: 0.9rem;
    color: var(--text);
}

/* 实时转写面板 */
.transcript-panel {
    padding: 12px 16px;
    min-height: 220px;
    max-height: 360px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.transcript-empty {
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
    margin: 40px 0;
}

.transcript-line {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.transcript-time {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--muted);
}

.transcript-text {
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--text);
    word-break: break-word;
}

.transcript-line.system {
    justify-content: center;
    background: transparent;
    color: var(--muted);
    font-size: 0.76rem;
}

/* 纪要模板选择 */
.template-panel {
    margin: 0 16px 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.template-textarea {
    width: 100%;
    min-height: 160px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.76rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    line-height: 1.5;
    resize: vertical;
}

/* 更多设置 */
.advanced-panel {
    margin: 0 16px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
}

.advanced-summary {
    padding: 8px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.advanced-summary::-webkit-details-marker {
    display: none;
}

.advanced-summary::before {
    content: '▸ ';
    display: inline-block;
    transition: transform 0.15s;
}

.advanced-panel[open] .advanced-summary::before {
    transform: rotate(90deg);
}

.advanced-body {
    padding: 0 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.advanced-label {
    font-size: 0.72rem;
    color: var(--muted);
}

.env-select {
    width: 100%;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.8rem;
}

.env-select:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.env-hint {
    margin: 0;
    font-size: 0.68rem;
    color: var(--muted);
    line-height: 1.35;
}

.npcid-row {
    display: flex;
    gap: 6px;
}

.npcid-input {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.78rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.npcid-input:disabled {
    opacity: 0.45;
}

.npcid-apply-btn {
    flex-shrink: 0;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
}

.npcid-apply-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* 按钮 */
.controls {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    flex: 1;
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.35);
    flex: 1;
}

.btn:not(:disabled):active {
    transform: scale(0.98);
}

.error-box {
    margin: 0 16px 16px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fecaca;
    font-size: 0.875rem;
}

.hint {
    padding: 0 16px 16px;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.5;
}

/* 纪要区 */
.summary-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.summary-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.summary-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.summary-status {
    font-size: 0.76rem;
    color: var(--muted);
}

.summary-status.done { color: #6ee7b7; }
.summary-status.error { color: #fca5a5; }

.summary-content {
    padding: 16px;
    min-height: 160px;
    max-height: 480px;
    overflow-y: auto;
    font-size: 0.88rem;
    line-height: 1.65;
}

.summary-content h1,
.summary-content h2,
.summary-content h3 {
    margin: 0 0 8px;
    color: var(--text);
}

.summary-content p {
    margin: 0 0 10px;
}

.summary-content ul,
.summary-content ol {
    margin: 0 0 10px;
    padding-left: 20px;
}

.summary-content strong {
    color: var(--accent);
}

.summary-content .cursor {
    display: inline-block;
    width: 7px;
    height: 1em;
    background: var(--accent);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 1s steps(2) infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}

.summary-actions {
    padding: 12px 16px 16px;
    display: flex;
    gap: 10px;
}

.transcript-final {
    padding: 12px 16px 16px;
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.transcript-final-line {
    display: flex;
    gap: 8px;
    align-items: baseline;
    font-size: 0.84rem;
}

.speaker-tag {
    flex-shrink: 0;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-dim);
    border: 1px solid rgba(16, 163, 127, 0.3);
    border-radius: 999px;
    padding: 1px 8px;
}

.transcript-final-time {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--muted);
}

/* ================================================================
 * 右侧工作区：实时字幕 / 原始转写 / 会议纪要 三个标签页
 * ================================================================ */
.caption-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px 16px 12px;
    border-bottom: 1px solid var(--border);
}

.caption-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.workspace {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 560px;
    height: calc(100dvh - 120px);
    min-width: 0;
}

.ws-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 10px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.ws-tab {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.86rem;
    font-weight: 500;
    padding: 9px 14px 11px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ws-tab:hover { color: var(--text); }

.ws-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.tab-count {
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 400;
}

.tab-badge {
    font-size: 0.66rem;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(16, 163, 127, 0.35);
}

.tab-badge.done { background: var(--accent); color: #04110d; }

.ws-pane {
    display: none;
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.ws-pane.active { display: flex; flex-direction: column; }

.pane-empty {
    margin: auto;
    padding: 24px;
    text-align: center;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.8;
}

.legend-partial { color: #b9c0cc; font-style: italic; }
.legend-final { color: var(--text); font-weight: 600; }

/* 实时字幕列表：完整可读，最新在底部 */
.caption-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

.cap-row {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 12px;
    padding: 8px 10px;
    border-radius: 10px;
    border-left: 3px solid transparent;
    transition: background 300ms ease, border-color 300ms ease;
}

.cap-time {
    font-size: 0.72rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--muted);
    padding-top: 4px;
}

.cap-body { min-width: 0; }

.cap-src {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text);
    word-break: break-word;
}

.cap-tr {
    margin-top: 2px;
    font-size: 0.9rem;
    line-height: 1.55;
    color: #8fd8c2;
    word-break: break-word;
}

.cap-tr:empty { display: none; }

.cap-tag {
    display: inline-block;
    margin-right: 6px;
    padding: 0 7px;
    border-radius: 999px;
    font-size: 0.64rem;
    line-height: 1.6;
    vertical-align: 2px;
}

/* 已定稿：刚锁定时闪一下 */
.cap-row.is-final.just-final { animation: cap-lock 1.2s ease; }

/* 大模型整理中（CAPTION_INTERIM） */
.cap-row.is-interim {
    background: rgba(16, 163, 127, 0.07);
    border-left-color: var(--accent);
}

.cap-row.is-interim .cap-tag { color: var(--accent); background: var(--accent-dim); }
.cap-row.is-interim .cap-src { color: #ffffff; }
.cap-row.is-updating .cap-body { animation: cap-rewrite 360ms ease; }

/* 实时识别（TRANSCRIPT_PARTIAL / 尚未整理的 TRANSCRIPT） */
.cap-row.is-partial .cap-src,
.cap-row.is-raw .cap-src { color: #b9c0cc; }
.cap-row.is-partial .cap-src { font-style: italic; }
.cap-row.is-partial { border-left-color: rgba(185, 192, 204, 0.5); }
.cap-row.is-partial .cap-tag,
.cap-row.is-raw .cap-tag { color: var(--muted); background: rgba(255, 255, 255, 0.05); }

.cap-row.is-partial .cap-src::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 3px;
    vertical-align: -0.15em;
    background: var(--muted);
    animation: cap-caret 0.9s steps(1) infinite;
}

.cap-row.is-system {
    display: block;
    text-align: center;
    color: var(--muted);
    font-size: 0.74rem;
    padding: 6px 0;
}

.cap-listening {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px 8px 80px;
    color: var(--muted);
    font-size: 0.78rem;
}

.cap-dots { display: inline-flex; gap: 5px; }
.cap-dots i {
    width: 6px; height: 6px; border-radius: 50%;
    background: rgba(127, 224, 196, 0.8);
    animation: cap-bounce 1.2s ease-in-out infinite;
}
.cap-dots i:nth-child(2) { animation-delay: 0.15s; }
.cap-dots i:nth-child(3) { animation-delay: 0.3s; }

.jump-latest {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(16, 163, 127, 0.5);
    background: #0f2a22;
    color: #7fe0c4;
    font-size: 0.78rem;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* 原始转写页 */
.ws-pane[data-pane="raw"] .transcript-panel {
    flex: 1;
    max-height: none;
    min-height: 0;
    padding: 16px 20px;
}

.transcript-line.is-partial .transcript-text { color: #b9c0cc; font-style: italic; }

/* 纪要页 */
.ws-pane[data-pane="summary"] { overflow-y: auto; }
.ws-pane[data-pane="summary"] .summary-section { padding: 16px; }
.ws-pane[data-pane="summary"] .summary-panel,
.ws-pane[data-pane="summary"] .transcript-final-panel { background: var(--bg); }

@keyframes cap-lock {
    0% { background: rgba(16, 163, 127, 0.22); }
    100% { background: transparent; }
}
@keyframes cap-rewrite {
    0% { opacity: 0.4; }
    100% { opacity: 1; }
}
@keyframes cap-caret {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}
@keyframes cap-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
    40% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 959px) {
    .workspace { height: 70dvh; min-height: 420px; }
    .cap-row { grid-template-columns: 1fr; gap: 2px; }
    .cap-listening { padding-left: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .caption-list { scroll-behavior: auto; }
    .cap-row, .cap-row * { animation: none !important; transition: none !important; }
}

@media (min-width: 960px) {
    /* 左栏较窄：按钮上下排列，避免文字折行 */
    .demo-main .controls { flex-direction: column; }
    .demo-main .controls .btn { width: 100%; }
    .control-panel { align-self: start; }
}
