/* ============================================================
   TMEformer — Bioinformatics Lab Dark Theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300..700;1,9..40,300..700&family=JetBrains+Mono:wght@400;500;600&family=Outfit:wght@400;500;600;700;800&display=swap');

/* ---- Design Tokens ---- */
:root {
    --bg-deep: #060d1f;
    --bg: #0a1929;
    --bg-elevated: #112240;
    --bg-elevated-2: #172a45;
    --border: #1e3a5f;
    --border-light: #233554;
    --text: #ccd6f6;
    --text-bright: #e6f1ff;
    --text-muted: #8892b0;
    --primary: #64ffda;
    --primary-dim: rgba(100, 255, 218, 0.12);
    --primary-glow: rgba(100, 255, 218, 0.25);
    --accent: #57cbff;
    --accent-dim: rgba(87, 203, 255, 0.12);
    --coral: #ff6b6b;
    --coral-dim: rgba(255, 107, 107, 0.12);
    --amber: #ffd93d;
    --amber-dim: rgba(255, 217, 61, 0.12);
    --success: #64ffda;
    --danger: #ff6b6b;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(100, 255, 218, 0.08);
    --sidebar-w: 220px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 10% 10%, rgba(100, 255, 218, 0.04) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 90% 80%, rgba(87, 203, 255, 0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

body > * { position: relative; z-index: 1; }

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent); }

/* ---- Fade-up animation ---- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

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

.main-content {
    animation: fadeUp 0.3s ease both;
}

/* ============================================================
   Layout: Sidebar
   ============================================================ */

.app-layout { display: flex; min-height: 100vh; }

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

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand a {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-bright);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-brand a:hover { color: var(--primary); }

.brand-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--primary);
    display: inline-block;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 500;
    transition: all var(--transition);
    text-decoration: none;
}

.sidebar-nav a:hover {
    background: var(--primary-dim);
    color: var(--text-bright);
}

.sidebar-nav a.active {
    background: var(--primary-dim);
    color: var(--primary);
    font-weight: 600;
}

.sidebar-nav a .nav-icon {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 2.5rem 3rem;
    min-height: 100vh;
}

/* ============================================================
   Typography
   ============================================================ */

h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 1.5rem;
    letter-spacing: -0.01em;
}

h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-bright);
    margin: 2rem 0 0.75rem;
    padding-left: 0.85rem;
    position: relative;
}

h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.15em;
    bottom: 0.15em;
    width: 3px;
    background: var(--primary);
    border-radius: 2px;
}

h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 0.4rem;
}

/* ============================================================
   Hero
   ============================================================ */

.hero {
    text-align: center;
    padding: 4rem 1rem 3rem;
}

.hero h1 {
    font-size: 2.6rem;
    font-weight: 800;
    color: var(--text-bright);
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.hero h1 .highlight {
    color: var(--primary);
    text-shadow: 0 0 30px var(--primary-glow);
}

.hero-desc {
    color: var(--text-muted);
    max-width: 520px;
    margin: 0 auto 2.5rem;
    font-size: 1.05rem;
    line-height: 1.7;
}

/* ---- Framework Gallery ---- */
.framework-gallery {
    max-width: 900px;
    margin: 3rem auto 0;
}

.framework-gallery h2 {
    text-align: center;
    padding-left: 0;
    margin-bottom: 1.25rem;
}

.framework-gallery h2::before { display: none; }

.gallery-viewport {
    position: relative;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.gallery-track {
    position: relative;
}

.gallery-slide {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    opacity: 0;
    transition: opacity 0.5s ease, transform 0.5s ease;
    transform: translateX(20px);
    pointer-events: none;
}

.gallery-slide.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.gallery-slide img {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    display: block;
}

.slide-caption {
    margin-top: 1rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
}

.gallery-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated-2);
    color: var(--text-bright);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    z-index: 10;
    line-height: 1;
}

.gallery-btn:hover {
    background: var(--primary);
    color: var(--bg-deep);
    border-color: var(--primary);
}

.gallery-btn.prev { left: 0.5rem; }
.gallery-btn.next { right: 0.5rem; }

.gallery-dots {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.gallery-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    cursor: pointer;
    transition: all var(--transition);
}

.gallery-dots .dot.active {
    background: var(--primary);
    box-shadow: 0 0 6px var(--primary-glow);
    transform: scale(1.2);
}

/* ---- Home Footer ---- */
.home-footer {
    text-align: center;
    margin-top: 2.5rem;
    padding: 1.25rem 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.home-footer a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition);
}

