/* ==========================================================================
   StreamFetch - Design System & Stylesheet
   Solid, purposeful styling without neon glows, glassmorphism, or decorative gradients.
   ========================================================================== */

:root {
    /* Canvas & Surfaces */
    --bg-canvas: #0b0f19;
    --bg-surface: #121826;
    --bg-surface-hover: #182032;
    --bg-surface-active: #1d283e;
    --bg-input: #0e1422;
    --bg-sunken: #090d15;

    /* Borders */
    --border-subtle: #1f2a3c;
    --border-muted: #28364d;
    --border-strong: #384964;
    --border-focus: #2563eb;

    /* Primary Brand Actions (Solid Royal Blue) */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-active: #1e40af;
    --primary-subtle: #172554;
    --primary-border: #1d4ed8;

    /* Semantic Status Colors */
    --success: #16a34a;
    --success-hover: #15803d;
    --success-bg: #091f16;
    --success-border: #166534;
    --success-text: #4ade80;

    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-bg: #220d11;
    --danger-border: #5a1a22;
    --danger-text: #f87171;

    --warning: #d97706;
    --warning-bg: #201507;
    --warning-border: #52350f;
    --warning-text: #fbbf24;

    /* Text */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    /* Typography */
    --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-full: 9999px;

    /* Clean subtle elevation without neon halos */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.45);

    --transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

/* Reset & Global */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    color-scheme: dark;
}

body {
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App Container */
.app-container {
    max-width: 980px;
    margin: 0 auto;
    padding: 2.5rem 1.25rem 4rem 1.25rem;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.brand-badge svg {
    color: var(--primary);
    flex-shrink: 0;
}

.hero-title {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.2;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.hero-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 1.5rem auto;
    line-height: 1.6;
}

.platform-pills {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.platform-tag {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.25rem 0.7rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

/* Main Cards / Surfaces */
.glass-card,
.solid-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    box-shadow: var(--shadow-md);
    margin-bottom: 1.75rem;
}

/* URL Search Form */
.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: var(--bg-input);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
    transition: var(--transition);
}

.search-wrapper:focus-within {
    border-color: var(--border-focus);
    outline: 2px solid rgba(37, 99, 235, 0.25);
}

.search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font-body);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.clear-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.clear-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-surface-hover);
}

/* Buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.4rem;
    background-color: var(--primary);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-sm);
    color: var(--text-inverse);
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.action-btn:hover {
    background-color: var(--primary-hover);
}

.action-btn:active {
    background-color: var(--primary-active);
}

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

.action-btn.secondary {
    background-color: var(--bg-surface-hover);
    border-color: var(--border-muted);
    color: var(--text-primary);
}

.action-btn.secondary:hover {
    background-color: var(--bg-surface-active);
    border-color: var(--border-strong);
}

.icon-btn {
    background-color: transparent;
    border: 1px solid var(--border-muted);
    color: var(--text-secondary);
    padding: 0.55rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-surface-hover);
    border-color: var(--border-strong);
}

.icon-btn.delete:hover {
    color: var(--danger-text);
    background-color: var(--danger-bg);
    border-color: var(--danger-border);
}

/* Spinner */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 0.7s linear infinite;
    display: inline-block;
    vertical-align: middle;
}

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

/* Video Info Preview Layout */
.video-preview-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.5rem;
    align-items: start;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-subtle);
}

.thumbnail-container {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    background-color: var(--bg-sunken);
    aspect-ratio: 16 / 9;
}

.thumbnail-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.duration-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background-color: rgba(0, 0, 0, 0.85);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-mono);
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.video-details {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.video-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-primary);
}

.uploader-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.uploader-name {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-primary);
    font-weight: 500;
}

.video-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    max-height: 4.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

/* Tabs */
.tabs-header {
    display: flex;
    gap: 0.5rem;
    background-color: var(--bg-sunken);
    padding: 0.3rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    margin-top: 1.5rem;
    margin-bottom: 1.25rem;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-surface);
}

