/* @import directives moved to <link> tags in index.html for parallel loading */

:root {
  --ws-badge-connected: #34d399;
  --ws-badge-reconnecting: #fbbf24;
  --ws-badge-offline: #fb7185;
}

.connection-badge-dot {
  flex: 0 0 auto;
}

.connection-badge-pulse {
  animation: connection-badge-pulse 1.6s ease-in-out infinite;
}

@keyframes connection-badge-pulse {
  0%, 100% { opacity: 0.45; transform: scale(0.92); }
  50% { opacity: 1; transform: scale(1.08); }
}

.floating-call-restore {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 10020;
}

@media (max-width: 1024px) {
  .floating-call-restore {
    right: 12px;
    bottom: 84px;
  }
}

/* ─── Agent Stream Enhancements ─── */
.stream-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
  min-width: 0;
}

.stream-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stream-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 0;
}

.stream-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 10px;
  min-height: 32px;
  min-width: 220px;
  max-width: 100%;
  flex: 1 1 260px;
  box-sizing: border-box;
}

.stream-search .input {
  border: none;
  background: transparent;
  padding: 0;
  font-size: 12px;
  min-width: 0;
  width: 100%;
  color: var(--text-primary);
}

.stream-search .input:focus {
  outline: none;
}

.input-compact {
  height: 28px;
  font-size: 12px;
}

.stream-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(52dvh, 460px);
  overflow-y: auto;
  padding-right: 2px;
  padding-bottom: 4px;
  min-width: 0;
}

.stream-item,
.stream-final-response {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card, rgba(255, 255, 255, 0.02));
  overflow: hidden;
  min-width: 0;
}

.stream-item.expanded,
.stream-final-response.expanded {
  border-color: rgba(148, 163, 184, 0.35);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
}

.stream-item-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.stream-item-toggle:disabled {
  cursor: default;
}

.stream-item-toggle-final {
  background: rgba(34, 197, 94, 0.06);
}

.stream-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  min-width: 0;
  grid-column: 1 / 2;
}

