/* Falkos Monitor v3.0 - Glassmorphism Responsive Design */

:root {
  --bg-primary: #02040a;
  --bg-secondary: #0d1117;
  --surface: rgba(13, 17, 23, 0.8);
  --surface-light: rgba(22, 27, 34, 0.9);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);
  
  --cyan: #06b6d4;
  --purple: #a855f7;
  --blue: #3b82f6;
  --emerald: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;
  
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  z-index: 9999;
  transition: opacity 0.5s;
}
.loading-screen.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(6, 182, 212, 0.2);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--cyan);
  letter-spacing: 0.15em;
}

/* App Container */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Glass Card */
.glass-card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all 0.2s ease;
}
.glass-card:hover { border-color: var(--border-hover); }

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: var(--space-md);
}
.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}
.logo {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), var(--bg-secondary));
  border: 1px solid rgba(6, 182, 212, 0.4);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}
.header-title h1 {
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.header-title h1 .gradient-text {
  background: linear-gradient(90deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.version {
  font-size: 0.6rem;
  padding: 2px 6px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
  animation: pulse 2s ease infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.status-text { color: var(--emerald); text-transform: uppercase; letter-spacing: 0.1em; }

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all 0.2s;
}
.btn:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.btn svg { width: 18px; height: 18px; }
.last-update {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border-radius: var(--radius-md);
}

/* Main Layout */
.main {
  flex: 1;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Stats Bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-md);
}
.stat-card {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.stat-icon {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: 1rem;
}
.stat-icon.cyan { background: rgba(6, 182, 212, 0.15); }
.stat-icon.blue { background: rgba(59, 130, 246, 0.15); }
.stat-icon.purple { background: rgba(168, 85, 247, 0.15); }
.stat-icon.amber { background: rgba(245, 158, 11, 0.15); }
.stat-icon.emerald { background: rgba(16, 185, 129, 0.15); }
.stat-badge {
  font-size: 0.6rem;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.15);
  color: var(--emerald);
}
.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
}
.stat-unit {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-left: 4px;
}

/* Main Grid */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: var(--space-lg);
  flex: 1;
  min-height: 500px;
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}
.section-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.9rem;
  font-weight: 600;
}
.section-title svg { width: 18px; height: 18px; color: var(--text-muted); }
.section-badge {
  font-size: 0.55rem;
  font-family: var(--font-mono);
  padding: 2px 6px;
  background: rgba(16, 185, 129, 0.2);
  color: var(--emerald);
  border-radius: var(--radius-sm);
  animation: pulse 2s ease infinite;
}

/* Architecture Section */
.architecture-section { display: flex; flex-direction: column; }
.architecture-container {
  flex: 1;
  position: relative;
  min-height: 320px;
  padding: var(--space-lg);
  overflow: hidden;
}

/* Flow Canvas */
.flow-canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.flow-canvas svg {
  width: 100%;
  height: 100%;
}

/* Service Nodes */
.nodes-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: var(--space-lg);
  height: 100%;
  padding: var(--space-md);
}
.service-node {
  padding: var(--space-md);
  cursor: pointer;
  transition: all 0.3s ease;
}
.service-node:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.service-node.center {
  grid-column: 1 / -1;
  justify-self: center;
  max-width: 220px;
}
.node-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}
.node-icon {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: 1rem;
}
.node-icon.cyan { background: rgba(6, 182, 212, 0.2); }
.node-icon.purple { background: rgba(168, 85, 247, 0.2); }
.node-icon.amber { background: rgba(245, 158, 11, 0.2); }
.node-info h3 { font-size: 0.85rem; font-weight: 600; }
.node-port { font-size: 0.65rem; font-family: var(--font-mono); color: var(--text-dim); }
.node-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}
.status-icon {
  width: 6px; height: 6px;
  border-radius: 50%;
}
.status-icon.online { background: var(--emerald); box-shadow: 0 0 6px var(--emerald); }
.status-icon.offline { background: var(--rose); box-shadow: 0 0 6px var(--rose); }
.status-icon.warning { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.node-metrics {
  display: flex;
  gap: var(--space-md);
  font-size: 0.65rem;
  color: var(--text-muted);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--border);
}
.node-metrics strong { color: var(--text); font-family: var(--font-mono); }

/* Flow Path Tracing */
.flow-path {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.6;
}
.flow-path.active {
  opacity: 1;
  stroke-dasharray: 8 4;
  animation: flowDash 1s linear infinite;
}
@keyframes flowDash { to { stroke-dashoffset: -12; } }
.flow-path.cyan { stroke: var(--cyan); filter: drop-shadow(0 0 4px rgba(6, 182, 212, 0.5)); }
.flow-path.purple { stroke: var(--purple); filter: drop-shadow(0 0 4px rgba(168, 85, 247, 0.5)); }
.flow-path.amber { stroke: var(--amber); filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.5)); }

