/* frontend/css/style.css — Lightweight Responsive Styles (~5KB) */
:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --video: #2563eb;
    --audio: #16a34a;
    --danger: #dc2626;
    --radius: 12px;
    --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --surface: #1e293b;
        --border: #334155;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --primary: #3b82f6;
    }
}

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    overflow-x: clip;
}

/* App Container */
.app-container {
    width: 100%;
    margin: 0 auto;
    padding: 12px 12px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

header.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.25rem;
    font-weight: 700;
}

/* Navigation Tabs */
.nav-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.nav-tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.825rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    border-radius: 8px;
    transition: color 0.15s, background-color 0.15s;
    position: relative;
}

.nav-tab-btn.active {
    color: var(--primary);
    background: var(--bg);
}

.nav-badge {
    position: absolute;
    top: 4px;
    right: 14px;
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Form Controls & Sizing */
input, select, button {
    font-size: 16px; /* Anti iOS auto-zoom */
    min-height: 44px; /* Touch target >= 44px */
    border-radius: 10px;
}

button {
    cursor: pointer;
}

.url-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.url-input-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2px 6px;
}

.url-input-wrap input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--text);
    outline: none;
    padding: 8px 6px;
}

.btn-icon {
    border: none;
    background: transparent;
    color: var(--muted);
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
    border: none;
    font-weight: 600;
    padding: 10px 16px;
    transition: filter 0.15s;
}

.btn-primary:active {
    filter: brightness(0.9);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 600;
    padding: 10px 16px;
}

.btn-danger {
    background: var(--danger);
    color: #ffffff;
    border: none;
    font-weight: 600;
}

/* Cards & Previews */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 16px;
}

.media-header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.media-thumb-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.media-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.duration-badge {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 2;
}

.btn-preview-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    border: 1px solid rgba(37, 99, 235, 0.3);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: background-color 0.15s, color 0.15s;
}

.btn-preview-link:hover {
    background: var(--primary);
    color: #fff;
}

/* Stream Player Container */
.stream-player-container {
    margin-top: 14px;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    animation: fadeInPlayer 0.25s ease;
}

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

.stream-player-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
}

.preview-player-video,
.preview-player-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: #000;
}

.preview-player-audio {
    width: 100%;
    padding: 14px 10px;
    display: block;
}

.preview-player-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}

.stream-live-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: #10b981;
}

.btn-close-player {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 600;
}

.btn-close-player:hover {
    color: var(--danger);
    background: rgba(220, 38, 38, 0.1);
}

.media-meta {
    min-width: 0;
}

.platform-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 20px;
    margin-bottom: 6px;
}

.media-title {
    margin: 0 0 4px;
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.media-author {
    color: var(--muted);
    font-size: 0.875rem;
    margin: 0 0 8px;
}

/* Segmented Output Toggle */
.output-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin: 12px 0;
}

.toggle-btn {
    border: none;
    background: transparent;
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    min-height: 46px;
    border-radius: 8px;
    transition: background-color 0.15s, color 0.15s;
}

.toggle-btn[data-type="video"].active {
    background: var(--video);
    color: #fff;
}

.toggle-btn[data-type="audio"].active {
    background: var(--audio);
    color: #fff;
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
}

.options-grid .full-span {
    grid-column: 1 / -1;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.field span {
    font-size: 0.85rem;
    color: var(--muted);
}

.field select {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.size-estimate {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 10px 0 4px;
}

/* Progress Box */
.progress-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin: 16px 0;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.progress-bar-bg {
    width: 100%;
    height: 10px;
    background: var(--bg);
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    transition: width 0.2s ease;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 6px;
}

/* Queue Card Stack on Mobile */
.queue-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 12px 0;
}

.queue-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    align-items: center;
}

.queue-item-info {
    min-width: 0;
}

.queue-item-title {
    font-size: 0.95rem;
    font-weight: 600;
    overflow-wrap: anywhere;
    margin: 0 0 4px;
}

.queue-item-meta {
    font-size: 0.8rem;
    color: var(--muted);
}

/* Playlist Scrollable Area */
.playlist-items {
    max-height: 52dvh;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.playlist-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.playlist-row:last-child {
    border-bottom: none;
}

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

.playlist-row-title {
    font-size: 0.9rem;
    font-weight: 500;
    overflow-wrap: anywhere;
    margin: 0;
}

/* Sticky Action Bar on Mobile */
.sticky-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 14px;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 90%;
    max-width: 400px;
    pointer-events: none;
}

.toast {
    background: #0f172a;
    color: #ffffff;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    animation: fadeIn 0.2s ease;
}

.toast.toast-error {
    background: #dc2626;
}

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

/* 📲 TABLET BREAKPOINT (>= 640px) */
@media (min-width: 640px) {
    .app-container {
        max-width: 740px;
        padding: 20px 20px 32px;
    }
    .nav-tabs {
        position: static;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 4px;
        margin-bottom: 20px;
    }
    .nav-tab-btn {
        flex-direction: row;
        gap: 6px;
    }
    .url-bar {
        flex-direction: row;
    }
    .url-input-wrap {
        flex: 1;
    }
    .media-header {
        grid-template-columns: 220px 1fr;
        align-items: start;
    }
}

/* 💻 PC / DESKTOP BREAKPOINT (>= 1024px) */
@media (min-width: 1024px) {
    .app-container {
        max-width: 860px;
    }
    .app-container.wide-tab {
        max-width: 980px;
    }
    .queue-item {
        grid-template-columns: 1fr 220px 44px;
        gap: 12px;
    }
}