.tab-btn.active {
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border-color: var(--border-muted);
    box-shadow: var(--shadow-sm);
}

/* Formats Grid */
.formats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.format-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    background-color: var(--bg-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.format-card:hover {
    border-color: var(--border-strong);
    background-color: var(--bg-surface-hover);
}

.format-card.selected {
    border-color: var(--primary);
    background-color: var(--primary-subtle);
    outline: 1px solid var(--primary);
}

.format-res {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.format-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.format-badge {
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-heading);
    padding: 0.15rem 0.45rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.format-card.selected .format-badge {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

/* Download Progress Card */
.progress-card {
    background-color: var(--bg-sunken);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-top: 1.25rem;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.progress-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.progress-percentage {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.progress-track {
    width: 100%;
    height: 8px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
    margin-bottom: 0.85rem;
}

.progress-fill {
    height: 100%;
    background-color: var(--primary);
    border-radius: var(--radius-full);
    transition: width 0.25s ease;
}

.progress-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.stat-item {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.stat-item span {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-family: var(--font-body);
    display: block;
    margin-bottom: 0.15rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Alert / Error Banner */
.alert-banner {
    background-color: var(--danger-bg);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-top: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.alert-banner-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--danger-text);
}

.alert-banner-message {
    font-size: 0.875rem;
    color: #fca5a5;
    word-break: break-word;
}

/* Success Card */
.success-box {
    text-align: center;
    padding: 1.75rem;
    background-color: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: var(--radius-md);
    margin-top: 1.5rem;
}

.success-icon {
    width: 48px;
    height: 48px;
    background-color: var(--success-border);
    color: var(--success-text);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.75rem auto;
}

.success-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.success-meta {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.save-file-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem 1.75rem;
    background-color: var(--success);
    color: #ffffff;
    border: 1px solid var(--success-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    margin-top: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.save-file-btn:hover {
    background-color: var(--success-hover);
}

/* Media Preview Player */
.media-preview-player {
    width: 100%;
    margin-top: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-muted);
    outline: none;
    background-color: #000;
    max-height: 420px;
}

/* History Section */
.section-title {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background-color: var(--bg-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

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

.history-thumb-info {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

.history-thumb {
    width: 72px;
    height: 40px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.history-text-col {
    min-width: 0;
}

.history-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 480px;
}

.history-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.history-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    margin-left: 1rem;
}

/* Responsive Layout */
@media (max-width: 768px) {
    .app-container {
        padding: 1.5rem 1rem 3rem 1rem;
    }

    .hero-title {
        font-size: 1.9rem;
    }

    .hero-subtitle {
        font-size: 0.95rem;
    }

    .search-wrapper {
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem;
    }

    .action-btn {
        width: 100%;
    }

    .video-preview-grid {
        grid-template-columns: 1fr;
    }

    .progress-stats {
        grid-template-columns: 1fr;
    }

    .history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .history-title {
        max-width: 100%;
    }

    .history-actions {
        width: 100%;
        justify-content: flex-end;
        margin-left: 0;
    }
}

/* Cookie Settings Badge & Modal */
.cookie-badge-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.85rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.cookie-badge-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background-color: var(--bg-surface-hover);
}

.cookie-badge-btn.active {
    border-color: rgba(74, 222, 128, 0.4);
    background-color: rgba(74, 222, 128, 0.08);
    color: #4ade80;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 580px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-body {
    padding: 1.5rem;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
}

.cookie-status-bar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.status-badge.success {
    background-color: rgba(74, 222, 128, 0.12);
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: #4ade80;
}

.status-badge.warning {
    background-color: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: #fbbf24;
}

.cookie-guide-box {
    background-color: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1rem;
}

.cookie-textarea {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.4;
    resize: vertical;
    outline: none;
    transition: var(--transition);
}

.cookie-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}
