:root {
    --bg-dark: #090b10;
    --bg-card: #12151f;
    --bg-card-hover: #181c29;
    --bg-input: #0d1017;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: #6366f1;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --radius-lg: 16px;
    --radius-md: 10px;
    --shadow-card: 0 12px 32px -8px rgba(0, 0, 0, 0.55);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 12% 10%, rgba(99, 102, 241, 0.14), transparent 32%),
        radial-gradient(circle at 88% 15%, rgba(16, 185, 129, 0.10), transparent 30%);
    color: var(--text-main);
    min-height: 100vh;
    line-height: 1.5;
}

.app-container {
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

/* Header */
.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    padding-bottom: 22px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.brand-box {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 20px;
    color: #fff;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.brand-title h1 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge-domain {
    font-size: 0.74rem;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    background: rgba(99, 102, 241, 0.16);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.brand-title p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.node-status {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-card);
    padding: 9px 15px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    font-size: 0.82rem;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent-emerald);
    box-shadow: 0 0 10px var(--accent-emerald);
}

.status-dot.offline {
    background: var(--accent-rose);
    box-shadow: 0 0 10px var(--accent-rose);
}

/* Platform Pills */
.platform-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.plat-pill {
    font-size: 0.77rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: #d1d5db;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.plat-pill.highlight {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.35);
    color: #6ee7b7;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 22px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    overflow-x: auto;
}

.tab-btn {
    background: var(--bg-card);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

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

.tab-btn.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-card);
    margin-bottom: 22px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 10px;
}

.card-title {
    font-size: 1.08rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 9px;
}

/* URL Bar */
.url-bar-group {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.url-input-wrap {
    flex: 1;
    min-width: 260px;
    position: relative;
    display: flex;
    align-items: center;
}

.url-input {
    width: 100%;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    color: var(--text-main);
    padding: 14px 110px 14px 16px;
    border-radius: var(--radius-md);
    font-size: 0.96rem;
    outline: none;
    transition: border-color 0.2s;
}

.url-input:focus {
    border-color: var(--border-focus);
}

.paste-btn {
    position: absolute;
    right: 8px;
    background: rgba(255, 255, 255, 0.07);
    color: #d1d5db;
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}

.paste-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

/* Buttons */
.btn {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.18s ease;
    text-decoration: none;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #fff;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-emerald {
    background: var(--accent-emerald);
    color: #052e16;
    font-weight: 700;
}

.btn-emerald:hover:not(:disabled) {
    background: #34d399;
}

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

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
}

.btn-danger {
    background: rgba(244, 63, 94, 0.14);
    color: #fda4af;
    border-color: rgba(244, 63, 94, 0.3);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(244, 63, 94, 0.25);
}

.btn-sm {
    padding: 7px 13px;
    font-size: 0.8rem;
    border-radius: 8px;
}

/* Options Grid */
.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    padding-top: 10px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-control {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.88rem;
    outline: none;
}

.form-control:focus {
    border-color: var(--border-focus);
}

textarea.form-control {
    min-height: 130px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}

.chk-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    cursor: pointer;
    user-select: none;
}

.chk-label input {
    accent-color: var(--accent-primary);
    width: 16px;
    height: 16px;
}

/* Analysis Preview Card */
.preview-box {
    display: none;
    background: rgba(99, 102, 241, 0.06);
    border: 1px solid rgba(99, 102, 241, 0.28);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 18px;
    gap: 18px;
    align-items: flex-start;
}

.preview-box.visible {
    display: flex;
    flex-wrap: wrap;
}

.preview-thumb {
    width: 210px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    background: #000;
    flex-shrink: 0;
}

.preview-meta {
    flex: 1;
    min-width: 240px;
}

.preview-meta h3 {
    font-size: 1.05rem;
    margin-bottom: 6px;
}

.preview-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.meta-tag {
    font-size: 0.76rem;
    padding: 3px 9px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.07);
    color: #e5e7eb;
}

/* KPI Stats Row */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 15px 18px;
}

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

.stat-value {
    font-size: 1.45rem;
    font-weight: 800;
    margin-top: 4px;
}

/* Job Queue & History List */
.job-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.job-item {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 15px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    transition: border-color 0.2s;
}

.job-item:hover {
    border-color: rgba(255, 255, 255, 0.18);
}

.job-main {
    flex: 1;
    min-width: 250px;
}

.job-top {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.plat-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 5px;
    background: rgba(99, 102, 241, 0.2);
    color: #c7d2fe;
    text-transform: uppercase;
}

.status-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 5px;
}

.status-completed {
    background: rgba(16, 185, 129, 0.18);
    color: #6ee7b7;
}

.status-downloading, .status-processing, .status-queued {
    background: rgba(245, 158, 11, 0.18);
    color: #fcd34d;
}

.status-failed, .status-cancelled {
    background: rgba(244, 63, 94, 0.18);
    color: #fda4af;
}

.job-title {
    font-weight: 600;
    font-size: 0.95rem;
    word-break: break-word;
}

.job-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 3px;
}

.progress-wrap {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 99px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-emerald));
    transition: width 0.35s ease;
}

.job-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Toast Notification */
.toast-box {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #1e2230;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    padding: 13px 18px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    font-size: 0.88rem;
    z-index: 9999;
    display: none;
}

.toast-box.show {
    display: block;
}

@media (max-width: 720px) {
    .app-container {
        padding: 16px 12px 48px;
    }
    .card {
        padding: 16px 14px;
        border-radius: 14px;
    }
    .top-header {
        gap: 12px;
        padding-bottom: 16px;
        margin-bottom: 18px;
    }
    .brand-title h1 {
        font-size: 1.15rem;
        flex-wrap: wrap;
    }
    .node-status {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 8px;
    }
    .nav-tabs {
        gap: 6px;
        padding-bottom: 10px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .nav-tabs::-webkit-scrollbar {
        display: none;
    }
    .tab-btn {
        padding: 9px 14px;
        font-size: 0.84rem;
    }
    .url-bar-group {
        flex-direction: column;
    }
    .url-input-wrap {
        min-width: 0;
        width: 100%;
    }
    /* 16px evita el zoom automático de iOS al enfocar campos */
    .url-input,
    .form-control,
    textarea,
    select {
        font-size: 16px;
    }
    .btn {
        width: 100%;
        min-height: 44px;
    }
    .job-actions .btn,
    .card-header .btn,
    .btn-sm {
        width: auto;
        min-height: 38px;
    }
    .job-item {
        padding: 13px 12px;
        gap: 10px;
    }
    .job-main {
        min-width: 0;
    }
    .preview-box {
        gap: 12px;
    }
    .preview-thumb {
        width: 100%;
        height: 170px;
    }
    .preview-meta {
        min-width: 0;
    }
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
    .stat-card {
        padding: 12px 14px;
    }
    .toast-box {
        left: 12px;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        max-width: none;
        text-align: center;
    }
}

@media (max-width: 380px) {
    .app-container {
        padding: 12px 10px 40px;
    }
    .card {
        padding: 14px 12px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .brand-logo {
        width: 40px;
        height: 40px;
        font-size: 17px;
    }
}