.home-footer a:hover {
    color: var(--primary);
}

.home-footer .footer-sep {
    margin: 0 0.75rem;
    opacity: 0.4;
}

/* ---- Feature Cards ---- */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
    max-width: 1000px;
    margin: 0 auto;
}

.feature-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem 1.5rem;
    text-align: left;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 220px;
}

.feature-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    opacity: 0;
    transition: opacity var(--transition);
}

.feature-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow), var(--shadow-glow);
}

.feature-card:hover::before { opacity: 1; }

.feature-card .card-icon {
    font-size: 1.5rem;
    margin-bottom: 0.6rem;
    display: block;
}

.feature-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 0.35rem;
}

.feature-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.feature-card .card-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: auto;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    transition: gap var(--transition);
}

.feature-card:hover .card-link { gap: 0.65rem; }

/* ============================================================
   Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.3rem;
    border-radius: var(--radius);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--bg-deep);
    box-shadow: 0 0 12px rgba(100, 255, 218, 0.15);
}

.btn-primary:hover {
    background: #7dffd0;
    box-shadow: 0 0 20px rgba(100, 255, 218, 0.3);
    transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

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

.btn-secondary:hover {
    background: var(--bg-elevated-2);
    border-color: var(--border-light);
    color: var(--text-bright);
}

.btn-cancel {
    background: var(--coral-dim);
    color: var(--coral);
    border: 1px solid rgba(255, 107, 107, 0.3);
}

.btn-cancel:hover {
    background: rgba(255, 107, 107, 0.2);
    border-color: var(--coral);
}

.btn-hero {
    padding: 0.7rem 2.2rem;
    font-size: 0.95rem;
    border-radius: 999px;
}

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

/* ---- Tooltip via data-tooltip attribute ---- */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    left: 100%;
    background: var(--bg-deep);
    color: var(--text-bright);
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.4;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 100;
}

[data-tooltip]::before {
    content: '';
    position: absolute;
    top: calc(100% + 2px);
    left: 100%;
    margin-left: -4px;
    border: 5px solid transparent;
    border-bottom-color: var(--border);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 100;
}

[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================================
   Forms
   ============================================================ */

.form-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 620px;
    box-shadow: var(--shadow);
    position: relative;
}

#query-form.form-card {
    max-width: 100%;
}

.form-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.form-group { margin-bottom: 1.2rem; }

.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 140px;
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    font-size: 0.84rem;
    color: var(--text);
    letter-spacing: 0.01em;
}

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-family: 'DM Sans', sans-serif;
    color: var(--text-bright);
    background: var(--bg);
    transition: all var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-dim);
    background: var(--bg-elevated-2);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238892b0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    padding-right: 2.2rem;
}

.form-group input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.form-group small {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.param-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 1rem;
}

/* ---- Radio Group ---- */
.radio-group {
    display: flex;
    gap: 1rem;
    margin-top: 0.3rem;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 500;
    font-size: 0.88rem;
    cursor: pointer;
}

.radio-group input[type="radio"] {
    accent-color: var(--primary);
}

/* ---- Gene Selector ---- */
.gene-selector { position: relative; }

.gene-selector-input {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 38px;
    cursor: text;
    background: var(--bg);
    transition: all var(--transition);
}

.gene-selector-input:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-dim);
}

.gene-selector-input input {
    border: none;
    outline: none;
    flex: 1;
    min-width: 120px;
    font-size: 0.88rem;
    padding: 0;
    font-family: 'DM Sans', sans-serif;
    color: var(--text-bright);
    background: transparent;
}

.gene-selector-input input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.gene-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--primary-dim);
    color: var(--primary);
    padding: 0.12rem 0.5rem;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
}

.gene-tag .remove {
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1;
    opacity: 0.5;
    transition: opacity var(--transition);
}

.gene-tag .remove:hover { opacity: 1; }

.gene-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 250px;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 100;
    display: none;
}

.gene-dropdown.open { display: block; }

.gene-option {
    padding: 0.45rem 0.7rem;
    cursor: pointer;
    font-size: 0.84rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    transition: background var(--transition);
}

.gene-option:hover { background: var(--primary-dim); }

.gene-option.selected {
    background: var(--primary-dim);
    color: var(--primary);
    font-weight: 600;
}

.gene-option input[type="checkbox"],
.gene-option input[type="radio"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    margin: 0;
    flex-shrink: 0;
}

