/* ── Base ─────────────────────────────────────────────── */
:root {
    --bg: #0f1117;
    --bg2: #1a1d27;
    --bg3: #242836;
    --border: #2e3347;
    --text: #e1e4ed;
    --text2: #8b8fa3;
    --primary: #6c5ce7;
    --primary-hover: #7c6df7;
    --danger: #e74c3c;
    --success: #27ae60;
    --warning: #f39c12;
    --radius: 10px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Navbar ──────────────────────────────────────────── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
    cursor: pointer;
}

.nav-links { display: flex; gap: 4px; }

.nav-link {
    padding: 8px 16px;
    border-radius: 6px;
    color: var(--text2);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    text-decoration: none;
}

.nav-link:hover { color: var(--text); background: var(--bg3); }
.nav-link.active { color: var(--primary); background: rgba(108,92,231,0.1); }

/* ── Layout ──────────────────────────────────────────── */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 16px;
}

.page { display: none; }
.page.active { display: block; }

/* ── Card ────────────────────────────────────────────── */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
}

.card h2 {
    font-size: 22px;
    margin-bottom: 6px;
}

.subtitle {
    color: var(--text2);
    font-size: 14px;
    margin-bottom: 24px;
}

/* ── Forms ────────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text2);
    margin-bottom: 6px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    border-color: var(--primary);
}

input::placeholder { color: var(--text2); opacity: 0.5; }

.file-upload {
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-upload input[type="file"] {
    font-size: 13px;
    color: var(--text2);
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text);
    background: var(--bg3);
}

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

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { width: 100%; padding: 14px; font-size: 16px; margin-top: 12px; }

/* ── Badges ──────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}
.badge-gray { background: var(--bg3); color: var(--text2); }
.badge-green { background: rgba(39,174,96,0.15); color: var(--success); }
.badge-yellow { background: rgba(243,156,18,0.15); color: var(--warning); }
.badge-red { background: rgba(231,76,60,0.18); color: #e74c3c; }

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text2);
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); }

.cookies-warning {
    margin-top: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(231,76,60,0.10);
    border: 1px solid rgba(231,76,60,0.35);
    color: #f1948a;
    font-size: 13px;
    line-height: 1.55;
}

/* ── Library page ─────────────────────────────────────── */
.library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.library-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
}
.library-toolbar input[type="text"] {
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    width: 240px;
}
.library-stats {
    color: var(--text2);
    font-size: 13px;
    margin: 6px 0 18px;
}
.library-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 18px;
}
.library-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.lib-video {
    width: 100%;
    aspect-ratio: 9 / 16;
    background: #000;
    display: block;
    max-height: 420px;
    object-fit: contain;
}
.lib-body {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.lib-title {
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
    line-height: 1.35;
}
.lib-source {
    color: var(--text2);
    font-size: 12px;
    line-height: 1.4;
}
.lib-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}
.lib-tag {
    background: var(--bg3);
    color: var(--text2);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
}
.lib-session {
    color: var(--text2);
    font-size: 11px;
}
.lib-session code {
    background: var(--bg3);
    padding: 1px 6px;
    border-radius: 4px;
}
.lib-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

/* ── Video Preview ───────────────────────────────────── */
.video-preview {
    margin-top: 12px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.video-preview img {
    width: 100%;
    display: block;
}

.video-title {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text2);
    background: var(--bg3);
}

/* ── Progress ────────────────────────────────────────── */
.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--bg3);
    border-radius: 4px;
    margin: 20px 0 12px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #a29bfe);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-message {
    color: var(--text2);
    font-size: 14px;
    margin-bottom: 16px;
}

.log-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    max-height: 250px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 16px;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ── Highlights ──────────────────────────────────────── */
.hl-options {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.hl-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.switch-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
}

/* Ensure the HTML `hidden` attribute works even when an element has an
 * explicit `display` rule (April 2026: multi-lang wrapper was staying
 * visible despite [hidden] because .switch-label sets display:flex). */
[hidden] {
    display: none !important;
}

.switch-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.portrait-mode-selector,
.subtitle-style-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg3);
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    flex-wrap: wrap;
}

.select-input {
    background: var(--bg2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    min-width: 220px;
}

.select-input:focus {
    outline: none;
    border-color: var(--accent);
}

.algo-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg3);
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.algo-selector .radio-label {
    align-items: flex-start;
    line-height: 1.4;
    white-space: normal;
}

.wm-position-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-width: 360px;
}

.wm-pos {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 4px;
    font-size: 12px;
    color: var(--text2);
    cursor: pointer;
    transition: all 0.15s;
}

.wm-pos:hover { border-color: var(--accent); color: var(--text); }
.wm-pos.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.watermark-preview {
    margin-top: 8px;
    padding: 12px;
    background: var(--bg3);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-align: center;
}

.watermark-preview img {
    max-height: 80px;
    max-width: 200px;
    object-fit: contain;
}

.wm-manual-pos {
    display: flex;
    gap: 16px;
    align-items: center;
}

.wm-manual-pos label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}

