/* Shared Ambulink mediaserver web UI */
:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface2: #243044;
    --border: #2d3a4f;
    --text: #e8edf4;
    --muted: #8b9cb3;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --radius: 10px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

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

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

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

/* ── Header / navbar ── */
.app-header {
    background: linear-gradient(180deg, #1e2a3d 0%, var(--surface) 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.header-top {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 24px;
    min-height: 64px;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    flex-shrink: 0;
    min-width: 180px;
}

.app-brand:hover { opacity: 0.92; }

.brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}

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

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }

.brand-title {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.02em;
}

.brand-sub {
    font-size: 0.7rem;
    color: var(--muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.app-nav-primary {
    display: flex;
    align-items: stretch;
    gap: 6px;
    flex: 1;
    justify-content: center;
    padding: 8px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border-radius: 10px;
    color: var(--muted);
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    min-width: 120px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border-color: var(--border);
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.45);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.2);
}

.nav-item.active .nav-icon {
    background: var(--accent);
    color: #fff;
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--surface2);
    flex-shrink: 0;
}

.nav-icon svg { width: 18px; height: 18px; }

.nav-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.nav-label {
    font-weight: 600;
    font-size: 0.875rem;
}

.nav-desc {
    font-size: 0.65rem;
    color: var(--muted);
    font-weight: 500;
}

.nav-item.active .nav-desc { color: rgba(255, 255, 255, 0.65); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.header-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 10px 24px 14px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
}

.btn-outline {
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-outline:hover {
    background: var(--surface2);
    color: var(--text);
    border-color: #4a6080;
}

.app-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.search-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface2);
    color: var(--text);
    font-size: 0.875rem;
    min-width: 180px;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    background: var(--surface2);
    color: var(--muted);
    border: 1px solid var(--border);
}

.chip.success { color: var(--success); border-color: rgba(34, 197, 94, 0.4); }
.chip.warn { color: var(--warn); }

.btn {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 0.8125rem;
    cursor: pointer;
}

.btn:hover { background: #2f4058; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.toggle-group {
    display: flex;
    background: var(--surface2);
    border-radius: 6px;
    padding: 3px;
    border: 1px solid var(--border);
}

.toggle-group button {
    padding: 5px 12px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.toggle-group button.active {
    background: var(--accent);
    color: #fff;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    color: var(--muted);
    cursor: pointer;
}

/* Stream groups */
.stream-groups { display: flex; flex-direction: column; gap: 20px; }

.app-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

.group-header h2 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.group-header .car-id {
    color: var(--accent);
    font-family: ui-monospace, monospace;
}

.group-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.8rem;
    color: var(--muted);
}

.group-body { padding: 14px; }

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

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

.stream-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.stream-card:hover { border-color: #4a6080; }
.stream-card.hidden { display: none; }
.stream-card.fullscreen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    border-radius: 0;
}

.stream-card-header {
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border);
}

.stream-title { font-weight: 500; font-family: ui-monospace, monospace; }
.stream-pod { font-size: 0.7rem; color: var(--muted); }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #555;
    flex-shrink: 0;
}

.status-dot.live {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.video-container {
    position: relative;
    background: #000;
    width: 100%;
    padding-bottom: 56.25%;
    cursor: pointer;
}

.video-container video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-loading {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 0.75rem;
}

.video-loading.hidden { display: none; }

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.stream-controls {
    display: flex;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid var(--border);
}

.stream-controls .btn { flex: 1; }

.track-badges {
    display: flex;
    gap: 4px;
    padding: 0 8px 8px;
}

.track-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--surface2);
    color: var(--muted);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
    grid-column: 1 / -1;
}

.app-group.collapsed .group-body { display: none; }

/* Cluster dashboard */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.stat-card .label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.stat-card .value {
    font-size: 1.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat-card .sub {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
}

.panel-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-body { padding: 0; overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

.health-ok { color: var(--success); }
.health-bad { color: var(--danger); }

.refresh-note {
    font-size: 0.75rem;
    color: var(--muted);
}

.chart-panel {
    padding: 16px 18px 20px;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
}

.legend-item::before {
    content: '';
    width: 12px;
    height: 3px;
    border-radius: 2px;
    background: currentColor;
}

.legend-item.whip { color: #3b82f6; }
.legend-item.whep { color: #a855f7; }
.legend-item.viewers { color: #22c55e; }

.chart-wrap {
    width: 100%;
    overflow: hidden;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
}

.chart-wrap canvas {
    display: block;
    width: 100%;
}

.chart-empty {
    text-align: center;
    padding: 40px 16px;
    color: var(--muted);
    font-size: 0.875rem;
}

.chart-empty.hidden,
canvas.hidden {
    display: none;
}

@media (max-width: 768px) {
    .header-top { flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
    .app-brand { min-width: auto; }
    .app-nav-primary {
        order: 3;
        width: 100%;
        justify-content: stretch;
        overflow-x: auto;
        padding-bottom: 4px;
    }
    .nav-item { min-width: 0; flex: 1; padding: 8px 10px; }
    .nav-desc { display: none; }
    .header-toolbar { padding: 10px 16px; }
    .streams-grid { grid-template-columns: 1fr; }
}
