/* Transcribe app — app-specific styles. Shared look/feel lives in
   ../../css/{shared,app-shell,modal,dropdown}.css.

   Design language: MD3 tonal, waveform-cyan accent, fluid spacing scale.
   Subject: audio → text transcription. The accent is waveform cyan, drawn
   from the colour of audio waveforms in professional DAWs. Signature: the
   recording state shows animated waveform bars instead of a plain dot.
   Mobile-first. Breakpoints: sm 640 · md 768 · lg 1024. */

:root {
    --tx-accent: #0891B2;
    --tx-accent-hover: #0E7490;
    --tx-accent-soft: color-mix(in srgb, #0891B2 12%, transparent);
    --tx-accent-softer: color-mix(in srgb, #0891B2 6%, transparent);
    --tx-danger: var(--md-error);
    --tx-danger-soft: color-mix(in srgb, var(--md-error) 12%, transparent);
    /* Vibrant recording red — stays vivid in both light and dark themes.
       --md-error flips to pale pink (#F2B8B5) in dark mode, which looks washed
       out on a record button. Use a fixed red so the CTA always reads "record". */
    --tx-record: #EF4444;
    --tx-record-hover: #DC2626;
    --tx-record-text: #FFFFFF;

    /* Fluid type scale — readable on phones, comfortable on desktop. */
    --tx-fs-xs: 0.75rem;
    --tx-fs-sm: 0.875rem;
    --tx-fs-base: 0.95rem;
    --tx-fs-md: 1rem;
    --tx-fs-lg: 1.125rem;
    --tx-fs-xl: 1.5rem;
}

.dark {
    --tx-accent: #22D3EE;
    --tx-accent-hover: #67E8F9;
    --tx-accent-soft: color-mix(in srgb, #22D3EE 12%, transparent);
    --tx-accent-softer: color-mix(in srgb, #22D3EE 6%, transparent);
}

/* Override shared MD3 primary with waveform cyan for this app's UI */
:root {
    --md-primary: var(--tx-accent);
    --md-on-primary: #FFFFFF;
    --md-primary-container: color-mix(in srgb, var(--tx-accent) 20%, var(--md-surface-container-low));
    --md-on-primary-container: var(--tx-accent);
}
.dark {
    --md-primary: var(--tx-accent);
    --md-on-primary: #0A1A1F;
    --md-primary-container: color-mix(in srgb, var(--tx-accent) 18%, var(--md-surface-container));
    --md-on-primary-container: var(--tx-accent);
}

body {
    -webkit-tap-highlight-color: transparent;
}

/* ──────────────────────────────────────────────────────────────────
   Page shell
   ────────────────────────────────────────────────────────────────── */
.tx-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.25rem 1rem 4rem;
}
@media (min-width: 768px) {
    .tx-main { padding: 2rem 1.5rem 5rem; }
}

.tx-card {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(15, 17, 24, 0.04);
    padding: 1.25rem;
}
@media (min-width: 768px) { .tx-card { padding: 1.75rem 2rem; } }

/* Views — all sections use the same vertical rhythm. */
.tx-view { display: flex; flex-direction: column; gap: 1.25rem; }
@media (min-width: 768px) { .tx-view { gap: 1.5rem; } }
.tx-view-center { align-items: center; text-align: center; padding: 2rem 0; }
/* Tailwind's `hidden` is `display: none`; our `.tx-view` rule loads later
   and would otherwise win the cascade. Force `hidden` to take precedence
   on view sections so showView() can actually hide them. */
.tx-view.hidden { display: none; }

/* View-switch entrance — a one-shot fade+rise on the newly-shown view so
   home↔recorder↔processing swaps aren't instant cuts. Class is toggled by
   showView(); the global reduced-motion kill-switch collapses it. */
.tx-view-enter { animation: tx-view-in var(--md-duration-m, 300ms) var(--md-easing-enter, cubic-bezier(0.05,0.7,0.1,1)) both; }
@keyframes tx-view-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Error-banner drop-in — matches the view entrance so the banner appears
   rather than snapping into place. */
.tx-banner-enter { animation: tx-banner-in var(--md-duration-s, 150ms) var(--md-easing-enter, cubic-bezier(0.05,0.7,0.1,1)) both; }
@keyframes tx-banner-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ──────────────────────────────────────────────────────────────────
   Card header (title + user chip)
   ────────────────────────────────────────────────────────────────── */
.tx-card-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
@media (min-width: 768px) {
    .tx-card-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}
.tx-card-header-titles { min-width: 0; }
.tx-card-subtitle {
    margin-top: 0.35rem;
    color: var(--md-on-surface-variant);
    font-size: var(--tx-fs-sm);
    line-height: 1.5;
    max-width: 60ch;
}
@media (min-width: 768px) { .tx-card-subtitle { font-size: var(--tx-fs-base); } }

/* User chip (avatar + name + logout) — reuses shell tokens. */
.tx-user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.25rem 0.25rem 0.5rem;
    border-radius: var(--md-shape-full);
    background: var(--md-surface-container);
    color: var(--md-on-surface);
    align-self: flex-start;
}
@media (min-width: 768px) { .tx-user-chip { align-self: auto; } }
.tx-user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    overflow: hidden; background: var(--md-surface-container-high);
    display: flex; align-items: center; justify-content: center;
    color: var(--md-on-surface-variant);
    flex-shrink: 0;
}
.tx-user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.tx-user-avatar .material-symbols-outlined { font-size: 22px; }
.tx-user-meta {
    display: flex; flex-direction: column; line-height: 1.15;
    font-size: var(--tx-fs-sm); padding-right: 0.25rem;
    min-width: 0;
}
.tx-user-greeting { color: var(--md-on-surface-variant); font-size: var(--tx-fs-xs); }
.tx-user-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 14ch; }

/* ──────────────────────────────────────────────────────────────────
   Drop zone
   ────────────────────────────────────────────────────────────────── */
