/* ============================================================
   RESET & BASE
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f7f8fa;
    --bg-2: #eef1f5;
    --card: #ffffff;
    --card-hover: #f3f4f6;
    --border: #e5e7eb;
    --border-light: #d1d5db;
    --text: #111827;
    --text-muted: #6b7280;
    --text-dim: #9ca3af;
    --accent: #2563eb;
    --accent-2: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    background: rgba(37,99,235,0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: "SF Mono", Monaco, monospace;
    color: #1d4ed8;
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: radial-gradient(circle at 20% 30%, rgba(37,99,235,0.15) 0%, transparent 50%),
                radial-gradient(circle at 80% 70%, rgba(14,165,233,0.15) 0%, transparent 50%),
                var(--bg);
}

.login-box {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 40px;
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.08);
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.brand-logo {
    text-align: center;
    margin-bottom: 16px;
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.login-box h1 {
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 28px;
    font-size: 14px;
}

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-2);
    padding: 4px;
    border-radius: 12px;
}

.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
    font-family: inherit;
}

.tab.active {
    background: var(--card-hover);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.form-group { display: flex; flex-direction: column; gap: 12px; }
.form-group.hidden { display: none; }

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

.input-icon {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.input-wrapper input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    color: var(--text);
    font-family: inherit;
    transition: all 0.2s;
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--accent-2);
    background: var(--card-hover);
    box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}

.input-wrapper input::placeholder { color: var(--text-dim); }

.error-msg {
    margin-top: 16px;
    padding: 12px;
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.3);
    color: #b91c1c;
    border-radius: 10px;
    font-size: 13px;
}

.error-msg.hidden { display: none; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: white;
    box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(37,99,235,0.35);
}

.btn-secondary {
    background: var(--card-hover);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    padding: 8px 12px;
}
.btn-ghost:hover { background: var(--card-hover); color: var(--text); }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#app-view { display: none; }
#app-view.active { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 24px 20px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

/* ============================================================
   AGENT SWITCHER
   ============================================================ */
.agent-switcher {
    position: relative;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.agent-switcher-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.agent-switcher-btn:hover { background: var(--card-hover); }

.agent-switcher-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-switcher-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 16px;
    right: 16px;
    background: var(--card);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.12);
    z-index: 200;
    padding: 6px;
    max-height: 320px;
    overflow-y: auto;
}

.agent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.12s;
}
.agent-item:hover { background: var(--card-hover); }
.agent-item.active { background: rgba(37,99,235,0.1); color: var(--accent); font-weight: 600; }

.agent-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.agent-item-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.agent-switcher-new {
    display: flex;
    gap: 6px;
    padding: 8px 6px 4px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}
.agent-switcher-new input {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-item:hover {
    background: var(--card-hover);
    color: var(--text);
    text-decoration: none;
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(37,99,235,0.15), rgba(14,165,233,0.1));
    color: var(--text);
    border-left: 3px solid var(--accent);
    padding-left: 11px;
}

.nav-badge {
    margin-left: auto;
    background: var(--accent);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    font-size: 16px;
    flex-shrink: 0;
}

.user-detail { min-width: 0; flex: 1; }

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-status {
    font-size: 11px;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 4px;
}

.user-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 32px;
    min-height: 100vh;
    max-width: calc(100vw - 240px);
}

.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }

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

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* ============================================================
   STATS GRID
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 16px;
    transition: all 0.2s;
    cursor: default;
    animation: fadeIn 0.5s ease backwards;
}

.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.2s; }

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-light);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg { width: 22px; height: 22px; }

.stat-uploaded .stat-icon { background: rgba(16,185,129,0.15); color: var(--success); }
.stat-pending .stat-icon { background: rgba(245,158,11,0.15); color: var(--warning); }
.stat-paused .stat-icon { background: rgba(59,130,246,0.15); color: var(--info); }
.stat-failed .stat-icon { background: rgba(239,68,68,0.15); color: var(--error); }

.stat-content { flex: 1; min-width: 0; }

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 20px;
    overflow: hidden;
    transition: border-color 0.2s;
    animation: fadeIn 0.5s ease backwards;
    animation-delay: 0.25s;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.card-body { padding: 24px; }