.input-sm {
    width: 60px;
    padding: 4px 8px;
    background: var(--bg2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    text-align: center;
}

.input-sm:focus {
    outline: none;
    border-color: var(--accent);
}

.watermark-composite-preview {
    margin-top: 12px;
    text-align: center;
    background: var(--bg3);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 12px;
}

.watermark-composite-preview img {
    max-height: 350px;
    border-radius: 8px;
    object-fit: contain;
}

.wm-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wm-preview-popup {
    background: var(--bg2);
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.wm-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 14px;
}

.wm-preview-body {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.wm-preview-body img {
    max-height: 80vh;
    max-width: 85vw;
    object-fit: contain;
    border-radius: 8px;
}

.hl-top-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 10px 14px;
    background: var(--bg3);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.hl-top-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.hl-top-item label {
    font-weight: 600;
    color: var(--text2);
    white-space: nowrap;
}

.hl-top-item select {
    background: var(--bg2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
}

.hl-top-item select:focus {
    outline: none;
    border-color: var(--accent);
}

.caption-lang-note {
    font-size: 12px;
    color: var(--text2);
    font-style: italic;
}

.option-group-label {
    font-size: 13px;
    color: var(--text2);
    white-space: nowrap;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.radio-label input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.highlights-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.highlight-card {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    gap: 14px;
    align-items: flex-start;
    transition: border-color 0.2s;
}

.highlight-card.selected { border-color: var(--primary); }

.highlight-card input[type="checkbox"] {
    margin-top: 3px;
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.hl-content { flex: 1; min-width: 0; }
.hl-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.hl-desc { font-size: 13px; color: var(--text2); margin-bottom: 8px; }

.hl-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text2);
}

.hl-meta span {
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 4px;
}

.virality-high { color: var(--success) !important; }
.virality-mid { color: var(--warning) !important; }

/* ── Results ─────────────────────────────────────────── */
.results-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.result-card {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.result-info {
    font-size: 14px;
}

.result-info .size {
    color: var(--text2);
    font-size: 12px;
}

/* ── Sessions ────────────────────────────────────────── */
.sessions-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.session-card {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: border-color 0.2s;
}

.session-card:hover { border-color: var(--primary); }

.session-info {
    flex: 1;
    min-width: 0;
}

.session-title {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-meta {
    font-size: 12px;
    color: var(--text2);
}

/* ── Settings Tabs ───────────────────────────────────── */
.settings-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    background: var(--bg3);
    color: var(--text2);
    white-space: nowrap;
    transition: all 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { background: var(--primary); color: #fff; }

.settings-panel { display: none; }
.settings-panel.active { display: block; }

.info-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 20px;
    line-height: 1.5;
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 8px;
}

.status-msg {
    font-size: 13px;
    color: var(--text2);
}

.status-msg.ok { color: var(--success); }
.status-msg.err { color: var(--danger); }

/* ── Confirm Modal ──────────────────────────────────── */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

.confirm-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px 32px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.2s ease;
}

.confirm-icon {
    font-size: 38px;
    margin-bottom: 12px;
}

.confirm-box h3 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.confirm-box p {
    font-size: 14px;
    color: var(--text2);
    margin-bottom: 22px;
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-actions .btn {
    min-width: 100px;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
}

.btn-danger:hover {
    background: #c0392b;
}

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

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

/* ── Toast ───────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 999;
    background: var(--bg3);
    border: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    transition: opacity 0.3s, transform 0.3s;
    opacity: 0;
    transform: translateY(10px);
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

.hidden { display: none !important; }

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

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; }
    .hl-options { flex-direction: column; align-items: flex-start; }
    .hl-actions { margin-left: 0; }
    .settings-tabs { gap: 2px; }
    .tab { padding: 6px 10px; font-size: 12px; }
    .card { padding: 18px; }
}

/* Feature-flag experimental badge */
.feature-experimental-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.35);
    border-radius: 3px;
    vertical-align: middle;
}

/* Video type detection badge (music warning on Highlight Selection) */
.video-type-badge {
    padding: 10px 14px;
    margin: 10px 0 14px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
}
.video-type-music {
    background: rgba(251, 191, 36, 0.12);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.35);
}

/* Sub-option styling for nested settings (e.g., lyric strategy under music mode) */
.sub-option {
  margin-left: 32px;
  margin-top: -4px;
  margin-bottom: 4px;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--text2);
}
.sub-option-label {
  min-width: 110px;
}
.sub-option select {
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
}

.disabled-group { opacity: 0.45; pointer-events: none; }

/* Subtitle scan panel — constrain height so rendered zones list
   doesn't push surrounding options around. Panel stays in flow
   but the zones list scrolls internally. */
#subtitle-scan-panel {
  margin-left: 32px;
  margin-top: 4px;
  margin-bottom: 8px;
  padding: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

#subtitle-scan-panel > div {
  width: 100%;
}

#btn-subtitle-scan {
  padding: 4px 12px;
  margin-bottom: 4px;
}

#subtitle-zones-list {
  max-height: 220px;
  overflow-y: auto;
  padding-right: 6px;
}

#subtitle-zones-list label.zone-checkbox {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  padding: 3px 0;
  font-size: 12px;
  line-height: 1.35;
  border-bottom: 1px dashed var(--border);
}

#subtitle-zones-list label.zone-checkbox:last-child {
  border-bottom: none;
}

#subtitle-zones-list strong {
  color: var(--text);
  margin-right: 4px;
}
