/* ============ Reset & Base ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

/* ============ Focus Ring ============ */
*:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
    border-radius: 4px;
}

/* ============ Login ============ */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 48px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
    max-width: 400px;
    width: 90%;
    animation: scaleIn 0.4s ease;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.login-box h1 {
    color: #667eea;
    margin-bottom: 8px;
}

.login-box p {
    color: #666;
    margin-bottom: 24px;
}

.login-input-wrap {
    margin-bottom: 16px;
}

.login-box input {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: border-color 0.2s;
}

.login-box input:focus {
    outline: none;
    border-color: #667eea;
}

.login-box input.has-error {
    border-color: #e53e3e;
}

.login-password {
    margin-top: 10px;
}

.login-password[hidden] {
    display: none;
}

.login-error {
    display: block;
    min-height: 20px;
    color: #e53e3e;
    font-size: 0.85rem;
    margin-top: 4px;
    text-align: left;
}

/* ============ Header ============ */
.header {
    background: white;
    padding: 16px 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 1.5rem;
    color: #667eea;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

#user-name {
    color: #666;
    font-size: 0.9rem;
}

/* ============ Workflow Steps ============ */
.workflow-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 16px 24px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
}

.workflow-step {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #9ca3af;
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.3s;
}

.workflow-step .step-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    transition: all 0.3s;
}

.workflow-step .step-icon svg {
    width: 16px;
    height: 16px;
}

.workflow-step.active {
    color: #667eea;
}

.workflow-step.active .step-icon {
    background: #667eea;
    color: white;
}

.workflow-step.completed {
    color: #10b981;
}

.workflow-step.completed .step-icon {
    background: #10b981;
    color: white;
}

.workflow-connector {
    width: 40px;
    height: 2px;
    background: #e5e7eb;
    margin: 0 8px;
    transition: background 0.3s;
}

.workflow-connector.active {
    background: #667eea;
}

.workflow-connector.completed {
    background: #10b981;
}

/* ============ Main ============ */
.main {
    max-width: 1400px;
    margin: 24px auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ============ Card ============ */
.card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    animation: fadeInUp 0.4s ease forwards;
    opacity: 0;
}

.card-full {
    animation-delay: 0s;
}

.card-settings {
    animation-delay: 0.1s;
    overflow-y: auto;
}

.card-results {
    animation-delay: 0.2s;
    display: flex;
    flex-direction: column;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.card h2 {
    font-size: 1.2rem;
    color: #333;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card h2 svg {
    width: 20px;
    height: 20px;
    color: #667eea;
}

.section-copy {
    margin-bottom: 20px;
    color: #5b6474;
    font-size: 0.95rem;
}

/* ============ Two-Column Grid ============ */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* ============ Buttons ============ */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

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

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #5a6fd6;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-outline {
    background: white;
    border: 2px solid #e0e0e0;
    color: #333;
}

.btn-outline:hover:not(:disabled) {
    border-color: #667eea;
    color: #667eea;
}

.btn-danger {
    background: #e53e3e;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #c53030;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-sm svg {
    width: 14px;
    height: 14px;
}

.btn-lg {
    padding: 14px 32px;
    font-size: 16px;
}

/* Loading state */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============ Toolbar ============ */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* ============ Input ============ */
.input-field {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.input-field:focus {
    outline: none;
    border-color: #667eea;
}

.select-inline {
    min-width: 200px;
    padding: 6px 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
}

/* ============ Upload Zone ============ */
.audio-top-row {
    display: flex;
    gap: 16px;
    align-items: stretch;
    margin-bottom: 16px;
}

.upload-zone {
    flex: 1;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
}

.upload-zone:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.03);
}

.upload-zone.dragover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.08);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.upload-zone-icon {
    width: 40px !important;
    height: 40px !important;
    color: #9ca3af;
    transition: color 0.2s;
}

.upload-zone:hover .upload-zone-icon,
.upload-zone.dragover .upload-zone-icon {
    color: #667eea;
}

