@font-face {
  font-family: Inter;
  src: url('/static/fonts/Inter-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: Inter;
  src: url('/static/fonts/Inter-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: Inter;
  src: url('/static/fonts/Inter-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/JetBrainsMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0a0e17;
  --bg-alt: #101928;
  --panel: #111827;
  --panel-2: #162033;
  --card: #1a2332;
  --card-soft: #202b3d;
  --border: #2a3a4f;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --healthy: #10b981;
  --warning: #f59e0b;
  --critical: #ef4444;
  --info: #3b82f6;
  --cpu: #8b5cf6;
  --memory: #06b6d4;
  --sidebar-w: 320px;
  --top-h: 62px;
  --bottom-h: 34px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #0f1a2d, var(--bg));
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

.layout {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: var(--top-h) 1fr var(--bottom-h);
  background: transparent;
}

.topbar {
  height: var(--top-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #111a2a 0%, #0f1725 100%);
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-right {
  justify-content: flex-end;
}

.brand-logo {
  width: 34px;
  height: 34px;
  filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.35));
}

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

.brand-sub {
  font-size: 0.76rem;
  color: var(--muted);
}

.workspace-pill,
.demo-badge,
.count-pill,
.stat-chip {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #0f1727;
}

.workspace-pill {
  padding: 6px 14px;
  font-weight: 600;
}

.demo-badge {
  padding: 4px 10px;
  color: #fbbf24;
  font-weight: 700;
  letter-spacing: 0.05em;
  font-size: 0.72rem;
}

.hidden {
  display: none !important;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 108px;
  font-variant-numeric: tabular-nums;
}

#onlineCount,
#warningCount,
#offlineCount {
  display: inline-block;
  width: 4ch;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
}

.stat-chip .dot,
.ws-status .dot,
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
}

.stat-chip.healthy .dot,
.status-dot.online,
.status-dot.running {
  background: var(--healthy);
}

.stat-chip.warning .dot,
.status-dot.warning,
.status-dot.degraded {
  background: var(--warning);
}

.stat-chip.critical .dot,
.status-dot.offline,
.status-dot.critical,
.status-dot.stopped {
  background: var(--critical);
}

.clock {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: #dbeafe;
  min-width: 76px;
  text-align: center;
}

.workspace-body {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  transition: grid-template-columns 260ms ease;
}

.layout.sidebar-collapsed .workspace-body {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
  min-width: 0;
  width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, #111a2a 0%, #0f1726 100%);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: width 260ms ease, opacity 260ms ease;
}

.layout.sidebar-collapsed .sidebar {
  width: 0;
  opacity: 0;
  border-right: 0;
}

.sidebar-head,
.sidebar-bottom {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.sidebar-head {
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

.sidebar-bottom {
  border-top: 1px solid rgba(148, 163, 184, 0.16);
}

#newWorkspaceBtn {
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  font-size: 0.77rem;
  justify-content: flex-start;
}

.workspace-nav {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
}

.search-input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c1321;
  color: var(--text);
  padding: 10px;
  font-size: 0.78rem;
}

.search-input:focus-visible,
.btn:focus-visible,
.sidebar-link:focus-visible,
.context-item:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 1px;
}

.sidebar-link {
  width: 100%;
  border: 1px solid #334155;
  background: #0e1624;
  border-radius: 8px;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  font-size: 0.77rem;
}

.sidebar-link.active {
  border-left: 3px solid var(--info);
  background: #152238;
}

.count-pill {
  padding: 2px 8px;
  font-size: 0.67rem;
  margin-left: 6px;
}

.workspace-group {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
  background: #121d2f;
}

.workspace-header {
  width: 100%;
  border: 0;
  background: #17253a;
  color: var(--text);
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 0.76rem;
  gap: 8px;
}

.workspace-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.workspace-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.workspace-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.workspace-list li {
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  padding: 7px 8px;
  display: block;
  align-items: center;
  cursor: pointer;
  transition: background 120ms ease;
  font-size: 0.74rem;
}

.workspace-list li:hover {
  background: #1c2a43;
}

.workspace-list li.active {
  background: #233655;
  border-left: 3px solid var(--info);
}

.mini-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.mini-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(15, 26, 40, 0.5), rgba(10, 14, 23, 0.4));
}

.view {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable both-edges;
  padding: 16px;
}

.view.active {
  display: block;
}

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

