/* StreamNOC Application Styles */

:root {
  --color-bg: #08090c;
  --color-surface: #12161d;
  --color-surface-2: #181f29;
  --color-text: #d7dee6;
  --color-text-muted: #6b7785;
  --color-primary: #3470ff;
  --color-primary-hover: #5a8bff;
  --color-success: #00d56a;
  --color-danger: #ff4d4d;
  --color-warning: #ffa51f;
  --color-border: #252d38;
  --color-border-2: #323c49;
  --color-nav-bg: #0b0e13;
  --color-nav-text: #d7dee6;
  --radius: 8px;
  --shadow: 4px 4px 0 rgba(0,0,0,0.45);
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
  --font-disp: "Anton", "Arial Narrow", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  margin: 0;
  background-color: var(--color-bg);
  background-image:
    linear-gradient(rgba(52,112,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(52,112,255,.045) 1px, transparent 1px),
    radial-gradient(1100px 560px at 82% -12%, rgba(52,112,255,.10), transparent 60%),
    radial-gradient(820px 460px at -8% 112%, rgba(0,213,106,.07), transparent 55%);
  background-size: 36px 36px, 36px 36px, 100% 100%, 100% 100%;
  background-repeat: repeat, repeat, no-repeat, no-repeat;
  background-attachment: fixed;
  color: var(--color-text);
  line-height: 1.55;
  font-size: 14px;
}

/* Navigation */
.main-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.5rem 1.5rem;
  background: var(--color-nav-bg);
  color: var(--color-nav-text);
  font-size: 0.875rem;
}