.tx-dropzone {
    position: relative;
    border: 2px dashed var(--border-color, #d1d5db);
    border-radius: 20px;
    padding: 2rem 1.25rem;
    text-align: center;
    cursor: pointer;
    background: var(--md-surface-container-low, #f8fafc);
    transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}
.tx-dropzone:hover,
.tx-dropzone:focus-visible {
    border-color: var(--tx-accent);
    background: var(--tx-accent-softer);
    outline: none;
}
.tx-dropzone.drag-over {
    border-color: var(--tx-accent);
    background: var(--tx-accent-softer);
    transform: scale(1.005);
}
@media (min-width: 768px) {
    .tx-dropzone { padding: 3rem 2rem; gap: 1rem; }
}
.tx-dropzone-icon-wrap {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--tx-accent-soft);
    color: var(--tx-accent);
    display: flex; align-items: center; justify-content: center;
    transition: transform 200ms ease;
}
.tx-dropzone:hover .tx-dropzone-icon-wrap { transform: translateY(-2px); }
.tx-dropzone-icon-wrap .material-symbols-outlined { font-size: 36px; }
.tx-dropzone-title {
    font-size: var(--tx-fs-md);
    font-weight: 600;
    color: var(--md-on-surface, #111827);
}
@media (min-width: 768px) { .tx-dropzone-title { font-size: var(--tx-fs-lg); } }
.tx-dropzone-sub {
    font-size: var(--tx-fs-sm);
    color: var(--md-on-surface-variant, #6b7280);
    margin-top: 0.15rem;
}
.tx-dropzone-formats {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem;
    margin-top: 0.25rem;
}
.tx-dropzone-formats span {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    background: var(--md-surface-container, #eef0f4);
    color: var(--md-on-surface-variant, #6b7280);
}

/* ──────────────────────────────────────────────────────────────────
   Action rows (record button, recorder buttons)
   ────────────────────────────────────────────────────────────────── */
.tx-action-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}
.tx-action-row-center { justify-content: center; }
.tx-hint {
    font-size: var(--tx-fs-sm);
    color: var(--md-on-surface-variant, #6b7280);
}

.tx-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0 1.25rem;
    height: 44px;
    font-size: var(--tx-fs-sm);
    font-weight: 600;
    border-radius: var(--md-shape-full);
    border: none;
    cursor: pointer;
    transition: background 150ms ease, transform 80ms ease, box-shadow 150ms ease;
    white-space: nowrap;
}
.tx-btn:active { transform: scale(0.98); }
.tx-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tx-btn .material-symbols-outlined { font-size: 20px; }
.tx-btn-sm { height: 36px; padding: 0 1rem; font-size: var(--tx-fs-xs); }

/* Record/stop buttons use --tx-record (vibrant red) instead of --tx-danger
   (MD3 error token) because --md-error turns pale pink in dark mode, making
   the record CTA look washed out. --tx-record stays a vivid red in both themes. */
.tx-btn-record { background: var(--tx-record); color: var(--tx-record-text); }
.tx-btn-record:hover { background: var(--tx-record-hover); }

.tx-btn-stop { background: var(--tx-record); color: var(--tx-record-text); }
.tx-btn-stop:hover { background: var(--tx-record-hover); }

.tx-btn-ghost {
    background: var(--md-surface-container, #eef0f4);
    color: var(--md-on-surface, #111827);
}
.tx-btn-ghost:hover { background: var(--md-surface-container-high, #e2e5eb); }

/* color: var(--md-on-primary) (not a hardcoded white) — --tx-accent turns
   into a bright cyan in dark mode, so white text loses almost all contrast.
   --md-on-primary already flips per theme (see the two overrides above). */
.tx-btn-primary {
    background: var(--tx-accent);
    color: var(--md-on-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.tx-btn-primary:hover { background: var(--tx-accent-hover); }

/* ──────────────────────────────────────────────────────────────────
   Options panel
   ────────────────────────────────────────────────────────────────── */
.tx-options {
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    background: var(--md-surface-container-low, #f8fafc);
    overflow: hidden;
}
.tx-options[open] { background: var(--md-surface-container-low, #f8fafc); }
.tx-options-summary {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.85rem 1rem;
    font-size: var(--tx-fs-sm);
    font-weight: 600;
    color: var(--md-on-surface, #1f1f1f);
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.tx-options-summary::-webkit-details-marker { display: none; }
.tx-options-chev {
    font-size: 20px;
    color: var(--md-on-surface-variant, #6b7280);
    transition: transform 150ms ease;
}
.tx-options[open] .tx-options-chev { transform: rotate(90deg); }
.tx-options-body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 0 1rem 1rem;
}
@media (min-width: 640px) { .tx-options-body { grid-template-columns: 1fr 1fr; } }
.tx-field { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.tx-field-full { grid-column: 1 / -1; }
.tx-label {
    font-size: var(--tx-fs-xs);
    font-weight: 600;
    color: var(--md-on-surface-variant, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tx-input,
.tx-textarea {
    width: 100%;
    background: var(--card-bg, #fff);
    color: var(--md-on-surface, #111827);
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 10px;
    padding: 0.55rem 0.75rem;
    font-size: var(--tx-fs-sm);
    line-height: 1.45;
    outline: none;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.tx-input:focus,
.tx-textarea:focus {
    border-color: var(--tx-accent);
    box-shadow: 0 0 0 3px var(--tx-accent-soft);
}
.tx-input-sm { padding: 0.35rem 0.6rem; font-size: var(--tx-fs-xs); height: 34px; }
.tx-textarea { resize: vertical; min-height: 60px; font-family: inherit; }

/* Speaker-identification row: a single inline line with the checkbox
 * and its label, mirroring the density of the rest of the options panel.
 * `.tx-hint-muted` softens the cost hint vs. the default `.tx-hint`
 * tone so the toggle visually reads as the primary affordance. */
.tx-diarize-row {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--tx-fs-sm);
    color: var(--md-on-surface, #111827);
    cursor: pointer;
    user-select: none;
}
.tx-diarize-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--tx-accent);
    cursor: pointer;
}
.tx-diarize-row input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}
.tx-diarize-label { font-weight: 500; }
.tx-hint-muted {
    color: var(--md-on-surface-variant, #6b7280);
    font-size: var(--tx-fs-xs);
    margin-top: 0.15rem;
}

/* ──────────────────────────────────────────────────────────────────
   Section (History etc.)
   ────────────────────────────────────────────────────────────────── */
.tx-section { display: flex; flex-direction: column; gap: 0.75rem; }
.tx-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.tx-section-title {
    font-size: var(--tx-fs-md);
    font-weight: 700;
    color: var(--md-on-surface, #111827);
}
.tx-section-tools { display: flex; align-items: center; gap: 0.4rem; }
.tx-search {
    position: relative;
    display: flex;
    align-items: center;
}
.tx-search-icon {
    position: absolute; left: 0.55rem;
    color: var(--md-on-surface-variant, #6b7280);
    font-size: 18px; pointer-events: none;
}
.tx-search-input {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 10px;
    padding: 0.4rem 0.6rem 0.4rem 2.1rem;
    font-size: var(--tx-fs-sm);
    width: 200px;
    outline: none;
    color: var(--md-on-surface, #111827);
}
.tx-search-input:focus { border-color: var(--tx-accent); box-shadow: 0 0 0 3px var(--tx-accent-soft); }
@media (max-width: 479px) { .tx-search-input { width: 140px; } }

.tx-list { display: flex; flex-direction: column; gap: 0.5rem; }

/* History card */
.history-card {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}
.history-card:hover { background: var(--tx-accent-softer); border-color: var(--tx-accent-soft); }
.history-card .history-meta { font-size: var(--tx-fs-xs); color: var(--md-on-surface-variant, #6b7280); flex-wrap: wrap; row-gap: 0.25rem; }
.history-card .history-meta > span { white-space: nowrap; }
.history-card .history-status {
    display: inline-block;
    font-size: 0.7rem; font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--tx-accent-soft);
    color: var(--tx-accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.history-card .history-status.failed     { background: var(--tx-danger-soft); color: var(--tx-danger); }
.history-card .history-status.processing { background: rgba(245, 158, 11, 0.15); color: #b45309; }
.history-card .history-title {
    font-weight: 600;
    font-size: var(--tx-fs-sm);
    color: var(--md-on-surface, #111827);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1; min-width: 0;
}

/* ──────────────────────────────────────────────────────────────────
   Recording view
   ────────────────────────────────────────────────────────────────── */
.tx-recorder {
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    background: var(--md-surface-container-low, #f8fafc);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 18px;
    padding: 1.5rem;
}
.tx-recorder-head { display: flex; align-items: center; gap: 0.75rem; }
.tx-recorder-label { font-size: var(--tx-fs-lg); font-weight: 600; }
.tx-recorder-timer {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    font-size: var(--tx-fs-md);
    color: var(--md-on-surface-variant, #6b7280);
}
.tx-level-wrap {
    display: flex; align-items: center; gap: 0.6rem;
    height: 56px;
    padding: 0 0.75rem;
    background: var(--md-surface-container, #eef0f4);
    border-radius: 12px;
}
.tx-level-icon { color: var(--md-on-surface-variant, #6b7280); font-size: 22px; }
.tx-level-bar { display: flex; align-items: flex-end; gap: 3px; flex: 1; height: 40px; overflow: hidden; }
#levelBar .level-bar {
    width: 4px;
    background: var(--tx-accent);
    border-radius: 2px;
    height: 4px;
    transition: height 60ms linear, opacity 80ms linear;
    opacity: 0.4;
}

.recording-dot {
    width: 12px; height: 12px;
    border-radius: 999px;
    background: var(--tx-record);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--tx-record) 50%, transparent);
    animation: tx-pulse 1.4s ease-out infinite;
}

/* ── Signature: animated waveform bars ──
   When recording, the status indicator becomes a 5-bar waveform that
   animates like a live audio meter. Replaces the plain pulsing dot. */
.recording-waveform {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    height: 16px;
}
.recording-waveform .wave-bar {
    width: 3px;
    background: var(--tx-record);
    border-radius: 1px;
    animation: wave-bounce 0.8s ease-in-out infinite;
}
.recording-waveform .wave-bar:nth-child(1) { height: 60%; animation-delay: 0s; }
.recording-waveform .wave-bar:nth-child(2) { height: 100%; animation-delay: 0.1s; }
.recording-waveform .wave-bar:nth-child(3) { height: 40%; animation-delay: 0.2s; }
.recording-waveform .wave-bar:nth-child(4) { height: 80%; animation-delay: 0.15s; }
.recording-waveform .wave-bar:nth-child(5) { height: 50%; animation-delay: 0.05s; }

@keyframes wave-bounce {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
    .recording-waveform .wave-bar { animation: none; transform: scaleY(0.6); }
}
@keyframes tx-pulse {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tx-record) 50%, transparent); }
    70%  { box-shadow: 0 0 0 12px color-mix(in srgb, var(--tx-record) 0%, transparent); }
    100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tx-record) 0%, transparent); }
}

/* ──────────────────────────────────────────────────────────────────
   Processing view
   ────────────────────────────────────────────────────────────────── */
/* Shared transcript viewer (view/index.html) loading / error placeholder.
   Center the spinner + status text both horizontally and vertically,
   mirroring the main app's .tx-view-center convention. */
.tx-view-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 0;
}
/* The loading/error placeholder carries an explicit unlayered display, which
   beats Tailwind v4's layered `.hidden` utility — so `showContent()` adding
   `.hidden` would never hide it and the spinner would stick forever on top of
   the loaded result (same cascade-layer trap as #appError below). Override it
   explicitly. #viewContent is hidden the same way for symmetry. */
#viewStatus.hidden,
#viewContent.hidden { display: none; }
.spinner {
    width: 56px; height: 56px;
    border-radius: 50%;
    border: 4px solid var(--tx-accent-soft);
    border-top-color: var(--tx-accent);
    animation: tx-spin 0.9s linear infinite;
}
@keyframes tx-spin { to { transform: rotate(360deg); } }
.tx-processing-label {
    margin-top: 1rem;
    font-size: var(--tx-fs-md);
    font-weight: 600;
}
.tx-processing-detail {
    margin-top: 0.25rem;
    font-size: var(--tx-fs-sm);
    color: var(--md-on-surface-variant, #6b7280);
    max-width: 32ch;
}

/* ──────────────────────────────────────────────────────────────────
   Result view — header / actions
   ────────────────────────────────────────────────────────────────── */
.tx-result-head {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
@media (min-width: 768px) {
    .tx-result-head {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
    }
}
.tx-result-meta { min-width: 0; flex: 1; }
.tx-result-title {
    width: 100%;
    font-size: var(--tx-fs-lg);
    font-weight: 700;
    color: var(--md-on-surface, #111827);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.25rem 0.4rem;
    margin-left: -0.4rem;
    outline: none;
    transition: border-color 120ms ease, background 120ms ease;
    font-family: inherit;
}
.tx-result-title:hover { border-color: var(--border-color, #e5e7eb); }
.tx-result-title:focus { border-color: var(--tx-accent); background: var(--tx-accent-softer); }
@media (min-width: 768px) { .tx-result-title { font-size: var(--tx-fs-xl); } }
.tx-result-pills {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
    padding-left: 0.4rem;
}
.tx-pill {
    display: inline-flex;
    align-items: center;
    font-size: var(--tx-fs-xs);
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--md-surface-container, #eef0f4);
    color: var(--md-on-surface-variant, #4b5563);
    letter-spacing: 0.02em;
}
.tx-result-time {
    font-size: var(--tx-fs-xs);
    color: var(--md-on-surface-variant, #6b7280);
    padding-left: 0.25rem;
}
.tx-result-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}
.tx-danger { color: var(--tx-danger) !important; }
.tx-danger:hover { color: var(--tx-danger) !important; }

/* ──────────────────────────────────────────────────────────────────
   Custom audio player (mirrors slides/studio)
   ────────────────────────────────────────────────────────────────── */
.custom-audio-player {
    display: flex;
    flex-direction: column;
    width: 100%;
    background: #f0f4f9;
    border-radius: 20px;
    padding: 12px;
    gap: 12px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    user-select: none;
}
.dark .custom-audio-player {
    background: #1e1f20;
    border-color: rgba(255, 255, 255, 0.1);
}
.audio-controls-main { display: flex; align-items: flex-end; gap: 12px; }
.play-pause-btn {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: #004a77;
    color: white !important;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: none;
    flex-shrink: 0;
}
.play-pause-btn:hover { transform: scale(1.05); background: #003a5c; }
.dark .play-pause-btn { background: #a8c7fa; color: #062e6f !important; }
.dark .play-pause-btn:hover { background: #d3e3fd; }
.progress-container { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.progress-bar-wrapper {
    position: relative;
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    cursor: pointer;
    overflow: visible;
    /* Claim touch gestures so dragging the audio scrubber seeks instead of
       scrolling the page (setupAudioPlayers attaches a document touchmove). */
    touch-action: none;
}
.dark .progress-bar-wrapper { background: rgba(255, 255, 255, 0.1); }
.progress-bar-fill {
    position: absolute; left: 0; top: 0; height: 100%;
    background: #004a77;
    border-radius: 3px; width: 0%;
    pointer-events: none;
}
.dark .progress-bar-fill { background: #a8c7fa; }
.progress-thumb {
    position: absolute; top: 50%; left: 0%;
    transform: translate(-50%, -50%);
    width: 14px; height: 14px;
    background: #004a77;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
    pointer-events: none;
}
.progress-bar-wrapper:hover .progress-thumb { transform: translate(-50%, -50%) scale(1.2); }
.dark .progress-thumb { background: #a8c7fa; }
.audio-time {
    font-size: 11px;
    color: #5f6368;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    font-family: monospace;
}
.dark .audio-time { color: #9aa0a6; }
.audio-action-btn {
    padding: 6px;
    border-radius: 50%;
    color: #5f6368 !important;
    transition: background 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.audio-action-btn:hover { background: rgba(0, 0, 0, 0.05); }
.dark .audio-action-btn { color: #c4c7c5 !important; }
.dark .audio-action-btn:hover { background: rgba(255, 255, 255, 0.1); }
.custom-audio-player .material-symbols-outlined { font-size: 24px; }

/* ──────────────────────────────────────────────────────────────────
   Tabs strip + responsive grid
   ────────────────────────────────────────────────────────────────── */
.tx-tabs {
    position: relative;
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    margin: 0 -0.25rem;
    padding: 0 0.25rem;
}
/* Sliding active-tab underline. Lives inside the (scrollable) tab bar so it
   tracks horizontal scroll for free; positionTabIndicator() sets its x-offset
   and width to the active button. Replaces the per-tab border-bottom so the
   accent line glides between tabs instead of fading in place. */
.tx-tab-indicator {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    width: 0;
    background: var(--tx-accent);
    border-radius: 2px;
    transform: translateX(0);
    opacity: 0;
    pointer-events: none;
    transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1),
                width 280ms cubic-bezier(0.16, 1, 0.3, 1);
}
.tx-tab-indicator.ready { opacity: 1; }
.tx-tabs::-webkit-scrollbar { display: none; }
.tx-tab {
    flex-shrink: 0;
    padding: 0.65rem 0.85rem;
    font-size: var(--tx-fs-sm);
    font-weight: 500;
    color: var(--md-on-surface-variant, #6b7280);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: color 120ms ease, border-color 120ms ease;
    font-family: inherit;
}
.tx-tab:hover { color: var(--md-on-surface, #111827); }
.tx-tab.active {
    color: var(--tx-accent);
    font-weight: 600;
    /* Underline is drawn by the sliding .tx-tab-indicator, not a static border. */
}

.tx-result-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}
@media (min-width: 1024px) {
    .tx-result-grid {
        grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
        gap: 1.5rem;
    }
}

/* Tab panels: on mobile/sm/md we toggle which panel is visible.
   On lg+ the transcript is pinned left, side panels are pinned right
   and only the active side panel shows. */
.tx-tab-panel { display: none; }
.tx-tab-panel.active { display: block; }
@media (min-width: 1024px) {
    #transcriptPanel { display: block; }                    /* always shown on lg+ */
    .tx-side-panels > .tx-tab-panel { display: none; }     /* …only active side panel */
    .tx-side-panels > .tx-tab-panel.active { display: flex; flex-direction: column; }
    .tx-transcript-panel { height: fit-content; }
    /* Chat panel matches the transcript panel's height (same max-height
       formula as #viewTranscriptPanel below) instead of sizing to its own
       content, so the two side-by-side columns end at the same line. The
       message list absorbs the slack and scrolls internally. */
    #viewPanelChat.active {
        max-height: calc(100dvh - 120px);
        overflow: hidden;
    }
    #viewPanelChat.active .tx-chat-list {
        flex: 1;
        min-height: 0;
        max-height: none;
    }
}

/* Slide-in when a tab panel becomes active. A CSS animation (re)starts as an
   element goes from display:none → shown, so this fires on a real tab switch.
   Scoped to panels that actually toggle: the side panels (every layout) and the
   transcript panel where it toggles (mobile + stacked). The split-desktop
   transcript is pinned-visible, so it's excluded below to avoid a needless
   fade. Disabled under prefers-reduced-motion further down. */
@keyframes txTabSlideIn {
    from { opacity: 0; transform: translateX(14px); }
    to   { opacity: 1; transform: translateX(0); }
}
.tx-side-panels > .tx-tab-panel.active,
#viewTranscriptPanel.active {
    animation: txTabSlideIn 200ms cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform, opacity;
}
@media (min-width: 1024px) {
    /* Pinned-visible in split layout — don't re-animate on tab clicks. */
    .tx-result-grid[data-layout="split"] #viewTranscriptPanel.active {
        animation: none;
        will-change: auto;
    }
}

.tx-transcript-panel {
    background: var(--md-surface-container-lowest, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    padding: 1rem;
}
@media (min-width: 1024px) {
    .tx-transcript-panel {
        position: sticky;
        top: 88px;
        max-height: calc(100vh - 120px);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
}
/* Viewer (/view): keep the transcript panel inside the viewport at every
   breakpoint so only its segment list scrolls — the page never grows past
   screen height. (The home result view already caps this on lg+ above.) */
#viewTranscriptPanel {
    max-height: calc(100dvh - 120px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#viewTranscriptPanel .tx-segments { flex: 1; min-height: 0; }

/* Combined translation view: under the Translation tab, each segment
   card in #viewTranscriptPanel shows the original text and the
   translation together (see .segment-translation) — there is no
   separate translation panel. The transcript panel takes the full
   grid width and the (now-empty) side panels area is hidden. The
   class is toggled explicitly in setActiveTab(). Specificity beats
   the stacked-mode "hide transcript unless its tab is active" rule
   below, so the transcript stays visible across all layouts. */
.tx-result-grid.tx-translation-active #viewTranscriptPanel,
.tx-result-grid.tx-translation-active[data-layout="stacked"] #viewTranscriptPanel {
    display: flex;
}
.tx-result-grid.tx-translation-active .tx-side-panels {
    display: none;
}
@media (min-width: 1000px) {
    .tx-result-grid.tx-translation-active #viewTranscriptPanel {
        grid-column: 1 / -1;
    }
}

/* Hint shown above the segment list on the Translation tab when no
   target language is picked yet, or a translation hasn't been
   generated for the selected language. */
.tx-translation-hint {
    font-size: var(--tx-fs-sm, 0.8125rem);
    color: var(--text-muted, #64748b);
    padding: 0.5rem 0.25rem;
}

/* Inline translation under a segment's original text (Translation tab). */
.segment-translation {
    margin-top: 0.35rem;
    padding-top: 0.35rem;
    border-top: 1px dashed var(--border-color, #e5e7eb);
    font-size: var(--tx-fs-sm, 0.8125rem);
    color: var(--text-muted, #64748b);
    line-height: 1.5;
}

/* Tabs row: tab strip on the left, layout toggle on the right (desktop only). */
.tx-tabs-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.tx-tabs-row .tx-tabs { flex: 1; border-bottom: none; }
.tx-layout-toggle {
    display: none;                 /* hidden on mobile — stacked is the only option */
    gap: 2px;
    padding: 2px;
    border-radius: 9999px;
    background: var(--md-surface-container, #f1f5f9);
    margin-bottom: 6px;            /* align with the tab strip baseline */
}
.tx-layout-opt {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    border-radius: 9999px;
    background: transparent;
    border: none;
    color: var(--text-muted, #64748b);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}
.tx-layout-opt:hover { color: var(--text-color, #0f172a); }
.tx-layout-opt.active {
    background: var(--md-surface-container-lowest, #fff);
    color: var(--tx-accent);
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.tx-layout-opt .material-symbols-outlined { font-size: 18px; }
/* Desktop threshold = 1000px (not Tailwind's lg/1024px). */
@media (min-width: 1000px) {
    .tx-layout-toggle { display: inline-flex; }
}

/* Default / split mode (desktop) — controlled by [data-layout] on the grid.
   The split (2-column) layout is the default; stacked collapses to a single
   column where the tab strip selects which panel is visible. */
.tx-result-grid { transition: grid-template-columns 160ms ease; }
@media (min-width: 1000px) {
    /* When the Transcript tab is active, it must occupy the full width
       regardless of layout mode. The right-hand side panel is for the
       other tabs (Summary, Minutes, Translation, Chat) — Transcript
       doesn't share a column with anything. */
    .tx-result-grid[data-layout="split"] #viewTranscriptPanel.active,
    .tx-result-grid[data-layout="stacked"] #viewTranscriptPanel.active {
        grid-column: 1 / -1;
    }
    .tx-result-grid[data-layout="split"] {
        grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
        gap: 1.5rem;
    }
    .tx-result-grid[data-layout="split"] #viewTranscriptPanel { display: flex; }
    .tx-result-grid[data-layout="split"] .tx-side-panels > .tx-tab-panel { display: none; }
    .tx-result-grid[data-layout="split"] .tx-side-panels > .tx-tab-panel.active { display: flex; }

    .tx-result-grid[data-layout="stacked"] {
        grid-template-columns: minmax(0, 1fr);
        gap: 1.25rem;
    }
    .tx-result-grid[data-layout="stacked"] #viewTranscriptPanel { display: none; }
    .tx-result-grid[data-layout="stacked"] #viewTranscriptPanel.active { display: flex; }
    .tx-result-grid[data-layout="stacked"] .tx-side-panels > .tx-tab-panel { display: none; }
    .tx-result-grid[data-layout="stacked"] .tx-side-panels > .tx-tab-panel.active { display: flex; }
}

/* Mid-width band (1000–1023px): at this width the side panel is too
   cramped to be a single full-height column alongside the transcript in
   split mode, and stacked mode is too sparse. Lay the side panels out as
   a 2-column mini-grid (Summary | Minutes, Translation | Chat) in the
   right column under split, or as a 2-column grid in stacked mode. */
@media (min-width: 1000px) and (max-width: 1023.98px) {
    /* Split: the right-hand side panels become a 2-column mini-grid; the
       active one takes the full row so it isn't awkwardly clipped. */
    .tx-result-grid[data-layout="split"] .tx-side-panels {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
        align-content: start;
    }
    .tx-result-grid[data-layout="split"] .tx-side-panels > .tx-tab-panel { display: none; }
    .tx-result-grid[data-layout="split"] .tx-side-panels > .tx-tab-panel.active {
        display: flex;
        flex-direction: column;
        grid-column: 1 / -1;          /* active spans both columns */
    }

    /* Stacked: the side panels area itself is a 2-column grid; the
       active one again spans the full row. */
    .tx-result-grid[data-layout="stacked"] {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1.25rem;
    }
    .tx-result-grid[data-layout="stacked"] .tx-side-panels {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
        grid-column: 1 / -1;           /* occupy full row beneath the transcript */
    }
    .tx-result-grid[data-layout="stacked"] .tx-side-panels > .tx-tab-panel { display: none; }
    .tx-result-grid[data-layout="stacked"] .tx-side-panels > .tx-tab-panel.active {
        display: flex;
        flex-direction: column;
        grid-column: 1 / -1;
    }
}

/* Auto-scroll: keep the active segment centred in the list. `manual` is a
   class the renderer adds once the user scrolls the list themselves, then
   removes on the next play/seek — prevents scroll-jacking after the user
   has moved away. */
.tx-segments.auto-scroll .segment-card.active {
    scroll-margin-block: 50%;
}
.tx-segments.is-manual .segment-card.active { /* no auto-scroll on .active */ }

/* Speaker rename input replaces the badge in-place. */
.speaker-rename-input {
    font-size: 0.7rem;
    line-height: 1.1;
    padding: 2px 6px;
    border-radius: 9999px;
    border: 1px solid var(--border-color, #cbd5e1);
    background: var(--md-surface-container-lowest, #fff);
    color: inherit;
    min-width: 4ch;
    max-width: 16ch;
    outline: none;
}
.speaker-rename-input:focus {
    box-shadow: 0 0 0 2px var(--tx-accent-soft, #c7d2fe);
}
.speaker-badge { cursor: pointer; user-select: none; }

.tx-segments {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    padding-right: 0.25rem;
}
@media (min-width: 1024px) {
    .tx-segments { overflow-y: auto; flex: 1; }
}

.tx-side-panels { display: flex; flex-direction: column; gap: 1rem; }
.tx-side-panel {
    /* Positioning context for the chat panel's floating jump-to-latest button. */
    position: relative;
    background: var(--md-surface-container-lowest, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    padding: 1rem 1rem 1.1rem;
}
.tx-side-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.tx-side-panel-title {
    font-size: var(--tx-fs-md);
    font-weight: 700;
    color: var(--md-on-surface, #111827);
}
.tx-regen {
    background: transparent;
    border: 1px solid var(--border-color, #d1d5db);
    color: var(--tx-accent);
    padding: 0.25rem 0.65rem;
    font-size: var(--tx-fs-xs);
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
    font-family: inherit;
}
.tx-regen:hover { background: var(--tx-accent-softer); border-color: var(--tx-accent); }
.tx-icon-btn { padding: 0.25rem 0.4rem; display: inline-flex; align-items: center; justify-content: center; }
.tx-icon-btn .material-symbols-outlined { font-size: 18px; }
.tx-side-panel-head-actions { display: flex; align-items: center; gap: 0.5rem; }
.tx-summary-toggle {
    display: flex;
    background: var(--md-surface-container-low, #f3f4f6);
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 999px;
    padding: 2px;
}
.tx-summary-toggle-opt {
    background: transparent;
    border: none;
    color: var(--md-on-surface-variant, #6b7280);
    padding: 0.2rem 0.6rem;
    font-size: var(--tx-fs-xs);
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    transition: background 120ms ease, color 120ms ease;
}
/* color: var(--md-on-primary) — see .tx-btn-primary above; --tx-accent flips
   to a bright cyan in dark mode, so a hardcoded white loses all contrast. */
.tx-summary-toggle-opt.active { background: var(--tx-accent); color: var(--md-on-primary); }
.tx-detailed-summary { font-size: var(--tx-fs-base); line-height: 1.6; }
.detailed-summary-overview {
    color: var(--md-on-surface, #1f1f1f);
    margin: 0 0 1rem;
}
.detailed-summary-part {
    border-top: 1px solid var(--border-color, #e5e7eb);
    padding: 0.85rem 0 0;
    margin-bottom: 0.85rem;
}
.detailed-summary-part:first-child { border-top: none; padding-top: 0; }
.detailed-summary-part h4 {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: var(--tx-fs-sm);
    font-weight: 700;
    color: var(--md-on-surface, #111827);
    margin: 0 0 0.35rem;
}
.detailed-summary-part-time {
    font-size: var(--tx-fs-xs);
    font-weight: 500;
    color: var(--md-on-surface-variant, #6b7280);
}
.detailed-summary-part p {
    color: var(--md-on-surface, #1f1f1f);
    margin: 0 0 0.6rem;
    white-space: pre-wrap;
}
.detailed-summary-part pre.mermaid {
    background: var(--md-surface-container-low, #f8fafc);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    padding: 0.75rem;
    overflow-x: auto;
    transition: opacity 0.15s ease;
}
.tx-mermaid-wrap { position: relative; min-height: 64px; }
.tx-mermaid-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tx-prose {
    font-size: var(--tx-fs-base);
    line-height: 1.6;
    color: var(--md-on-surface, #1f1f1f);
    white-space: pre-wrap;
    word-break: break-word;
}
.tx-prose p { margin: 0 0 0.75rem; }
.tx-prose p:last-child { margin-bottom: 0; }


/* Chat */
.tx-chat-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-height: 50vh;
    overflow-y: auto;
    /* Anchor incoming stream chunks to the bottom so the browser itself keeps
       the viewport steady while content grows above the fold. */
    overflow-anchor: auto;
    margin-bottom: 0.75rem;
    padding-right: 0.25rem;
    /* No scroll-behavior:smooth here — it would turn every streamed chunk's
       scrollTop assignment into an animation that never catches up to the
       growing content. The jump-to-latest button opts into smooth explicitly
       via scrollTo({behavior}). */
}
.chat-message {
    position: relative;
    border-radius: 14px;
    padding: 0.6rem 0.9rem;
    font-size: var(--tx-fs-sm);
    line-height: 1.55;
    word-break: break-word;
    max-width: 100%;
    border: 1px solid var(--border-color, #e5e7eb);
    background: var(--card-bg, #fff);
}
.chat-message.user {
    background: var(--tx-accent-soft);
    border-color: color-mix(in srgb, var(--tx-accent) 22%, transparent);
    margin-left: 2rem;
    /* Tail-side corner tightened so the two roles read as opposite speakers
       at a glance, without resorting to hard-to-theme bubble tails. */
    border-bottom-right-radius: 5px;
    color: var(--md-on-surface, #111827);
}
.chat-message.assistant {
    background: var(--md-surface-container-low, #f8fafc);
    border-color: var(--border-color, #e5e7eb);
    margin-right: 2rem;
    border-bottom-left-radius: 5px;
}
.chat-message.is-error { border-color: color-mix(in srgb, var(--md-error) 45%, transparent); }
/* Only user text is preformatted. Assistant content is markdown-rendered HTML,
   where pre-wrap would turn the newlines markdown-it emits between block tags
   into visible blank lines, doubling every paragraph gap. */
.chat-message.user .tx-msg-body { white-space: pre-wrap; }
.tx-msg-flow { display: flex; flex-direction: column; gap: 0.35rem; }
@media (max-width: 479px) {
    .chat-message.user, .chat-message.assistant { margin-left: 0; margin-right: 0; }
}

/* Streaming caret — a soft block that trails the last streamed character, so
   a pause between chunks still reads as "live" rather than "stuck". */
.chat-message.is-streaming .chat-stream-text:last-child > *:last-child::after {
    content: '';
    display: inline-block;
    width: 0.45em;
    height: 1em;
    margin-left: 0.12em;
    vertical-align: -0.15em;
    border-radius: 2px;
    background: var(--tx-accent);
    opacity: 0.75;
    animation: tx-caret 1s steps(2) infinite;
}
@keyframes tx-caret { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
    .chat-message.is-streaming .chat-stream-text:last-child > *:last-child::after { animation: none; }
}

/* Status chip — what the model is doing before/between visible text. */
.tx-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: var(--tx-fs-xs, 0.75rem);
    color: var(--md-on-surface-variant, #6b7280);
    padding: 0.1rem 0 0.35rem;
}
.tx-status-chip.is-hidden { display: none; }
.tx-status-label { letter-spacing: 0.01em; }
.tx-dots { display: inline-flex; gap: 3px; align-items: center; }
.tx-dots i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--tx-accent);
    opacity: 0.35;
    animation: tx-dot 1.2s ease-in-out infinite;
}
.tx-dots i:nth-child(2) { animation-delay: 0.16s; }
.tx-dots i:nth-child(3) { animation-delay: 0.32s; }
@keyframes tx-dot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
    .tx-dots i { animation: none; opacity: 0.6; }
}

/* Reasoning trace (Gemini thought summaries), collapsed by default. */
.tx-thoughts {
    margin: 0 0 0.5rem;
    border-left: 2px solid var(--md-outline-variant, #d1d5db);
    padding-left: 0.6rem;
}
.tx-thoughts-summary {
    cursor: pointer;
    font-size: var(--tx-fs-xs, 0.75rem);
    color: var(--md-on-surface-variant, #6b7280);
    list-style: none;
    user-select: none;
}
.tx-thoughts-summary::-webkit-details-marker { display: none; }
.tx-thoughts-summary::before { content: '▸ '; display: inline-block; transition: transform 120ms ease; }
.tx-thoughts[open] > .tx-thoughts-summary::before { content: '▾ '; }
.tx-thoughts-body {
    margin-top: 0.35rem;
    font-size: var(--tx-fs-xs, 0.75rem);
    line-height: 1.5;
    color: var(--md-on-surface-variant, #6b7280);
    white-space: pre-wrap;
    max-height: 14rem;
    overflow-y: auto;
}

/* [mm:ss] citations — click to seek the recording. */
.tx-ts-cite {
    display: inline;
    font: inherit;
    font-variant-numeric: tabular-nums;
    color: var(--tx-accent);
    background: var(--tx-accent-softer);
    border: 0;
    border-radius: 5px;
    padding: 0 0.28em;
    margin: 0 0.05em;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}
.tx-ts-cite:hover { background: var(--tx-accent-soft); color: var(--tx-accent-hover); }
.tx-ts-cite:focus-visible { outline: 2px solid var(--tx-accent); outline-offset: 1px; }

/* Per-message actions (copy). Revealed on hover/focus so they don't compete
   with the text, but always present for touch. */
.tx-msg-actions {
    display: flex;
    gap: 0.25rem;
    justify-content: flex-end;
    margin-top: 0.35rem;
    opacity: 0;
    transition: opacity 140ms ease;
}
.chat-message:hover .tx-msg-actions,
.chat-message:focus-within .tx-msg-actions { opacity: 1; }
@media (hover: none) {
    .tx-msg-actions { opacity: 1; }
}
.tx-msg-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--md-on-surface-variant, #6b7280);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}
.tx-msg-action:hover { background: var(--md-surface-container, rgba(0,0,0,0.06)); color: var(--md-on-surface, #1f1f1f); }
.tx-msg-action .material-symbols-outlined { font-size: 16px; }
.tx-msg-action.is-done { color: var(--tx-accent); }
.tx-msg-action.is-failed { color: var(--md-error, #b3261e); }

/* Inline turn failure + retry. */
.tx-msg-error {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    font-size: var(--tx-fs-xs, 0.75rem);
    color: var(--md-error, #b3261e);
}
.tx-msg-error.is-partial { margin-top: 0.5rem; opacity: 0.85; }
.tx-msg-error-icon { font-size: 16px; }
.tx-msg-error-text { flex: 1; min-width: 8rem; }
.tx-msg-retry {
    border: 1px solid currentColor;
    background: transparent;
    color: inherit;
    font: inherit;
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
    cursor: pointer;
}
.tx-msg-retry:hover { background: var(--tx-danger-soft); }

/* Jump-to-latest, shown when the user has scrolled away from the live edge. */
.tx-jump-latest {
    position: absolute;
    right: 1.1rem;
    bottom: 6.5rem;
    z-index: 3;
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid var(--border-color, #e5e7eb);
    background: var(--card-bg, #fff);
    color: var(--md-on-surface, #1f1f1f);
    box-shadow: 0 2px 10px rgba(0,0,0,0.14);
    cursor: pointer;
}
.tx-jump-latest.is-visible { display: inline-flex; }
.tx-jump-latest .material-symbols-outlined { font-size: 19px; }
.tx-jump-latest:hover { border-color: var(--tx-accent); color: var(--tx-accent); }

/* Web-search citation cards. */
.tx-sources { margin: 0.4rem 0 0.2rem; }
.tx-sources-summary {
    cursor: pointer;
    list-style: none;
    font-size: var(--tx-fs-xs, 0.75rem);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--md-on-surface-variant, #6b7280);
}
.tx-sources-summary::-webkit-details-marker { display: none; }
.tx-sources-count {
    display: inline-block;
    min-width: 1.1rem;
    text-align: center;
    border-radius: 999px;
    background: var(--md-surface-container, rgba(0,0,0,0.06));
    padding: 0 0.3rem;
    letter-spacing: 0;
}
.tx-sources-grid { display: flex; flex-direction: column; gap: 0.3rem; margin-top: 0.4rem; }
.tx-source-card {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.4rem 0.55rem;
    border-radius: 9px;
    border: 1px solid var(--border-color, #e5e7eb);
    background: var(--card-bg, #fff);
    text-decoration: none;
    transition: border-color 120ms ease, background 120ms ease;
}
.tx-source-card:hover { border-color: var(--tx-accent); background: var(--tx-accent-softer); }
.tx-source-idx {
    flex-shrink: 0;
    width: 17px;
    height: 17px;
    border-radius: 5px;
    background: var(--md-surface-container, rgba(0,0,0,0.06));
    color: var(--md-on-surface-variant, #6b7280);
    font-size: 0.65rem;
    line-height: 17px;
    text-align: center;
}
.tx-source-body { display: flex; flex-direction: column; min-width: 0; }
.tx-source-title {
    font-size: var(--tx-fs-xs, 0.75rem);
    font-weight: 500;
    color: var(--tx-accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tx-source-host {
    font-size: 0.68rem;
    color: var(--md-on-surface-variant, #6b7280);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tool-block failure / limitation notices. */
.tx-block-error,
.tx-block-note {
    font-size: var(--tx-fs-xs, 0.75rem);
    line-height: 1.5;
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    margin: 0.4rem 0;
}
.tx-block-error {
    color: var(--md-error, #b3261e);
    border: 1px solid color-mix(in srgb, var(--md-error) 35%, transparent);
    background: var(--tx-danger-soft);
}
.tx-block-note {
    color: var(--md-on-surface-variant, #6b7280);
    border: 1px dashed var(--md-outline-variant, #d1d5db);
}
/* Source of a diagram mermaid refused to render — kept readable inside the
   failure notice rather than replaced by mermaid's bomb graphic. */
.tx-block-error > details { margin-top: 0.3rem; }
.tx-block-error > details > summary {
    cursor: pointer;
    color: var(--md-on-surface-variant, #6b7280);
}
.tx-diagram-source {
    margin: 0.35rem 0 0;
    padding: 0.4rem 0.5rem;
    max-height: 16rem;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    border-radius: 6px;
    background: var(--md-surface-variant, #f1f3f4);
    color: var(--md-on-surface, #1f1f1f);
    font-family: var(--tx-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
}
.tx-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.tx-chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 140px;
    background: var(--md-surface-container-low, #f3f4f6);
    border: 1px solid transparent;
    border-radius: var(--md-shape-xl, 24px);
    padding: 0.6rem 1rem;
    font-size: var(--tx-fs-sm);
    line-height: 1.45;
    color: var(--md-on-surface, #111827);
    resize: none;
    outline: none;
    font-family: inherit;
    transition: border-color 120ms ease;
}
.tx-chat-input:focus { border-color: var(--tx-accent); background: var(--card-bg, #fff); }
.tx-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.25rem 0 0.5rem;
}
.tx-chat-suggestions.hidden { display: none; }
.tx-sq-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--md-outline-variant, #d1d5db);
    background: var(--md-surface-container-low, #f3f4f6);
    color: var(--md-on-surface-variant, #6b7280);
    font-size: var(--tx-fs-xs, 0.75rem);
    font-family: inherit;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tx-sq-chip:hover {
    border-color: var(--tx-accent);
    color: var(--tx-accent);
    background: var(--card-bg, #fff);
}
.tx-sq-chip:focus-visible {
    outline: 2px solid var(--tx-accent);
    outline-offset: 1px;
}
.tx-chat-attach {
    cursor: pointer;
    color: var(--md-on-surface-variant, #6b7280);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    width: 44px;
    border-radius: 999px;
    flex-shrink: 0;
    transition: background 120ms ease;
}
.tx-chat-attach:hover { background: var(--md-surface-container, rgba(0,0,0,0.05)); }
.tx-chat-attach .material-symbols-outlined { font-size: 22px; }
.tx-chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.4rem 0;
    grid-column: 1 / -1;
}
.tx-chat-attachments.hidden { display: none; }
.tx-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: var(--md-secondary-container, #e0e7ff);
    color: var(--md-on-secondary-container, #1e1b4b);
    font-size: var(--tx-fs-xs, 0.75rem);
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tx-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-chip-x { background: none; border: 0; cursor: pointer; color: inherit; font-size: 1rem; line-height: 1; padding: 0 0.15rem; flex-shrink: 0; }
.tx-chip.is-uploading { opacity: 0.7; }
.tx-chip-spinner {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    animation: tx-spin 700ms linear infinite;
}
@keyframes tx-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .tx-chip-spinner { animation-duration: 2s; }
}
.tx-msg-attachments { margin-top: 0.4rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }

/* Send doubles as Stop while a turn is streaming. */
.tx-chat-form button[type="button"].is-stopping,
.tx-chat-form .tx-btn.is-stopping {
    background: var(--tx-danger-soft);
    border-color: color-mix(in srgb, var(--md-error) 45%, transparent);
    color: var(--md-error, #b3261e);
}
.chat-message.assistant .visualization-block,
.chat-message.assistant .chart-block,
.chat-message.assistant .mermaid-block,
.chat-message.assistant .search-results-block { background: var(--card-bg, rgba(0,0,0,0.02)); }
.chat-message.assistant pre { background: rgba(0,0,0,0.05); padding: 0.5rem; border-radius: 6px; overflow-x: auto; font-size: 0.85em; }
.chat-message.assistant code { background: rgba(0,0,0,0.05); padding: 0.1rem 0.3rem; border-radius: 4px; font-size: 0.9em; }
.chat-message.assistant pre code { background: none; padding: 0; }
.chat-message.assistant p { margin: 0.4rem 0; }
.chat-message.assistant ul { list-style: disc; margin: 0.4rem 0; padding-left: 1.4rem; }
.chat-message.assistant ol { list-style: decimal; margin: 0.4rem 0; padding-left: 1.4rem; }
.chat-message.assistant li { margin: 0.15rem 0; }
/* markdown-it wraps "loose" list items (blank line between bullets in the
   source, common in LLM output) in <p> — without this override that p's
   margin stacks on top of the li margin above, doubling the visual gap. */
.chat-message.assistant li > p { margin: 0; }
.chat-message.assistant a { color: var(--tx-accent); }
.chat-message.assistant table {
    width: 100%;
    margin: 0.5rem 0;
    border-collapse: collapse;
    font-size: 0.9em;
}
.chat-message.assistant th,
.chat-message.assistant td {
    border: 1px solid var(--border-color, #e5e7eb);
    padding: 0.35rem 0.6rem;
    text-align: left;
}
.chat-message.assistant thead th {
    background: rgba(0,0,0,0.05);
    font-weight: 600;
}

/* Dark theme: the tints above are black-on-light washes that vanish against a
   dark surface — restate them as white-on-dark at the same perceived weight. */
.dark .chat-message.assistant pre,
.dark .chat-message.assistant code,
.dark .chat-message.assistant thead th { background: rgba(255,255,255,0.08); }
.dark .chat-message.assistant pre code { background: none; }
.dark .tx-msg-action:hover,
.dark .tx-source-idx,
.dark .tx-sources-count { background: rgba(255,255,255,0.1); }
.dark .tx-jump-latest { box-shadow: 0 2px 12px rgba(0,0,0,0.5); }

/* ──────────────────────────────────────────────────────────────────
   Minutes
   ────────────────────────────────────────────────────────────────── */
.minutes-section h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--md-on-surface-variant, #6b7280);
    margin: 0.5rem 0 0.5rem;
    font-weight: 700;
}
.minutes-section:first-of-type h4 { margin-top: 0; }
.minutes-section ul { list-style: disc; padding-left: 1.25rem; margin: 0; }
.minutes-section li { margin-bottom: 0.35rem; }
.minutes-section .action-item {
    background: var(--tx-accent-softer);
    border: 1px solid var(--tx-accent-soft);
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.45rem;
    font-size: var(--tx-fs-sm);
    line-height: 1.45;
}
.minutes-section .action-item .owner { font-weight: 700; color: var(--tx-accent); }

/* ──────────────────────────────────────────────────────────────────
   Transcript segment cards
   ────────────────────────────────────────────────────────────────── */
.segment-card {
    background: var(--md-surface-container-low, #f8fafc);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    padding: 0.7rem 0.85rem;
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}
.segment-card:hover { background: var(--tx-accent-softer); }
.segment-card.active {
    background: var(--tx-accent-soft);
    border-color: var(--tx-accent);
}
.segment-card.editing { background: var(--tx-accent-softer); }
.segment-timestamp {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--tx-accent-soft);
    color: var(--tx-accent);
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    margin-top: 0.1rem;
    cursor: pointer;
}
.segment-timestamp:hover { background: var(--tx-accent-soft); }
/* Translation toolbar that sits above .tx-result-grid (and therefore
   above #viewTranscriptPanel). Houses the language <select> + Translate
   button. Stays visible on every tab, not just the Translation tab. */
.tx-translation-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--md-outline-variant, rgba(0, 0, 0, 0.08));
    border-radius: 0.5rem;
    background: var(--md-surface-container, rgba(0, 0, 0, 0.02));
}
.tx-translation-toolbar-icon {
    font-size: 18px;
    color: var(--tx-accent);
    flex-shrink: 0;
}
.tx-translation-toolbar-label {
    font-size: var(--tx-fs-sm, 0.875rem);
    font-weight: 600;
    color: var(--md-on-surface-variant, #475569);
    margin-right: 0.25rem;
}
.tx-translation-toolbar select { min-width: 9rem; flex: 0 0 auto; }
/* The custom-select widget (js/shared/ui-utils.js) replaces the <select>
   with a `.custom-select-wrapper` that defaults to width:100% — without
   this it stretches to fill the toolbar instead of sizing to its content.
   max-width caps the wrapper so the long "Pick a language to translate."
   placeholder (≈17rem at 14px) doesn't push the toolbar wider than its
   siblings. .current-value keeps its ellipsis so the placeholder truncates
   rather than overflowing. */
.tx-translation-toolbar .custom-select-wrapper { width: auto; min-width: 9rem; max-width: 10rem; flex: 0 0 auto; }
/* Override the shared dropdown's flex:1 on .current-value (dropdown.css) so
   the trigger sizes to the actual selected text (e.g. "English", "中文")
   instead of stretching to fill max-width. When the placeholder is shown
   it's truncated with ellipsis by .current-value's overflow/text-overflow. */
.tx-translation-toolbar .custom-select .current-value { flex: 0 1 auto; max-width: 100%; }
.tx-translation-toolbar .tx-btn { margin-left: auto; }

.segment-body { flex: 1; min-width: 0; }
.segment-text {
    font-size: var(--tx-fs-base);
    line-height: 1.6;
    color: var(--md-on-surface, #111827);
    /* Normalize any embedded newlines that may exist in older records;
       the backend already strips them for new transcriptions. */
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.segment-text[contenteditable="true"] {
    outline: 2px solid var(--tx-accent);
    outline-offset: 2px;
    border-radius: 6px;
    padding: 2px 4px;
}
.speaker-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    margin-bottom: 0.3rem;
    color: #fff;
    letter-spacing: 0.02em;
}
/* s1/s2/s3/s4/s7 use MD3 role tokens that pastelize in dark mode (e.g.
   --md-primary → bright cyan, --md-tertiary → light pink) — the shared
   white text above is unreadable against them there, so pair each with its
   matching --md-on-* token instead. s5/s6/s8 are fixed (non-reactive) hexes
   that already contrast fine with white in both themes. */
.speaker-badge.s1 { background: var(--md-primary); color: var(--md-on-primary); }
.speaker-badge.s2 { background: var(--md-tertiary); color: var(--md-on-tertiary); }
.speaker-badge.s3 { background: var(--md-warning); color: var(--md-on-warning); }
.speaker-badge.s4 { background: var(--md-success); color: var(--md-on-success); }
.speaker-badge.s5 { background: #0ea5e9; }
.speaker-badge.s6 { background: #8b5cf6; }
.speaker-badge.s7 { background: var(--md-error); color: var(--md-on-error); }
.speaker-badge.s8 { background: #14b8a6; }
.segment-edit-btn {
    opacity: 0;
    transition: opacity 120ms ease;
    color: var(--md-on-surface-variant, #6b7280);
    flex-shrink: 0;
    padding: 4px;
    border-radius: 6px;
}
.segment-card:hover .segment-edit-btn,
.segment-card:focus-within .segment-edit-btn { opacity: 1; }
.segment-edit-btn:hover { background: var(--tx-accent-soft); color: var(--tx-accent); }
/* Touch devices have no hover — keep edit affordance visible. */
@media (hover: none) { .segment-edit-btn { opacity: 1; } }

.segment-delete-btn {
    opacity: 0;
    transition: opacity 120ms ease;
    color: var(--md-on-surface-variant, #6b7280);
    flex-shrink: 0;
    padding: 4px;
    border-radius: 6px;
}
.segment-card:hover .segment-delete-btn,
.segment-card:focus-within .segment-delete-btn { opacity: 1; }
.segment-delete-btn:hover { background: var(--tx-danger-soft); color: var(--tx-danger); }
/* Touch devices have no hover — keep delete affordance visible. */
@media (hover: none) { .segment-delete-btn { opacity: 1; } }

/* ──────────────────────────────────────────────────────────────────
   App error banner
   ────────────────────────────────────────────────────────────────── */
#appError.hidden { display: none; }   /* beat Tailwind v4 cascade layers */
.tx-app-error {
    margin-top: 1rem;
    background: var(--tx-danger-soft);
    border: 1px solid color-mix(in srgb, var(--md-error) 30%, transparent);
    color: var(--md-on-error-container);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: var(--tx-fs-sm);
}
.dark .tx-app-error { color: #fecaca; }
.tx-app-error .material-symbols-outlined { font-size: 20px; margin-top: 1px; }
.tx-app-error-msg { font-weight: 600; }
.tx-app-error-detail {
    font-size: var(--tx-fs-xs);
    margin-top: 0.2rem;
    opacity: 0.85;
}

/* ──────────────────────────────────────────────────────────────────
   Scrollbar polish
   ────────────────────────────────────────────────────────────────── */
.tx-segments::-webkit-scrollbar,
.tx-chat-list::-webkit-scrollbar { width: 6px; }
.tx-segments::-webkit-scrollbar-thumb,
.tx-chat-list::-webkit-scrollbar-thumb {
    background: var(--tx-accent-soft);
    border-radius: 3px;
}
.tx-segments::-webkit-scrollbar-thumb:hover,
.tx-chat-list::-webkit-scrollbar-thumb:hover {
    background: var(--tx-accent);
}

/* ──────────────────────────────────────────────────────────────────
   Translation controls
   ────────────────────────────────────────────────────────────────── */
.tx-translation-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}
.tx-translation-controls select:disabled,
.tx-translation-controls button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

/* ──────────────────────────────────────────────────────────────────
   Regenerate loading states
   ────────────────────────────────────────────────────────────────── */
.spinner-inline {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--tx-accent-soft);
    border-top-color: var(--tx-accent);
    border-radius: 50%;
    animation: tx-spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 4px;
}
@keyframes tx-spin { to { transform: rotate(360deg); } }

.tx-regen:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.tx-loading-shimmer {
    position: relative;
    overflow: hidden;
    min-height: 3em;
    border-radius: 6px;
    background: var(--tx-accent-softer);
}
.tx-loading-shimmer::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(99,102,241,0.08) 40%,
        rgba(99,102,241,0.12) 50%,
        rgba(99,102,241,0.08) 60%,
        transparent 100%
    );
    animation: tx-shimmer 1.5s ease-in-out infinite;
}
@keyframes tx-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ──────────────────────────────────────────────────────────────────
   Reduced motion: disable decorative animations for users who prefer it.
   ────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .spinner,
    .spinner-inline {
        animation: none;
        opacity: 0.7;
    }
    .tx-loading-shimmer::after {
        animation: none;
    }
    .tx-side-panels > .tx-tab-panel.active,
    #viewTranscriptPanel.active {
        animation: none;
        will-change: auto;
    }
    .tx-tab-indicator {
        transition: none;
    }
    .tx-loading-shimmer {
        background: var(--tx-surface-2, rgba(99,102,241,0.06));
    }
    .tx-pulse {
        animation: none;
        opacity: 0.7;
    }
    * {
        transition-duration: 0.01ms !important;
    }
}

/* ──────────────────────────────────────────────────────────────────
   Print: transcripts are still useful on paper.
   ────────────────────────────────────────────────────────────────── */
@media print {
    .shell-header, .tx-tabs, .tx-result-actions, .tx-side-panels,
    .custom-audio-player, .tx-app-error { display: none !important; }
    .tx-card { box-shadow: none; border: none; }
    .tx-transcript-panel { max-height: none; overflow: visible; }
}