/* Request Tracer */
.request-tracer {
  position: absolute;
  bottom: var(--space-md);
  left: var(--space-md);
  right: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: rgba(0,0,0,0.6);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  z-index: 10;
}
.tracer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xs);
}
.tracer-title {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--cyan);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}
.tracer-title::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--cyan);
  border-radius: 50%;
  animation: pulse 1s ease infinite;
}
.tracer-path {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  overflow-x: auto;
  padding: var(--space-xs) 0;
}
.tracer-node {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 4px 8px;
  background: var(--surface-light);
  border-radius: var(--radius-sm);
  font-size: 0.65rem;
  font-family: var(--font-mono);
  white-space: nowrap;
  transition: all 0.3s ease;
}
.tracer-node.active {
  background: rgba(6, 182, 212, 0.2);
  border: 1px solid var(--cyan);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.3);
}
.tracer-node.completed { color: var(--emerald); }
.tracer-node.pending { color: var(--text-dim); }
.tracer-arrow {
  color: var(--text-dim);
  font-size: 0.8rem;
}
.tracer-arrow.active {
  color: var(--cyan);
  animation: arrowPulse 0.5s ease infinite;
}
@keyframes arrowPulse { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(3px); } }
.tracer-time {
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-left: auto;
}

/* Chat Section */
.chat-section { display: flex; flex-direction: column; }
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
}
.chat-tabs { display: flex; gap: 4px; }
.chat-tab {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
}
.chat-tab:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.chat-tab.active { background: var(--cyan); color: white; }
.chat-count { font-size: 0.7rem; font-family: var(--font-mono); color: var(--text-dim); }

.chat-list-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-list-header {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.7rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm);
}
.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 4px;
}
.chat-item:hover { background: rgba(255,255,255,0.05); }
.chat-avatar {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.chat-content { flex: 1; min-width: 0; }
.chat-name { font-size: 0.8rem; font-weight: 500; }
.chat-preview {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.chat-time { font-size: 0.6rem; font-family: var(--font-mono); color: var(--text-dim); }
.chat-badge {
  font-size: 0.55rem;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--cyan);
  color: white;
}

/* Messages View */
.messages-container { display: none; flex-direction: column; height: 100%; }
.messages-container.active { display: flex; }
.messages-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
}
.back-btn {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.back-btn:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.messages-user h3 { font-size: 0.85rem; font-weight: 600; }
.messages-user span { font-size: 0.7rem; color: var(--text-muted); }
.messages-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.message { display: flex; gap: var(--space-sm); max-width: 85%; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }
.message-avatar {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
}
.message.user .message-avatar { background: linear-gradient(135deg, var(--cyan), var(--blue)); }
.message.assistant .message-avatar { background: linear-gradient(135deg, var(--purple), #7c3aed); }
.message-bubble {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  font-size: 0.8rem;
  line-height: 1.5;
}
.message.user .message-bubble { background: var(--cyan); color: white; border-bottom-right-radius: 4px; }
.message.assistant .message-bubble { background: var(--surface-light); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.message-time { font-size: 0.6rem; color: var(--text-dim); margin-top: 4px; }
.message.user .message-time { text-align: right; }

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  text-align: center;
  flex: 1;
}
.empty-icon { font-size: 2.5rem; opacity: 0.3; margin-bottom: var(--space-md); }
.empty-title { font-size: 0.9rem; font-weight: 600; margin-bottom: var(--space-xs); }
.empty-text { font-size: 0.75rem; color: var(--text-muted); }

/* Events Section */
.events-section { margin-top: auto; }
.events-container { max-height: 180px; overflow: hidden; }
.events-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid var(--border);
}
.events-title {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--emerald);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.events-title::before { content: '●'; animation: pulse 2s ease infinite; }
.events-time { font-size: 0.6rem; font-family: var(--font-mono); color: var(--text-dim); }
.events-body {
  height: 140px;
  overflow-y: auto;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  line-height: 1.8;
}
.event-line { display: flex; gap: var(--space-sm); }
.event-time { color: var(--text-dim); flex-shrink: 0; }
.event-type { flex-shrink: 0; }
.event-type.info { color: var(--cyan); }
.event-type.success { color: var(--emerald); }
.event-type.warning { color: var(--amber); }
.event-type.error { color: var(--rose); }
.event-message { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Toast */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  min-width: 280px;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(100px); } }
.toast.removing { animation: slideOut 0.3s ease forwards; }
@keyframes slideOut { to { opacity: 0; transform: translateX(100px); } }
.toast-icon { font-size: 1rem; }
.toast-content { flex: 1; }
.toast-title { font-size: 0.8rem; font-weight: 600; }
.toast-message { font-size: 0.7rem; color: var(--text-muted); }
.toast-close {
  width: 20px; height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.toast-close:hover { background: rgba(255,255,255,0.1); }

/* Footer */
.footer {
  padding: var(--space-md) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.footer-links { display: flex; gap: var(--space-md); }
.footer-links a { color: var(--text-muted); text-decoration: none; }
.footer-links a:hover { color: var(--cyan); }

/* Responsive */
@media (max-width: 1200px) {
  .stats-bar { grid-template-columns: repeat(3, 1fr); }
  .main-grid { grid-template-columns: 1fr; }
  .chat-section { min-height: 400px; }
}
@media (max-width: 768px) {
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .header { padding: var(--space-md); }
  .main { padding: var(--space-md); }
  .nodes-grid { grid-template-columns: 1fr; gap: var(--space-md); }
  .service-node.center { grid-column: auto; max-width: none; }
}
@media (max-width: 480px) {
  .stats-bar { grid-template-columns: 1fr; }
  .header-title h1 { font-size: 1rem; }
  .stat-value { font-size: 1.25rem; }
}