.gene-option:has(input:disabled) {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.gene-selector-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ============================================================
   Task / Progress Cards
   ============================================================ */

.task-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    max-width: 620px;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.task-row {
    display: flex;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

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

.task-label {
    font-weight: 600;
    min-width: 120px;
    font-size: 0.82rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.task-value {
    font-size: 0.88rem;
    color: var(--text-bright);
    font-family: 'JetBrains Mono', monospace;
}

.task-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.progress-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    max-width: 620px;
    margin-top: 1.25rem;
    box-shadow: var(--shadow);
}

.progress-header { margin-bottom: 0.75rem; }

.progress-details {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.progress-row {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.progress-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.progress-value {
    font-size: 0.95rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-bright);
}

.log-details {
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
}

.log-summary {
    cursor: pointer;
    font-size: 0.78rem;
    color: var(--text-muted);
    user-select: none;
}

.log-output {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-deep);
    color: var(--text-muted);
    padding: 0.75rem;
    border-radius: var(--radius);
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    white-space: pre-wrap;
    word-break: break-all;
    margin-top: 0.5rem;
    border: 1px solid var(--border);
}

/* ============================================================
   Status Badges
   ============================================================ */

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-queued { background: rgba(136, 146, 176, 0.15); color: #8892b0; }
.status-running { background: var(--accent-dim); color: var(--accent); }
.status-success { background: var(--primary-dim); color: var(--primary); }
.status-failed { background: var(--coral-dim); color: var(--coral); }
.status-done { background: var(--primary-dim); color: var(--primary); }

/* ============================================================
   Alerts
   ============================================================ */

.alert {
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.88rem;
    border: 1px solid transparent;
}

.alert-error {
    background: var(--coral-dim);
    color: var(--coral);
    border-color: rgba(255, 107, 107, 0.25);
}

/* ============================================================
   Spinner
   ============================================================ */

.spinner {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.spinner-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.88rem;
}

.spinner-inline::before {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid var(--primary-dim);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.queued-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.88rem;
}

.queued-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* ============================================================
   Tables
   ============================================================ */

.result-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.25rem 0;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    table-layout: auto;
}

.result-table th,
.result-table td {
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 0;
}

/* Give the first column a reasonable fixed width */
.result-table th:first-child,
.result-table td:first-child {
    width: 160px;
}

.result-table th {
    background: var(--bg-elevated-2);
    padding: 0.7rem 1rem;
    text-align: left;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.result-table th:not(:first-child) { text-align: right; }

.table-subtitle {
    margin: -0.5rem 0 0.5rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.result-table td {
    padding: 0.55rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.84rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text);
}

.result-table td:not(:first-child) { text-align: right; }

/* Action column (last col) — compact, centered (not for p-value tables) */
#pval-table-container .result-table th:last-child,
#pval-table-container .result-table td:last-child {
    width: auto;
    text-align: right;
    min-width: 80px;
}

/* Query tables: keep Analyze column compact */
#main-conditions-table .result-table th:last-child,
#main-conditions-table .result-table td:last-child,
#background-conditions-table .result-table th:last-child,
#background-conditions-table .result-table td:last-child {
    width: 1%;
    white-space: nowrap;
    text-align: center;
}

/* Stat result tables: keep Analyze column compact */
#pval-table-container .result-table th:last-child,
#pval-table-container .result-table td:last-child {
    width: auto;
    text-align: right;
    min-width: 80px;
}

.task-actions-inline {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.task-actions-inline a {
    font-size: 0.78rem;
    padding: 0.2rem 0.5rem;
    color: var(--primary);
    font-weight: 600;
}

.task-actions-inline .btn-cancel {
    font-size: 0.78rem;
    padding: 0.15rem 0.5rem;
}

.result-table tbody tr { transition: background var(--transition); }
.result-table tbody tr:hover { background: var(--bg-elevated-2); }

/* Sortable columns */
.result-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.5rem;
}

.result-table th.sortable:hover {
    background: var(--bg);
    color: var(--text-bright);
}

.result-table th.sortable .sort-arrow {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.68rem;
    color: var(--text-muted);
}

.result-table th.sortable .sort-arrow.active {
    color: var(--primary);
}

/* Bar cell */
.bar-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    justify-content: flex-end;
}

.bar {
    height: 8px;
    border-radius: 4px;
    min-width: 4px;
    transition: width 0.3s ease;
    flex-shrink: 0;
}

