/* ─────────────────────────────────────────────────────────────
   Component primitives. Buttons, pills, cards, inputs, tables,
   toasts, toggles, progress, skeletons, badges.
   ───────────────────────────────────────────────────────────── */

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 16px; border-radius: var(--r-md);
  font-family: var(--font-body); font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent; white-space: nowrap;
  transition: all var(--t-fast) var(--ease);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-1); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn:focus-visible { box-shadow: var(--ring-strong); }

.btn-primary   { background: var(--accent-text); color: #fff; border-color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--bg-canvas); color: var(--text-primary); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-ghost     { background: transparent; color: var(--accent-text); }
.btn-ghost:hover { background: var(--accent-bg); box-shadow: none; transform: none; }
.btn-danger    { background: transparent; color: var(--danger-text); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger-bg); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--r-sm); }
.btn-lg { padding: 11px 24px; font-size: 15px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }
.btn-icon.btn-sm { width: 28px; height: 28px; padding: 4px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ── Status pills ─────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: var(--r-xs);
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  letter-spacing: 0.06em; border: 1px solid; white-space: nowrap;
  text-transform: uppercase;
}
.pill-accent  { color: var(--accent-text);  background: var(--accent-bg);  border-color: var(--accent-border); }
.pill-success { color: var(--success-text); background: var(--success-bg); border-color: var(--success-border); }
.pill-warning { color: var(--yellow-text);  background: var(--yellow-bg);  border-color: var(--yellow-border); }
.pill-danger  { color: var(--danger-text);  background: var(--danger-bg);  border-color: var(--danger-border); }
.pill-neutral { color: var(--text-tertiary); background: var(--bg-app);    border-color: var(--line-strong); }

.pill-xs { font-size: 8px; padding: 1px 5px; }

/* ── Autonomy badges ──────────────────────────────────────── */
.autonomy-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 600; border: 1px solid;
}
.autonomy-l1 { color: var(--yellow-text);  background: var(--yellow-bg);  border-color: var(--yellow-border); }
.autonomy-l2 { color: var(--accent-text);  background: var(--accent-bg);  border-color: var(--accent-border); }
.autonomy-l3 { color: var(--success-text); background: var(--success-bg); border-color: var(--success-border); }
.autonomy-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.autonomy-badge-sm { font-size: 10px; padding: 2px 8px; }
.autonomy-badge-sm .autonomy-dot { width: 6px; height: 6px; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-canvas); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--space-4);
  transition: border-color var(--t-fast) var(--ease);
}
.card:hover { border-color: var(--line-strong); }
.card-accent { border-color: var(--line-accent); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.card-subtitle { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

/* ── Metric cards ─────────────────────────────────────────── */
.metric-card {
  background: var(--bg-canvas); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 20px;
  transition: all var(--t-fast) var(--ease);
}
.metric-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-1); }
.metric-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-tertiary); margin-bottom: 8px;
}
.metric-value {
  font-family: var(--font-display); font-size: 36px; font-weight: 400;
  letter-spacing: -0.02em; color: var(--text-primary); line-height: 1.1; margin-bottom: 6px;
}
.metric-change { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.metric-change.up   { color: var(--success-text); }
.metric-change.down { color: var(--danger-text); }
.metric-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }

/* Sparkline (CSS bar chart) */
.sparkline { display: flex; align-items: flex-end; gap: 2px; height: 40px; margin-top: 12px; }
.sparkline .bar {
  flex: 1; background: var(--accent-bg); border-radius: 2px 2px 0 0;
  min-width: 3px; transition: background var(--t-fast) var(--ease);
}
.sparkline .bar:hover { background: var(--accent-text); }

