/* ============================================================
   Design System
   ============================================================ */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222533;
    --bg-card-hover: #2a2e3f;
    --border: #333750;
    --border-focus: #5b6abf;

    --text-primary: #e8eaf0;
    --text-secondary: #9ca3bf;
    --text-muted: #6b7294;

    --accent: #5b6abf;
    --accent-hover: #6e7ed4;
    --accent-light: rgba(91, 106, 191, 0.15);

    --success: #34d399;
    --success-bg: rgba(52, 211, 153, 0.1);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, 0.1);
    --error: #f87171;
    --error-bg: rgba(248, 113, 113, 0.1);

    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', Consolas, monospace;

    --sp-xs: 4px;
    --sp-sm: 8px;
    --sp-md: 16px;
    --sp-lg: 24px;
    --sp-xl: 32px;
    --sp-2xl: 48px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);

    --max-width: 1100px;
    --nav-height: 64px;
}

/* ============================================================
   Reset & Base
   ============================================================ */

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ============================================================
   Navigation
   ============================================================ */

#nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--nav-height);
    padding: 0 var(--sp-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

#nav-steps {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
}

.nav-step {
    display: flex;
    align-items: center;
    gap: var(--sp-xs);
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-step:hover { border-color: var(--text-secondary); color: var(--text-secondary); }
.nav-step.active { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.nav-step.completed { border-color: var(--success); color: var(--success); }

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--border);
    font-size: 12px;
    font-weight: 700;
}

.nav-step.active .step-num { background: var(--accent); color: #fff; }
.nav-step.completed .step-num { background: var(--success); color: #fff; }

.nav-arrow { color: var(--text-muted); font-size: 14px; }

/* ============================================================
   Views
   ============================================================ */

.view {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--sp-xl) var(--sp-lg);
}

.view.hidden { display: none; }

.view h2 {
    font-size: 20px;
    margin-bottom: var(--sp-md);
    color: var(--text-primary);
}

.input-section, .settings-section {
    margin-bottom: var(--sp-2xl);
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-sm);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}
.btn-secondary:hover:not(:disabled) { background: var(--accent-light); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--text-secondary); color: var(--text-primary); }

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

/* ============================================================
   Form Elements
   ============================================================ */

.input-group { margin-bottom: var(--sp-lg); }

.input-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: var(--sp-xs);
}

.input-row {
    display: flex;
    gap: var(--sp-sm);
}

.input-row input[type="text"] {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.input-row input[type="text"]:focus { border-color: var(--border-focus); }
.input-row input[type="text"]::placeholder { color: var(--text-muted); }

/* ============================================================
   Cards
   ============================================================ */

.video-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--sp-lg);
    margin: var(--sp-md) 0;
    display: flex;
    gap: var(--sp-lg);
    align-items: center;
}

.video-card.hidden { display: none; }

.video-card img {
    width: 160px;
    height: 90px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.video-card .video-info h3 {
    font-size: 15px;
    margin-bottom: var(--sp-xs);
}

.video-card .video-info p {
    font-size: 13px;
    color: var(--text-secondary);
}

.video-card .video-status {
    margin-left: auto;
    color: var(--success);
    font-size: 20px;
}

/* ============================================================
   Upload Zone
   ============================================================ */

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-2xl) var(--sp-lg);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.upload-icon { font-size: 40px; margin-bottom: var(--sp-sm); }

.upload-zone p { color: var(--text-secondary); font-size: 14px; }
.upload-hint { font-size: 12px !important; color: var(--text-muted) !important; }
.upload-formats { font-size: 11px !important; color: var(--text-muted) !important; margin-top: var(--sp-sm); }

/* ============================================================
   Progress Bar
   ============================================================ */

.upload-file-info {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: var(--sp-sm);
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    width: 0;
    transition: width 0.3s ease;
}

.progress-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--sp-xs);
    font-size: 13px;
    color: var(--text-secondary);
}

/* ============================================================
   Messages
   ============================================================ */

