/* Video2SRT — Components v2.0
 * Refactored: Enhanced depth, micro-interactions, better visual hierarchy
 */

/* ── Button ───────────────────────────────────────────────────────────── */
.btn {
    --_btn-bg: var(--color-bg-elev-3);
    --_btn-fg: var(--color-text);
    --_btn-border: var(--color-border-strong);
    --_btn-bg-hover: var(--color-bg-elev-4);
    --_btn-shadow: var(--shadow-xs);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    height: 36px;
    padding: 0 var(--space-md);
    background: var(--_btn-bg);
    color: var(--_btn-fg);
    border: 1px solid var(--_btn-border);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--_btn-shadow);
    transition:
        background-color var(--duration-fast) var(--ease-out),
        color var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out),
        transform var(--duration-fast) var(--ease-out);
    white-space: nowrap;
    user-select: none;
    /* .action-group-row lets its children shrink below their content width, and
       a button label never wraps — so a long label in a narrow grid column used
       to run straight out past the border. Clip at the border, and give a
       <span> label an ellipsis so the truncation reads as deliberate. Icons and
       the toggle switch are flex-shrink: 0 and keep their size. */
    overflow: hidden;
}
.btn > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn:hover {
    background: var(--_btn-bg-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-xs);
}
.btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-xs);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; transform: none; }
.btn > svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-sm { height: 30px; padding: 0 var(--space-sm); font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-lg { height: 44px; padding: 0 var(--space-lg); font-size: var(--text-md); border-radius: var(--radius-lg); }
.btn-icon { padding: 0; width: 36px; height: 36px; }
.btn-icon.btn-sm { width: 30px; height: 30px; }
.btn-icon.btn-lg { width: 44px; height: 44px; }
.btn-block { display: flex; width: 100%; }

.btn-primary {
    --_btn-bg: var(--color-accent);
    --_btn-fg: #FFFFFF;
    --_btn-border: var(--color-accent);
    --_btn-bg-hover: var(--color-accent-hover);
    --_btn-shadow: 0 8px 18px rgba(225, 29, 72, 0.18);
}
.btn-primary:hover {
    border-color: var(--color-accent-hover);
    box-shadow: 0 10px 22px rgba(225, 29, 72, 0.22);
}
.btn-primary > svg {
    color: #FFFFFF;
    opacity: 1;
    stroke: currentColor;
}
.btn-primary:hover > svg,
.btn-primary:active > svg,
.btn-primary:focus > svg {
    color: #FFFFFF;
    opacity: 1;
}

.btn-success {
    --_btn-bg: var(--color-success);
    --_btn-fg: #FFFFFF;
    --_btn-border: var(--color-success);
    --_btn-bg-hover: #16A34A;
    --_btn-shadow: 0 2px 8px rgba(34, 197, 94, 0.20);
}
.btn-success:hover { box-shadow: 0 4px 16px rgba(34, 197, 94, 0.25); }

.btn-danger {
    --_btn-bg: var(--color-error);
    --_btn-fg: #FFFFFF;
    --_btn-border: var(--color-error);
    --_btn-bg-hover: #DC2626;
    --_btn-shadow: 0 2px 8px rgba(239, 68, 68, 0.20);
}

.btn-ghost {
    --_btn-bg: transparent;
    --_btn-fg: var(--color-text-muted);
    --_btn-border: transparent;
    --_btn-bg-hover: var(--color-bg-elev-3);
    --_btn-shadow: none;
}
.btn-ghost:hover { color: var(--color-text); box-shadow: none; }

.btn-secondary {
    --_btn-bg: var(--color-bg-elev-3);
    --_btn-fg: var(--color-text-muted);
    --_btn-border: var(--color-border-strong);
    --_btn-bg-hover: var(--color-bg-elev-4);
}
.btn-secondary:hover { color: var(--color-text); }

.btn[aria-pressed="true"],
.btn.is-active {
    background: var(--color-accent-soft);
    color: var(--color-accent);
    border-color: var(--color-accent);
    box-shadow: var(--shadow-glow-accent);
}

/* Spinner adjacent to text inside button */
.btn .spinner-inline {
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* ── Input / Select / Textarea ───────────────────────────────────────── */
.input,
.select,
.textarea {
    display: block;
    width: 100%;
    height: 40px;
    padding: 0 var(--space-md);
    background: rgba(7, 8, 20, 0.42);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    box-shadow: var(--shadow-inset);
    transition:
        border-color var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out),
        background var(--duration-fast) var(--ease-out);
}
.input::placeholder,
.textarea::placeholder { color: var(--color-text-subtle); }

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: var(--shadow-focus), var(--shadow-inset);
    background: rgba(7, 8, 20, 0.62);
}

.input[aria-invalid="true"] {
    border-color: var(--color-error);
    box-shadow: 0 0 0 3px var(--color-error-soft), var(--shadow-inset);
}

.textarea {
    height: auto;
    min-height: 96px;
    padding: var(--space-sm) var(--space-md);
    line-height: var(--leading-normal);
    resize: vertical;
    font-family: var(--font-mono);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.field-label {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-muted);
}
.field-error {
    font-size: var(--text-xs);
    color: var(--color-error);
    min-height: 16px;
}

/* Select wrapper for custom arrow */
.select-wrap { position: relative; display: block; }
.select {
    appearance: none;
    padding-right: var(--space-2xl);
    cursor: pointer;
}
.select-wrap::after {
    content: '';
    position: absolute;
    right: 14px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--color-text-subtle);
    border-bottom: 2px solid var(--color-text-subtle);
    transform: translateY(-65%) rotate(45deg);
    pointer-events: none;
    transition: border-color var(--duration-fast) var(--ease-out);
}
.select-wrap:hover::after { border-color: var(--color-text-muted); }

/* Password input wrap */
.pwd-wrap { position: relative; }
.pwd-wrap .input { padding-right: 44px; }
.pwd-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: var(--color-text-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.pwd-toggle:hover { color: var(--color-text); background: var(--color-bg-elev-2); }
.pwd-toggle > svg { width: 18px; height: 18px; }

/* ── Badge ────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    font-size: var(--text-2xs);
    font-weight: var(--weight-semibold);
    line-height: 1.4;
    border-radius: var(--radius-full);
    background: var(--color-bg-elev-3);
    color: var(--color-text-muted);
    letter-spacing: 0.01em;
}
.badge > svg { width: 12px; height: 12px; }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-error { background: var(--color-error-soft); color: var(--color-error); }
.badge-info { background: var(--color-info-soft); color: var(--color-info); }
.badge-accent { background: var(--color-accent-soft); color: var(--color-accent); }

/* ── Card ─────────────────────────────────────────────────────────────── */
.card {
    background: var(--color-bg-elev-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    transition:
        border-color var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out);
}
.card:hover {
    border-color: var(--color-border-strong);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-elev-1);
}
.card-header h3,
.card-header h4 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}
.card-header svg { width: 16px; height: 16px; color: var(--color-accent); }
.card-body { padding: var(--space-md); }
.card-footer {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--color-border);
    flex-wrap: wrap;
}

/* ── Progress ─────────────────────────────────────────────────────────── */
.progress {
    width: 100%;
    height: 6px;
    background: var(--color-bg-elev-3);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-inset);
}
.progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--color-accent), #F43F5E, var(--color-accent));
    background-size: 200% 100%;
    border-radius: var(--radius-full);
    transition: width var(--duration-slow) var(--ease-out);
}
.progress-bar.is-animated {
    animation: gradientShift 2s ease infinite, progressStripe 0.6s linear infinite;
    background-image: linear-gradient(135deg,
        rgba(255,255,255,0.18) 25%, transparent 25%,
        transparent 50%, rgba(255,255,255,0.18) 50%,
        rgba(255,255,255,0.18) 75%, transparent 75%, transparent),
        linear-gradient(90deg, var(--color-accent), #F43F5E);
    background-size: 1rem 1rem, 100% 100%;
}
.progress-text {
    margin-top: 6px;
    font-size: var(--text-2xs);
    color: var(--color-text-subtle);
    font-family: var(--font-mono);
    text-align: right;
}

/* ── Spinner ──────────────────────────────────────────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border-strong);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }

/* ── Skeleton ─────────────────────────────────────────────────────────── */
.skeleton {
    display: block;
    background: linear-gradient(90deg,
        var(--color-bg-elev-3) 0%,
        var(--color-bg-elev-2) 50%,
        var(--color-bg-elev-3) 100%);
    background-size: 800px 100%;
    border-radius: var(--radius-sm);
    animation: shimmer 1.4s infinite linear;
}
.skeleton-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg-elev-2);
}