/* ── Data tables ──────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.data-table thead th {
  text-align: left; padding: 10px 14px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-tertiary);
  border-bottom: 1px solid var(--line-strong); background: var(--bg-app);
  position: sticky; top: 0; z-index: 2;
}
.data-table tbody td {
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  color: var(--text-secondary); transition: background var(--t-instant) var(--ease);
}
.data-table tbody tr:hover td { background: var(--bg-hover); }
.data-table tbody tr.selected td { background: var(--accent-bg); }
.data-table .col-mono { font-family: var(--font-mono); font-size: 12px; color: var(--text-tertiary); }
.data-table .col-primary { color: var(--text-primary); font-weight: 500; }
.data-table .col-right { text-align: right; }

/* ── Form elements ────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-hint { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }
.input {
  width: 100%; padding: 9px 12px; background: var(--bg-canvas);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  color: var(--text-primary); font-family: var(--font-body); font-size: 13px;
  transition: all var(--t-fast) var(--ease);
}
.input:hover { border-color: var(--accent-border); }
.input:focus { outline: 0; border-color: var(--accent-text); box-shadow: var(--ring); }
.input::placeholder { color: var(--text-quaternary); }
.input-error { border-color: var(--danger-text); }
.input-error:focus { box-shadow: 0 0 0 3px var(--danger-bg); }

textarea.input { resize: vertical; min-height: 80px; line-height: 1.5; }

/* form-input: alias used by auto-generated modal forms */
.form-input {
  width: 100%; padding: 9px 12px; background: var(--bg-canvas);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  color: var(--text-primary); font-family: var(--font-body); font-size: 13px;
  transition: all var(--t-fast) var(--ease);
}
.form-input:hover { border-color: var(--accent-border); }
.form-input:focus { outline: 0; border-color: var(--accent-text); box-shadow: var(--ring); }
.form-input::placeholder { color: var(--text-quaternary); }
.form-input--error { border-color: var(--danger-text) !important; box-shadow: 0 0 0 3px var(--danger-bg) !important; }
select.form-input { cursor: pointer; appearance: auto; }
textarea.form-input { resize: vertical; min-height: 80px; line-height: 1.5; }
.form-fields { max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.form-checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-primary); cursor: pointer; }
.form-checkbox input { accent-color: var(--accent-text); }

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' fill='none' stroke='%237A8B92' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}

/* ── Toggle switch ────────────────────────────────────────── */
.toggle { position: relative; width: 40px; height: 22px; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0; background: var(--bg-active);
  border: 1px solid var(--line-strong); border-radius: var(--r-full);
  cursor: pointer; transition: all var(--t-fast) var(--ease);
}
.toggle-track::after {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-tertiary); transition: all var(--t-fast) var(--ease);
}
.toggle input:checked + .toggle-track { background: var(--accent-bg-strong); border-color: var(--accent-border); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); background: var(--accent-text); }

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--line); margin-bottom: 20px;
}
.tab {
  padding: 10px 16px; font-size: 13px; font-weight: 500; color: var(--text-tertiary);
  cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all var(--t-fast) var(--ease); font-family: var(--font-body);
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent-text); font-weight: 600; }

/* ── Toast / notifications ────────────────────────────────── */
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px; border-radius: var(--r-md);
  border: 1px solid; max-width: 400px; box-shadow: var(--shadow-2);
}
.toast-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.toast-warning { background: var(--yellow-bg);  border-color: var(--yellow-border);  color: var(--yellow-text); }
.toast-danger  { background: var(--danger-bg);  border-color: var(--danger-border);  color: var(--danger-text); }
.toast-info    { background: var(--accent-bg);  border-color: var(--accent-border);  color: var(--accent-text); }
.toast-body { font-size: 13px; line-height: 1.4; flex: 1; }
.toast-title { font-weight: 600; margin-bottom: 2px; }

/* ── Progress bar ─────────────────────────────────────────── */
.progress { height: 6px; background: var(--bg-active); border-radius: var(--r-full); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--r-full); transition: width var(--t-slow) var(--ease); }
.progress-accent  .progress-fill { background: var(--accent-text); }
.progress-success .progress-fill { background: var(--success-text); }
.progress-warning .progress-fill { background: var(--yellow-text); }
.progress-danger  .progress-fill { background: var(--danger-text); }