.error-msg {
    color: var(--error);
    font-size: 13px;
    margin-top: var(--sp-sm);
    padding: var(--sp-sm) var(--sp-md);
    background: var(--error-bg);
    border-radius: var(--radius-sm);
}

.warning-msg {
    color: var(--warning);
    font-size: 13px;
    margin-top: var(--sp-sm);
    padding: var(--sp-sm) var(--sp-md);
    background: var(--warning-bg);
    border-radius: var(--radius-sm);
}

.hidden { display: none !important; }

.hint { color: var(--text-muted); font-size: 13px; margin-bottom: var(--sp-md); }

/* ============================================================
   Badges
   ============================================================ */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.badge-info { background: var(--accent-light); color: var(--accent); }
.badge-cost { background: var(--success-bg); color: var(--success); }
.badge-time { background: var(--warning-bg); color: var(--warning); }
.badge-input { background: rgba(160,174,192,0.15); color: var(--text-secondary); }
.badge-multi { background: var(--warning-bg); color: var(--warning); }

/* ============================================================
   Divider
   ============================================================ */

.divider {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
    margin: var(--sp-xl) 0;
    color: var(--text-muted);
    font-size: 13px;
}

.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ============================================================
   Template Grid
   ============================================================ */

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--sp-md);
    margin: var(--sp-md) 0;
}

.template-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--sp-lg);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.template-card:hover { background: var(--bg-card-hover); border-color: var(--text-muted); }
.template-card.selected { border-color: var(--accent); background: var(--accent-light); }
.template-card.disabled { opacity: 0.4; cursor: not-allowed; }

.template-card .tc-header {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-sm);
    margin-bottom: var(--sp-sm);
}

.template-card .tc-checkbox {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.template-card .tc-name {
    font-size: 15px;
    font-weight: 600;
}

.template-card .tc-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: var(--sp-sm);
    line-height: 1.5;
}

.template-card .tc-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-xs);
}

/* ============================================================
   Settings Toolbar & Estimate Bar
   ============================================================ */

.settings-toolbar {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
    margin-bottom: var(--sp-lg);
    flex-wrap: wrap;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    margin-left: auto;
}

.toggle-label input[type="checkbox"] { accent-color: var(--accent); }

.estimate-bar {
    display: flex;
    gap: var(--sp-xl);
    padding: var(--sp-md) var(--sp-lg);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-secondary);
}

.estimate-bar strong { color: var(--text-primary); }

/* ============================================================
   View Actions
   ============================================================ */

.view-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-md);
    margin-top: var(--sp-xl);
    padding-top: var(--sp-lg);
    border-top: 1px solid var(--border);
}

/* ============================================================
   Progress Cards (Analysis Status)
   ============================================================ */

.progress-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--sp-lg);
    text-align: center;
}

.progress-card .pc-icon { font-size: 28px; margin-bottom: var(--sp-sm); }
.progress-card .pc-name { font-size: 14px; font-weight: 600; margin-bottom: var(--sp-xs); }
.progress-card .pc-status { font-size: 12px; color: var(--text-muted); }
.progress-card .pc-error { font-size: 12px; color: var(--error); margin-top: var(--sp-sm); }

.progress-card.status-pending { border-color: var(--border); }
.progress-card.status-running { border-color: var(--accent); }
.progress-card.status-done { border-color: var(--success); }
.progress-card.status-error { border-color: var(--error); }

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

.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============================================================
   Result Cards
   ============================================================ */

.results-actions {
    margin-bottom: var(--sp-md);
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: var(--sp-md);
    overflow: hidden;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-lg);
    border-bottom: 1px solid var(--border);
}

.result-header h3 { font-size: 16px; }

.result-header .result-btns {
    display: flex;
    gap: var(--sp-sm);
}

.result-metrics {
    display: flex;
    gap: var(--sp-xl);
    padding: var(--sp-lg);
    flex-wrap: wrap;
}

.metric {
    text-align: center;
    min-width: 100px;
}

.metric-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.metric-value.color-high { color: var(--success); }
.metric-value.color-medium { color: var(--warning); }
.metric-value.color-low { color: var(--error); }

.metric-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.result-detail {
    border-top: 1px solid var(--border);
}