/* ── Empty state ──────────────────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-2xl) var(--space-lg);
    color: var(--color-text-subtle);
    gap: var(--space-sm);
}
.empty-state-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--color-bg-elev-3);
    color: var(--color-text-subtle);
    margin-bottom: var(--space-md);
    border: 1px solid var(--color-border);
}
.empty-state-icon > svg { width: 28px; height: 28px; }
.empty-state h4 { font-size: var(--text-md); color: var(--color-text-muted); }
.empty-state p { font-size: var(--text-sm); color: var(--color-text-subtle); max-width: 320px; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast-region {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-width: 380px;
    width: calc(100% - var(--space-2xl));
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-left: 3px solid var(--color-text-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: fadeInUp var(--duration-base) var(--ease-out) both;
}
.toast.is-leaving {
    animation: fadeIn var(--duration-fast) var(--ease-out) reverse forwards;
}
.toast-success { border-left-color: var(--color-success); }
.toast-error   { border-left-color: var(--color-error); }
.toast-warning { border-left-color: var(--color-warning); }
.toast-info    { border-left-color: var(--color-info); }

.toast-icon { flex-shrink: 0; padding-top: 2px; }
.toast-icon > svg { width: 18px; height: 18px; }
.toast-success .toast-icon { color: var(--color-success); }
.toast-error .toast-icon { color: var(--color-error); }
.toast-warning .toast-icon { color: var(--color-warning); }
.toast-info .toast-icon { color: var(--color-info); }

.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
.toast-message { font-size: var(--text-sm); color: var(--color-text-muted); line-height: var(--leading-snug); }

.toast-close {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--color-text-subtle);
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.toast-close:hover { color: var(--color-text); background: var(--color-bg-elev-3); }
.toast-close > svg { width: 14px; height: 14px; }

/* ── Dialog (native <dialog>) ─────────────────────────────────────────── */
dialog.dialog {
    margin: auto;
    padding: 0;
    background: var(--color-bg-elev-1);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    width: min(95vw, 560px);
    max-height: min(90vh, 720px);
    overflow: hidden;
    animation: fadeInScale var(--duration-base) var(--ease-out);
}
dialog.dialog::backdrop {
    background: rgba(5, 5, 16, 0.80);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: fadeIn var(--duration-fast) var(--ease-out);
}
dialog.dialog-lg { width: min(95vw, 1100px); max-height: min(92vh, 840px); }
dialog.segment-edit-dialog {
    width: min(92vw, 760px);
}

.dialog-inner {
    display: flex;
    flex-direction: column;
    max-height: inherit;
}
.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-elev-1);
}
.dialog-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
}
.dialog-title > svg { width: 20px; height: 20px; color: var(--color-accent); }
.dialog-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-lg); }
.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--color-border);
}

/* ── Short video generator ──────────────────────────────────────────── */
.short-generator-dialog {
    width: min(94vw, 980px);
    max-height: min(90vh, 820px);
}
.short-generator-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
}
.short-generator-form {
    display: grid;
    grid-template-columns: minmax(140px, 1.1fr) repeat(4, minmax(108px, 0.8fr)) auto;
    align-items: end;
    gap: var(--space-sm);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border);
}
.short-generator-form .field.is-disabled {
    opacity: 0.5;
}
.short-generator-form .btn {
    min-width: 108px;
    white-space: nowrap;
}
.short-analysis-status {
    min-height: 20px;
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
}
.short-candidate-list {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    min-height: 120px;
}
.short-candidate-row {
    display: grid;
    flex: 0 0 auto;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: stretch;
    column-gap: var(--space-md);
    min-height: 128px;
    padding: 14px 10px;
    border-bottom: 1px solid var(--color-border);
    overflow: hidden;
}
.short-candidate-row:last-child {
    border-bottom: 0;
}
.short-candidate-row.is-selected {
    background: var(--color-accent-soft);
}
.short-candidate-rank {
    align-self: center;
    color: var(--color-text-subtle);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    text-align: center;
}
.short-candidate-copy {
    display: grid;
    align-content: center;
    gap: 6px;
    min-width: 0;
}
.short-candidate-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-md);
}
.short-candidate-heading strong {
    overflow: hidden;
    color: var(--color-text);
    font-size: var(--text-sm);
    text-overflow: ellipsis;
    white-space: nowrap;
}
.short-candidate-heading span,
.short-candidate-meta,
.short-mode-toolbar strong {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    white-space: nowrap;
}
.short-candidate-copy p {
    display: -webkit-box;
    overflow: hidden;
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    line-height: var(--leading-snug);
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
}
.short-candidate-clips {
    display: flex;
    min-width: 0;
    min-height: 28px;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 0;
    padding: 0 0 6px;
    scrollbar-width: thin;
}
.short-candidate-clip {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
    height: 20px;
    padding: 0 5px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
}
.short-candidate-clip b {
    color: var(--color-accent);
}
.short-candidate-copy small {
    display: block;
    overflow: hidden;
    margin: 0;
    color: var(--color-text-subtle);
    font-size: var(--text-2xs);
    line-height: var(--leading-snug);
    text-overflow: ellipsis;
    white-space: nowrap;
}
.short-candidate-meta {
    display: flex;
    align-self: center;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 246px;
}
.short-candidate-meta b {
    color: var(--color-accent);
    font-size: var(--text-md);
}
.short-candidate-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}
.short-candidate-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    min-height: 120px;
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
}
.short-candidate-skeleton {
    display: grid;
    grid-template-columns: 72px 1fr 120px;
    gap: var(--space-sm);
    align-items: center;
    min-height: 86px;
    border-bottom: 1px solid var(--color-border);
}
.short-candidate-skeleton .skeleton {
    height: 12px;
}
.short-mode-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}
.short-mode-label {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 8px;
    border: 1px solid rgba(225, 29, 72, 0.36);
    border-radius: var(--radius-sm);
    background: var(--color-accent-soft);
    color: var(--color-accent);
    font-size: var(--text-2xs);
    font-weight: var(--weight-bold);
}
.short-range-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 12;
    min-width: 8px;
    border: 1px solid rgba(225, 29, 72, 0.88);
    background: rgba(225, 29, 72, 0.06);
    box-shadow: inset 0 0 0 1px rgba(225, 29, 72, 0.08);
    pointer-events: none;
}
.short-range-overlay.is-dragging {
    background: rgba(225, 29, 72, 0.1);
}
.short-range-caption {
    position: absolute;
    top: 4px;
    left: 50%;
    max-width: calc(100% - 44px);
    overflow: hidden;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: rgba(12, 15, 29, 0.9);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    text-overflow: ellipsis;
    white-space: nowrap;
    transform: translateX(-50%);
}
.short-range-order {
    position: absolute;
    top: 4px;
    left: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-sm);
    background: var(--color-accent);
    color: #f8fafc;
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    font-weight: var(--weight-bold);
}
.short-range-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 1px solid rgba(225, 29, 72, 0.45);
    border-radius: var(--radius-sm);
    background: rgba(12, 15, 29, 0.92);
    color: var(--color-text-muted);
    cursor: pointer;
    pointer-events: auto;
}
.short-range-remove:hover {
    border-color: var(--color-accent);
    color: #f8fafc;
}
.short-range-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 12px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: ew-resize;
    pointer-events: auto;
    touch-action: none;
}
.short-range-handle::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 3px;
    height: 24px;
    border-radius: var(--radius-full);
    background: var(--color-accent);
    transform: translateY(-50%);
}
.short-range-handle.start {
    left: -6px;
}
.short-range-handle.start::after {
    left: 5px;
}
.short-range-handle.end {
    right: -6px;
}
.short-range-handle.end::after {
    right: 5px;
}