.two-col-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 900px) {
    .two-col-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-green { background: rgba(16,185,129,0.15); color: #047857; }
.badge-red { background: rgba(239,68,68,0.15); color: #b91c1c; }
.badge-yellow { background: rgba(245,158,11,0.15); color: #b45309; }
.badge-blue { background: rgba(59,130,246,0.15); color: #1d4ed8; }

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-2);
    border-radius: 10px;
    overflow: hidden;
    margin: 8px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #2563eb, #0ea5e9);
    border-radius: 10px;
    transition: width 0.5s ease;
}

/* ============================================================
   VIDEOS GRID
   ============================================================ */
.videos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.video-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
    animation: fadeIn 0.3s ease;
}

.video-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-2);
    box-shadow: 0 12px 32px rgba(14,165,233,0.15);
}

.video-thumb {
    position: relative;
    aspect-ratio: 3 / 4;
    background: linear-gradient(135deg, var(--card-hover), var(--bg-2));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.video-thumb.status-uploaded {
    background: linear-gradient(135deg, rgba(16,185,129,0.2), rgba(16,185,129,0.05));
}
.video-thumb.status-pending {
    background: linear-gradient(135deg, rgba(245,158,11,0.2), rgba(245,158,11,0.05));
}
.video-thumb.status-pending_space {
    background: linear-gradient(135deg, rgba(59,130,246,0.2), rgba(59,130,246,0.05));
}
.video-thumb.status-failed {
    background: linear-gradient(135deg, rgba(239,68,68,0.2), rgba(239,68,68,0.05));
}

.video-thumb svg {
    width: 48px;
    height: 48px;
    color: var(--text-dim);
    opacity: 0.5;
}

.video-status-dot {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-dot-uploaded { background: var(--success); }
.status-dot-pending { background: var(--warning); }
.status-dot-pending_space { background: var(--info); }
.status-dot-failed { background: var(--error); }

.video-info { padding: 12px; }

.video-id {
    font-family: "SF Mono", Monaco, monospace;
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 8px;
}

.video-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-dim);
}