.bar-label {
    font-size: 0.78rem;
    font-family: 'JetBrains Mono', monospace;
    white-space: nowrap;
    color: var(--text-muted);
    min-width: 52px;
    text-align: right;
}

/* Search bar */
.table-search-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.table-search-bar input {
    flex: 1;
    max-width: 300px;
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.84rem;
    font-family: 'DM Sans', sans-serif;
    color: var(--text-bright);
    background: var(--bg);
    transition: all var(--transition);
}

.table-search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-dim);
}

.table-search-bar input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.table-search-bar .search-count {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    font-size: 0.84rem;
    color: var(--text-muted);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.pagination-controls button {
    padding: 0.25rem 0.6rem;
    font-size: 0.78rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: all var(--transition);
}

.pagination-controls button:hover:not(:disabled) {
    background: var(--primary);
    color: var(--bg-deep);
    border-color: var(--primary);
}

.pagination-controls button:disabled {
    opacity: 0.3;
    cursor: default;
}

.pagination-controls select {
    padding: 0.2rem 0.35rem;
    font-size: 0.78rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
}

/* ============================================================
   Details / Collapsible
   ============================================================ */

details summary {
    font-weight: 600;
    padding: 0.5rem 0;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.84rem;
    transition: color var(--transition);
    list-style: none;
}

details summary::-webkit-details-marker { display: none; }

details summary::before {
    content: '▸ ';
    display: inline-block;
    transition: transform var(--transition);
}

details[open] summary::before { transform: rotate(90deg); }

details summary:hover { color: var(--text-bright); }

details[open] summary {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* ============================================================
   ISP Submit — Two-Column Layout
   ============================================================ */

.submit-layout {
    display: flex;
    gap: 2rem;
    align-items: stretch;
    min-height: 600px;
}

.submit-layout > .form-card {
    flex: 1;
    min-width: 0;
}

.submit-figure {
    flex: 0 0 420px;
    position: relative;
}

.submit-figure img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* ---- Perturbation Plan ---- */

.plan-card {
    background: linear-gradient(135deg, var(--bg-elevated) 0%, var(--bg-elevated-2) 100%);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem 2rem;
    margin: 2.5rem 0 0;
    box-shadow: none;
    max-width: 100%;
}

.plan-card h2 {
    margin-top: 0;
    margin-bottom: 1rem;
}

.plan-row {
    display: flex;
    gap: 1rem;
    padding: 0.6rem 0;
    border-bottom: 1px dashed var(--border);
    font-size: 0.88rem;
    align-items: flex-start;
}

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

.plan-label {
    min-width: 100px;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
}

.plan-value {
    color: var(--text-bright);
    line-height: 1.6;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
    .sidebar { width: 56px; }
    .sidebar-brand a span:not(.brand-dot),
    .sidebar-nav a span:not(.nav-icon),
    .sidebar-footer { display: none; }
    .sidebar-nav a { justify-content: center; padding: 0.6rem; }
    .main-content { margin-left: 56px; padding: 2rem 1.5rem; }
    .hero h1 { font-size: 2rem; }
    .feature-grid { grid-template-columns: 1fr; }
    .submit-layout { flex-direction: column; min-height: auto; }
    .submit-figure { flex: none; width: 100%; max-width: 480px; margin: 1.5rem auto 0; position: static; }
    .submit-figure img { position: static; width: 100%; height: auto; object-fit: unset; }
    .summary-cards { grid-template-columns: 1fr; }
    .chart-row { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 1.5rem 1rem; }
    .form-card { padding: 1.25rem; }
    .param-grid { grid-template-columns: 1fr; }
    .hero { padding: 2.5rem 0.5rem 2rem; }
    .hero h1 { font-size: 1.6rem; }
}

/* ============================================================
   Summary Section (ISP Query charts)
   ============================================================ */

.summary-section {
    margin-top: 2.5rem;
    padding: 1.5rem 0;
}

.summary-section > h2 {
    font-size: 1.1rem;
    margin-bottom: 1.2rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-bright);
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.2rem 1.5rem;
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.summary-card.type-target::before { background: var(--primary); }
.summary-card.type-tme-comp::before { background: #ffa726; }
.summary-card.type-tme-rank::before { background: #ab47bc; }

.summary-card-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.summary-card-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-bright);
    line-height: 1.2;
}

.summary-card-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    line-height: 1.5;
}

.chart-row {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 1.5rem;
}

.chart-container {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

/* Volcano section — wider left panel */
#pval-section .chart-row {
    grid-template-columns: 1fr 340px;
}

/* Bar chart tabs */
.bar-tabs {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.bar-tab {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.78rem;
    padding: 0.25rem 0.7rem;
    cursor: pointer;
    transition: all var(--transition);
}

.bar-tab:hover {
    border-color: var(--border-light);
    color: var(--text-bright);
}

.bar-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--bg-deep);
    font-weight: 600;
}

