/* BIIOTECH Lab Intelligence — Dashboard */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --bg-input: #1a1a3e;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --text-muted: #777;
    --accent: #00d4ff;
    --accent-dim: #0097b2;
    --success: #4CAF50;
    --warning: #FFC107;
    --error: #ff4444;
    --border: #2a2a4e;
    --radius: 8px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────── */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header h1 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--accent);
}

.header-center { display: flex; align-items: center; }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--bg-card);
}
.status-badge.running { color: var(--success); }
.status-badge.waiting { color: var(--warning); }
.status-badge.paused { color: var(--warning); }
.status-badge.error { color: var(--error); }
.status-badge.idle { color: var(--text-muted); }
.status-badge.completed { color: var(--accent); }

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.running { background: var(--success); animation: pulse 1.5s infinite; }
.status-dot.waiting { background: var(--warning); animation: pulse 2s infinite; }
.status-dot.paused { background: var(--warning); }
.status-dot.error { background: var(--error); }
.status-dot.idle { background: var(--text-muted); }
.status-dot.completed { background: var(--accent); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.header-right span { white-space: nowrap; }

/* ── Tab navigation ────────────────────────────────────── */
.tab-nav {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 3px;
}
.tab-btn {
    padding: 6px 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
}
.tab-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
}
.tab-btn:hover:not(.active) { color: var(--text-primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Phase bar ─────────────────────────────────────────── */
.phase-bar {
    background: var(--bg-secondary);
    padding: 12px 24px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.phase-step {
    flex: 1;
    text-align: center;
    padding: 8px;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
    background: var(--bg-input);
    color: var(--text-muted);
    transition: all 0.3s;
}
.phase-step.active {
    background: var(--accent);
    color: var(--bg-primary);
    font-weight: 700;
}
.phase-step.done {
    background: var(--success);
    color: #fff;
}
.phase-arrow {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ── Grid layout ───────────────────────────────────────── */
.dashboard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px 24px;
    max-width: 1600px;
    margin: 0 auto;
}

.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

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

.card-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--accent);
}

.card-body {
    padding: 16px;
}

/* ── Progress card ─────────────────────────────────────── */
.progress-bar-container { margin-bottom: 12px; }
.progress-bar-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 0.85rem;
}
.progress-bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.5s ease;
}
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-value {
    font-weight: 600;
    color: var(--accent);
}

/* ── Activity card ─────────────────────────────────────── */
.current-activity { font-size: 0.95rem; }
.activity-lab {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 8px;
}
.activity-detail {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ── Results table (dashboard card) ───────────────────── */
.results-table-wrap { max-height: 300px; overflow-y: auto; }
.results-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.results-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    padding: 8px;
    text-align: left;
    font-weight: 600;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
}
.results-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.results-table tr:hover td { background: var(--bg-card); }

/* ── Errors panel ──────────────────────────────────────── */
.errors-list { max-height: 250px; overflow-y: auto; }
.error-item {
    padding: 8px;
    margin-bottom: 6px;
    border-radius: 4px;
    font-size: 0.8rem;
    border-left: 3px solid;
}
.error-item.error {
    background: rgba(255, 68, 68, 0.1);
    border-color: var(--error);
}
.error-item.warning {
    background: rgba(255, 193, 7, 0.1);
    border-color: var(--warning);
}
.error-time { font-size: 0.75rem; color: var(--text-muted); }
.error-message { color: var(--text-primary); }

/* ── Live log ──────────────────────────────────────────── */
.log-panel { grid-column: 1 / -1; }
.log-controls { display: flex; gap: 8px; }
.log-controls button {
    padding: 4px 10px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}