.video-status-label {
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-label-uploaded { background: rgba(16,185,129,0.15); color: #047857; }
.status-label-pending { background: rgba(245,158,11,0.15); color: #b45309; }
.status-label-pending_space { background: rgba(59,130,246,0.15); color: #1d4ed8; }
.status-label-failed { background: rgba(239,68,68,0.15); color: #b91c1c; }
.status-label-downloaded { background: rgba(14,165,233,0.15); color: #6d28d9; }

/* ============================================================
   FILTER TABS
   ============================================================ */
.filter-tabs {
    display: flex;
    gap: 4px;
    background: var(--card);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
    overflow-x: auto;
}

.filter-tab {
    padding: 6px 14px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.filter-tab:hover { color: var(--text); }
.filter-tab.active {
    background: var(--card-hover);
    color: var(--text);
}

/* ============================================================
   INPUTS
   ============================================================ */
.input-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
    flex-wrap: wrap;
}

input[type="text"],
input[type="password"],
input[type="email"] {
    padding: 10px 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    color: var(--text);
    font-family: inherit;
    transition: all 0.2s;
    width: 100%;
}

input:focus {
    outline: none;
    border-color: var(--accent-2);
    background: var(--card-hover);
    box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}

input::placeholder { color: var(--text-dim); }

.input-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.flex-1 { flex: 1; min-width: 200px; }

/* ============================================================
   MISC
   ============================================================ */
.muted {
    color: var(--text-muted);
    font-size: 13px;
}

.scan-result {
    margin-top: 16px;
    padding: 14px 18px;
    border-radius: 10px;
    font-size: 13px;
    animation: slideDown 0.3s ease;
}

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

.scan-result.success {
    background: rgba(16,185,129,0.1);
    border: 1px solid rgba(16,185,129,0.3);
    color: #047857;
}

.scan-result.error {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.3);
    color: #b91c1c;
}

.steps-list {
    margin-left: 20px;
    margin-top: 8px;
}

.steps-list li {
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
}

.steps-list code {
    display: inline-block;
    margin-top: 4px;
    word-break: break-all;
    max-width: 100%;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

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

.info-label {
    color: var(--text-muted);
    font-size: 13px;
}

.info-value {
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.loading-spinner {
    grid-column: 1 / -1;
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-2);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 40px auto;
}

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

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 24px;
    padding: 16px;
}

#page-info {
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.12);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-family: inherit;
    line-height: 1;
}

.modal-close:hover {
    background: var(--card-hover);
    color: var(--text);
}

.modal-body { padding: 24px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    background: var(--card);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 14px 18px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toastIn 0.3s ease;
    pointer-events: auto;
}

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

.toast.toast-out {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
    to { opacity: 0; transform: translateX(100px); }
}

.toast-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
    font-weight: 700;
}

.toast-success .toast-icon { background: rgba(16,185,129,0.15); color: var(--success); }
.toast-error .toast-icon { background: rgba(239,68,68,0.15); color: var(--error); }
.toast-warning .toast-icon { background: rgba(245,158,11,0.15); color: var(--warning); }
.toast-info .toast-icon { background: rgba(59,130,246,0.15); color: var(--info); }

.toast-content { flex: 1; min-width: 0; }

.toast-close {
    background: none; border: none; cursor: pointer;
    color: var(--text-dim); font-size: 16px; line-height: 1;
    padding: 2px 4px; flex-shrink: 0;
}
.toast-close:hover { color: var(--text); }

.toast-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.toast-message {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: relative;
        height: auto;
        flex-direction: row;
        padding: 12px;
        overflow-x: auto;
    }

    .sidebar-brand { border: none; padding: 0 12px 0 0; }
    .sidebar-nav { flex-direction: row; padding: 0; gap: 8px; }
    .nav-item span:not(.nav-badge) { display: none; }
    .sidebar-footer { border: none; padding: 0 0 0 12px; }
    .user-detail { display: none; }

    /* fixed + explicit offset: escapes .sidebar's overflow-x:auto (which clips
       absolutely-positioned children) now that the sidebar is a short horizontal bar */
    .agent-switcher-menu {
        position: fixed;
        top: 88px;
        left: 12px;
        right: auto;
        width: min(280px, calc(100vw - 24px));
    }

    .main-content {
        margin-left: 0;
        max-width: 100%;
        padding: 20px;
    }

    .page-header { flex-direction: column; align-items: flex-start; }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .videos-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

/* ============================================================
   NEW: Profiles, log viewer, modals (namespaced), etc.
   ============================================================ */

.link { color: var(--accent-2); cursor: pointer; font-size: 13px; }
.link:hover { text-decoration: underline; }

.actions-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input, .select-input {
    background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
    padding: 10px 14px; border-radius: 10px; font-size: 14px;
    font-family: inherit; min-width: 200px; transition: all .15s;
}
.search-input:focus, .select-input:focus {
    outline: none; border-color: var(--accent-2);
    box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
.select-input { cursor: pointer; }

/* Profiles */
.profiles-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; margin-top: 20px; }
.profile-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 16px; padding: 18px; transition: all .15s;
}
.profile-card:hover { border-color: var(--border-light); transform: translateY(-2px); }
.profile-card.profile-disabled { opacity: .6; border-style: dashed; }
.profile-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.profile-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px; color: #fff; flex-shrink: 0;
}
.profile-info { flex: 1; min-width: 0; }
.profile-name-row { display: flex; align-items: center; gap: 6px; }
.profile-name {
    font-weight: 600; font-size: 14px; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.profile-url {
    font-size: 11px; color: var(--text-dim); margin-top: 3px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-family: "SF Mono", Menlo, monospace;
}
.icon-btn {
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; padding: 3px 6px; border-radius: 5px;
    font-size: 12px; transition: all .15s; font-family: inherit;
}
.icon-btn:hover { background: var(--card-hover); color: var(--text); }

/* Toggle */
.switch { position: relative; display: inline-block; width: 42px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--border); transition: .25s; border-radius: 22px;
}
.slider::before {
    position: absolute; content: ""; height: 16px; width: 16px;
    left: 3px; bottom: 3px; background: #fff;
    transition: .25s; border-radius: 50%;
}
.switch input:checked + .slider { background: linear-gradient(90deg, #2563eb, #0ea5e9); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.profile-folder-row {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 12px; background: var(--bg-2);
    border-radius: 8px; margin-bottom: 12px; font-size: 12px;
}
.folder-icon { font-size: 13px; }
.profile-folder {
    flex: 1; color: var(--text-muted);
    font-family: "SF Mono", Menlo, monospace;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.profile-stats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.mini-stat { padding: 3px 9px; border-radius: 20px; font-size: 10.5px; font-weight: 600; letter-spacing: .3px; }
.mini-stat.stat-up { background: rgba(16,185,129,.15); color: #047857; }
.mini-stat.stat-pd { background: rgba(245,158,11,.15); color: #b45309; }
.mini-stat.stat-pa { background: rgba(59,130,246,.15); color: #1d4ed8; }
.mini-stat.stat-fa { background: rgba(239,68,68,.15); color: #b91c1c; }
.mini-stat.total { background: rgba(14,165,233,.15); color: #6d28d9; }

.progress-bar.small { height: 4px; margin-bottom: 14px; }

.profile-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.profile-actions button { flex: 1; min-width: 80px; padding: 8px 10px; font-size: 12px; }
.btn-danger {
    background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.35);
    color: #b91c1c; padding: 8px 12px; border-radius: 10px; cursor: pointer;
    font-family: inherit; font-size: 13px; font-weight: 500; transition: all .15s;
}
.btn-danger:hover { background: rgba(239,68,68,.2); border-color: #ef4444; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state h3 { color: var(--text); font-size: 18px; margin-bottom: 8px; font-weight: 600; }
.empty-state p { margin-bottom: 20px; font-size: 14px; }
.empty-state-icon { display: block; width: 48px; height: 48px; margin: 0 auto 14px; color: var(--text-dim); opacity: .5; }

/* ============================================================
   SKELETON LOADERS
   ============================================================ */
.skeleton-card {
    height: 88px;
    border-radius: 16px;
    margin-bottom: 12px;
    background: linear-gradient(90deg, var(--card) 25%, var(--bg-2) 50%, var(--card) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.4s ease-in-out infinite;
}
@keyframes skeletonShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ============================================================
   LIVE INDICATOR
   ============================================================ */
.live-dot-wrap {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; font-weight: 600; color: var(--text-muted);
}
.live-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 0 rgba(16,185,129,0.6);
    animation: livePulse 1.8s ease-in-out infinite;
}
@keyframes livePulse {
    0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.6); }
    70% { box-shadow: 0 0 0 7px rgba(16,185,129,0); }
    100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

/* ============================================================
   SETTINGS TABS
   ============================================================ */
.settings-tabs {
    display: flex; gap: 4px; margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.settings-tab {
    background: none; border: none; cursor: pointer;
    font-family: inherit; font-size: 14px; font-weight: 500;
    color: var(--text-muted); padding: 10px 18px;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    margin-bottom: -1px;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

/* ============================================================
   ACTIVITY FEED (Live Monitor + Logs)
   ============================================================ */
.activity-feed { display: flex; flex-direction: column; gap: 2px; }

.activity-item {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border);
    animation: slideUp 0.25s ease;
}
.activity-item:last-child { border-bottom: none; }

.activity-icon {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 13px; font-weight: 700;
    margin-top: 1px;
}
.activity-success .activity-icon { background: rgba(16,185,129,0.15); color: var(--success); }
.activity-error .activity-icon   { background: rgba(239,68,68,0.15); color: var(--error); }
.activity-warning .activity-icon { background: rgba(245,158,11,0.15); color: var(--warning); }
.activity-info .activity-icon    { background: rgba(59,130,246,0.15); color: var(--info); }

.activity-body { flex: 1; min-width: 0; }
.activity-message { font-size: 13.5px; color: var(--text); line-height: 1.4; }
.activity-meta {
    display: flex; gap: 8px; align-items: center; margin-top: 3px;
    font-size: 11.5px; color: var(--text-dim);
}
.activity-category {
    text-transform: uppercase; letter-spacing: 0.03em;
    background: var(--card-hover); padding: 1px 7px; border-radius: 6px;
    font-weight: 600;
}

/* Modal (namespaced to avoid conflict) */
.modal-x {
    position: fixed; inset: 0; background: rgba(0,0,0,.7);
    backdrop-filter: blur(4px); display: flex; align-items: center;
    justify-content: center; z-index: 1000; padding: 20px;
}
.modal-x.hidden { display: none !important; }
.modal-x-box {
    background: var(--card); border: 1px solid var(--border-light);
    border-radius: 16px; width: 100%; max-width: 460px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.12);
    animation: modalIn .3s ease;
}
.modal-x-wide { max-width: 760px; }
.modal-x-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-x-head h3 { font-size: 18px; font-weight: 600; }
.modal-x-close {
    background: transparent; border: none; color: var(--text-muted);
    font-size: 24px; cursor: pointer; width: 32px; height: 32px;
    border-radius: 8px; display: flex; align-items: center;
    justify-content: center; line-height: 1; transition: all .15s; font-family: inherit;
}
.modal-x-close:hover { background: var(--card-hover); color: var(--text); }
.modal-x-body { padding: 24px; }
.modal-x-body label {
    display: block; font-size: 12px; font-weight: 600;
    color: var(--text-muted); margin-bottom: 6px; margin-top: 14px;
    text-transform: uppercase; letter-spacing: .03em;
}
.modal-x-body label:first-child { margin-top: 0; }
.modal-x-body input {
    width: 100%; padding: 10px 14px; background: var(--bg-2);
    border: 1px solid var(--border); border-radius: 10px;
    color: var(--text); font-size: 14px; font-family: inherit;
}
.modal-x-body input:focus {
    outline: none; border-color: var(--accent-2);
    box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
.modal-x-foot {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 16px 24px; border-top: 1px solid var(--border);
}

/* Log viewer */
.log-status-row {
    display: flex; gap: 24px; padding: 14px 16px;
    background: var(--bg-2); border-radius: 10px; margin-bottom: 14px;
}
.log-status-item { display: flex; flex-direction: column; gap: 4px; }
.log-label {
    font-size: 10px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .6px; font-weight: 600;
}
.log-value { font-size: 15px; font-weight: 600; color: var(--text); }
.log-terminal {
    /* Stays dark on purpose (terminal aesthetic) even in the light theme —
       so its text colors below are the light-on-dark pastel set, not the
       page's normal light-theme (dark-on-light) badge colors. */
    background: #05070a; border: 1px solid #1a1d24;
    border-radius: 10px; padding: 14px; height: 380px;
    overflow-y: auto; font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px; line-height: 1.7; color: #9ca3af;
}
.log-line { padding: 1px 0; word-break: break-word; white-space: pre-wrap; }
.log-line.log-info { color: #9ca3af; }
.log-line.log-success { color: #6ee7b7; }
.log-line.log-warn { color: #fcd34d; }
.log-line.log-error { color: #fca5a5; }

/* Videos list */
.videos-list { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.video-row {
    display: flex; align-items: center; gap: 14px;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 10px; padding: 12px 16px; transition: border-color .15s;
}
.video-row:hover { border-color: var(--border-light); }
.video-thumb-sm {
    width: 48px; height: 48px; border-radius: 8px;
    background: linear-gradient(135deg, var(--card-hover), var(--bg-2)); flex-shrink: 0;
}
.video-body { flex: 1; min-width: 0; }
.video-sub {
    font-size: 11px; color: var(--text-dim); margin-top: 3px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-family: "SF Mono", Menlo, monospace;
}
.video-status-cell {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .5px; padding: 4px 10px; border-radius: 20px;
}
.status-pending { background: rgba(245,158,11,.15); color: #b45309; }
.status-pending_space { background: rgba(59,130,246,.15); color: #1d4ed8; }
.status-uploaded { background: rgba(16,185,129,.15); color: #047857; }
.status-failed { background: rgba(239,68,68,.15); color: #b91c1c; }
.status-downloaded { background: rgba(14,165,233,.15); color: #6d28d9; }

/* Recent videos mini grid */
.recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.video-mini { background: var(--bg-2); border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.video-thumb { height: 90px; background: linear-gradient(135deg, var(--card-hover), var(--bg-2)); }
.video-meta { padding: 10px; }
.video-title {
    font-size: 12px; font-weight: 500; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 5px;
}
.video-mini .video-status {
    font-size: 9.5px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .5px; padding: 2px 7px; border-radius: 20px; display: inline-block;
}

/* Dropbox panel */
.db-account {
    font-size: 12px; color: var(--text-muted);
    margin-bottom: 10px; font-family: "SF Mono", Menlo, monospace;
}
.db-bar-row {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 6px; font-size: 12px;
}
.db-folder { margin-top: 12px; font-size: 12px; color: var(--text-muted); }
.db-folder b { color: #6d28d9; font-family: "SF Mono", Menlo, monospace; }

@media (max-width: 768px) {
    .profiles-list { grid-template-columns: 1fr; }
    .search-input { min-width: 0; flex: 1; }
    .modal-x-wide { max-width: 100%; }
    .log-terminal { height: 260px; }
}

/* ============================================================
   VNC Login Modal
   ============================================================ */
.modal-x-vnc {
    max-width: 960px;
}
.modal-x-body-vnc {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 80vh;
}
.vnc-instructions {
    padding: 12px 20px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}
.vnc-instructions p {
    margin: 4px 0;
    line-height: 1.5;
}
.vnc-frame-wrapper {
    flex: 1;
    background: #000;
    overflow: hidden;
    position: relative;
}
.vnc-frame-wrapper iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}
.vnc-status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text);
    min-height: 46px;
}
.vnc-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #666;
    flex-shrink: 0;
}
.vnc-dot-idle { background: #666; }
.vnc-dot-running { background: #f59e0b; animation: vncPulse 1.2s infinite; }
.vnc-dot-completed { background: #22c55e; }
.vnc-dot-failed { background: #ef4444; }
@keyframes vncPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}
.vnc-log-tail {
    margin-left: auto;
    font-family: "SF Mono", Menlo, monospace;
    font-size: 11px;
    color: var(--text-dim);
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   QR Login Modal
   ============================================================ */
.modal-x-qr { max-width: 500px; }
.modal-x-body-qr { padding: 0; }

.qr-instructions {
    padding: 14px 20px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}
.qr-instructions p { margin: 4px 0; line-height: 1.6; }

.qr-image-wrapper {
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    position: relative;
    min-height: 340px;
}
.qr-image-wrapper img {
    max-width: 280px;
    max-height: 280px;
    width: auto;
    height: auto;
    border-radius: 12px;
    display: block;
}
.qr-loading {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: #666;
    font-size: 13px;
}
.qr-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: qrSpin 0.8s linear infinite;
}
@keyframes qrSpin { to { transform: rotate(360deg); } }

.qr-status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text);
}
.qr-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #666;
    flex-shrink: 0;
}
.qr-dot-idle { background: #666; }
.qr-dot-running { background: #f59e0b; animation: qrPulse 1.2s infinite; }
.qr-dot-completed { background: #22c55e; }
.qr-dot-failed { background: #ef4444; }
@keyframes qrPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.now-processing-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}
.now-processing-active {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
}
.now-processing-cooldown {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #9a3412;
}
.now-processing-icon {
    flex-shrink: 0;
}
.now-processing-spinner {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #93c5fd;
    border-top-color: #1e40af;
    animation: nowProcessingSpin 0.8s linear infinite;
}
@keyframes nowProcessingSpin {
    to { transform: rotate(360deg); }
}

/* Sidebar activity indicator — always visible regardless of page, so it's
   the one reliable place to check whether the system is working. */
.sidebar-activity {
    margin: 0 20px 12px;
    padding: 8px 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    background: var(--bg-2, #f3f4f6);
}
.sidebar-activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.sidebar-activity-idle .sidebar-activity-dot { background: #9ca3af; }
.sidebar-activity-idle .sidebar-activity-text { color: #6b7280; }

.sidebar-activity-working { background: #eff6ff; }
.sidebar-activity-working .sidebar-activity-dot {
    background: #2563eb;
    animation: sidebarActivityPulse 1.2s infinite;
}
.sidebar-activity-working .sidebar-activity-text { color: #1e40af; }

.sidebar-activity-cooldown { background: #fff7ed; }
.sidebar-activity-cooldown .sidebar-activity-dot { background: #ea580c; }
.sidebar-activity-cooldown .sidebar-activity-text { color: #9a3412; }

.sidebar-activity-error { background: #fef2f2; }
.sidebar-activity-error .sidebar-activity-dot {
    background: #dc2626;
    animation: sidebarActivityPulse 1.2s infinite;
}
.sidebar-activity-error .sidebar-activity-text { color: #b91c1c; }

@keyframes sidebarActivityPulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(37,99,235,0.4); }
    50% { opacity: 0.6; }
}