@media (max-width: 980px) {
    .short-generator-form {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .short-generator-form .btn {
        width: 100%;
    }
}

@media (max-width: 760px) {
    .short-generator-form {
        grid-template-columns: 1fr 1fr;
    }
    .short-generator-form .btn {
        width: 100%;
    }
    .short-candidate-row {
        grid-template-columns: 24px minmax(0, 1fr);
        min-height: 150px;
        padding: 12px 6px;
    }
    .short-candidate-meta {
        grid-column: 2;
        justify-content: space-between;
        min-width: 0;
    }
    .short-candidate-actions {
        grid-column: auto;
        justify-self: end;
    }
    .short-candidate-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }
}
.edit-text-input {
    height: auto;
    min-height: 120px;
    padding: var(--space-sm) var(--space-md);
    line-height: var(--leading-snug);
    resize: vertical;
}

/* ── Source intake / Dropzone ────────────────────────────────────────── */
.source-workbench {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    align-items: start;
}
.source-primary {
    min-width: 0;
    padding: var(--space-lg);
    background:
        radial-gradient(circle at 0% 0%, rgba(225, 29, 72, 0.08), transparent 28%),
        linear-gradient(180deg, rgba(248, 250, 252, 0.035), transparent 42%),
        rgba(13, 16, 32, 0.82);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}
.source-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}
.source-kicker {
    display: block;
    margin-bottom: 3px;
    color: var(--color-accent);
    font-size: var(--text-2xs);
    font-weight: var(--weight-bold);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.source-panel-header h3 {
    color: var(--color-text);
    font-size: var(--text-xl);
    letter-spacing: -0.035em;
}
.source-limit-strip {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
}
.source-limit-strip span {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    background: rgba(248, 250, 252, 0.035);
    color: var(--color-text-subtle);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
}
.extract-mode-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-sm);
}
.extract-mode-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: 2px 4px 0;
}
.extract-mode-header h3 {
    color: var(--color-text);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}
.extract-mode-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-sm);
}
.extract-mode-option {
    position: relative;
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: var(--space-sm);
    min-height: 66px;
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: rgba(248, 250, 252, 0.03);
    color: var(--color-text-muted);
    cursor: pointer;
    transition:
        background var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out),
        color var(--duration-fast) var(--ease-out);
}
.extract-mode-option:hover {
    color: var(--color-text);
    border-color: var(--color-border-strong);
    background: rgba(248, 250, 252, 0.055);
}
.extract-mode-option.is-active {
    color: var(--color-text);
    border-color: rgba(225, 29, 72, 0.52);
    background: var(--color-accent-soft);
}
.extract-mode-option input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.extract-mode-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: rgba(248, 250, 252, 0.055);
    color: var(--color-accent);
}
.extract-mode-icon svg {
    width: 16px;
    height: 16px;
}
.extract-mode-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.extract-mode-copy strong {
    overflow: hidden;
    color: inherit;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-overflow: ellipsis;
    white-space: nowrap;
}
.extract-mode-copy small {
    overflow: hidden;
    color: var(--color-text-subtle);
    font-size: var(--text-2xs);
    line-height: var(--leading-snug);
    text-overflow: ellipsis;
    white-space: nowrap;
}
.extract-mode-settings {
    padding-top: 2px;
}
.source-status-card {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    padding: var(--space-sm);
}
.source-status-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    padding: 4px 8px;
}
.source-status-item + .source-status-item {
    border-left: 1px solid var(--color-border);
}
.source-status-item span {
    color: var(--color-text-subtle);
    font-size: var(--text-2xs);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.source-status-item strong {
    overflow: hidden;
    color: var(--color-text);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}
.source-tabs {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 4px;
    padding: 3px;
    background: rgba(248, 250, 252, 0.04);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.source-tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    min-height: 32px;
    padding: 0 12px;
    color: var(--color-text-muted);
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition:
        color 180ms var(--ease-out),
        background 180ms var(--ease-out),
        box-shadow 180ms var(--ease-out);
}
.source-tab:hover { color: var(--color-text); }
.source-tab.is-active {
    color: var(--color-text);
    background: var(--color-bg-elev-3);
    box-shadow: var(--shadow-xs);
}
.source-tab:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}
.link-import-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.link-input {
    height: auto;
    min-height: 112px;
    max-height: 180px;
    resize: vertical;
    line-height: 1.45;
}
.field-help {
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
}
.link-import-actions,
.link-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}
.check-row {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: var(--text-sm);
}
.check-row input,
.link-card-check {
    accent-color: var(--color-accent);
}
.link-results {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--color-border);
}
.link-results-header { margin-bottom: var(--space-sm); }
.link-results-header > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.link-results-header strong { color: var(--color-text); }
.link-results-header span {
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
}
.link-card-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
}
.link-card {
    display: grid;
    grid-template-columns: auto 58px minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-sm);
    padding: 7px;
    background: rgba(7, 8, 20, 0.34);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition:
        border-color 180ms var(--ease-out),
        background 180ms var(--ease-out);
}
.link-card:hover {
    background: var(--color-bg-elev-3);
    border-color: var(--color-border-strong);
}
.link-card:has(.link-card-check:checked) {
    border-color: var(--color-border-accent);
    background: var(--color-accent-subtle);
}
.link-card-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 38px;
    overflow: hidden;
    color: var(--color-text-subtle);
    background: var(--color-bg-elev-3);
    border-radius: var(--radius-sm);
}
.link-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.link-card-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 1px;
}
.link-card-body strong {
    overflow: hidden;
    color: var(--color-text);
    font-size: var(--text-sm);
    text-overflow: ellipsis;
    white-space: nowrap;
}
.link-card-body span,
.link-card-duration {
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
}
.source-loading,
.source-error,
.source-empty {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-md);
    color: var(--color-text-muted);
    background: rgba(7, 8, 20, 0.34);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.source-error {
    color: var(--color-error);
    background: var(--color-error-soft);
}
.source-error p {
    margin-top: 2px;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}
