@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root, [data-theme="dark"] {
    --bg: #0c0e14;
    --bg-surface: #12141c;
    --bg-elevated: #181a24;
    --bg-hover: #1e2030;
    --border: #262838;
    --border-subtle: #1e2030;
    --text: #e8eaf0;
    --text-muted: #8b8fa3;
    --text-faint: #5c5f73;
    --accent: #6c63ff;
    --accent-hover: #7f78ff;
    --accent-subtle: rgba(108,99,255,0.1);
    --green: #22c55e;
    --green-subtle: rgba(34,197,94,0.1);
    --yellow: #eab308;
    --yellow-subtle: rgba(234,179,8,0.1);
    --red: #ef4444;
    --red-subtle: rgba(239,68,68,0.1);
    --radius: 8px;
    --radius-sm: 6px;
    --term-bg: #0a0a1a;
    --zoom-backdrop: rgba(0,0,0,0.92);
}

[data-theme="light"] {
    --bg: #f5f5f7;
    --bg-surface: #ffffff;
    --bg-elevated: #f0f0f3;
    --bg-hover: #e8e8ec;
    --border: #d4d4d8;
    --border-subtle: #e4e4e8;
    --text: #1a1a2e;
    --text-muted: #6b6b80;
    --text-faint: #9b9bae;
    --accent: #5b52e6;
    --accent-hover: #4840d4;
    --accent-subtle: rgba(91,82,230,0.08);
    --green: #16a34a;
    --green-subtle: rgba(22,163,74,0.08);
    --yellow: #ca8a04;
    --yellow-subtle: rgba(202,138,4,0.08);
    --red: #dc2626;
    --red-subtle: rgba(220,38,38,0.08);
    --term-bg: #1a1a2e;
    --zoom-backdrop: rgba(0,0,0,0.6);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overflow: hidden;
    height: 100vh;
    display: flex;
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Sidebar */
#sidebar {
    width: 220px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px 16px 16px;
}

.sidebar-header h1 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

#status {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-faint);
    display: flex;
    align-items: center;
    gap: 6px;
}

#status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    flex-shrink: 0;
}

#status.connected { color: var(--green); }
#status.connected::before { background: var(--green); box-shadow: 0 0 6px var(--green); }
#status.error { color: var(--red); }
#status.error::before { background: var(--red); }

.sidebar-nav {
    list-style: none;
    padding: 4px 8px;
    flex: 1;
}

.nav-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    transition: all 0.15s ease;
}

.nav-item:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.nav-item.active {
    color: var(--accent);
    background: var(--accent-subtle);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

#theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    font-weight: 500;
    width: 100%;
    margin-bottom: 12px;
    transition: all 0.15s;
}

#theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text);
}

#sidebar-summary {
    font-size: 11px;
    color: var(--text-faint);
}

#sidebar-summary .summary-line {
    margin-bottom: 3px;
    display: flex;
    justify-content: space-between;
}

#sidebar-summary .summary-value { color: var(--text-muted); font-weight: 500; }
#sidebar-summary .summary-value.ok { color: var(--green); }
#sidebar-summary .summary-value.warn { color: var(--yellow); }
#sidebar-summary .summary-value.bad { color: var(--red); }

/* Main content */
#content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.view {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* Labs Grid */
#view-labs {
    background: var(--bg);
}

#grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px;
    overflow-y: auto;
    align-content: start;
}

.cell {
    background: var(--term-bg, var(--bg-surface));
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.cell:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 4px 12px rgba(108,99,255,0.15);
}

.cell-label {
    position: absolute;
    top: 6px;
    left: 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-faint);
    z-index: 2;
    pointer-events: none;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.cell-terminal {
    transform-origin: top left;
    pointer-events: none;
}

.cell.disconnected {
    border-color: var(--red);
    opacity: 0.5;
}

.cell.opted-out {
    opacity: 0.35;
}

.cell-inactive {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 9px;
    font-weight: 600;
    color: var(--red);
    background: var(--red-subtle);
    padding: 1px 6px;
    border-radius: 8px;
    z-index: 2;
    pointer-events: none;
    animation: pulse 2s infinite;
}

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

.cell-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--text-faint);
    z-index: 1;
    pointer-events: none;
}

/* Panels */
.panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 16px;
    padding: 24px;
}

.panel h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

/* Info table */
.info-table {
    width: 100%;
    border-collapse: collapse;
}

.info-table td {
    padding: 10px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border-subtle);
}

.info-table tr:last-child td {
    border-bottom: none;
}

