/* ============================================================
   Live Automation Console — premium dark, glass, real-time.
   Self-contained. No external dependencies.
   ============================================================ */

:root {
  --bg: #0b1120;
  --bg-2: #0e1525;
  --surface: #131c32;
  --surface-2: #18223c;
  --border: #25324f;
  --border-soft: #1d2944;
  --text: #eef3fb;
  --text-dim: #a6b6d3;
  --text-mute: #74849f;
  --accent: #4f8cff;
  --accent-2: #6aa1ff;
  --good: #2fbf71;
  --bad: #ff5c5c;
  --warn: #ffb020;
  --build: #b07bff;
  --radius: 14px;
  --radius-sm: 10px;
  --maxw: 1160px;
  font-synthesis: none;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.theme-live { --theme: var(--accent); }

/* ---------- Ambient background ---------- */
.bg-fx { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.glow-blob { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.5; }
.glow-1 { width: 640px; height: 640px; top: -160px; left: -120px;
  background: radial-gradient(circle, rgba(79,140,255,0.22), transparent 70%); }
.glow-2 { width: 560px; height: 560px; top: 34%; right: -160px;
  background: radial-gradient(circle, rgba(176,123,255,0.16), transparent 70%); }
.glow-3 { width: 560px; height: 560px; bottom: -200px; left: 30%;
  background: radial-gradient(circle, rgba(47,191,113,0.12), transparent 72%); }

/* ---------- Topbar ---------- */
.topbar {
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 17, 32, 0.78);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.2px; }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--theme); box-shadow: 0 0 14px var(--theme); }
.topnav { display: flex; gap: 6px; flex-wrap: wrap; }
.topnav a { color: var(--text-dim); text-decoration: none; padding: 7px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.topnav a:hover { background: var(--surface); color: var(--text); }
.topnav a.active { background: var(--theme); color: #07101f; }

/* ---------- Page ---------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: 26px 20px 64px; }
.page-title { font-size: clamp(26px, 4vw, 38px); font-weight: 800; letter-spacing: -0.4px; line-height: 1.1; margin: 6px 0; }
.page-sub { color: var(--text-dim); font-size: 16px; max-width: 640px; }
.eyebrow { text-transform: uppercase; letter-spacing: 2px; font-size: 12px; font-weight: 700; color: var(--accent-2); }

/* ---------- Glass card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.glass {
  position: relative;
  background: rgba(255, 255, 255, 0.04);
  -webkit-backdrop-filter: blur(12px) saturate(160%); backdrop-filter: blur(12px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px;
  background: linear-gradient(180deg, rgba(255,255,255,0.45), rgba(255,255,255,0.05) 40%, rgba(255,255,255,0.02));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none;
}
.card-title { margin: 0 0 12px; font-size: 16px; position: relative; }

/* ---------- Console head / controls ---------- */
.console-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 28px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.console-intro { flex: 1 1 460px; }
.console-controls { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.ctl-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.live-badge {
  display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800;
  letter-spacing: 1.5px; text-transform: uppercase; color: var(--good);
  background: rgba(47,191,113,0.12); border: 1px solid rgba(47,191,113,0.4);
  padding: 6px 12px; border-radius: 999px;
}
.live-badge.is-paused { color: var(--warn); background: rgba(255,176,32,0.12); border-color: rgba(255,176,32,0.4); }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 0 currentColor; animation: livePulse 1.8s ease-out infinite; }
.live-badge.is-paused .live-dot { animation: none; }
@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(47,191,113,0.5); }
  70% { box-shadow: 0 0 0 7px rgba(47,191,113,0); }
  100% { box-shadow: 0 0 0 0 rgba(47,191,113,0); }
}

.ctl {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 9px; padding: 9px 14px; font-size: 13px; font-weight: 700; cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.ctl:hover { border-color: var(--accent); transform: translateY(-1px); }
.ctl:active { transform: translateY(0); }
.ctl--bad:hover { border-color: var(--bad); }
.ctl--warn:hover { border-color: var(--warn); }

.sim-note { color: var(--text-mute); font-size: 12.5px; margin: 4px 0 22px; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 16px 18px; }
.stat-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value { font-size: 30px; font-weight: 800; margin-top: 6px; letter-spacing: -0.5px; line-height: 1; }
.stat-value--good { color: var(--good); }
.stat-value--warn { color: var(--warn); }
.stat-value--bad { color: var(--bad); }
.stat-value--mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 26px; }
.stat-value.bump { animation: bump .35s ease; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* ---------- Pipeline ---------- */
.pipe-card { padding-bottom: 8px; }
.pipe-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; position: relative; }
.spark-wrap { display: flex; align-items: center; gap: 8px; }
.spark-label { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.6px; }
.spark { width: 140px; height: 36px; display: block; }
#spark-line { stroke: var(--accent-2); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.pipe-track { overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; padding: 10px 0 4px; }
.pipe-rail { position: relative; min-width: 660px; height: 96px; }
.pipe-line {
  position: absolute; top: 26px; height: 2px; background: var(--border);
  left: 0; width: 0; border-radius: 2px;
}
.pipe-progress {
  position: absolute; top: 26px; height: 2px; left: 0; width: 0;
  background: linear-gradient(90deg, transparent, var(--accent)); border-radius: 2px;
  transition: width .26s ease;
}
.pipe-token {
  position: absolute; top: 26px; left: 0; width: 16px; height: 16px; border-radius: 50%;
  margin: -8px 0 0 -8px; background: var(--accent);
  box-shadow: 0 0 0 4px rgba(79,140,255,0.18), 0 0 14px 2px rgba(79,140,255,0.7);
  opacity: 0; transform: translateX(0);
  transition: transform .26s cubic-bezier(.4,.05,.2,1), background .2s, box-shadow .2s, opacity .2s;
}
.pipe-token.is-on { opacity: 1; }
.pipe-token.token--good { background: var(--good); box-shadow: 0 0 0 4px rgba(47,191,113,0.18), 0 0 14px 2px rgba(47,191,113,0.7); }
.pipe-token.token--warn { background: var(--warn); box-shadow: 0 0 0 4px rgba(255,176,32,0.18), 0 0 14px 2px rgba(255,176,32,0.7); }
.pipe-token.token--bad  { background: var(--bad);  box-shadow: 0 0 0 4px rgba(255,92,92,0.18), 0 0 14px 2px rgba(255,92,92,0.7); }

