/* ================================================================
   Engine Monitoring UI
   ================================================================ */

/* ── Container ── */
.mon-root { width: 100%; max-width: 1400px; padding: 0 16px 24px; }

/* ── Status Bar ── */
.mon-status-bar {
  display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center;
  padding: 10px 16px; border-radius: 8px;
  background: rgba(148,163,184,0.06); border: 1px solid rgba(148,163,184,0.12);
  font-size: 0.82rem; margin-bottom: 16px;
}
.mon-status-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
  margin-right: 6px; vertical-align: middle;
}
.mon-status-dot.connected    { background: #16a34a; }
.mon-status-dot.disconnected { background: #dc2626; animation: mon-pulse 1.5s infinite; }
.mon-status-dot.reconnected  { background: #ea580c; animation: mon-pulse 1.5s infinite; }
.mon-status-label  { color: var(--text-secondary, #94a3b8); }
.mon-status-value  { font-weight: 600; color: var(--text-primary, #e2e8f0); margin-right: 4px; }
.mon-status-sep    { color: rgba(148,163,184,0.25); }
.mon-status-warn   { color: #f59e0b; }
.mon-status-danger { color: #ef4444; }

/* ── Engine State Banner ── */
.mon-engine-banner {
  padding: 8px 14px; border-radius: 6px; font-size: 0.8rem; margin-bottom: 12px;
  display: none; align-items: center; gap: 8px;
}
.mon-engine-banner.disconnected {
  display: flex; background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
}
.mon-engine-banner.reconnected {
  display: flex; background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
}

/* ── Charts ── */
.mon-charts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-bottom: 16px; min-height: 220px;
}
.mon-chart-card {
  background: rgba(148,163,184,0.04); border: 1px solid rgba(148,163,184,0.1);
  border-radius: 8px; padding: 12px; position: relative;
}
.mon-chart-title {
  font-size: 0.78rem; font-weight: 600; color: var(--text-secondary, #94a3b8);
  margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px;
}
.mon-chart-canvas { width: 100%; height: 180px; }

/* ── Filters ── */
.mon-filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 14px; margin-bottom: 12px; border-radius: 8px;
  background: rgba(148,163,184,0.04); border: 1px solid rgba(148,163,184,0.1);
}
.mon-filters select, .mon-filters input {
  padding: 5px 8px; border-radius: 4px; font-size: 0.8rem;
  background: var(--bg-primary, #0f172a); color: var(--text-primary, #e2e8f0);
  border: 1px solid rgba(148,163,184,0.2);
}
.mon-filters select { min-width: 100px; }
.mon-filters input[type="text"] { min-width: 160px; }
.mon-btn-sm {
  padding: 5px 12px; border-radius: 4px; font-size: 0.78rem; font-weight: 500;
  cursor: pointer; border: 1px solid rgba(148,163,184,0.2);
  background: rgba(148,163,184,0.08); color: var(--text-primary, #e2e8f0);
  transition: background 0.15s;
}
.mon-btn-sm:hover { background: rgba(148,163,184,0.16); }
.mon-btn-sm.primary { background: rgba(59,130,246,0.15); border-color: rgba(59,130,246,0.3); color: #60a5fa; }
.mon-btn-sm.primary:hover { background: rgba(59,130,246,0.25); }
.mon-btn-sm:disabled { opacity: 0.4; cursor: default; }

/* ── Toolbar ── */
.mon-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; margin-bottom: 8px; font-size: 0.8rem;
}
.mon-toolbar-left { display: flex; align-items: center; gap: 10px; }
.mon-toolbar-right { margin-left: auto; display: flex; gap: 6px; }
.mon-selected-count { color: var(--text-secondary, #94a3b8); }

/* ── Request Table ── */
.mon-table-wrap { overflow-x: auto; margin-bottom: 12px; }
.mon-table {
  width: 100%; border-collapse: collapse; font-size: 0.8rem;
}
.mon-table th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-primary, #0f172a);
  text-align: left; padding: 8px 10px; font-weight: 600; font-size: 0.75rem;
  color: var(--text-secondary, #94a3b8); text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 1px solid rgba(148,163,184,0.15);
}
.mon-table td {
  padding: 7px 10px; border-bottom: 1px solid rgba(148,163,184,0.06);
  color: var(--text-primary, #e2e8f0);
}
.mon-table tr:hover td { background: rgba(148,163,184,0.04); }
.mon-table tr.live td { background: rgba(59,130,246,0.05); }
.mon-table .mon-cell-id {
  font-family: monospace; font-size: 0.75rem; cursor: pointer; color: #60a5fa;
}
.mon-table .mon-cell-id:hover { text-decoration: underline; }
.mon-cell-summary {
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: monospace; font-size: 0.75rem; color: var(--text-secondary, #94a3b8);
}
.mon-cell-time { white-space: nowrap; font-size: 0.75rem; color: var(--text-secondary, #94a3b8); }
.mon-cell-cb { width: 28px; text-align: center; }
.mon-cell-cb input { cursor: pointer; }

/* ── Type Badges ── */
.mon-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 0.7rem; font-weight: 600; line-height: 1.4;
}
.mon-badge-query       { background: #dbeafe; color: #1d4ed8; }
.mon-badge-sal         { background: #ede9fe; color: #6d28d9; }
.mon-badge-profile     { background: #ffedd5; color: #c2410c; }
.mon-badge-enrichment  { background: #d1fae5; color: #065f46; }
.mon-badge-knowledge   { background: #ccfbf1; color: #0f766e; }
.mon-badge-metadata    { background: #e2e8f0; color: #475569; }
.mon-badge-container   { background: #e0e7ff; color: #3730a3; }

/* ── Status Icons ── */
.mon-st { font-size: 0.85rem; }
.mon-st-completed  { color: #16a34a; }
.mon-st-failed     { color: #dc2626; }
.mon-st-cancelled  { color: #ca8a04; }
.mon-st-running    { color: #3b82f6; animation: mon-pulse 1.5s infinite; }

/* ── Duration Colors ── */
.mon-dur-fast      { color: #16a34a; }
.mon-dur-normal    { color: #ca8a04; }
.mon-dur-slow      { color: #ea580c; }
.mon-dur-very-slow { color: #dc2626; }

/* ── Load More ── */
.mon-load-more {
  text-align: center; padding: 12px;
}

/* ── Detail Panel ── */
.mon-detail {
  position: fixed; right: 0; top: 0; bottom: 0; width: 50%; min-width: 400px;
  background: var(--bg-primary, #0f172a); border-left: 1px solid rgba(148,163,184,0.15);
  z-index: 100; transform: translateX(100%); transition: transform 0.2s ease;
  display: flex; flex-direction: column; overflow: hidden;
}
.mon-detail.open { transform: translateX(0); }
.mon-detail-header {
  padding: 16px; border-bottom: 1px solid rgba(148,163,184,0.1);
  display: flex; justify-content: space-between; align-items: flex-start;
}
.mon-detail-close {
  cursor: pointer; font-size: 1.2rem; color: var(--text-secondary, #94a3b8);
  background: none; border: none; padding: 4px 8px;
}
.mon-detail-close:hover { color: var(--text-primary, #e2e8f0); }
.mon-detail-tabs {
  display: flex; border-bottom: 1px solid rgba(148,163,184,0.1);
}
.mon-detail-tab {
  padding: 8px 16px; font-size: 0.8rem; cursor: pointer; border: none;
  background: none; color: var(--text-secondary, #94a3b8);
  border-bottom: 2px solid transparent;
}
.mon-detail-tab.active { color: #60a5fa; border-bottom-color: #60a5fa; }
.mon-detail-body {
  flex: 1; overflow-y: auto; padding: 16px;
}
.mon-detail-meta { font-size: 0.82rem; color: var(--text-secondary, #94a3b8); margin-bottom: 4px; }
.mon-detail-meta strong { color: var(--text-primary, #e2e8f0); }
.mon-json-block {
  background: rgba(148,163,184,0.06); border-radius: 6px; padding: 12px;
  font-family: monospace; font-size: 0.75rem; white-space: pre-wrap;
  overflow-x: auto; color: var(--text-primary, #e2e8f0);
}
.mon-timing-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 0.82rem;
}
.mon-timing-label { min-width: 80px; color: var(--text-secondary, #94a3b8); }
.mon-timing-bar-bg {
  flex: 1; height: 18px; background: rgba(148,163,184,0.08); border-radius: 4px; overflow: hidden;
}
.mon-timing-bar {
  height: 100%; background: #3b82f6; border-radius: 4px; transition: width 0.3s;
}
.mon-timing-value { min-width: 80px; text-align: right; font-family: monospace; font-size: 0.75rem; }

/* ── Compare View ── */
.mon-compare-overlay {
  position: fixed; inset: 0; z-index: 110;
  background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center;
}
.mon-compare-overlay.open { display: flex; }
.mon-compare-box {
  background: var(--bg-primary, #0f172a); border: 1px solid rgba(148,163,184,0.15);
  border-radius: 10px; width: 90%; max-width: 1200px; max-height: 85vh;
  overflow-y: auto; padding: 20px;
}
.mon-compare-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.mon-compare-grid {
  display: grid; gap: 1px; background: rgba(148,163,184,0.1);
  border-radius: 6px; overflow: hidden;
}
.mon-compare-cell {
  background: var(--bg-primary, #0f172a); padding: 8px 12px; font-size: 0.8rem;
}
.mon-compare-cell.header {
  font-weight: 600; background: rgba(148,163,184,0.06);
}
.mon-compare-cell.diff { background: rgba(250,204,21,0.08); }

/* ── Debug Trace Panel ── */
.mon-debug-panel {
  position: sticky; bottom: 0; max-height: 200px; overflow-y: auto;
  background: #1e1e2e; color: #cdd6f4; border-top: 2px solid #45475a;
  font-family: monospace; font-size: 0.7rem; display: none;
}
.mon-debug-panel.open { display: block; }
.mon-debug-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px; background: #313244; position: sticky; top: 0;
  font-size: 0.72rem; font-weight: 600;
}
.mon-debug-header button {
  padding: 2px 8px; font-size: 0.68rem; border-radius: 3px;
  cursor: pointer; background: #45475a; color: #cdd6f4; border: none; margin-left: 6px;
}
.mon-debug-header button:hover { background: #585b70; }
.mon-trace-entry { padding: 1px 10px; border-bottom: 1px solid #313244; white-space: nowrap; }
.mon-trace-ts    { color: #6c7086; margin-right: 8px; }
.mon-trace-evt   { color: #89b4fa; font-weight: 600; display: inline-block; min-width: 150px; }
.mon-trace-data  { color: #a6adc8; }
.mon-trace-entry.error .mon-trace-evt { color: #f38ba8; }
.mon-trace-entry.warn  .mon-trace-evt { color: #fab387; }

/* ── Animation ── */
@keyframes mon-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .mon-charts { grid-template-columns: 1fr; }
  .mon-detail { width: 100%; min-width: unset; }
}