.info-table td:first-child {
    color: var(--text-muted);
    width: 140px;
    font-weight: 500;
}

.info-table td:last-child {
    color: var(--text);
}

.info-table code {
    background: var(--bg-elevated);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    border: 1px solid var(--border);
}

.info-table .value-ok { color: var(--green); }
.info-table .value-warn { color: var(--yellow); }
.info-table .value-bad { color: var(--red); }

/* Instance table */
.instance-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.instance-table th {
    text-align: left;
    padding: 10px 16px;
    color: var(--text-faint);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.instance-table td {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.instance-table tr:last-child td {
    border-bottom: none;
}

.instance-table tr:hover td {
    background: var(--bg-hover);
}

.instance-table strong {
    font-weight: 600;
    color: var(--text);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 500;
}

.badge::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
}

.badge-running { background: var(--green-subtle); color: var(--green); }
.badge-running::before { background: var(--green); }
.badge-pending { background: var(--yellow-subtle); color: var(--yellow); }
.badge-pending::before { background: var(--yellow); }
.badge-error { background: var(--red-subtle); color: var(--red); }
.badge-error::before { background: var(--red); }
.badge-connected { background: var(--green-subtle); color: var(--green); }
.badge-connected::before { background: var(--green); }
.badge-disconnected { background: rgba(92,95,115,0.1); color: var(--text-faint); }
.badge-disconnected::before { background: var(--text-faint); }

.instance-table a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.instance-table a:hover {
    text-decoration: underline;
}

/* Actions */
.actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.action-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.action-group label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    min-width: 80px;
}

.scale-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.scale-controls .btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
}

#instance-count {
    min-width: 40px;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

/* Buttons */
.btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s ease;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-faint);
}

.btn-danger {
    color: var(--red);
    border-color: rgba(239,68,68,0.3);
}

.btn-danger:hover {
    background: var(--red-subtle);
    border-color: var(--red);
}

.btn-small {
    padding: 4px 12px;
    font-size: 12px;
}

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-accent:hover {
    background: var(--accent-hover);
}

/* Zoom overlay */
#zoom-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--zoom-backdrop);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

#zoom-overlay.hidden {
    display: none;
}

#zoom-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}

#zoom-title {
    font-size: 14px;
    font-weight: 600;
}

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

#zoom-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
}

#zoom-close:hover {
    color: var(--red);
    background: var(--red-subtle);
}

#zoom-terminal {
    flex: 1;
    padding: 8px;
}

/* Activity */
.gauge-row {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.gauge-card {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}

.gauge-card .gauge-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.gauge-card .gauge-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

.gauge-card .gauge-value.low { color: var(--red); }
.gauge-card .gauge-value.medium { color: var(--yellow); }
.gauge-card .gauge-value.high { color: var(--green); }

.chart-container {
    height: 200px;
    position: relative;
}

.activity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.participant-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.participant-card.opted-out {
    opacity: 0.35;
}

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

.participant-name {
    font-weight: 600;
    font-size: 13px;
}

.participant-relative {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 99px;
}

.participant-relative.above { background: var(--green-subtle); color: var(--green); }
.participant-relative.average { background: var(--yellow-subtle); color: var(--yellow); }
.participant-relative.below { background: var(--red-subtle); color: var(--red); }

.participant-gauges {
    display: flex;
    gap: 8px;
}

.mini-gauge {
    flex: 1;
    text-align: center;
}

.mini-gauge .mini-label {
    font-size: 10px;
    color: var(--text-faint);
    margin-bottom: 2px;
}

.mini-gauge .mini-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.mini-gauge .mini-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}

.mini-gauge .mini-value {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 2px;
}

.participant-chart {
    height: 50px;
}

/* Alias input */
.alias-input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
    width: 120px;
    outline: none;
    transition: border-color 0.15s;
}

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

.alias-input::placeholder {
    color: var(--text-faint);
}

/* Broadcast */
.panel-hint {
    font-size: 12px;
    color: var(--text-faint);
    margin-bottom: 16px;
    line-height: 1.6;
}

.broadcast-input {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.broadcast-input input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

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

.broadcast-input input::placeholder {
    color: var(--text-faint);
}

.broadcast-log {
    max-height: 200px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
}

.broadcast-log-entry {
    padding: 4px 0;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    gap: 12px;
}

.broadcast-log-time {
    color: var(--text-faint);
    white-space: nowrap;
}

.broadcast-log-cmd {
    color: var(--accent);
}

.broadcast-log-result {
    color: var(--text-muted);
    margin-left: auto;
}

.timer-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

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

.template-item {
    position: relative;
}

.template-del {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.15s;
}

.template-item:hover .template-del {
    opacity: 1;
}

.template-del:hover {
    color: var(--red);
    background: var(--red-subtle);
}

.template-editor {
    max-width: 400px;
}

.template-add .template-btn {
    border-style: dashed;
    color: var(--text-faint);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
}

.template-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: all 0.15s;
}

