/* DHub Glassmorphism Design System */
:root {
    --bg-main: #090d16;
    --bg-surface: rgba(17, 24, 39, 0.7);
    --bg-surface-hover: rgba(30, 41, 59, 0.85);
    --bg-input: rgba(15, 23, 42, 0.75);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(0, 242, 254, 0.3);

    --primary: #00f2fe;
    --primary-gradient: linear-gradient(135deg, #00f2fe 0%, #3b82f6 100%);
    --purple-gradient: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;

    --status-queued: #f59e0b;
    --status-downloading: #10b981;
    --status-paused: #3b82f6;
    --status-completed: #8b5cf6;
    --status-failed: #f43f5e;
    --status-retrying: #f97316;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-title: 'Outfit', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(0, 242, 254, 0.12) 0px, transparent 50%),
        radial-gradient(at 50% 50%, rgba(16, 185, 129, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: var(--font-sans);
    min-height: 100vh;
    padding: 1.5rem 1rem;
    line-height: 1.5;
}

.app-container {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Glassmorphism Surface Base */
.glass {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

/* App Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.25rem 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.logo-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #090d16;
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.35);
    flex-shrink: 0;
}

.logo-icon i {
    width: 22px;
    height: 22px;
}

.brand-text h1 {
    font-family: var(--font-title);
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    line-height: 1.2;
}

.brand-text h1 span {
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    background: rgba(0, 242, 254, 0.12);
    color: var(--primary);
    border: 1px solid rgba(0, 242, 254, 0.25);
    font-family: var(--font-mono);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.825rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.status-indicator-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #10b981;
    font-size: 0.75rem;
    font-weight: 600;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    animation: pulse 1.5s infinite;
}

/* Button Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 1.1rem;
    min-height: 40px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    text-decoration: none;
    user-select: none;
    white-space: nowrap;
}

.btn i {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--primary-gradient);
    color: #090d16;
    box-shadow: 0 4px 14px rgba(0, 242, 254, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 242, 254, 0.45);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    min-height: 36px;
    font-size: 0.8rem;
}

.btn-danger-outline {
    background: rgba(244, 63, 94, 0.12) !important;
    color: #f43f5e !important;
    border: 1px solid rgba(244, 63, 94, 0.3) !important;
}

.btn-danger-outline:hover {
    background: rgba(244, 63, 94, 0.22) !important;
    border-color: rgba(244, 63, 94, 0.5) !important;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.85rem;
}

.metric-card {
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    transition: var(--transition);
}

.metric-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

.metric-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.metric-icon i {
    width: 18px;
    height: 18px;
}

.active-icon { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.speed-icon { background: rgba(0, 242, 254, 0.12); color: #00f2fe; }
.total-icon { background: rgba(139, 92, 246, 0.12); color: #a855f7; }
.completed-icon { background: rgba(99, 102, 241, 0.12); color: #818cf8; }

.metric-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.metric-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    white-space: nowrap;
}

/* Download Form */
.download-form-section {
    padding: 1rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.url-group {
    flex: 2;
}

.filename-group {
    flex: 1;
}

.input-icon {
    position: absolute;
    left: 0.85rem;
    width: 16px;
    height: 16px;
    color: var(--text-dim);
    pointer-events: none;
}

.input-group input {
    width: 100%;
    min-height: 42px;
    padding: 0.5rem 0.85rem 0.5rem 2.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.url-group input {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding-right: 2.6rem;
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(0, 242, 254, 0.2);
}

.btn-icon-inside {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-icon-inside:hover {
    color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
}

/* ==========================================================================
   Control Bar (Search Box & Batch Actions)
   ========================================================================== */
.control-bar {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1 1 300px;
    min-width: 250px;
}

.search-icon {
    position: absolute;
    left: 0.85rem;
    width: 16px;
    height: 16px;
    color: var(--text-dim);
    pointer-events: none;
    z-index: 2;
}

.search-box input {
    width: 100% !important;
    min-height: 40px !important;
    height: 40px !important;
    padding: 0 1rem 0 2.5rem !important;
    background: var(--bg-input) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
    color: var(--text-main) !important;
    font-family: var(--font-sans) !important;
    font-size: 0.875rem !important;
    outline: none !important;
    box-shadow: none !important;
    transition: var(--transition) !important;
}

.search-box input::placeholder {
    color: var(--text-dim);
    opacity: 0.8;
}

.search-box input:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 12px rgba(0, 242, 254, 0.2) !important;
}

.batch-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Downloads Section & Tabs */
.downloads-section {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.section-header h2 {
    font-family: var(--font-title);
    font-size: 1.25rem;
    font-weight: 700;
}

.tabs-scroll-container {
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tabs-scroll-container::-webkit-scrollbar {
    display: none;
}

.tabs {
    display: flex;
    gap: 0.25rem;
    background: rgba(15, 23, 42, 0.6);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.35rem 0.75rem;
    min-height: 32px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    background: rgba(30, 41, 59, 0.9);
    color: var(--primary);
}

.badge {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-family: var(--font-mono);
}

.tab-btn.active .badge {
    background: rgba(0, 242, 254, 0.15);
    color: var(--primary);
}

.jobs-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.empty-state {
    padding: 3rem 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
}

.empty-state i {
    width: 40px;
    height: 40px;
    color: var(--text-dim);
}

/* Job Card */
.job-card {
    padding: 1rem 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: var(--transition);
}

.job-card:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.job-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.85rem;
}

.job-title-group {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    flex: 1;
}

.job-filename-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow: hidden;
}

.ext-tag {
    font-size: 0.65rem;
    font-family: var(--font-mono);
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0, 242, 254, 0.12);
    color: var(--primary);
    border: 1px solid rgba(0, 242, 254, 0.25);
    text-transform: uppercase;
    flex-shrink: 0;
}

.job-filename {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.job-url {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.675rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-badge.queued { background: rgba(245, 158, 11, 0.12); color: var(--status-queued); border: 1px solid rgba(245, 158, 11, 0.25); }
.status-badge.downloading { background: rgba(16, 185, 129, 0.12); color: var(--status-downloading); border: 1px solid rgba(16, 185, 129, 0.25); }
.status-badge.paused { background: rgba(59, 130, 246, 0.12); color: var(--status-paused); border: 1px solid rgba(59, 130, 246, 0.25); }
.status-badge.completed { background: rgba(139, 92, 246, 0.12); color: var(--status-completed); border: 1px solid rgba(139, 92, 246, 0.25); }
.status-badge.failed { background: rgba(244, 63, 94, 0.12); color: var(--status-failed); border: 1px solid rgba(244, 63, 94, 0.25); }
.status-badge.retrying { background: rgba(249, 115, 22, 0.12); color: var(--status-retrying); border: 1px solid rgba(249, 115, 22, 0.25); }

.pulse-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
    100% { opacity: 0.3; transform: scale(0.8); }
}

/* Progress bar */
.progress-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-bar-bg {
    height: 6px;
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.4);
}

.progress-bar-fill.completed {
    background: var(--purple-gradient);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.4);
}

.progress-bar-fill.failed { background: #f43f5e; box-shadow: none; }
.progress-bar-fill.paused { background: #3b82f6; box-shadow: none; }

.job-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.meta-stats {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: var(--font-mono);
    flex-wrap: wrap;
}

.stat-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.job-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.action-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 5px 9px;
    min-height: 34px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    text-decoration: none;
}

.action-btn i {
    width: 14px;
    height: 14px;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

.action-btn.btn-danger:hover {
    background: rgba(244, 63, 94, 0.2);
    border-color: rgba(244, 63, 94, 0.4);
    color: #f43f5e;
}

.action-btn.btn-success {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.3);
}

.action-btn.btn-success:hover {
    background: rgba(16, 185, 129, 0.25);
}

.error-text {
    font-size: 0.8rem;
    color: #f43f5e;
    background: rgba(244, 63, 94, 0.1);
    padding: 0.35rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(244, 63, 94, 0.2);
}

/* ==========================================================================
   Details Modal - FIXED OVERLAY (STRICT HIDE RULE)
   ========================================================================== */
.modal-backdrop {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.75) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 1rem !important;
    z-index: 999999 !important;
}

/* Hidden state MUST NOT render in page flow */
.modal-backdrop.hidden,
div#details-modal.hidden {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.modal-content {
    width: 100%;
    max-width: 580px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-family: var(--font-title);
    font-size: 1.2rem;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    font-size: 0.85rem;
}

.detail-row {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border-color);
}

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

.detail-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.detail-val {
    font-family: var(--font-mono);
    word-break: break-all;
    color: var(--text-main);
}

/* Toast Container */
#toast-container {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000000;
}

.toast {
    background: #1e293b;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
    animation: slideIn 0.25s ease;
}

.toast i {
    width: 16px;
    height: 16px;
}

.toast.success { border-left: 4px solid #10b981; }
.toast.error { border-left: 4px solid #f43f5e; }

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

/* Responsive Breakpoints */
@media (max-width: 900px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    body { padding: 0.85rem 0.5rem; }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .btn-text { display: none; }

    .form-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
    }

    .url-group, .filename-group {
        width: 100%;
    }

    .btn-submit-job {
        width: 100%;
    }

    .control-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
    }

    .search-box {
        width: 100%;
    }

    .batch-actions {
        width: 100%;
        justify-content: space-between;
    }

    .batch-actions .btn {
        flex: 1;
        justify-content: center;
    }

    .job-meta-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .job-actions {
        width: 100%;
        justify-content: flex-end;
    }
}