.stage {
  position: absolute; top: 0; width: 92px; margin-left: -46px;
  display: flex; flex-direction: column; align-items: center; gap: 7px; text-align: center;
}
.stage-dot {
  width: 14px; height: 14px; border-radius: 50%; background: var(--surface-2);
  border: 2px solid var(--border); margin-top: 19px; transition: all .2s; position: relative; z-index: 1;
}
.stage-name { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.stage-count { font-size: 12px; font-weight: 800; color: var(--text-mute); font-variant-numeric: tabular-nums; }
.stage.is-active .stage-dot { border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 5px rgba(79,140,255,0.16); }
.stage.is-active .stage-name { color: var(--text); }
.stage.done .stage-dot { border-color: var(--good); background: rgba(47,191,113,0.5); }
.stage.flash-bad .stage-dot { border-color: var(--bad); background: var(--bad); box-shadow: 0 0 0 5px rgba(255,92,92,0.18); }
.stage.flash-bad .stage-name { color: #ffb3b3; }
.stage.flash-warn .stage-dot { border-color: var(--warn); background: var(--warn); box-shadow: 0 0 0 5px rgba(255,176,32,0.18); }
.stage.flash-warn .stage-name { color: #ffd98a; }

.pipe-now { font-size: 13px; color: var(--text-dim); margin: 12px 2px 6px; min-height: 18px; }
.pipe-now b { color: var(--text); }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
/* Let flex/grid children shrink below their content so inner scrollers (log,
   table) contain overflow instead of widening the page. */
.grid-2 > *, .stat-grid > *, .console-head > * { min-width: 0; }

/* ---------- Log / stream ---------- */
.log {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px;
  background: rgba(6, 10, 20, 0.55); border: 1px solid var(--border-soft); border-radius: 10px;
  padding: 12px; height: 230px; overflow-y: auto; scrollbar-width: thin;
}
.log-line { padding: 2px 0; white-space: pre-wrap; word-break: break-word; animation: lineIn .25s ease; }
.log-line .ts { color: #5d6e8c; }
.log-ok { color: #7ee2a8; } .log-err { color: #ff9a9a; } .log-warn { color: #ffd27a; } .log-info { color: #9fc0ff; }
@keyframes lineIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---------- CRM table ---------- */
.table-scroll { overflow-x: auto; }
.crm-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 430px; }
.crm-table th, .crm-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border-soft); }
.crm-table th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.crm-table tbody tr:last-child td { border-bottom: 0; }
.crm-table tr.fresh { animation: rowIn .5s ease; }
@keyframes rowIn { from { background: rgba(79,140,255,0.16); } to { background: transparent; } }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.badge--good { background: rgba(47,191,113,0.18); color: var(--good); }
.hint { font-size: 12px; color: var(--text-mute); margin-top: 12px; }

/* ---------- Activity feed ---------- */
.feed { display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.feed-msg {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: 10px;
  background: rgba(6, 10, 20, 0.4); border: 1px solid var(--border-soft); animation: lineIn .3s ease;
}
.feed-avatar {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto;
  background: linear-gradient(135deg, #6c4cff, #4f8cff);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; color: #fff;
}
.feed-body { font-size: 13px; }
.feed-body b { color: var(--text); }
.feed-meta { color: var(--text-mute); font-size: 11px; }

/* ---------- Footer ---------- */
.page-footer { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--border-soft); color: var(--text-mute); font-size: 12px; max-width: 820px; }

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .console-controls { align-items: flex-start; }
  .ctl-row { justify-content: flex-start; }
}
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
  .glass { -webkit-backdrop-filter: blur(7px) saturate(150%); backdrop-filter: blur(7px) saturate(150%); }
  .glow-blob { filter: blur(64px); }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 26px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .pipe-token, .pipe-progress { transition: none !important; }
  .live-dot { animation: none !important; }
  .stat-value.bump { animation: none !important; }
  .log-line, .feed-msg, .crm-table tr.fresh { animation: none !important; }
}