.result-detail summary {
    padding: var(--sp-md) var(--sp-lg);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
}

.result-detail summary:hover { color: var(--text-primary); }

.result-body {
    padding: 0 var(--sp-lg) var(--sp-lg);
}

/* ============================================================
   Generic Data Rendering
   ============================================================ */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin: var(--sp-sm) 0;
}

.data-table th {
    background: var(--bg-secondary);
    padding: var(--sp-sm) var(--sp-md);
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: var(--sp-sm) var(--sp-md);
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: top;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

.value-object {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--sp-xs) var(--sp-md);
    font-size: 13px;
}

.value-object dt {
    color: var(--text-secondary);
    font-weight: 500;
}

.value-object dd { color: var(--text-primary); }

.value-list {
    list-style: disc;
    padding-left: var(--sp-lg);
    font-size: 13px;
}

.value-list li { margin-bottom: var(--sp-xs); }

.str { color: var(--text-primary); }
.num { color: var(--accent); font-family: var(--font-mono); }
.bool { color: var(--warning); }
.null { color: var(--text-muted); font-style: italic; }

/* ============================================================
   History
   ============================================================ */

.history-card {
    display: flex;
    align-items: center;
    gap: var(--sp-lg);
    padding: var(--sp-md) var(--sp-lg);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: var(--sp-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.history-card:hover { background: var(--bg-card-hover); border-color: var(--text-muted); }

.history-card img {
    width: 120px;
    height: 68px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.history-card .hc-info { flex: 1; }
.history-card .hc-info h4 { font-size: 14px; margin-bottom: 2px; }
.history-card .hc-info p { font-size: 12px; color: var(--text-secondary); }

.history-card .hc-badge {
    padding: 4px 10px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.empty-state, .loading-state {
    text-align: center;
    padding: var(--sp-2xl);
    color: var(--text-muted);
    font-size: 14px;
}

/* ============================================================
   Toast Notifications
   ============================================================ */

#toast-container {
    position: fixed;
    top: calc(var(--nav-height) + var(--sp-md));
    right: var(--sp-lg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--sp-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
    padding: var(--sp-md) var(--sp-lg);
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

.toast-info { background: var(--bg-card); border: 1px solid var(--accent); color: var(--text-primary); }
.toast-success { background: var(--bg-card); border: 1px solid var(--success); color: var(--success); }
.toast-warning { background: var(--bg-card); border: 1px solid var(--warning); color: var(--warning); }
.toast-error { background: var(--bg-card); border: 1px solid var(--error); color: var(--error); }

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    margin-left: auto;
    padding: 0 4px;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast-exit {
    animation: slideOut 0.3s ease forwards;
}

@keyframes slideOut {
    to { transform: translateX(100%); opacity: 0; }
}

/* ============================================================
   Multi-Video List
   ============================================================ */

.mv-card {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
    padding: var(--sp-sm) var(--sp-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: var(--sp-sm);
    font-size: 13px;
}

.mv-card img {
    width: 80px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
}

.mv-card .mv-info { flex: 1; }
.mv-card .mv-info strong { display: block; font-size: 13px; }
.mv-card .mv-info span { color: var(--text-secondary); font-size: 12px; }

.mv-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
}
.mv-remove:hover { color: var(--error); }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
    .template-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
    .nav-step .step-label { display: none; }
    .estimate-bar { flex-direction: column; gap: var(--sp-sm); }
    .view-actions { flex-direction: column; }
    .view-actions .btn { width: 100%; justify-content: center; }
    .video-card { flex-direction: column; text-align: center; }
    .video-card img { width: 100%; height: auto; max-width: 240px; }
    .result-metrics { justify-content: center; }
    .settings-toolbar { flex-direction: column; align-items: flex-start; }
    .toggle-label { margin-left: 0; }
}

@media (max-width: 480px) {
    .template-grid { grid-template-columns: 1fr; }
    .input-row { flex-direction: column; }
    .history-card { flex-direction: column; text-align: center; }
    .history-card img { width: 100%; max-width: 200px; }
}
