/* ============================================================
   HLS Downloader — тёмная тема (dev-tool), одна колонка
   ============================================================ */

:root {
    --bg: #14161b;
    --bg-elev: #1c1f26;
    --bg-input: #22262f;
    --border: #2b2f3a;
    --border-strong: #3a3f4d;
    --text: #e6e8ed;
    --text-dim: #9aa1ad;
    --text-faint: #6b7280;
    --accent: #4f8cff;
    --accent-2: #7c5cff;
    --accent-grad: linear-gradient(135deg, #4f8cff 0%, #7c5cff 100%);
    --green: #34d399;
    --red: #f87171;
    --yellow: #fbbf24;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    background-image:
        radial-gradient(1200px 400px at 50% -100px, rgba(124, 92, 255, 0.12), transparent 70%),
        radial-gradient(900px 300px at 80% 0, rgba(79, 140, 255, 0.10), transparent 70%);
    background-attachment: fixed;
}

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 32px 20px 40px;
}

/* Шапка */
header { text-align: center; margin-bottom: 28px; }
header h1 {
    font-size: 2em;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
header .subtitle { color: var(--text-dim); margin-top: 6px; font-size: 0.98em; }

/* Карточки-блоки */
.card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.card h3 {
    font-size: 1.05em;
    margin-bottom: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Инструкция */
.instructions { font-size: 0.92em; color: var(--text-dim); }
.instructions ol { margin-left: 18px; }
.instructions ul { margin: 4px 0 4px 18px; }
.instructions li { margin: 4px 0; }
.instructions strong { color: var(--text); }
code, kbd {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 0.9em;
    color: var(--accent);
    font-family: "SF Mono", Menlo, Consolas, monospace;
}

/* Поля ввода */
label { display: block; margin-bottom: 8px; color: var(--text-dim); font-size: 0.92em; }
textarea,
input[type="text"],
input[type="password"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px 14px;
    font-size: 0.95em;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: vertical;
}
textarea::placeholder,
input::placeholder { color: var(--text-faint); }
textarea:focus,
input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

/* Кнопки */
.btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 22px;
    font-size: 0.98em;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
    font-family: inherit;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
    background: var(--accent-grad);
    color: white;
    width: 100%;
    margin-top: 14px;
    box-shadow: 0 6px 18px rgba(79, 140, 255, 0.35);
}
.btn-success {
    background: var(--accent-grad);
    color: white;
    width: 100%;
    margin-top: 16px;
}
.btn-success:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Раскрывающиеся блоки (логин, обрезка, памятка) */
.login-section,
.trim-section,
.curl-help {
    margin: 14px 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
}
.login-section summary,
.trim-section summary,
.curl-help summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-dim);
}
.login-section summary:hover,
.trim-section summary:hover,
.curl-help summary:hover { color: var(--text); }

.login-fields,
.trim-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
    align-items: center;
}
.login-fields input[type="text"],
.login-fields input[type="password"] { flex: 1 1 200px; width: auto; }
.trim-fields input { max-width: 120px; display: inline-block; width: auto; }
.trim-fields label { display: inline-block; margin: 0; color: var(--text-dim); }
.login-remember { font-size: 0.9em; color: var(--text-dim); white-space: nowrap; }
.login-note,
.trim-note,
.curl-help-note {
    font-size: 0.85em;
    color: var(--text-faint);
    margin-top: 10px;
}
.curl-help ol { margin: 12px 0 0 18px; color: var(--text-dim); font-size: 0.9em; }
.curl-help li { margin: 3px 0; }

/* Сообщение об ошибке */
.error-message {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.35);
    border-left: 3px solid var(--red);
    color: #fca5a5;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    white-space: pre-line;
}

/* Индикатор загрузки */
.loading {
    text-align: center;
    padding: 30px;
    color: var(--text-dim);
}
.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 14px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Миниатюра и инфо о видео */
.thumbnail-section { margin-bottom: 16px; }
.thumbnail-section h3 {
    text-transform: uppercase;
    font-size: 0.75em;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    font-weight: 700;
    margin-bottom: 8px;
}
.thumbnail-section img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.video-info { margin-bottom: 16px; }
.video-info h3 { font-size: 1.05em; margin-bottom: 6px; }
.video-info p { color: var(--text-dim); font-size: 0.9em; margin: 2px 0; }
.video-info strong { color: var(--text); }