.upload-zone-text {
    color: #6b7280;
    font-size: 0.95rem;
    font-weight: 500;
}

.upload-zone-hint {
    color: #9ca3af;
    font-size: 0.8rem;
}

.upload-progress-track {
    width: 100%;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.upload-progress-bar {
    height: 100%;
    background: #667eea;
    border-radius: 2px;
    width: 0%;
    transition: width 0.2s;
}

.record-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 100px;
}

.btn-record {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 0.8rem;
    padding: 0;
}

.btn-record svg {
    width: 24px;
    height: 24px;
}

.btn-record.recording {
    border-color: #e53e3e;
    color: #e53e3e;
    animation: recordPulse 1.5s ease-in-out infinite;
}

@keyframes recordPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.3); }
    50% { box-shadow: 0 0 0 12px rgba(229, 62, 62, 0); }
}

.record-timer {
    font-family: monospace;
    color: #e53e3e;
    font-weight: 600;
    font-size: 0.9rem;
}

/* ============ Audio Table ============ */
.audio-table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
}

th {
    font-weight: 600;
    color: #666;
    font-size: 0.85rem;
    text-transform: uppercase;
}

tr:hover {
    background: #f9f9f9;
}

.audio-name {
    cursor: pointer;
    border-bottom: 1px dashed #999;
    transition: color 0.2s;
}

.audio-name:hover {
    color: #667eea;
}

.audio-preview-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: #f3f4f6;
    color: #6b7280;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-right: 8px;
    vertical-align: middle;
}

.audio-preview-btn:hover {
    background: #667eea;
    color: white;
}

.audio-preview-btn svg {
    width: 14px;
    height: 14px;
}

/* ============ Dictionary ============ */
.dict-add-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.dict-add-row .input-field {
    flex: 1;
    min-width: 140px;
}

.dict-table-wrap {
    max-height: 250px;
    overflow-y: auto;
    border-radius: 8px;
}

.dict-table {
    width: 100%;
    border-collapse: collapse;
}

.dict-table th {
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

.dict-edit-input {
    padding: 4px 8px;
    border: 2px solid #667eea;
    border-radius: 6px;
    font-size: 14px;
    width: 100%;
}

.setting-hint {
    display: block;
    font-size: 0.78rem;
    color: #9ca3af;
    margin-top: 4px;
}

/* ============ Settings ============ */
.settings-essential {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 12px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.setting-item label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: #555;
    font-size: 0.9rem;
}

.setting-item select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    transition: border-color 0.2s;
}

.setting-item select:focus {
    outline: none;
    border-color: #667eea;
}

/* Advanced Settings Toggle */
.advanced-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: #6b7280;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 0;
    transition: color 0.2s;
}

.advanced-toggle:hover {
    color: #667eea;
}

.advanced-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.3s;
}

.advanced-toggle.open svg {
    transform: rotate(180deg);
}

/* Collapsible */
.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0;
}

.collapsible-content.open {
    max-height: 600px;
    padding: 12px 0;
}

/* ============ Run Mode Cards ============ */
.run-mode-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 20px;
}

.mode-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px;
    border-radius: 14px;
    border: 1px solid #e5e7eb;
    transition: box-shadow 0.2s;
}

.mode-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