.source-loading.compact,
.source-error.compact,
.source-empty.compact {
    padding: var(--space-sm);
    font-size: var(--text-xs);
}
.link-import-action-buttons {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
}
.drawer-scrim {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, 0.46);
    backdrop-filter: blur(3px);
}
.link-history-drawer {
    position: fixed;
    top: var(--navbar-height);
    right: 0;
    z-index: 81;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(600px, calc(100vw - 24px));
    height: calc(100vh - var(--navbar-height));
    background:
        linear-gradient(180deg, rgba(248, 250, 252, 0.035), transparent 42%),
        rgba(10, 13, 26, 0.98);
    border-left: 1px solid var(--color-border);
    box-shadow: -18px 0 50px rgba(0, 0, 0, 0.34);
    overflow-x: hidden;
    transform: translateX(104%);
    visibility: hidden;
    pointer-events: none;
    transition: transform 240ms var(--ease-out);
}
.link-history-drawer.is-open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}
.link-history-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}
.link-history-drawer-header h3 {
    color: var(--color-text);
    margin: 0;
    font-size: var(--text-lg);
    line-height: 1.1;
    letter-spacing: -0.02em;
}
.link-history-drawer-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-height: 0;
    padding: var(--space-sm) var(--space-md) var(--space-md);
    overflow: hidden;
}
.link-history-filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    align-items: end;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: rgba(7, 8, 20, 0.24);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.link-history-filters .field {
    min-width: 0;
    margin: 0;
}
.link-history-filters .btn {
    min-height: 36px;
    align-self: end;
    white-space: nowrap;
}
.link-history-drawer-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: nowrap;
}
.link-history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 2px;
}
.link-history-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.link-history-group h5 {
    color: var(--color-text-subtle);
    font-size: var(--text-2xs);
    font-weight: var(--weight-bold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.link-history-table {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.link-history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    min-width: 0;
    padding: 8px 10px;
    color: var(--color-text-muted);
    background: rgba(7, 8, 20, 0.25);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition:
        background 180ms var(--ease-out),
        border-color 180ms var(--ease-out);
}
.link-history-row:hover {
    background: var(--color-bg-elev-3);
    border-color: var(--color-border-strong);
}
.link-history-main {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.link-history-url {
    overflow: hidden;
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: copy;
    text-align: left;
    line-height: 1.2;
}
.link-history-url:hover {
    color: var(--color-accent);
}
.link-history-meta {
    color: var(--color-text-subtle);
    font-size: var(--text-2xs);
    line-height: 1.2;
}
.link-history-row-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    flex-wrap: nowrap;
}
.history-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 18px;
    min-width: 44px;
    padding: 0 7px;
    border-radius: var(--radius-full);
    font-size: var(--text-2xs);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
}
.history-status.is-completed {
    color: var(--color-success);
    background: var(--color-success-soft);
}
.history-status.is-parsed {
    color: var(--color-accent);
    background: var(--color-accent-soft);
}
.history-status.is-failed {
    color: var(--color-error);
    background: var(--color-error-soft);
}
@media (max-width: 980px) {
    .source-workbench {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 640px) {
    .link-history-drawer {
        top: 0;
        width: 100vw;
        height: 100vh;
    }
    .source-workbench {
        grid-template-columns: 1fr;
    }
    .source-panel-header {
        flex-direction: column;
    }
    .source-limit-strip {
        justify-content: flex-start;
    }
    .source-toolbar {
        display: flex;
        align-items: stretch;
        flex-direction: column;
        gap: var(--space-sm);
    }
    .source-tabs {
        display: flex;
        width: 100%;
    }
    .source-tab {
        flex: 1;
        justify-content: center;
        padding-inline: var(--space-sm);
    }
    .source-primary {
        padding: var(--space-md);
    }
    .extract-mode-toggle {
        grid-template-columns: 1fr;
    }
    .source-status-card {
        grid-template-columns: 1fr;
    }
    .source-status-item + .source-status-item {
        border-left: 0;
        border-top: 1px solid var(--color-border);
    }
    .link-results-header {
        align-items: stretch;
        flex-direction: column;
    }
    .link-results-header .btn {
        width: 100%;
    }
    .link-import-action-buttons {
        width: 100%;
        flex-direction: column;
    }
    .link-card {
        grid-template-columns: auto 58px minmax(0, 1fr);
    }
    .link-card-thumb {
        width: 58px;
        height: 44px;
    }
    .link-card-duration {
        display: none;
    }
    .link-history-filters {
        align-items: stretch;
        flex-direction: column;
        display: flex;
    }
    .link-history-filters .field,
    .link-history-filters .btn {
        width: 100%;
    }
    .link-history-row {
        flex-direction: column;
        align-items: stretch;
    }
    .link-history-row-actions {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl) var(--space-xl);
    background: rgba(7, 8, 20, 0.32);
    border: 2px dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
    text-align: center;
    cursor: pointer;
    overflow: hidden;
    transition:
        border-color var(--duration-base) var(--ease-out),
        background var(--duration-base) var(--ease-out),
        box-shadow var(--duration-base) var(--ease-out);
}
/* Subtle gradient background on hover */
.dropzone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 0%, var(--color-accent-soft), transparent 70%);
    opacity: 0;
    transition: opacity var(--duration-base) var(--ease-out);
    pointer-events: none;
}
.dropzone:hover::before,
.dropzone:focus-visible::before,
.dropzone.is-dragover::before { opacity: 1; }

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-dragover {
    border-color: var(--color-accent);
    background: var(--color-bg-elev-2);
    box-shadow: var(--shadow-glow-accent);
}
.dropzone-icon {
    width: 54px;
    height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--color-bg-elev-3);
    color: var(--color-accent);
    margin-bottom: var(--space-md);
    border: 1px solid var(--color-border);
    transition:
        background var(--duration-base) var(--ease-out),
        transform var(--duration-base) var(--ease-out),
        box-shadow var(--duration-base) var(--ease-out);
}
.dropzone-icon > svg { width: 26px; height: 26px; }
.dropzone:hover .dropzone-icon,
.dropzone.is-dragover .dropzone-icon {
    background: var(--color-accent-soft);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow-accent);
}
.dropzone h3 { font-size: var(--text-lg); margin-bottom: var(--space-xs); position: relative; }
.dropzone p { font-size: var(--text-sm); color: var(--color-text-subtle); max-width: 420px; position: relative; }
.dropzone-hint {
    margin-top: var(--space-lg);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-md);
    font-size: var(--text-xs);
    color: var(--color-text-subtle);
    position: relative;
}

/* ── Recording indicator ──────────────────────────────────────────────── */
.recording-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-md);
    background: var(--color-success-soft);
    border: 1px solid var(--color-success);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    color: var(--color-success);
    box-shadow: var(--shadow-glow-success);
}
.recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-success);
    animation: recordPulse 1.2s var(--ease-in-out) infinite;
}
.recording-time {
    font-family: var(--font-mono);
    font-weight: var(--weight-medium);
}

/* ── Cue list ────────────────────────────────────────────────────────── */
.cue-item-arrow { color: var(--color-text-subtle); }
.cue-item-del {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: transparent;
    border: 0;
    color: var(--color-text-subtle);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.cue-item-del:hover { color: var(--color-error); background: var(--color-error-soft); }
.cue-item-del > svg { width: 14px; height: 14px; }

/* ── OCR result item ─────────────────────────────────────────────────── */
.ocr-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-elev-2);
    border: 1px solid var(--color-border);
    border-left-width: 3px;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    transition:
        border-color var(--duration-fast) var(--ease-out),
        background var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out);
}
.ocr-item:last-child { margin-bottom: 0; }
.ocr-item:hover { border-color: var(--color-border-strong); }
.ocr-item.is-active {
    background: var(--color-accent-soft) !important;
    border-color: var(--color-accent) !important;
    border-left-color: var(--color-accent) !important;
    box-shadow: var(--shadow-glow-accent);
}
.ocr-item-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}
.ocr-item-num {
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    font-weight: var(--weight-semibold);
    color: var(--color-accent);
}
.ocr-item-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
    margin-left: auto;
}
.ocr-retry-btn,
.ocr-edit-btn {
    width: 24px !important;
    height: 24px !important;
    padding: 0 !important;
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease-out);
}
.ocr-item:hover .ocr-retry-btn,
.ocr-item:hover .ocr-edit-btn { opacity: 1; }
@media (hover: none) {
    .ocr-retry-btn, .ocr-edit-btn { opacity: 1; }
}
.ocr-item-time {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    color: var(--color-accent);
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 2px 4px;
    margin: -2px -4px;
}
.ocr-item-time:hover,
.ocr-item-time:focus-visible { background: var(--color-bg-elev-3); }
.ocr-item-text {
    font-size: var(--text-sm);
    color: var(--color-text);
    line-height: var(--leading-snug);
    word-break: break-word;
}
.ocr-item-empty {
    font-size: var(--text-xs);
    color: var(--color-text-subtle);
    font-style: italic;
}
.ocr-item.conf-high  { border-left-color: var(--color-success); }
.ocr-item.conf-mid   { border-left-color: var(--color-warning); }
.ocr-item.conf-low   { border-left-color: var(--color-error); }
.ocr-item.conf-none  { border-left-color: var(--color-border-strong); }