.bar-tab.active[data-key="target_rank"] {
    background: #64ffda;
    border-color: #64ffda;
}

.bar-tab.active[data-key="tme_composition"] {
    background: #ffa726;
    border-color: #ffa726;
}

.bar-tab.active[data-key="tme_rank"] {
    background: #ab47bc;
    border-color: #ab47bc;
}

/* ============================================================
   Re-analyze overlay
   ============================================================ */

#reanalyze-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 26, 0.85);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.overlay-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem 3rem;
    text-align: center;
    min-width: 300px;
    animation: fadeUp 0.3s ease both;
}

.overlay-content p {
    color: var(--text-bright);
    font-size: 1.1rem;
    margin: 1rem 0 0.5rem;
}

.overlay-spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.overlay-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
}

.overlay-icon-success {
    background: rgba(100, 255, 218, 0.15);
    color: #64ffda;
}

.overlay-icon-error {
    background: rgba(255, 107, 107, 0.15);
    color: #ff6b6b;
}

.overlay-error {
    color: var(--text-muted) !important;
    font-size: 0.9rem !important;
    max-width: 400px;
    word-break: break-word;
    margin-bottom: 1.2rem !important;
}

.overlay-content .btn {
    margin-top: 0.5rem;
    min-width: 80px;
}

/* Boxplot — constrain width, center */
#boxplot-chart {
    max-width: 800px;
    margin: 0 auto;
}

/* ---- Multi-select dropdown ---- */
.multi-select { position: relative; }

.ms-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 40px;
    padding: 0.45rem 0.75rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.88rem;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
    gap: 0.4rem;
    flex-wrap: wrap;
}

.ms-trigger:hover, .ms-trigger.open {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-dim);
}

.ms-placeholder { flex: 1; }
.ms-arrow { font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; }

.ms-select-all-btn {
    flex-shrink: 0;
    padding: 0.1rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 700;
    font-family: 'DM Sans', sans-serif;
    color: var(--primary);
    background: var(--primary-dim);
    border: 1px solid rgba(100, 255, 218, 0.2);
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1.3;
}
.ms-select-all-btn:hover {
    background: var(--primary);
    color: var(--bg-deep);
}

.ms-clear-btn {
    background: var(--coral-dim);
    color: var(--coral);
    border-color: rgba(255, 107, 107, 0.2);
}
.ms-clear-btn:hover {
    background: var(--coral);
    color: var(--bg-deep);
}

.ms-tags { display: flex; gap: 0.35rem; flex-wrap: wrap; flex: 1; }

.ms-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.5rem;
    background: var(--primary-dim);
    color: var(--primary);
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
}

.ms-tag .ms-tag-remove { cursor: pointer; opacity: 0.7; font-size: 0.9rem; line-height: 1; }
.ms-tag .ms-tag-remove:hover { opacity: 1; }

.ms-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    z-index: 200;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-height: 280px;
    display: flex;
    flex-direction: column;
}

.ms-search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-deep);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-bright);
    font-size: 0.88rem;
    outline: none;
    font-family: inherit;
}
.ms-search-input::placeholder { color: var(--text-muted); }

.ms-list { overflow-y: auto; max-height: 230px; padding: 0.25rem 0; }

.ms-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 0.88rem;
    color: var(--text);
    white-space: nowrap;
}
.ms-option:hover { background: var(--primary-dim); }

.ms-option input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }

.ms-option.selected {
    background: var(--primary-dim);
    color: var(--primary);
    font-weight: 500;
}

/* ============================================================
   Overall Header Panel (merged task + params + significance)
   ============================================================ */

.overall-header {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.overall-row {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    padding: 0.4rem 0;
}

.overall-row-meta {
    align-items: center;
}

.overall-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 0;
}

.overall-label {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-muted);
    min-width: 160px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.overall-summary {
    flex: 1;
    color: var(--text);
    font-size: 0.88rem;
    line-height: 1.5;
}

.meta-id {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-bright);
    font-size: 0.95rem;
    font-weight: 500;
}