.mode-card-file {
    background: linear-gradient(180deg, #eef4ff 0%, #ffffff 68%);
    border-color: #c7d2fe;
}

.mode-card-live {
    background: linear-gradient(180deg, #fff7ed 0%, #ffffff 68%);
    border-color: #fed7aa;
}

.mode-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.mode-card h3 {
    margin: 4px 0 0;
    font-size: 1rem;
    color: #1f2937;
}

.mode-eyebrow {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: #667eea;
}

.mode-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 28px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(102, 126, 234, 0.12);
    color: #4c63d2;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

.mode-badge svg {
    width: 12px;
    height: 12px;
}

.mode-badge-live {
    background: rgba(245, 158, 11, 0.15);
    color: #b45309;
}

.mode-description {
    color: #4b5563;
    font-size: 0.88rem;
}

.mode-summary {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.mode-summary-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #64748b;
    text-transform: uppercase;
}

.mode-summary-value {
    font-size: 0.95rem;
    color: #1f2937;
}

.mode-summary-value.is-empty {
    color: #94a3b8;
}

.mode-hint {
    font-size: 0.82rem;
    color: #6b7280;
}

.mode-btn-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mode-start-btn {
    justify-content: center;
    width: 100%;
}

.live-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: normal;
    cursor: pointer;
}

.checkbox-group.disabled {
    opacity: 0.5;
}

.checkbox-group.disabled label {
    cursor: not-allowed;
}

/* ============ Recording (legacy dot removed, using btn-record now) ============ */
.record-dot {
    display: none;
}

/* ============ Results ============ */
.result-container {
    min-height: 200px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    padding: 16px;
    background: #fafafa;
    border-radius: 8px;
    flex: 1;
}

.placeholder {
    color: #999;
    text-align: center;
    padding: 40px;
}

/* ============ Empty State ============ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    gap: 8px;
}

.empty-state-icon {
    width: 48px !important;
    height: 48px !important;
    color: #d1d5db;
    margin-bottom: 8px;
}

.empty-state-icon.spinning {
    animation: spin 1.5s linear infinite;
}

.empty-state-text {
    color: #6b7280;
    font-size: 1rem;
    font-weight: 500;
}

.empty-state-sub {
    color: #9ca3af;
    font-size: 0.85rem;
}

/* ============ Segments ============ */
.segment {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

/* Only animate newly added segments */
.segment-new {
    animation: segmentIn 0.3s ease;
}

@keyframes segmentIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.speaker-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: white;
    text-transform: uppercase;
}

.speaker-icon.unknown { background: #94a3b8; }
.speaker-icon.speaker-0 { background: #3b82f6; }
.speaker-icon.speaker-1 { background: #10b981; }
.speaker-icon.speaker-2 { background: #f59e0b; }
.speaker-icon.speaker-3 { background: #ef4444; }
.speaker-icon.speaker-4 { background: #8b5cf6; }
.speaker-icon.speaker-5 { background: #ec4899; }

.speaker-icon.known {
    background: #059669;
    border: 2px solid #047857;
}

.speaker-icon.partial {
    background: #f59e0b;
    border: 2px solid #d97706;
}

.segment-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.segment-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 4px;
}

.segment-speaker {
    font-weight: 600;
    color: #667eea;
}

.segment-speaker.known { color: #059669; }
.segment-speaker.partial { color: #b45309; }

.partial-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.7rem;
    font-weight: 600;
    vertical-align: middle;
}

.backfilled-icon {
    margin-left: 4px;
    font-size: 0.85em;
    color: #f59e0b;
    cursor: help;
}

.segment-time {
    font-family: monospace;
}

.segment-text {
    color: #333;
}

.segment-debug {
    margin-top: 10px;
    border: 1px solid #dbe4ee;
    border-radius: 10px;
    background: #f8fafc;
    overflow: hidden;
}

.segment-debug summary {
    cursor: pointer;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 700;
    color: #475569;
    list-style: none;
    user-select: none;
}

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

.segment-debug[open] summary {
    border-bottom: 1px solid #dbe4ee;
    background: #f1f5f9;
}

.segment-debug-body {
    display: grid;
    gap: 10px;
    padding: 12px;
}

.segment-debug-item {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
}

.segment-debug-title {
    padding: 8px 10px;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
    color: #64748b;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.segment-debug-pre {
    margin: 0;
    padding: 10px 12px;
    color: #1f2937;
    font-size: 0.8rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    overflow: auto;
    max-height: 240px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.segment.partial {
    border: 1px dashed #fcd34d;
    background: #fffbeb;
}

.segment-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: auto;
    padding-top: 8px;
}

.segment-actions .btn {
    padding: 4px 10px;
    font-size: 0.75rem;
}

/* ============ Profile Section ============ */
.profile-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

.profile-section h3 {
    font-size: 0.95rem;
    color: #374151;
}

.collapsible-header {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
    padding: 8px 0;
    transition: color 0.2s;
}

.collapsible-header:hover {
    color: #667eea;
}

.collapsible-header svg {
    width: 16px;
    height: 16px;
}

.collapse-chevron {
    margin-left: auto;
    transition: transform 0.3s;
}

.collapse-chevron.open {
    transform: rotate(180deg);
}

.profile-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.profile-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f3f4f6;
    border-radius: 20px;
    font-size: 0.85rem;
}

.profile-item .speaker-icon {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
}

.profile-item .profile-name {
    font-weight: 500;
}

.profile-item .profile-count {
    color: #6b7280;
    font-size: 0.75rem;
}

.profile-item .btn-remove {
    padding: 2px 6px;
    font-size: 0.7rem;
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    transition: color 0.2s;
}

.profile-item .btn-remove:hover {
    color: #ef4444;
}

/* ============ Live Status ============ */
.live-status {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 0.85rem;
    font-weight: 600;
}

.live-status.pending { background: #fef3c7; color: #92400e; }
.live-status.active { background: #dcfce7; color: #166534; }
.live-status.error { background: #fee2e2; color: #991b1b; }

/* ============ Status Badge ============ */
.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-badge.publishing {
    background: #fef3c7;
    color: #92400e;
    animation: statusPulse 2s ease-in-out infinite;
}

.status-badge.finished { background: #d1fae5; color: #065f46; }
.status-badge.error { background: #fee2e2; color: #991b1b; }

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ============ Audio Player Bar ============ */
.audio-player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 200;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.audio-player-bar audio {
    flex: 1;
    height: 36px;
    max-width: 600px;
}

.player-close-btn {
    padding: 6px;
}

.player-close-btn svg {
    width: 16px;
    height: 16px;
}

.player-filename {
    font-size: 0.85rem;
    color: #6b7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* ============ Toast ============ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    border-left: 4px solid #667eea;
    pointer-events: auto;
    animation: toastIn 0.3s ease;
    max-width: 100%;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

.toast-success { border-left-color: #10b981; }
.toast-error { border-left-color: #e53e3e; }
.toast-info { border-left-color: #667eea; }

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.toast-success .toast-icon { color: #10b981; }
.toast-error .toast-icon { color: #e53e3e; }
.toast-info .toast-icon { color: #667eea; }

.toast-message {
    flex: 1;
    font-size: 0.9rem;
    color: #333;
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 2px;
    transition: color 0.2s;
}

.toast-close:hover {
    color: #333;
}

.toast-close svg {
    width: 16px;
    height: 16px;
}

/* ============ Modal ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    overscroll-behavior: contain;
}

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

.modal-box {
    background: white;
    border-radius: 16px;
    padding: 28px;
    max-width: 440px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-box h3 {
    font-size: 1.1rem;
    color: #1f2937;
    margin-bottom: 16px;
}

.modal-box .modal-text {
    color: #4b5563;
    font-size: 0.95rem;
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-box .modal-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.modal-box .modal-input:focus {
    outline: none;
    border-color: #667eea;
}

.modal-box.modal-box-report {
    width: min(520px, 94vw);
}

.modal-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

.modal-textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
    min-height: 96px;
    margin-bottom: 8px;
    transition: border-color 0.2s;
}

.modal-textarea:focus {
    outline: none;
    border-color: #667eea;
}

.report-split-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin: 0 0 12px;
}

.report-split-option {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.7rem;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    background: #f8fafc;
    font-size: 0.85rem;
    color: #334155;
    cursor: pointer;
    user-select: none;
}

.report-split-option:has(input:checked) {
    border-color: #667eea;
    background: #eef2ff;
    color: #3730a3;
    font-weight: 600;
}

.report-split-option input {
    margin: 0;
    accent-color: #667eea;
}

.modal-report-preview {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.modal-report-meta {
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 6px;
}

.modal-report-text {
    font-size: 0.95rem;
    color: #1f2937;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

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

.modal-box.modal-box-debug {
    width: min(1100px, 94vw);
    max-width: 1100px;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    padding: 24px;
}

.modal-box.modal-box-debug #modal-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    margin-bottom: 16px;
    overscroll-behavior: contain;
}

.modal-debug-shell {
    height: auto;
    min-height: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-debug-context {
    color: #64748b;
    font-size: 0.82rem;
    line-height: 1.4;
}

.modal-box.modal-box-debug .segment-debug-body {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 12px;
    padding: 0;
    overflow: visible;
    align-content: start;
}

.modal-box.modal-box-debug .segment-debug-pre {
    max-height: none;
    overflow: visible;
}

.segment-flow {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 2px 0;
}

.segment-flow-step {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 16px;
    border: 1px solid #dbe4ee;
    border-radius: 14px;
    background: #f8fbff;
}

.segment-flow-badge {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.segment-flow-meta {
    color: #64748b;
    font-size: 0.8rem;
    line-height: 1.4;
}

.segment-flow-value {
    margin: 0;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    color: #0f172a;
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    overflow: visible;
}

.segment-flow-arrow {
    align-self: center;
    color: #94a3b8;
    font-size: 1.35rem;
    line-height: 1;
}

html.modal-open,
body.modal-open {
    overflow: hidden;
    overscroll-behavior: none;
}

/* ============ Responsive ============ */
@media (max-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr;
    }

    .result-container {
        max-height: 500px;
    }
}

@media (max-width: 768px) {
    .main {
        padding: 0 16px;
    }

    .card {
        padding: 16px;
    }

    .header {
        padding: 12px 16px;
    }

    .header h1 {
        font-size: 1.2rem;
    }

    /* Workflow steps compact */
    .workflow-steps {
        padding: 12px 16px;
    }

    .workflow-step span {
        display: none;
    }

    .workflow-connector {
        width: 24px;
    }

    /* Upload zone */
    .audio-top-row {
        flex-direction: column;
    }

    .upload-zone {
        padding: 16px;
    }

    .btn-record {
        width: 64px;
        height: 64px;
    }

    /* Settings */
    .settings-essential {
        grid-template-columns: 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    /* Mode cards */
    .mode-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .live-actions {
        align-items: stretch;
    }

    .live-actions .btn {
        justify-content: center;
    }

    /* Audio table -> cards */
    table, thead, tbody, th, td, tr {
        display: block;
    }

    thead {
        display: none;
    }

    tr {
        margin-bottom: 12px;
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        padding: 12px;
        background: white;
    }

    td {
        padding: 4px 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #666;
        font-size: 0.8rem;
        text-transform: uppercase;
        margin-right: 12px;
    }

    td:last-child {
        justify-content: flex-end;
        gap: 8px;
        padding-top: 8px;
        margin-top: 4px;
        border-top: 1px solid #f0f0f0;
    }

    /* Toast */
    .toast-container {
        left: 12px;
        right: 12px;
        max-width: none;
    }

    /* Modal */
    .modal-box {
        width: calc(100% - 32px);
    }

    .modal-box.modal-box-debug {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 24px);
        padding: 18px;
    }

    .modal-box.modal-box-debug .segment-debug-body {
        grid-template-columns: 1fr;
    }

    .segment-flow-step {
        padding: 12px 14px;
    }

    /* Audio player bar */
    .audio-player-bar {
        padding: 8px 12px;
        flex-wrap: wrap;
    }

    .audio-player-bar audio {
        width: 100%;
        order: 2;
    }

    .player-filename {
        max-width: none;
        order: 1;
    }

    /* Touch targets */
    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 36px;
    }
}

/* ============ 処理方式 (リアルタイム型 / ファイル型) ============ */
.mode-select-item {
    margin-bottom: 12px;
}

.mode-select-item label {
    font-size: 0.85rem;
}

.setting-item.is-disabled label,
.setting-item.is-disabled select {
    opacity: 0.5;
}

.setting-item.is-disabled select {
    cursor: not-allowed;
    background: #f3f4f6;
}

.setting-item .file-mode-hint {
    color: #b45309;
}

/* ============ ジョブ一覧 (ファイル型 / リアルタイム型) ============ */
.file-jobs-section .mode-hint {
    margin: 4px 0 10px;
}

.file-jobs-count {
    font-size: 0.8rem;
    color: #6b7280;
    font-weight: 500;
    margin-left: 6px;
}

.file-running-progress-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    width: 100%;
    margin: 0;
}

.file-running-progress-grid.is-single {
    grid-template-columns: minmax(0, 1fr);
}

.file-job-progress-card {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
    padding: 14px;
    min-width: 0;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.file-job-progress-head {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.file-job-progress-icon {
    width: 22px !important;
    height: 22px !important;
    color: #667eea;
}

.file-job-progress-icon.spinning {
    animation: spin 1.5s linear infinite;
}

.file-job-progress-title {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-job-progress-title strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #111827;
    font-size: 0.95rem;
}

.file-job-progress-title span {
    color: #6b7280;
    font-size: 0.78rem;
    line-height: 1.35;
}

.file-job-progress-code {
    margin-top: 10px;
    min-height: 24px;
}

.file-job-progress-code .job-code-btn {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-progress-card {
    justify-content: flex-start;
    margin: 12px 0 8px;
}

.file-progress-card .progress-track {
    width: min(240px, 100%);
    flex: 1;
}

.file-job-progress-note {
    color: #6b7280;
    font-size: 0.8rem;
    line-height: 1.45;
    margin: 0 0 12px;
    min-height: 2.3em;
}

.file-job-progress-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.file-jobs-table th,
.file-jobs-table td {
    padding: 8px 10px;
    font-size: 0.85rem;
    white-space: nowrap;
    vertical-align: middle;
}

.file-jobs-table td[data-label="操作"] {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.job-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.78rem;
}

.job-code-btn {
    border: none;
    background: #f3f4f6;
    border-radius: 6px;
    padding: 3px 8px;
    cursor: pointer;
    color: #374151;
    transition: background 0.2s;
}

.job-code-btn:hover {
    background: #e0e7ff;
    color: #3730a3;
}

.file-jobs-empty {
    color: #9ca3af;
    font-size: 0.85rem;
    padding: 6px 0;
}

.file-jobs-error {
    color: #991b1b;
    font-size: 0.75rem;
    max-width: 260px;
    white-space: normal;
    margin-top: 4px;
}

.progress-track {
    width: 90px;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
}

.progress-fill {
    height: 100%;
    background: #667eea;
    transition: width 0.3s;
}

/* 推定進捗は縞模様で「実測ではない」ことを示す */
.progress-fill.is-estimated {
    background-image: repeating-linear-gradient(
        -45deg,
        #667eea 0 6px,
        #8b9cf0 6px 12px
    );
}

.file-jobs-note {
    color: #6b7280;
    font-size: 0.75rem;
    margin-top: 4px;
    white-space: normal;
    max-width: 220px;
}

.file-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 10px 0;
    color: #6b7280;
    font-size: 0.85rem;
}

.file-progress .progress-track {
    width: 180px;
}

/* ジョブ一覧の状態バッジ */
.status-badge.uploading,
.status-badge.queued {
    background: #e0e7ff;
    color: #3730a3;
    animation: statusPulse 2s ease-in-out infinite;
}

.status-badge.processing {
    background: #fef3c7;
    color: #92400e;
    animation: statusPulse 2s ease-in-out infinite;
}

.status-badge.stopped {
    background: #e5e7eb;
    color: #374151;
}

@media (max-width: 900px) {
    .file-running-progress-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}