/* ── Subtitle segments (CapCut-like strip) ───────────────────────────── */
.segment-track {
    position: relative;
    min-height: 136px;
    width: max-content;
    border-radius: var(--radius-lg);
    background: transparent;
    --segment-lane-step: 40px;
    --segment-lane-top: 8px;
}
.segment-item {
    position: absolute;
    top: 46px;
    height: 76px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 88px;
    padding: 10px 12px;
    background:
        linear-gradient(180deg, rgba(17, 22, 42, 0.96), rgba(7, 8, 20, 0.96));
    border: 1px solid rgba(248, 250, 252, 0.08);
    border-radius: 12px;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.04),
        0 10px 24px rgba(0, 0, 0, 0.28);
    cursor: pointer;
    overflow: hidden;
    user-select: none;
    backdrop-filter: blur(8px);
    transition:
        border-color var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out),
        transform var(--duration-fast) var(--ease-out);
}
.segment-item:hover {
    border-color: var(--color-border-strong);
    transform: translateY(-1px);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 14px 32px rgba(0, 0, 0, 0.34);
}
.segment-item:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}
.segment-item.is-active {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-glow-accent);
}
.segment-item.is-selected {
    border-color: rgba(96, 165, 250, 0.85);
    box-shadow:
        inset 0 0 0 1px rgba(96, 165, 250, 0.18),
        0 0 0 2px rgba(96, 165, 250, 0.16),
        0 10px 24px rgba(0, 0, 0, 0.30);
}
.segment-item.is-dragging {
    z-index: 10;
    border-color: var(--color-accent);
    box-shadow: var(--shadow-lg);
    transform: none;
}
.segment-item.status-empty { opacity: 0.72; }
.segment-item::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: linear-gradient(90deg, rgba(225, 29, 72, 0.9), rgba(244, 63, 94, 0.2));
    opacity: 0.65;
}
.segment-item.is-active::before {
    opacity: 1;
}
.segment-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    min-width: 0;
}
.segment-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: var(--radius-full);
    background: var(--color-bg-elev-3);
    color: var(--color-text-subtle);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    flex-shrink: 0;
}
.segment-time {
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    color: var(--color-text-subtle);
    white-space: nowrap;
}
.segment-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1;
}
.segment-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--color-text);
    font-size: var(--text-xs);
    line-height: var(--leading-snug);
    word-break: break-word;
}
.segment-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-top: auto;
}
.segment-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease-out);
}
.segment-item:hover .segment-actions,
.segment-item:focus-within .segment-actions,
.segment-item.is-active .segment-actions {
    opacity: 1;
}
@media (hover: none) {
    .segment-actions { opacity: 1; }
}
.segment-playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 18px;
    transform: translateX(-9px);
    pointer-events: auto;
    z-index: 20;
    cursor: ew-resize;
    touch-action: none;
}
.segment-playhead::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 8px;
    width: 2px;
    background: linear-gradient(180deg, rgba(225, 29, 72, 0.95), rgba(225, 29, 72, 0.2));
    box-shadow: 0 0 0 1px rgba(225, 29, 72, 0.18), 0 0 18px rgba(225, 29, 72, 0.22);
}
.segment-playhead::after {
    content: '';
    position: absolute;
    top: 0;
    left: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.18);
}
.segment-playhead-time {
    position: absolute;
    top: -30px;
    left: 9px;
    z-index: 2;
    min-width: max-content;
    padding: 4px 7px;
    border: 1px solid rgba(244, 63, 94, 0.46);
    border-radius: var(--radius-sm);
    background: rgba(7, 8, 20, 0.96);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32);
    color: #FFE4E6;
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 4px);
    transition:
        opacity var(--duration-fast) var(--ease-out),
        transform var(--duration-fast) var(--ease-out);
    white-space: nowrap;
}
.segment-playhead-time::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    width: 7px;
    height: 7px;
    border-right: 1px solid rgba(244, 63, 94, 0.46);
    border-bottom: 1px solid rgba(244, 63, 94, 0.46);
    background: rgba(7, 8, 20, 0.96);
    transform: translate(-50%, -4px) rotate(45deg);
}
.segment-stage.is-scrubbing .segment-playhead-time,
.segment-playhead:hover .segment-playhead-time {
    opacity: 1;
    transform: translate(-50%, 0);
}
.segment-stage.is-scrubbing,
.segment-stage.is-scrubbing .segment-playhead {
    cursor: ew-resize;
}
.segment-stage.is-scrubbing .segment-playhead::after,
.segment-playhead:hover::after {
    box-shadow: 0 0 0 5px rgba(225, 29, 72, 0.24), 0 8px 20px rgba(225, 29, 72, 0.30);
}
.segment-drag-guide {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    z-index: 18;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(148, 163, 184, 0.58), rgba(148, 163, 184, 0.16));
    box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.08);
    transform: translateX(-0.5px);
}
.segment-drag-guide span {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    background: rgba(15, 23, 42, 0.88);
    border: 1px solid rgba(148, 163, 184, 0.22);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    white-space: nowrap;
    box-shadow: var(--shadow-xs);
}
.segment-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 12px;
    background: transparent;
    cursor: ew-resize;
    touch-action: none;
}
.segment-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    width: 3px;
    height: 44px;
    margin-top: -22px;
    border-radius: var(--radius-full);
    background: rgba(248, 250, 252, 0.28);
}
.segment-handle.start { left: -1px; }
.segment-handle.start::before { left: 3px; }
.segment-handle.end { right: -1px; }
.segment-handle.end::before { right: 3px; }
.segment-handle:hover::before { background: var(--color-accent); }
.segment-empty { min-height: 110px; }
.segment-item.seekable { cursor: grab; }
.segment-item.seekable:active { cursor: grabbing; }

.segment-layer-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    box-sizing: border-box;
    width: max-content;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(17, 22, 42, 0.90), rgba(7, 8, 20, 0.84));
}
.timeline-lane {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 0;
    align-items: stretch;
    background: transparent;
}
.timeline-lane + .timeline-lane {
    border-top: 1px solid rgba(148, 163, 184, 0.12);
}
.timeline-lane-label {
    position: sticky;
    left: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 18px 14px;
    margin-right: 0;
    border-right: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.timeline-lane-label strong {
    color: var(--color-text);
    font-size: var(--text-sm);
    text-transform: none;
    letter-spacing: 0;
}
.timeline-lane-label span {
    color: var(--color-text-subtle);
    text-transform: none;
    letter-spacing: 0;
    font-size: var(--text-2xs);
    overflow: hidden;
    text-overflow: ellipsis;
}
.timeline-lane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.track-mute-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text-subtle);
    background: transparent;
    cursor: pointer;
    transition:
        color var(--duration-fast) var(--ease-out),
        background var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out);
}
.track-mute-btn:hover {
    color: var(--color-text);
    background: rgba(248, 250, 252, 0.06);
}
.track-mute-btn.is-muted {
    color: var(--color-error);
    background: var(--color-error-soft);
    border-color: rgba(239, 68, 68, 0.26);
}
.track-mute-btn > svg {
    width: 14px;
    height: 14px;
}
.track-volume-control {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    margin-top: 2px;
    color: var(--color-text-subtle);
    font-size: var(--text-2xs);
    text-transform: none;
    letter-spacing: 0;
}
.track-volume-control span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
    color: var(--color-text-subtle);
    font-size: var(--text-2xs);
}
.track-volume-control b {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-weight: var(--weight-semibold);
}
.track-volume-control input[type="range"] {
    width: 100%;
    height: 12px;
    margin: 0;
    accent-color: var(--color-accent);
    background:
        repeating-linear-gradient(
            to right,
            transparent 0,
            transparent calc(2.5% - 1px),
            rgba(148, 163, 184, 0.34) calc(2.5% - 1px),
            rgba(148, 163, 184, 0.34) 2.5%
        );
    cursor: pointer;
}
.timeline-lane-track {
    position: relative;
    min-height: 38px;
    border: 0;
    border-radius: 0;
    background: transparent;
}
.timeline-lane-track.is-freeform,
.segment-track.is-freeform {
    background: transparent;
}
.timeline-lane-track.subtitle-combined-track {
    min-height: 54px;
}
.timeline-lane-track.is-muted {
    opacity: 0.58;
    filter: saturate(0.85);
}
.timeline-lane-track.is-placeholder {
    display: flex;
    align-items: center;
    padding: 0 12px;
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
}
.timeline-source-chip {
    width: max-content;
    max-width: min(420px, calc(100% - 16px));
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.22);
    background:
        linear-gradient(180deg, rgba(30, 27, 75, 0.95), rgba(15, 15, 35, 0.96));
    color: var(--color-text-muted);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 7px 11px;
    font-size: var(--text-xs);
    letter-spacing: 0.02em;
}
.timeline-source-chip strong {
    color: var(--color-text);
    font-size: var(--text-xs);
}
.timeline-source-chip span {
    color: var(--color-text-subtle);
}
.timeline-source-chip.is-muted {
    opacity: 0.58;
    filter: saturate(0.7);
}
.tts-empty {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-subtle);
}
.tts-empty.is-compact {
    width: 1px;
    height: 1px;
    overflow: hidden;
}
.tts-empty .btn {
    height: 28px;
}
.tts-audio-item {
    position: absolute;
    top: 6px;
    height: 26px;
    min-width: 132px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: linear-gradient(180deg, rgba(14, 116, 144, 0.92), rgba(8, 47, 73, 0.92));
    color: #ECFEFF;
    overflow: hidden;
    box-shadow: 0 8px 18px rgba(8, 47, 73, 0.22);
}
.tts-audio-item.is-muted {
    opacity: 0.55;
    filter: grayscale(0.35);
}
/* Segment finished server-side but not folded into the merged track/
   registered as playable audio yet — shown as done-but-provisional so
   generation progress reads clip-by-clip instead of an all-or-nothing wait. */