.log-controls button.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}
.log-stream {
    background: #0d0d1a;
    border-radius: 4px;
    padding: 12px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.78rem;
    line-height: 1.4;
    max-height: 300px;
    overflow-y: auto;
    color: var(--text-secondary);
}
.log-line { padding: 1px 0; }
.log-line.info { color: var(--text-secondary); }
.log-line.warning { color: var(--warning); }
.log-line.error { color: var(--error); }
.log-line .log-time { color: var(--text-muted); margin-right: 8px; }
.log-line .log-type { font-weight: 600; margin-right: 8px; }

/* ── Stats card ────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.stat-box {
    background: var(--bg-input);
    padding: 12px;
    border-radius: var(--radius);
    text-align: center;
}
.stat-box-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent);
}
.stat-box-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── 5-column stats grid ──────────────────────────────────── */
.stats-grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

/* ── Country ranking ──────────────────────────────────────── */
.country-ranking { max-height: 300px; overflow-y: auto; }
.country-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.85rem;
}
.country-row .country-name {
    min-width: 80px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.country-row .country-bar-wrap {
    flex: 1;
    height: 16px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}
.country-row .country-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.4s ease;
}
.country-row .country-count {
    min-width: 32px;
    text-align: right;
    font-weight: 600;
    color: var(--accent);
    font-size: 0.8rem;
}

/* ── Method breakdown ─────────────────────────────────────── */
.method-breakdown { }
.method-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}
.method-row:last-child { border-bottom: none; }
.method-row .method-name { color: var(--text-secondary); }
.method-row .method-count {
    font-weight: 600;
    color: var(--accent);
}

/* ── Bucket breakdown ─────────────────────────────────────── */
.bucket-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.bucket-stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.bucket-stat .bucket-count {
    font-weight: 700;
}

/* ═══════════════════════════════════════════════════════════
   DATA TAB
   ═══════════════════════════════════════════════════════════ */

.data-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}
.data-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.data-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.data-search {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    width: 280px;
    outline: none;
}
.data-search:focus { border-color: var(--accent); }
.data-search::placeholder { color: var(--text-muted); }

.data-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Buttons ──────────────────────────────────────────── */
.btn {
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-accent {
    background: var(--accent);
    color: var(--bg-primary);
}
.btn-accent:hover { background: var(--accent-dim); }
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* ── Data table ───────────────────────────────────────── */
.data-table-wrap {
    overflow-x: auto;
    padding: 0 24px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 900px;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table th {
    background: var(--bg-card);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--accent);
    border-bottom: 2px solid var(--accent-dim);
    white-space: nowrap;
    user-select: none;
}
.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { color: #fff; }
.data-table th.sort-asc::after { content: ' \u25B2'; font-size: 0.7rem; }
.data-table th.sort-desc::after { content: ' \u25BC'; font-size: 0.7rem; }

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.data-table tbody tr:hover td {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Priority bucket badges */
.bucket { padding: 2px 8px; border-radius: 10px; font-weight: 600; font-size: 0.8rem; }
.bucket-1 { background: #ff4444; color: #fff; }
.bucket-2 { background: #ff8800; color: #fff; }
.bucket-3 { background: #FFC107; color: #1a1a2e; }
.bucket-4 { background: #4CAF50; color: #fff; }
.bucket-5 { background: var(--text-muted); color: #fff; }
.bucket-0 { background: var(--bg-input); color: var(--text-muted); }

/* Source badge */
.source-badge { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; }
.source-seed { background: var(--accent-dim); color: #fff; }
.source-discovered { background: #9c27b0; color: #fff; }
.source-scored { background: var(--success); color: #fff; }

/* ── Pagination ───────────────────────────────────────── */
.data-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 16px 24px;
}
.page-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}
.page-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}
.page-btn:hover:not(.active) { border-color: var(--text-muted); }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
    .dashboard { grid-template-columns: 1fr; padding: 8px; }
    .header { padding: 12px; }
    .phase-bar { padding: 8px; overflow-x: auto; }
    .log-panel { grid-column: 1; }
    .data-search { width: 180px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-grid-5 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.9rem;
}