.stream-item-title {
  flex: 1 1 220px;
  min-width: 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stream-item-preview {
  grid-column: 1 / 2;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stream-item-tool {
  font-size: 12px;
  text-transform: none;
  max-width: min(44vw, 320px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-item-time {
  color: var(--text-hint);
  font-size: 11px;
  margin-left: auto;
  flex-shrink: 0;
}

.stream-item-chevron {
  grid-column: 2 / 3;
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--text-hint);
  font-size: 13px;
}

.stream-item-details {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 180ms ease, border-color 180ms ease;
  border-top: 1px solid transparent;
}

.stream-item-details.expanded {
  grid-template-rows: 1fr;
  border-top-color: var(--border);
}

.stream-item-details-inner {
  min-height: 0;
  overflow: hidden;
  padding: 0 12px;
}

.wf-palette-backdrop {
  position: absolute;
  inset: 0;
  z-index: 32;
  background: rgba(3, 7, 18, 0.55);
  backdrop-filter: blur(3px);
}

.wf-palette {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, calc(100% - 32px));
  max-height: min(70vh, 720px);
  overflow: hidden;
  background: var(--color-bg, #0d1117);
  border: 1px solid var(--color-border, #2a3040);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wf-palette-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wf-palette-title-group {
  flex: 1;
  min-width: 0;
}

.wf-palette-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text, #fff);
}

.wf-palette-subtitle {
  font-size: 11px;
  color: var(--color-text-secondary, #9ca3af);
  opacity: 0.85;
  margin-top: 3px;
}

.wf-palette-hints {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  opacity: 0.7;
}

.wf-palette-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-right: 2px;
}

.wf-node-search-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--color-border, #2a3040);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--color-text, #fff);
  cursor: pointer;
  background: var(--color-bg-secondary, #131722);
  transition: border 0.15s, background 0.15s;
}

.wf-node-search-item.active {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.66);
}

.wf-node-search-item-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.wf-node-search-label {
  font-weight: 700;
  font-size: 13px;
}

.wf-node-category-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.wf-node-search-type {
  font-size: 11px;
  opacity: 0.55;
}

.wf-node-search-description {
  font-size: 12px;
  opacity: 0.78;
  line-height: 1.4;
}

.wf-node-chip-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.wf-node-chip-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.wf-node-chip-label {
  font-size: 11px;
  color: var(--color-text-secondary, #9ca3af);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.wf-node-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.wf-node-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  font-size: 11px;
  background: var(--color-bg-secondary, #1e293b);
  color: var(--color-text-secondary, #94a3b8);
  letter-spacing: 0.04em;
}

.wf-node-chip-more {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}

.wf-node-chip-fallback {
  opacity: 0.6;
}

.wf-node-search-empty {
  text-align: center;
  padding: 20px;
  opacity: 0.6;
}

.wf-shortcuts-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wf-shortcut-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.wf-shortcut-key {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.14);
}

.wf-shortcut-desc {
  font-size: 13px;
  opacity: 0.82;
  text-align: right;
  flex: 1;
}

.stream-item-details.expanded .stream-item-details-inner {
  padding: 10px 12px 12px;
}

.stream-item-details-scroll {
  max-height: min(44dvh, 360px);
  overflow-y: auto;
}

.stream-item-pre {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-family: var(--font-mono, "JetBrains Mono", monospace);
}

.stream-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  border: 1px solid transparent;
  flex-shrink: 0;
}

.stream-tag-tool_call {
  background: rgba(59, 130, 246, 0.16);
  color: var(--color-inprogress);
  border-color: rgba(59, 130, 246, 0.4);
}

.stream-tag-tool_result {
  background: rgba(16, 185, 129, 0.16);
  color: var(--color-done);
  border-color: rgba(16, 185, 129, 0.35);
}

.stream-tag-error {
  background: rgba(239, 68, 68, 0.16);
  color: var(--color-error);
  border-color: rgba(239, 68, 68, 0.35);
}

.stream-tag-file {
  background: rgba(100, 116, 139, 0.14);
  color: var(--text-secondary);
  border-color: rgba(100, 116, 139, 0.35);
}

.stream-tag-model {
  background: rgba(34, 197, 94, 0.16);
  color: var(--color-done);
  border-color: rgba(34, 197, 94, 0.35);
}

.stream-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}

.stream-empty-icon {
  font-size: 20px;
}

.stream-empty-icon svg {
  width: 1em;
  height: 1em;
  display: inline-block;
}

.stream-empty-text {
  font-size: 12px;
  text-align: center;
}

@media (max-width: 768px) {
  .stream-search {
    flex-basis: 100%;
    min-width: 0;
  }

  .stream-actions {
    align-items: stretch;
  }

  .stream-actions .btn {
    flex: 1 1 auto;
  }

  .stream-list {
    max-height: min(50dvh, 380px);
  }
}

/* ─── Telemetry Tab ─── */
.telemetry-tab {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.telemetry-tab .section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.telemetry-summary .metric-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-hint);
}

.metric-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.telemetry-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.telemetry-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.telemetry-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.telemetry-label {
  color: var(--text-secondary);
}

.telemetry-count {
  font-weight: 600;
  color: var(--text-primary);
}

.telemetry-alerts {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.telemetry-alert-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.telemetry-alert-meta {
  font-size: 12px;
  color: var(--text-hint);
  margin-top: 4px;
}

/* ─── Usage Analytics Tab ─── */
.analytics-tab {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.analytics-header {
  flex-wrap: wrap;
  gap: 10px;
}

.analytics-title-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.analytics-since {
  font-size: 12px;
  color: var(--text-hint);
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 4px;
}

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

/* Period toggle */
.analytics-period-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.analytics-period-btn {
  background: none;
  border: none;
  color: var(--text-hint);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border-right: 1px solid var(--border);
}

.analytics-period-btn:last-child {
  border-right: none;
}

.analytics-period-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.analytics-period-btn.active {
  background: var(--accent-muted);
  color: var(--accent);
  font-weight: 600;
}

/* Stats row */
.analytics-stats-row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.analytics-stat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 0.15s;
}

.analytics-stat:hover {
  border-color: var(--accent-muted);
}

.analytics-stat-icon {
  font-size: 20px;
  opacity: 0.8;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.analytics-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-hint);
  line-height: 1;
  margin-bottom: 5px;
}

.analytics-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.02em;
}

/* Trend chart card */
.analytics-trend-card {
  overflow: hidden;
}

.analytics-trend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.analytics-trend-tabs {
  display: flex;
  gap: 4px;
}

.analytics-trend-tab {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-hint);
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.analytics-trend-tab:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.analytics-trend-tab.active {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
}

/* Legend */
.analytics-legend {
  margin-bottom: 8px;
}

.analytics-legend-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}

.analytics-legend-category {
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-hint);
}

.analytics-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
}

.analytics-legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* SVG chart */
.analytics-trend-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 160px;
  margin-top: 4px;
}

/* Top-N grid */
.analytics-top-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* Bar chart */
.analytics-bar-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.analytics-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.analytics-bar-label {
  flex: 0 0 90px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.analytics-bar-track {
  flex: 1;
  height: 6px;
  background: var(--surface-hover);
  border-radius: 3px;
  overflow: hidden;
}

.analytics-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.analytics-bar-count {
  flex: 0 0 28px;
  text-align: right;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 12px;
}

.task-related-link-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.5);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.task-related-link-chip:hover {
  border-color: rgba(96, 165, 250, 0.5);
  background: rgba(30, 41, 59, 0.75);
  transform: translateY(-1px);
}

.task-related-link-chip[data-emphasis="true"] {
  border-color: rgba(96, 165, 250, 0.32);
  background: rgba(37, 99, 235, 0.14);
}

.task-related-link-chip .task-related-link-kind {
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
}

.task-related-link-chip .task-related-link-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

button.task-related-link-chip {
  appearance: none;
}