.tts-audio-item.is-pending {
    border-style: dashed;
    background: linear-gradient(180deg, rgba(21, 128, 61, 0.55), rgba(8, 47, 27, 0.75));
}
/* Voice ran longer than its available window even after speed/tempo fitting
   and got cut off — flagged instead of looking identical to a clean fit. */
.tts-audio-item.is-trimmed {
    border-color: rgba(251, 191, 36, 0.6);
    background: linear-gradient(180deg, rgba(146, 64, 14, 0.75), rgba(69, 26, 3, 0.85));
}
.tts-audio-item.is-trimmed .tts-audio-title svg {
    color: #FBBF24;
}
.tts-audio-title {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: max-content;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
}
.tts-audio-delete {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin-left: auto;
    padding: 0;
    border: 0;
    border-radius: var(--radius-full);
    background: rgba(15, 23, 42, 0.5);
    color: #ECFEFF;
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.tts-audio-delete:hover {
    background: var(--color-error);
    color: #fff;
}
.tts-audio-delete:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.tts-lane-count {
    color: var(--color-text-subtle);
    font-size: var(--text-2xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tts-waveform {
    position: absolute;
    inset: 5px 8px;
    opacity: 0.35;
    background:
        repeating-linear-gradient(
            to right,
            transparent 0,
            transparent 5px,
            rgba(236, 254, 255, 0.70) 5px,
            rgba(236, 254, 255, 0.70) 7px,
            transparent 7px,
            transparent 11px
        );
    mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        #000 18%,
        #000 82%,
        transparent 100%
    );
}

/* ── Music clip (draggable background-music block on the timeline) ─────── */
.timeline-lane:has(.music-lane-track) .timeline-lane-label,
.music-lane-controls {
    justify-content: center;
    gap: 0;
    padding: 4px 8px;
    min-height: 32px;
}
.music-lane-control-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    width: 100%;
}
.music-lane-controls .track-mute-btn {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    border-color: rgba(148, 163, 184, 0.18);
    background: rgba(248, 250, 252, 0.035);
}
.music-lane-controls .track-volume-control {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex: 1;
    min-width: 0;
    margin-top: 0;
    gap: 6px;
}
.music-lane-controls .track-volume-control span {
    justify-content: flex-end;
    order: 2;
    width: 34px;
    flex: 0 0 34px;
    line-height: 1;
}
.music-lane-controls .track-volume-control input[type="range"] {
    flex: 1;
    min-width: 0;
    height: 10px;
}
.music-lane-track {
    position: relative;
    min-height: 32px;
}
.music-empty-hint {
    display: inline-flex;
    align-items: center;
    height: 100%;
    padding: 0 12px;
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    pointer-events: none;
}
.music-clip {
    position: absolute;
    top: 4px;
    height: 24px;
    min-width: 80px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(168, 85, 247, 0.32);
    background:
        linear-gradient(180deg, rgba(88, 28, 135, 0.82), rgba(59, 7, 100, 0.82));
    color: rgba(245, 243, 255, 0.92);
    overflow: hidden;
    cursor: grab;
    touch-action: none;
    box-shadow: 0 6px 14px rgba(76, 29, 149, 0.18);
}
.music-clip.is-dragging { cursor: grabbing; }
.music-clip.is-muted { opacity: 0.55; filter: grayscale(0.35); }
.music-clip.is-selected {
    border-color: rgba(96, 165, 250, 0.86);
    box-shadow:
        0 0 0 2px rgba(96, 165, 250, 0.18),
        0 8px 18px rgba(37, 99, 235, 0.22);
}
.music-clip-title {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    pointer-events: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.music-clip-title svg {
    flex-shrink: 0;
    width: 13px;
    height: 13px;
}
.music-clip-title .text-subtle {
    flex-shrink: 0;
    font-size: var(--text-2xs);
}
.music-waveform {
    position: absolute;
    inset: 5px 8px;
    opacity: 0.18;
    background: repeating-linear-gradient(
        to right,
        transparent 0,
        transparent 4px,
        rgba(245, 243, 255, 0.65) 4px,
        rgba(245, 243, 255, 0.65) 5px,
        transparent 6px,
        transparent 13px
    );
    mask-image: linear-gradient(to bottom, transparent 0%, #000 20%, #000 80%, transparent 100%);
    pointer-events: none;
}
.music-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 12px;
    background: transparent;
    cursor: ew-resize;
    touch-action: none;
    z-index: 2;
}
.music-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    width: 3px;
    height: 14px;
    margin-top: -7px;
    border-radius: var(--radius-full);
    background: rgba(245, 243, 255, 0.55);
}
.music-handle.start { left: -1px; }
.music-handle.start::before { left: 3px; }
.music-handle.end { right: -1px; }
.music-handle.end::before { right: 3px; }
.music-handle:hover::before { background: #F5F3FF; }

.srt-empty {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 38px;
    padding: 0 12px;
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
}
.srt-empty-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.srt-lane-track {
    overflow: hidden;
}
.srt-output-item {
    position: absolute;
    top: 6px;
    height: 26px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(34, 197, 94, 0.30);
    background: linear-gradient(180deg, rgba(20, 83, 45, 0.92), rgba(6, 32, 18, 0.95));
    color: #ECFDF5;
    box-shadow: 0 8px 18px rgba(6, 32, 18, 0.20);
    overflow: hidden;
}
.srt-output-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: max-content;
    font-size: var(--text-xs);
}
.srt-output-badge strong {
    font-size: var(--text-xs);
}
.srt-output-meta {
    min-width: 0;
    color: rgba(236, 253, 245, 0.8);
    font-size: var(--text-2xs);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
.srt-output-actions {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.srt-output-actions .btn {
    width: 26px;
    height: 26px;
}
.srt-lane-track .srt-segment-item {
    top: 6px;
    height: 26px;
    min-width: 76px;
    padding: 0 10px;
    border-radius: var(--radius-md);
    flex-direction: row;
    align-items: center;
    gap: 8px;
    background: rgba(20, 83, 45, 0.90);
    border-color: rgba(34, 197, 94, 0.24);
    color: #ECFDF5;
    box-shadow: 0 8px 18px rgba(6, 32, 18, 0.18);
}
.srt-lane-track .srt-segment-item:hover {
    border-color: rgba(74, 222, 128, 0.36);
    background: rgba(22, 101, 52, 0.94);
}
.srt-lane-track .srt-segment-item.is-selected,
.srt-lane-track .srt-segment-item.is-active {
    border-color: rgba(134, 239, 172, 0.48);
    box-shadow: 0 0 0 1px rgba(134, 239, 172, 0.20), 0 10px 24px rgba(6, 32, 18, 0.28);
}
.srt-lane-track .srt-segment-item .segment-index {
    background: rgba(236, 253, 245, 0.10);
    color: #F0FDF4;
}
.srt-lane-track .srt-segment-item .segment-text-inline {
    color: #F0FDF4;
}
.segment-track .segment-item {
    top: var(--segment-item-top, 6px);
    height: 28px;
    min-width: 0;
    padding: 0 10px;
    border-radius: var(--radius-md);
    flex-direction: row;
    align-items: center;
    gap: 8px;
    background: rgba(30, 41, 59, 0.92);
}
.subtitle-combined-track .segment-item {
    height: 32px;
    padding: 0 12px;
}
.subtitle-combined-track .segment-item.is-compact {
    padding: 0 3px;
    justify-content: center;
}
.subtitle-combined-track .segment-item.is-compact .segment-inline {
    flex: 0 1 auto;
    justify-content: center;
}
.subtitle-combined-track .segment-item.is-compact .segment-text-stack,
.subtitle-combined-track .segment-item.is-compact .segment-confidence-dot {
    display: none;
}
.subtitle-combined-track .segment-item.is-compact .segment-index {
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
}
.subtitle-combined-track .segment-item .segment-inline {
    align-items: center;
}
.subtitle-combined-track .segment-text-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}
.subtitle-combined-track .segment-translation-inline {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #BFDBFE;
    font-size: var(--text-2xs);
    line-height: 1.1;
}
.subtitle-combined-track .segment-text-inline {
    line-height: 1.1;
}
.segment-track .segment-item::before {
    display: none;
}
.segment-track .segment-item-top,
.segment-track .segment-body,
.segment-track .segment-meta,
.segment-track .segment-actions {
    display: none;
}
.segment-track .segment-label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}
.segment-track .segment-index {
    width: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    box-sizing: border-box;
    background: rgba(248, 250, 252, 0.08);
}
.segment-track .segment-time {
    font-size: var(--text-2xs);
}
.segment-track .segment-text {
    display: block;
    -webkit-line-clamp: 1;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.segment-track .segment-badge {
    margin-left: auto;
    flex-shrink: 0;
}
.segment-track .segment-handle::before {
    height: 28px;
    margin-top: -14px;
}
.segment-track .segment-handle.start::before { left: 4px; }
.segment-track .segment-handle.end::before { right: 4px; }
.segment-track .segment-item .segment-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
}
.segment-track .segment-item .segment-text-inline {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
    font-size: var(--text-xs);
}
.segment-track .segment-item .segment-badge-inline {
    flex-shrink: 0;
}
.segment-track .segment-item .segment-timing-inline {
    flex-shrink: 0;
    color: var(--color-text-subtle);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
}
.segment-track.is-freeform .segment-item {
    top: var(--segment-item-top, 6px);
    cursor: grab;
}
.segment-track.is-freeform .segment-item.is-dragging { cursor: grabbing; }
.segment-confidence-dot {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    background: var(--color-text-subtle);
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.10);
}
.segment-confidence-dot.conf-high {
    background: var(--color-success);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}