.agent-card {
  background: linear-gradient(180deg, #1a2638, #162133);
  border: 1px solid var(--border);
  border-left: 4px solid var(--healthy);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 10px 22px rgba(1, 4, 10, 0.32);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.agent-card.warning {
  border-left-color: var(--warning);
}

.agent-card.critical,
.agent-card.offline {
  border-left-color: var(--critical);
  background: linear-gradient(180deg, #2a1116, #1d0c10);
  animation: softPulse 2.4s ease-in-out infinite;
}

@keyframes softPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.9; }
}

.card-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.card-host {
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-display,
.card-meta,
.card-last {
  color: var(--muted);
  font-size: 0.82rem;
}

.card-display {
  margin-top: 4px;
}

.card-meta {
  margin-top: 6px;
}

.card-divider {
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  margin: 10px 0;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  border: 1px solid #31435a;
  background: #0f1728;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.74rem;
  color: #c7d2e5;
}

.metric {
  margin-bottom: 9px;
}

.metric-head {
  display: flex;
  justify-content: space-between;
  color: #c6d2e7;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.progress {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #0e1726;
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.progress > span {
  display: block;
  height: 100%;
  width: 0;
  transition: width 220ms ease;
}

.progress.cpu > span { background: var(--cpu); }
.progress.mem > span { background: var(--memory); }
.progress.disk > span { background: var(--info); }

.service-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.service-pill {
  border: 1px solid #33455f;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.73rem;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  background: #0f1728;
}

.layout.density-tiny .agent-grid {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 9px;
}

.layout.density-tiny .agent-card {
  border-radius: 10px;
  padding: 9px;
  box-shadow: 0 7px 16px rgba(1, 4, 10, 0.26);
}

.layout.density-tiny .card-line {
  gap: 6px;
}

.layout.density-tiny .card-host {
  font-size: 1.02rem;
  gap: 6px;
}

.layout.density-tiny .card-display,
.layout.density-tiny .card-meta,
.layout.density-tiny .card-last {
  font-size: 0.74rem;
}

.layout.density-tiny .card-display {
  margin-top: 2px;
}

.layout.density-tiny .card-meta {
  margin-top: 4px;
}

.layout.density-tiny .card-divider {
  margin: 7px 0;
}

.layout.density-tiny .tags {
  gap: 4px;
  margin-top: 5px;
}

.layout.density-tiny .tag {
  padding: 1px 6px;
  font-size: 0.66rem;
}

.layout.density-tiny .metric {
  margin-bottom: 6px;
}

.layout.density-tiny .metric-head {
  font-size: 0.75rem;
  margin-bottom: 3px;
}

.layout.density-tiny .progress {
  height: 7px;
}

.layout.density-tiny .service-row {
  gap: 5px;
}

.layout.density-tiny .service-pill {
  padding: 2px 6px;
  font-size: 0.66rem;
  gap: 5px;
}

.service-pill.running { border-color: #0f8e64; }
.service-pill.degraded { border-color: #d38a08; }
.service-pill.stopped { border-color: #be3030; }

.card-last.warning { color: var(--warning); }
.card-last.critical { color: var(--critical); }

.empty-state {
  border: 1px dashed rgba(148, 163, 184, 0.34);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  color: var(--muted);
  background: rgba(17, 24, 39, 0.55);
}

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.detail-title {
  font-size: 1.45rem;
  font-weight: 700;
}

.btn {
  border: 1px solid #334155;
  border-radius: 8px;
  background: #0f1727;
  padding: 8px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover {
  background: #15243a;
}

.btn-icon {
  width: 36px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.btn-icon-svg,
.lucide-icon {
  flex: 0 0 auto;
}

.btn-label {
  font-size: 0.75rem;
}

#densityToggle,
#demoToggle,
#audioToggle {
  height: 34px;
  justify-content: center;
  white-space: nowrap;
}

#densityToggle {
  width: 126px;
}

#demoToggle {
  width: 92px;
}

#audioToggle {
  width: 112px;
}

.workspace-icon {
  color: #94a3b8;
}

.btn-primary {
  background: linear-gradient(180deg, #2563eb, #1e40af);
  border-color: #1e3a8a;
}

.btn-primary:hover {
  background: linear-gradient(180deg, #2f6ef2, #2449bd);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 12px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #1a2638, #162133);
  padding: 12px;
}

.spark-wrap {
  position: relative;
}

.sparkline {
  width: 100%;
  height: 170px;
  display: block;
}

.spark-tip {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease;
  border: 1px solid #334155;
  background: rgba(3, 7, 15, 0.95);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.72rem;
  color: #dbeafe;
}

.detail-services-panel {
  margin-top: 12px;
}

.services-table-wrap {
  margin-top: 8px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 10px;
  overflow-y: auto;
  max-height: 340px;
  scrollbar-gutter: stable;
}

.services-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0;
  table-layout: fixed;
}

.services-table th,
.services-table td {
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  padding: 8px;
  font-size: 0.82rem;
  text-align: left;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.services-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #18263d;
}

.services-table tbody tr {
  height: 38px;
}

.services-table tr.running { background: rgba(16, 185, 129, 0.07); }
.services-table tr.degraded { background: rgba(245, 158, 11, 0.08); }
.services-table tr.stopped { background: rgba(239, 68, 68, 0.09); }

.services-table th:nth-child(1),
.services-table td:nth-child(1) { width: 34px; }
.services-table th:nth-child(2),
.services-table td:nth-child(2) { width: 24%; }
.services-table th:nth-child(3),
.services-table td:nth-child(3) { width: 70px; text-align: right; }
.services-table th:nth-child(4),
.services-table td:nth-child(4) { width: 90px; }
.services-table th:nth-child(5),
.services-table td:nth-child(5) { width: 74px; text-align: right; }
.services-table th:nth-child(6),
.services-table td:nth-child(6) { width: 88px; text-align: right; }
.services-table th:nth-child(7),
.services-table td:nth-child(7) { width: 110px; text-align: right; }
.services-table th:nth-child(8),
.services-table td:nth-child(8) { width: 84px; text-align: center; }

.services-table td:nth-child(3),
.services-table td:nth-child(5),
.services-table td:nth-child(6),
.services-table td:nth-child(7) {
  font-family: 'JetBrains Mono', monospace;
}

.log-panel {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d1117;
  color: #c9d1d9;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  max-height: 280px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.log-line.error { color: #ff6b6b; }
.log-line.warn { color: #fbbf24; }
.log-line.time { color: #60a5fa; }

.log-layout {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 12px;
}

.log-tree,
.log-pane {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #1a2638, #162133);
  overflow: auto;
}

.log-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  background: #18263d;
}

.log-toolbar input[type='text'],
.log-toolbar input[type='date'] {
  border: 1px solid #334155;
  border-radius: 7px;
  background: #0d1626;
  color: var(--text);
  padding: 7px;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.log-table th,
.log-table td {
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  padding: 7px;
  vertical-align: top;
}

.log-table tr:nth-child(2n) {
  background: rgba(148, 163, 184, 0.05);
}

.log-tree details {
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  padding: 4px 7px;
}

.log-tree summary {
  cursor: pointer;
  color: #d2e1f8;
  padding: 3px;
}

.log-tree .tree-btn {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 6px;
  cursor: pointer;
}

.log-tree .tree-btn:hover,
.log-tree .tree-btn.active {
  background: #233655;
  border-color: #2f4667;
}

.modal {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #1a2638, #162133);
  color: var(--text);
  width: min(520px, 95vw);
  color-scheme: dark;
}

.modal::backdrop {
  background: rgba(2, 6, 12, 0.65);
}

.modal-form {
  display: grid;
  gap: 10px;
}

.modal-form input,
.modal-form textarea,
.modal-form select {
  width: 100%;
  border: 1px solid #334155;
  background: #0c1321;
  color: var(--text);
  border-radius: 8px;
  padding: 8px;
}

.modal-form select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #94a3b8 50%),
    linear-gradient(135deg, #94a3b8 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(50% - 2px),
    calc(100% - 10px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

.modal-form select option {
  background: #0c1321;
  color: var(--text);
}

.modal-form menu {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.choice-list {
  max-height: 320px;
  overflow: auto;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 6px;
  display: grid;
  gap: 6px;
}

.choice-item-btn {
  border: 1px solid #334155;
  border-radius: 7px;
  background: #0f1728;
  color: var(--text);
  text-align: left;
  padding: 8px;
  cursor: pointer;
}

.choice-item-btn:hover {
  background: #1d2b43;
}

.context-menu {
  position: fixed;
  z-index: 5000;
  min-width: 220px;
  padding: 6px;
  background: #0f1728;
  border: 1px solid #334155;
  border-radius: 10px;
  box-shadow: 0 18px 38px rgba(2, 4, 10, 0.5);
  display: grid;
  gap: 4px;
}

.context-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 8px;
  cursor: pointer;
}

.context-item:hover {
  background: #223654;
  border-color: #334f73;
}

.context-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toast-container {
  position: fixed;
  right: 14px;
  top: calc(var(--top-h) + 8px);
  z-index: 6000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  min-width: 280px;
  max-width: 420px;
  border: 1px solid #31445d;
  border-left: 4px solid var(--critical);
  border-radius: 10px;
  background: #0f1728;
  padding: 10px;
  box-shadow: 0 15px 28px rgba(2, 4, 10, 0.45);
  transform: translateX(16px);
  opacity: 0;
  animation: slideIn 180ms forwards;
  cursor: pointer;
}

.toast.recovery {
  border-left-color: var(--healthy);
}

@keyframes slideIn {
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.bottombar {
  border-top: 1px solid var(--border);
  background: #0e1523;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 0.78rem;
  color: var(--muted);
}

.ws-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.ws-status.connected .dot { background: var(--healthy); }
.ws-status.reconnecting .dot { background: var(--warning); }
.ws-status.disconnected .dot { background: var(--critical); }

@media (max-width: 1300px) {
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    min-height: var(--top-h);
    padding-bottom: 10px;
  }

  .topbar-center {
    justify-content: flex-start;
  }

  .topbar-right {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .layout {
    grid-template-rows: auto 1fr var(--bottom-h);
  }
}

@media (max-width: 1100px) {
  .agent-grid {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .log-layout {
    grid-template-columns: 1fr;
  }
}