.main-nav a { color: var(--color-nav-text); text-decoration: none; }
.main-nav a:hover { color: #fff; }

.nav-brand a { font-weight: 700; font-size: 1.1rem; color: #fff !important; }
.nav-links { display: flex; gap: 1rem; flex: 1; }

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.nav-user button {
  background: transparent;
  border: 1px solid var(--color-text-muted);
  color: var(--color-nav-text);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.75rem;
}

/* Container */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* Flash messages */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.flash-notice { background: #d1e7dd; color: #0f5132; }
.flash-alert { background: #f8d7da; color: #842029; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h2 { margin-top: 0; font-size: 1.1rem; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}
th { font-weight: 600; color: var(--color-text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr:hover { background: #f8f9fa; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
  line-height: 1.5;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-outline {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-outline:hover { background: var(--color-bg); }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.25rem; font-size: 0.875rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  line-height: 1.5;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(52, 112, 255, 0.25);
}
.form-group .hint { font-size: 0.75rem; color: var(--color-text-muted); margin-top: 0.25rem; }
.form-check { display: flex; align-items: center; gap: 0.5rem; }
.form-check input[type="checkbox"] { width: auto; }

.form-errors {
  background: #f8d7da;
  color: #842029;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.form-errors ul { margin: 0.25rem 0 0; padding-left: 1.25rem; }

/* Grid utilities */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Flex utilities */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }

/* Badge */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-online { background: #d1e7dd; color: #0f5132; }
.badge-offline { background: #e2e3e5; color: #41464b; }
.badge-unseen { background: #fff3cd; color: #664d03; }

/* Status indicator */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.35rem;
}
.status-dot-online { background: var(--color-success); }
.status-dot-offline { background: var(--color-text-muted); }
.status-dot-error { background: var(--color-danger); }

/* Metric cards */
.metric {
  text-align: center;
  padding: 1rem;
}
.metric-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.metric-label { font-size: 0.75rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Page header */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.page-header p { margin: 0; color: var(--color-text-muted); font-size: 0.875rem; }

/* Multi-viewer grid */
.multi-viewer-grid {
  display: grid;
  gap: 4px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.tile {
  position: relative;
  background: #111;
  overflow: hidden;
}

.tile-header {
  padding: 0.25rem 0.5rem;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 0.75rem;
  z-index: 2;
  position: relative;
}
.tile-label { font-weight: 500; }

.tile-body {
  position: relative;
  aspect-ratio: 16/9;
}
.tile-body video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17,17,17,0.85);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.tile-overlay.visible {
  opacity: 1;
}
.tile-overlay-text {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.tile-focused { outline: 3px solid var(--color-success); outline-offset: -3px; }
.tile-selected { outline: 2px solid var(--color-primary); outline-offset: -2px; }

/* Audio meter canvas */
.audio-meter-canvas {
  border-radius: 2px;
  background: #333;
}

/* Sparkline */
.sparkline { display: block; width: 100%; }

/* Dark mode for multi-viewer and shared views */
body.dark-mode {
  --color-bg: #0a0a0a;
  --color-surface: #1a1a1a;
  --color-text: #e0e0e0;
  --color-text-muted: #888;
  --color-border: #333;
}
body.dark-mode .form-group input,
body.dark-mode .form-group select,
body.dark-mode .form-group textarea {
  background: #222;
  color: var(--color-text);
  border-color: var(--color-border);
}
body.dark-mode .form-errors {
  background: #3d1c1c;
  color: #f8d7da;
}
body.dark-mode .flash-notice {
  background: #1c3d2a;
  color: #d1e7dd;
}
body.dark-mode .flash-alert {
  background: #3d1c1c;
  color: #f8d7da;
}
body.dark-mode .empty-state {
  color: var(--color-text-muted);
}

/* Login page */
.login-container {
  max-width: 420px;
  margin: 4rem auto;
  padding: 0 1rem;
}
.login-container .card {
  padding: 2rem;
}
.login-container h1 {
  font-size: 1.75rem;
  margin: 0;
}

/* Empty states */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}
.empty-state p { margin: 0.5rem 0; }

/* Utility: truncate */
.truncate {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Links */
a { color: var(--color-primary); }
a:hover { color: var(--color-primary-hover); }

/* Color field */
.form-group input[type="color"] {
  height: 38px;
  padding: 4px;
  cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .main-nav { flex-wrap: wrap; }
  .nav-links { order: 3; width: 100%; }
}

/* ---- Signal routing topology ---- */
.topology-toolbar {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding-bottom: 0.75rem; margin-bottom: 0.5rem; border-bottom: 1px solid var(--color-border);
}
.topology-sep { width: 1px; height: 22px; background: var(--color-border); margin: 0 0.25rem; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-outline.on { border-color: #fd7e14; color: #b3590a; background: #fff3e6; }
.topology-srv-label { font-size: 0.8rem; color: var(--color-text-muted); }
.topology-chips { display: inline-flex; gap: 0.4rem; flex-wrap: wrap; }
.topo-chip {
  display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; user-select: none;
  font-size: 0.8rem; padding: 0.25rem 0.65rem; border: 1px solid var(--color-border); border-radius: 20px;
}
.topo-chip.off { opacity: 0.45; text-decoration: line-through; }
.topo-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.topology-summary { font-size: 0.8rem; color: var(--color-text-muted); }
.topology-summary b { color: var(--color-text); }
.topology-legend { margin-left: auto; display: flex; gap: 0.9rem; font-size: 0.75rem; color: var(--color-text-muted); }
.topology-legend i { display: inline-block; width: 20px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.topology-legend i.active { background: #198754; }
.topology-legend i.configured { background: repeating-linear-gradient(90deg,#0d6efd 0 6px,transparent 6px 10px); }
.topology-legend i.ended { background: #adb5bd; }
.topology-legend i.reconnecting { background: #fd7e14; animation: topoPulse 1.1s ease-in-out infinite; }

.topology-canvas { position: relative; overflow-x: auto; }
.topology-canvas svg { width: 100%; display: block; }
.topo-col-label { fill: var(--color-text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }

.topo-edge { fill: none; stroke-width: 2; opacity: 0.9; transition: opacity 0.15s; }
.topo-edge.active { stroke: #198754; }
.topo-edge.configured { stroke: #0d6efd; stroke-dasharray: 6 4; }
.topo-edge.ended { stroke: #adb5bd; stroke-dasharray: 2 5; opacity: 0.6; }
.topo-edge.reconnecting { stroke: #fd7e14; stroke-width: 2.5; stroke-dasharray: 8 4;
  animation: topoMarch 1s linear infinite, topoPulse 1.1s ease-in-out infinite; }
.topo-edge.dim { opacity: 0.08 !important; animation: none; }
@keyframes topoMarch { to { stroke-dashoffset: -24; } }
@keyframes topoPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.topo-box { fill: var(--color-surface); stroke: var(--color-border); stroke-width: 1.5; }
.topo-node:hover .topo-box { stroke: #fd7e14; cursor: pointer; }
.topo-node.sel .topo-box { stroke: #fd7e14; stroke-width: 2.5; }
.topo-node.dim { opacity: 0.25; }
.topo-label { fill: var(--color-text); font-size: 12px; }
.topo-sub { fill: var(--color-text-muted); font-size: 10px; }
.topo-node.reconnecting .topo-box { stroke: #fd7e14; stroke-width: 2.5; animation: topoPulse 1.1s ease-in-out infinite; }

.topology-tip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity 0.1s; max-width: 250px;
  background: #1a1a2e; color: #e0e0e0; border-radius: var(--radius); padding: 0.5rem 0.65rem; font-size: 0.78rem; z-index: 5;
}
.topology-tip b { color: #fd7e14; }
.topology-tip .row { color: #adb5bd; }
.topology-empty {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  text-align: center; padding: 2rem; color: var(--color-text-muted); font-size: 0.85rem;
}
.topology-details { margin-top: 1rem; }
.topology-details summary { cursor: pointer; color: var(--color-text-muted); font-size: 0.85rem; }
.topology-details > :not(summary) { margin-top: 1rem; }

/* ============================================================
   Hybrid theme — Mission Control × Signal Grid
   Dark operational base wearing Signal Grid's personality.
   ============================================================ */

/* Display type */
h1, h2, h3,
.metric-value, .page-header h1, .login-container h1,
.nav-brand a, .card h2 {
  font-family: var(--font-disp);
  font-weight: 400;
  letter-spacing: 0.02em;
}
.card h2, .page-header h1 { text-transform: uppercase; letter-spacing: 0.03em; }

/* Navigation bar */
.main-nav { border-bottom: 2px solid var(--color-border); background: var(--color-nav-bg); }
.nav-brand a {
  font-size: 1.45rem !important; color: #06140c !important;
  background: var(--color-success); padding: 0.1rem 0.6rem; border-radius: 5px;
}
.nav-links a { text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.78rem; }
.nav-links a:hover { color: var(--color-success); }
.nav-user button:hover { border-color: var(--color-success); color: var(--color-success); }

/* Cards → panels */
.card {
  background: var(--color-surface); border: 2px solid var(--color-border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card h2 { font-size: 1.15rem; }

/* Tables — dark, header bar */
th { background: var(--color-text-muted); color: var(--color-bg); }
td { border-bottom: 1px solid rgba(37, 45, 56, 0.7); }
tbody tr:hover { background: rgba(52, 112, 255, 0.06); }

/* Badges → stickers (outlined) */
.badge {
  background: transparent !important; border: 2px solid currentColor;
  border-radius: 4px; font-family: var(--font-disp); letter-spacing: 0.04em;
  padding: 0.05rem 0.5rem; font-size: 0.72rem;
}
.badge-online { color: var(--color-success); }
.badge-offline { color: var(--color-text-muted); }
.badge-unseen { color: var(--color-warning); }
.badge-neutral { color: var(--color-text-muted); }

/* Status dots */
.status-dot-online { background: var(--color-success); box-shadow: 0 0 8px var(--color-success); }

/* Metric cards → KPI colour-block tiles */
.card.metric { text-align: left; border-top-width: 4px; border-top-color: var(--color-primary); }
.metric-value { font-size: 2.6rem; line-height: 0.85; }
.grid-3 > .metric:nth-child(1) { border-top-color: var(--color-success); }
.grid-3 > .metric:nth-child(1) .metric-value { color: var(--color-success); }
.grid-3 > .metric:nth-child(2) { border-top-color: var(--color-primary); }
.grid-3 > .metric:nth-child(2) .metric-value { color: var(--color-primary); }
.grid-3 > .metric:nth-child(3) { border-top-color: var(--color-warning); }
.grid-3 > .metric:nth-child(3) .metric-value { color: var(--color-warning); }

/* Buttons */
.btn-outline { color: var(--color-text); border-color: var(--color-border-2); }
.btn-outline:hover { background: var(--color-surface-2); border-color: var(--color-text-muted); }
.btn-outline.on { border-color: var(--color-warning); color: var(--color-warning); background: rgba(255, 165, 31, 0.1); }

/* Forms — dark fields */
.form-group input, .form-group select, .form-group textarea {
  background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border-2);
}

/* Flash / errors — dark, calm */
.flash-notice { background: rgba(0, 213, 106, 0.12); color: var(--color-success); }
.flash-alert { background: rgba(255, 77, 77, 0.12); color: #ff9a9a; }
.form-errors { background: rgba(255, 77, 77, 0.1); color: #ff9a9a; }

/* Topology — dark accents matching the palette */
.topology-toolbar, .topology-sep { border-color: var(--color-border); }
.topology-sep { background: var(--color-border); }
.topo-chip { border-color: var(--color-border-2); }
.topo-edge.active { stroke: var(--color-success); filter: drop-shadow(0 0 3px rgba(0, 213, 106, 0.5)); }
.topo-edge.configured { stroke: var(--color-primary); }
.topo-edge.ended { stroke: var(--color-text-muted); }
.topo-edge.reconnecting { stroke: var(--color-warning); }
.topo-edge.derived { stroke: #a371f7; stroke-dasharray: 5 5; opacity: 0.85; }
.topo-edge.abr { stroke: #2bd4d9; }
.topo-node.abr .topo-box { stroke: #2bd4d9; }
.topology-legend i.active { background: var(--color-success); }
.topology-legend i.derived { background: repeating-linear-gradient(90deg, #a371f7 0 5px, transparent 5px 9px); }
.topology-legend i.abr { background: #2bd4d9; }
.topology-legend i.configured { background: repeating-linear-gradient(90deg, var(--color-primary) 0 6px, transparent 6px 10px); }
.topology-legend i.ended { background: var(--color-text-muted); }
.topology-legend i.reconnecting { background: var(--color-warning); }
.topo-box { fill: var(--color-surface-2); stroke: var(--color-border-2); }
.topo-node:hover .topo-box, .topo-node.sel .topo-box, .topo-node.reconnecting .topo-box { stroke: var(--color-warning); }
.topo-node.live .topo-box { stroke: rgba(0, 213, 106, 0.55); }
.topo-live { fill: var(--color-success); filter: drop-shadow(0 0 4px var(--color-success)); animation: topoPulse 1.8s ease-in-out infinite; }

/* ---- Polish: Plex Sans body, Plex Mono on data surfaces, Anton display ---- */
table, code, kbd, pre,
.topo-label, .topo-sub, .topo-col-label,
.nav-links a, .topology-summary, .metric-label, .truncate {
  font-family: var(--font-mono);
}
code { background: var(--color-surface-2); padding: 0.05rem 0.35rem; border-radius: 4px; font-size: 0.85em; }
.nav-links a { font-size: 0.75rem; }
.card { padding: 1.1rem 1.25rem; }
.card h2 { letter-spacing: 0.03em; margin-bottom: 0.75rem; }
.btn { font-family: var(--font-body); font-weight: 500; }
.page-header h1 { font-size: 1.65rem; }
.empty-state { color: var(--color-text-muted); }
a:hover { color: var(--color-primary-hover); }
.topology-tip { background: var(--color-surface-2); border: 1px solid var(--color-border-2); color: var(--color-text); }
.topology-tip b { color: var(--color-warning); }
.topology-tip .row { color: var(--color-text-muted); }