.segment-confidence-dot.conf-mid {
    background: var(--color-warning);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.14);
}
.segment-confidence-dot.conf-low {
    background: var(--color-error);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.14);
}

/* ── Caption overlay (on video preview) ──────────────────────────────── */
.caption-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none; /* let the video receive clicks; boxes opt back in */
    overflow: hidden;
}
.detect-region-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: none;
    overflow: hidden;
    pointer-events: none;
}
.detect-region-overlay.is-active {
    display: block;
    pointer-events: auto;
}
.detect-region-selection {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid var(--color-accent);
    border-radius: var(--radius-sm);
    box-shadow:
        0 0 0 9999px rgba(2, 4, 12, 0.58),
        inset 0 0 0 1px rgba(255, 255, 255, 0.48);
    cursor: move;
    outline: none;
    touch-action: none;
}
.detect-region-selection:focus-visible {
    box-shadow:
        0 0 0 9999px rgba(2, 4, 12, 0.58),
        inset 0 0 0 1px rgba(255, 255, 255, 0.48),
        0 0 0 3px rgba(225, 29, 72, 0.28);
}
.detect-region-selection.is-dragging {
    cursor: grabbing;
}
.detect-region-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid #f8fafc;
    border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.38);
    touch-action: none;
}
.detect-region-handle.n,
.detect-region-handle.s {
    left: 50%;
    transform: translateX(-50%);
    cursor: ns-resize;
}
.detect-region-handle.e,
.detect-region-handle.w {
    top: 50%;
    transform: translateY(-50%);
    cursor: ew-resize;
}
.detect-region-handle.n { top: -2px; }
.detect-region-handle.s { bottom: -2px; }
.detect-region-handle.e { right: -2px; }
.detect-region-handle.w { left: -2px; }
.detect-region-handle.ne,
.detect-region-handle.nw { top: -2px; }
.detect-region-handle.se,
.detect-region-handle.sw { bottom: -2px; }
.detect-region-handle.ne,
.detect-region-handle.se { right: -2px; cursor: nesw-resize; }
.detect-region-handle.nw,
.detect-region-handle.sw { left: -2px; cursor: nwse-resize; }
.detect-region-handle.ne,
.detect-region-handle.sw { cursor: nesw-resize; }
.detect-region-toolbar {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px;
    border: 1px solid rgba(248, 250, 252, 0.16);
    border-radius: var(--radius-md);
    background: rgba(7, 8, 20, 0.92);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
}
.preview-stage.is-fullscreen .detect-region-toolbar {
    right: 58px;
}
.detect-region-size {
    min-width: 64px;
    padding: 0 4px;
    color: #e2e8f0;
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    font-variant-numeric: tabular-nums;
    text-align: center;
    white-space: nowrap;
}
#btn-detect-region.is-active {
    border-color: rgba(225, 29, 72, 0.72);
    background: rgba(225, 29, 72, 0.16);
    color: #ffe4e6;
}
#btn-detect-region.is-stale {
    box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.72);
}
.caption-box {
    position: absolute;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    cursor: move;
    touch-action: none;
    border: 1.5px solid transparent;
    border-radius: 5px;      /* subtle rounding */
    overflow: visible;       /* allow resize handles to sit on the edge */
    /* background colour is set inline per-caption (the yellow fill) */
}
.caption-box .caption-text {
    display: inline-block;
    max-width: 100%;
    line-height: 1.2;
    /* Clean Vietnamese-capable face with graceful fallback. */
    font-family: var(--caption-font-family, 'Be Vietnam Pro', 'Avenir Next', 'Helvetica Neue', system-ui, sans-serif);
    letter-spacing: 0.01em;
    background: transparent; /* fill lives on .caption-box now */
    white-space: pre-wrap;
    word-break: break-word;
    outline: none;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}
.caption-box .cap-line {
    display: block;
}
.caption-box:hover { border-color: rgba(96, 165, 250, 0.45); }
.caption-box.is-selected {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px rgba(225, 29, 72, 0.35);
}
.caption-box .caption-text[contenteditable="true"] {
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.6);
}
.caption-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--color-accent);
    border: 2px solid #fff;
    border-radius: 50%;
    opacity: 0;
    cursor: nwse-resize;
    touch-action: none;
}
.caption-handle.r {
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    cursor: ew-resize;
}
.caption-handle.b {
    left: 50%;
    bottom: -8px;
    transform: translateX(-50%);
    cursor: ns-resize;
}
.caption-handle.br { right: -8px; bottom: -8px; }
.caption-box.is-selected .caption-handle { opacity: 1; }

/* ── Timeline ────────────────────────────────────────────────────────── */
.timeline {
    position: relative;
    width: 100%;
    height: 36px;
    background: var(--color-bg-elev-1);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: grab;
    user-select: none;
    overflow: visible;
    touch-action: none;
    box-shadow: var(--shadow-inset);
}
.timeline:active { cursor: grabbing; }
.timeline-track {
    position: absolute;
    top: 50%;
    left: var(--space-sm);
    right: var(--space-sm);
    height: 5px;
    background: var(--color-bg-elev-3);
    border-radius: var(--radius-full);
    transform: translateY(-50%);
}
.timeline-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--color-accent), #F43F5E);
    border-radius: var(--radius-full);
    transition: width 50ms linear;
    position: absolute;
    inset: 0;
    width: 0;
    box-shadow: 0 0 8px rgba(225, 29, 72, 0.30);
}
/* ── SRT preview ─────────────────────────────────────────────────────── */
.srt-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: var(--leading-snug);
}
.srt-entry {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-elev-1);
    transition: border-color var(--duration-fast) var(--ease-out);
}
.srt-entry:hover { border-color: var(--color-border-strong); }
.srt-entry-meta {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-2xs);
}
.srt-index { color: var(--color-accent); font-weight: var(--weight-semibold); }
.srt-time { color: var(--color-text-subtle); }
.srt-text { color: var(--color-text); white-space: pre-wrap; }

/* ── Help shortcuts list ─────────────────────────────────────────────── */
.shortcut-list { display: flex; flex-direction: column; gap: var(--space-sm); }
.shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--color-border);
}
.shortcut-row:last-child { border-bottom: 0; }
.shortcut-row span:first-child { color: var(--color-text-muted); font-size: var(--text-sm); }
.shortcut-keys { display: inline-flex; gap: 4px; }