/* ── Skeleton loader ──────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-active) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--r-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Agent health dot ─────────────────────────────────────── */
.agent-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.agent-dot.healthy  { background: var(--success-text); }
.agent-dot.degraded { background: var(--yellow-text); }
.agent-dot.down     { background: var(--danger-text); }

/* ── Signal strength indicator ────────────────────────────── */
.signal-bar { display: flex; gap: 2px; }
.signal-bar span { width: 4px; height: 14px; border-radius: 1px; background: var(--line-strong); }
.signal-high .signal-bar span { background: var(--success-text); }
.signal-medium .signal-bar span:nth-child(-n+3) { background: var(--yellow-text); }
.signal-low .signal-bar span:nth-child(-n+2) { background: var(--danger-text); }

/* ── Stat inline ──────────────────────────────────────────── */
.stat-inline { display: flex; align-items: baseline; gap: 4px; }
.stat-value { font-family: var(--font-mono); font-size: 14px; font-weight: 600; color: var(--text-primary); }
.stat-label { font-size: 11px; color: var(--text-tertiary); }

/* ── Approval card ────────────────────────────────────────── */
.approval-card {
  background: var(--bg-canvas); border: 1px solid var(--yellow-border);
  border-radius: var(--r-md); padding: 16px; border-left: 3px solid var(--yellow-text);
}

/* ── Timeline ─────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px;
  width: 2px; background: var(--line);
}
.timeline-item { position: relative; padding: 8px 0 16px; }
.timeline-dot {
  position: absolute; left: -20px; top: 12px; width: 12px; height: 12px;
  border-radius: 50%; border: 2px solid var(--bg-canvas); z-index: 1;
}
.timeline-dot.accent  { background: var(--accent-text); }
.timeline-dot.success { background: var(--success-text); }
.timeline-dot.warning { background: var(--yellow-text); }
.timeline-dot.danger  { background: var(--danger-text); }
.timeline-time { font-family: var(--font-mono); font-size: 11px; color: var(--text-tertiary); }
.timeline-event { font-size: 13px; color: var(--text-primary); font-weight: 500; }
.timeline-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.empty-state-desc { font-size: 13px; color: var(--text-tertiary); max-width: 360px; margin: 0 auto 16px; }

/* ── Journey / step connector ─────────────────────────────── */
.step-flow { display: flex; align-items: center; gap: 0; overflow-x: auto; padding: 12px 0; }
.step-node {
  width: 80px; height: 44px; border-radius: var(--r-md); border: 1px solid var(--line-strong);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: var(--text-primary);
  background: var(--bg-canvas); flex-shrink: 0;
  transition: all var(--t-fast) var(--ease);
}
.step-node.active { background: var(--accent-bg); border-color: var(--accent-text); }
.step-node-module { font-family: var(--font-mono); font-size: 9px; color: var(--accent-text); margin-top: 2px; }
.step-connector { width: 24px; height: 2px; background: var(--line-strong); flex-shrink: 0; }

/* ── Chart containers ─────────────────────────────────────── */
.chart-container { width: 100%; overflow: hidden; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.chart-legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* ── Data-color step dots (for run events) ────────────────── */
.step-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.step-dot-1 { background: var(--data-1); }
.step-dot-2 { background: var(--data-2); }
.step-dot-3 { background: var(--data-3); }
.step-dot-4 { background: var(--data-4); }
.step-dot-5 { background: var(--data-5); }
.step-dot-6 { background: var(--data-6); }
.step-dot-7 { background: var(--data-7); }
.step-dot-8 { background: var(--data-8); }

/* ── Tooltip (data-tooltip) ───────────────────────────────── */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip); position: absolute;
  bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(4px);
  padding: 5px 10px; background: var(--bg-active); color: var(--text-primary);
  font-size: 12px; font-weight: 500; border-radius: var(--r-sm);
  white-space: nowrap; pointer-events: none; opacity: 0;
  transition: all var(--t-fast) var(--ease);
  box-shadow: var(--shadow-1); border: 1px solid var(--line-strong); z-index: 50;
}
[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