/* Формат-табы */
.quality-section h3 { margin-bottom: 14px; }
.format-tabs { display: flex; gap: 10px; margin-bottom: 16px; }
.tab-btn {
    flex: 1;
    padding: 11px;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    font-family: inherit;
    transition: all 0.2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    background: var(--accent-grad);
    color: white;
    border-color: transparent;
}

/* Сетка качеств */
.qualities-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}
.quality-card {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.quality-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.quality-card.selected {
    border-color: var(--accent);
    background: rgba(79, 140, 255, 0.12);
    box-shadow: 0 0 0 1px var(--accent) inset;
}
.quality-card.audio-single { grid-column: 1 / -1; }
.quality-label { font-size: 1.15em; font-weight: 700; color: var(--text); }
.quality-info { font-size: 0.82em; color: var(--text-dim); margin-top: 3px; }

/* Очередь и история */
.download-queue h3 {
    text-transform: uppercase;
    font-size: 0.78em;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    font-weight: 700;
    margin: 6px 0 12px;
}
#download-history { margin-top: 6px; }

.queue-item {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 12px;
    transition: border-color 0.3s, box-shadow 0.3s;
}
.queue-item.highlight-duplicate { animation: highlight-pulse 1.5s ease; }
@keyframes highlight-pulse {
    0%, 100% { border-color: var(--border); box-shadow: none; }
    30% { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.25); }
}

.queue-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.queue-title {
    font-weight: 600;
    font-size: 0.96em;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    color: var(--text);
}
.queue-number {
    background: var(--accent-grad);
    color: white;
    border-radius: 6px;
    padding: 1px 7px;
    font-size: 0.8em;
    font-weight: 700;
}
.format-badge {
    font-size: 0.72em;
    padding: 2px 7px;
    border-radius: 5px;
    font-weight: 700;
}
.format-video { background: rgba(79, 140, 255, 0.18); color: #7cb0ff; }
.format-audio { background: rgba(124, 92, 255, 0.18); color: #a48cff; }

.queue-item-status { font-size: 0.85em; font-weight: 600; white-space: nowrap; }
.status-downloading { color: var(--accent); }
.status-completed { color: var(--green); }
.status-queued { color: var(--yellow); }
.status-failed { color: var(--red); }
.status-cancelled { color: var(--text-faint); }

/* Прогресс */
.progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 6px;
}
.progress-fill {
    height: 100%;
    background: var(--accent-grad);
    border-radius: 999px;
    transition: width 0.4s;
}
.progress-text { font-size: 0.8em; color: var(--text-dim); text-align: right; }

.queue-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.queue-actions .filename-input { flex: 1 1 200px; width: auto; padding: 8px 12px; }
.queue-actions .btn-download {
    background: rgba(52, 211, 153, 0.15);
    color: var(--green);
    border: 1px solid rgba(52, 211, 153, 0.4);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.queue-actions .btn-download:hover { background: rgba(52, 211, 153, 0.25); transform: translateY(-1px); }
.queue-actions .btn-cancel {
    background: rgba(248, 113, 113, 0.12);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.4);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.queue-actions .btn-cancel:hover { background: rgba(248, 113, 113, 0.22); transform: translateY(-1px); }

/* Кнопка переключения истории */
.btn-toggle-history {
    background: transparent;
    color: var(--text-dim);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px;
    width: 100%;
    cursor: pointer;
    margin: 12px 0;
    font-size: 0.9em;
    font-family: inherit;
    transition: all 0.2s;
}
.btn-toggle-history:hover { color: var(--text); border-color: var(--accent); }

/* Футер */
footer {
    text-align: center;
    color: var(--text-faint);
    font-size: 0.85em;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}
.footer-actions { margin-top: 12px; display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.btn-cleanup {
    background: transparent;
    color: var(--text-faint);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 0.85em;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.btn-cleanup:hover { color: var(--red); border-color: rgba(248, 113, 113, 0.4); }

/* Адаптив */
@media (max-width: 600px) {
    .container { padding: 20px 14px 30px; }
    header h1 { font-size: 1.6em; }
    .card { padding: 18px; }
    .format-tabs { flex-direction: column; }
    .qualities-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
    .queue-item-header { flex-direction: column; align-items: flex-start; }
}