/* ── Batch video list ─────────────────────────────────────────────────── */
.batch-list-wrapper {
    width: 100%;
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border);
}
.batch-list-wrapper .card-header {
    padding: 0 0 var(--space-sm);
    border-bottom: 0;
    background: transparent;
}
.batch-header h3 {
    letter-spacing: 0.01em;
}
.batch-header h3 [data-icon] {
    display: inline-flex;
    color: var(--color-accent);
}
.batch-header h3 svg { width: 16px; height: 16px; }
.batch-actions {
    display: flex;
    gap: var(--space-sm);
}
.batch-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0;
    min-height: 0;
    max-height: clamp(180px, calc(100vh - 600px), 420px);
    overflow-y: auto;
}
.batch-empty {
    display: flex;
    min-height: 112px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-lg) var(--space-md);
    color: var(--color-text-subtle);
    text-align: center;
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    background: rgba(7, 8, 20, 0.22);
}
.batch-empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    color: var(--color-accent);
    background: var(--color-accent-soft);
}
.batch-empty-icon svg {
    width: 20px;
    height: 20px;
}
.batch-empty strong {
    color: var(--color-text);
    font-size: var(--text-sm);
}
.batch-empty span {
    max-width: 250px;
    font-size: var(--text-xs);
    line-height: var(--leading-snug);
}
.batch-item {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: var(--space-md);
    row-gap: 6px;
    padding: 10px 12px;
    background: rgba(7, 8, 20, 0.36);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition:
        border-color var(--duration-fast) var(--ease-out),
        background var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out),
        transform var(--duration-fast) var(--ease-out);
}
.batch-item:hover {
    border-color: var(--color-border-strong);
    background: var(--color-bg-elev-3);
    transform: translateY(-1px);
    box-shadow: var(--shadow-xs);
}
.batch-item.is-active {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-glow-accent);
}
.batch-item.status-row-uploading,
.batch-item.status-row-downloading {
    border-color: rgba(59, 130, 246, 0.24);
}
.batch-item.status-row-detecting,
.batch-item.status-row-uploaded {
    border-color: rgba(245, 158, 11, 0.22);
}
.batch-item.status-row-ready {
    border-color: rgba(34, 197, 94, 0.22);
}
.batch-item.status-row-error {
    border-color: rgba(239, 68, 68, 0.30);
}
.batch-item-thumb {
    position: relative;
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: center;
    width: 64px;
    height: 44px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-subtle);
    background:
        linear-gradient(135deg, rgba(248, 250, 252, 0.06), transparent),
        var(--color-bg-elev-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}
.batch-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.batch-item-status {
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    flex-shrink: 0;
    font-weight: var(--weight-semibold);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.28);
}
.batch-item-status.status-pending { background: var(--color-bg-elev-3); color: var(--color-text-subtle); }
.batch-item-status.status-uploading { background: var(--color-info-soft); color: var(--color-info); }
.batch-item-status.status-downloading { background: var(--color-info-soft); color: var(--color-info); }
.batch-item-status.status-uploaded { background: var(--color-warning-soft); color: var(--color-warning); }
.batch-item-status.status-detecting { background: var(--color-warning-soft); color: var(--color-warning); }
.batch-item-status.status-ready { background: var(--color-success-soft); color: var(--color-success); }
.batch-item-status.status-error { background: var(--color-error-soft); color: var(--color-error); }
.batch-item-info {
    grid-column: 2;
    grid-row: 1 / span 2;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}
.batch-item-topline {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}
.batch-item-name {
    flex: 1;
    min-width: 0;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.batch-item-meta {
    font-size: var(--text-xs);
    color: var(--color-text-subtle);
    line-height: 1.25;
}
.batch-mode-toggle {
    display: inline-flex;
    width: fit-content;
    max-width: 100%;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: rgba(15, 23, 42, 0.52);
    box-shadow: var(--shadow-inset);
}
.batch-mode-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 24px;
    min-width: 58px;
    padding: 0 7px;
    border: 0;
    border-radius: calc(var(--radius-sm) - 2px);
    background: transparent;
    color: var(--color-text-muted);
    font-size: var(--text-2xs);
    font-weight: var(--weight-semibold);
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: none !important;
    animation: none !important;
    -webkit-tap-highlight-color: transparent;
}
.batch-mode-btn *,
.batch-mode-btn.is-active,
.batch-mode-btn:hover,
.batch-mode-btn:active,
.batch-mode-btn:focus {
    transition: none !important;
    animation: none !important;
}
.batch-mode-btn svg {
    width: 12px;
    height: 12px;
    stroke-width: 2.4;
}
.batch-mode-btn:hover:not(:disabled) {
    color: var(--color-text-muted);
    background: transparent;
}
.batch-mode-btn:active {
    transform: none;
}
.batch-mode-btn.is-active {
    color: #06111f;
    background: var(--color-accent);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.24);
}
.batch-mode-btn.is-active:hover,
.batch-mode-btn.is-active:active,
.batch-mode-btn.is-active:focus {
    color: #06111f;
    background: var(--color-accent);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.24);
}
.batch-mode-btn:disabled {
    cursor: not-allowed;
    opacity: 0.56;
}
.batch-status-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: 52px;
    height: 24px;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    font-size: var(--text-2xs);
    font-weight: var(--weight-semibold);
    line-height: 1;
    text-align: center;
    white-space: nowrap;
}
.batch-status-label.status-pending { color: var(--color-text-subtle); background: var(--color-bg-elev-3); }
.batch-status-label.status-uploading { color: var(--color-info); background: var(--color-info-soft); }
.batch-status-label.status-downloading { color: var(--color-info); background: var(--color-info-soft); }
.batch-status-label.status-uploaded { color: var(--color-warning); background: var(--color-warning-soft); }
.batch-status-label.status-detecting { color: var(--color-warning); background: var(--color-warning-soft); }
.batch-status-label.status-ready { color: var(--color-success); background: var(--color-success-soft); }
.batch-status-label.status-error { color: var(--color-error); background: var(--color-error-soft); }
.batch-item-foot {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}
.batch-item-foot:empty {
    display: none;
}
.batch-item-progress {
    flex: 1;
    min-width: 120px;
    height: 4px;
    background: var(--color-bg-elev-3);
    border-radius: var(--radius-full);
    overflow: hidden;
    box-shadow: var(--shadow-inset);
}
.batch-item-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--color-accent), #F43F5E, var(--color-accent));
    background-size: 200% 100%;
    border-radius: var(--radius-full);
    transition: width 150ms var(--ease-out);
    animation: gradientShift 2s ease infinite;
}
.batch-item-progress-bar.is-indeterminate {
    animation: gradientShift 1.2s linear infinite, pulse 1.4s ease-in-out infinite;
}
.batch-item-ranges {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
}
.batch-item-tts-state {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    font-size: var(--text-xs);
    white-space: nowrap;
    color: var(--color-success);
}
.batch-item-actions {
    grid-column: 3;
    grid-row: 1 / span 2;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    justify-content: flex-end;
    align-self: center;
    min-width: max-content;
}

@media (max-width: 640px) {
    .batch-list-wrapper .card-header {
        align-items: stretch;
        flex-direction: column;
    }
    .batch-actions {
        width: 100%;
    }
    .batch-actions .btn {
        flex: 1;
    }
    .batch-item {
        grid-template-columns: 54px minmax(0, 1fr);
    }
    .batch-item-thumb {
        grid-column: 1;
        grid-row: 1;
        width: 54px;
        height: 42px;
    }
    .batch-item-info {
        grid-column: 2;
        grid-row: 1;
    }
    .batch-item-actions {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-content: flex-start;
        padding-left: 62px;
        flex-wrap: wrap;
    }
    .batch-item-info {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }
    .batch-item-topline,
    .batch-item-foot {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }
    .batch-mode-toggle {
        width: 100%;
    }
    .batch-mode-btn {
        flex: 1;
        min-width: 0;
    }
    .batch-item-progress {
        width: 100%;
        min-width: 0;
    }
}