.template-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.template-btn .tmpl-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
}

.template-btn .tmpl-cmd {
    font-size: 11px;
    color: var(--text-faint);
    font-family: 'SF Mono', 'Fira Code', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-tall {
    height: 300px;
}

/* Heatmap */
#heatmap-container {
    overflow-x: auto;
}

.heatmap-table {
    border-collapse: collapse;
    font-size: 11px;
    width: 100%;
}

.heatmap-table th {
    padding: 4px 6px;
    color: var(--text-faint);
    font-weight: 500;
    text-align: center;
    font-size: 10px;
    white-space: nowrap;
}

.heatmap-table td {
    padding: 0;
}

.heatmap-table .hm-label {
    padding: 4px 8px;
    color: var(--text-muted);
    font-weight: 500;
    text-align: right;
    white-space: nowrap;
}

.hm-cell {
    width: 100%;
    height: 24px;
    border-radius: 2px;
    margin: 1px;
}

/* Responsive */
@media (min-width: 1600px) {
    #grid { grid-template-columns: repeat(6, 1fr); }
}

@media (max-width: 1200px) {
    #grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 800px) {
    #sidebar { width: 180px; }
    #grid { grid-template-columns: repeat(2, 1fr); }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}

/* --- Feedback --- */
.feedback-overview {
    display: flex;
    gap: 16px;
    align-items: stretch;
    margin-bottom: 20px;
}

.feedback-barometer {
    flex: 0 0 120px;
}

.barometer-card {
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 20px 16px;
    text-align: center;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
}

.barometer-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.barometer-value {
    font-size: 36px;
    font-weight: 700;
}

.barometer-value.low { color: var(--red); }
.barometer-value.medium { color: var(--yellow); }
.barometer-value.high { color: var(--green); }

.barometer-indicator {
    width: 40px;
    height: 6px;
    border-radius: 3px;
    margin: 0 auto;
}

.feedback-spectrums {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Spectrum bars */
.spectrum-card {
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}

.spectrum {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.spectrum-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.spectrum-neg {
    color: var(--text-muted);
    min-width: 120px;
}

.spectrum-pos {
    color: var(--text-muted);
    min-width: 120px;
    text-align: right;
}

.spectrum-status {
    font-weight: 600;
    font-size: 14px;
}

.spectrum-status.high { color: var(--green); }
.spectrum-status.medium { color: var(--yellow); }
.spectrum-status.low { color: var(--red); }

.spectrum-track {
    position: relative;
    height: 8px;
    background: linear-gradient(to right,
        var(--red),
        var(--yellow) 40%,
        var(--yellow) 60%,
        var(--green));
    border-radius: 4px;
    opacity: 0.3;
}

.spectrum-marker {
    position: absolute;
    top: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    transform: translateX(-50%);
    border: 2px solid var(--bg-surface);
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
    transition: left 0.5s ease;
}

/* Mini spectrum for participant cards */
.participant-spectrums {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mini-spectrum {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.mini-spectrum-dim {
    font-size: 11px;
    color: var(--text-muted);
}

.mini-spectrum-status {
    font-size: 11px;
    font-weight: 600;
}

.mini-spectrum-status.high { color: var(--green); }
.mini-spectrum-status.medium { color: var(--yellow); }
.mini-spectrum-status.low { color: var(--red); }

.spectrum-track.mini {
    height: 4px;
}

.spectrum-track.mini .spectrum-marker {
    width: 10px;
    height: 10px;
    top: -3px;
}

/* --- Task Catalog Tabs --- */
.task-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.task-tab {
    padding: 6px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s;
}

.task-tab.active {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent);
}

.task-tab:hover:not(.active) {
    background: var(--bg-hover);
}

/* --- Task Preview --- */
.task-preview-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
}

.task-preview-desc code {
    background: var(--bg-elevated);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}

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

.task-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-elevated);
    color: var(--text-muted);
}

/* --- Verify Grid --- */
.verify-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.verify-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
}

.verify-badge.passed {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
}

.verify-badge.failed {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
}

.verify-badge.pending {
    background: var(--bg);
    color: var(--text-faint);
}
