/* ============================================================
   NEXUS — "Cosmic Fusion" (Fleet Dashboard)
   Ported 1:1 from Mohamed's reference design:
   slate-950 + radial indigo gradient, glassmorphic cards,
   SVG ring gauges with glow + sparklines, emoji agent cards,
   equalizer bars, flower orb, bottom dock.
   ============================================================ */

:root {
  --bg-1: #1e1b4b;            /* radial gradient top-left */
  --bg-2: #090d16;
  --bg-3: #030712;
  --glass-bg: rgba(15, 23, 42, 0.55);
  --glass-bg-solid: rgba(15, 23, 42, 0.85);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(255, 255, 255, 0.18);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --text: #f1f5f9;
  --text-soft: #94a3b8;       /* slate-400 */
  --text-faint: #64748b;      /* slate-500 */
  --track: #1e293b;           /* slate-800 gauge track */
  --pink: #ec4899;            /* pink-500 — CPU */
  --amber: #fbbf24;           /* amber-400 — RAM */
  --cyan: #22d3ee;            /* cyan-400 — Disk */
  --emerald: #34d399;         /* emerald-400 — running */
  --purple: #a855f7;          /* purple-500 */
  --rose: #e11d48;            /* rose-600 — orb */
  --indigo: #6366f1;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: url('/static/images/nebula.jpg') no-repeat center center fixed;
  background-size: cover;
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--text-soft); }

/* ---------- cosmic glow overlay ---------- */
.cosmic-bg {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(circle at 80% 20%, rgba(219, 39, 119, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 20% 70%, rgba(6, 182, 212, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 60%);
}

/* ---------- glass cards ---------- */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  transition: border-color .2s, box-shadow .2s;
}
.glass-card:hover {
  border-color: var(--glass-border-hover);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5), 0 0 15px rgba(168, 85, 247, 0.15);
}
.glass-nav {
  background: var(--glass-bg-solid);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.liquidGL { position: relative; z-index: 1 !important; }

/* ---------- layout ---------- */
#shell { position: relative; z-index: 10; }
.container { max-width: 640px; margin: 0 auto; padding: 24px 16px 140px; }

/* ---------- header ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.topbar-title { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.4); margin: 0; }
.btn-refresh {
  background: var(--glass-bg); backdrop-filter: blur(16px);
  border: 1px solid rgba(34, 211, 238, 0.3); color: var(--cyan);
  padding: 6px 16px; border-radius: 99px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background .2s;
}
.btn-refresh:hover { background: rgba(34, 211, 238, 0.1); }

/* ---------- filter pills ---------- */
.pill-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 18px; scrollbar-width: none; }
.pill-row::-webkit-scrollbar { display: none; }
.pill {
  flex: none; background: var(--glass-bg); backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border); border-radius: 99px;
  padding: 6px 12px; font-size: 12px; font-weight: 500; color: var(--text-soft);
  display: flex; align-items: center; gap: 6px; white-space: nowrap; transition: color .2s;
}
.pill:hover { color: #fff; }
.pill b { color: var(--glow-color, var(--text)); font-weight: 700; font-family: ui-monospace, monospace; }
.pill.cpu { --glow-color: var(--pink); }
.pill.ram { --glow-color: var(--amber); }
.pill.disk { --glow-color: var(--cyan); }
.pill.agents { --glow-color: var(--emerald); }

/* ---------- holo gauge row ---------- */
.holo-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.holo-card {
  border-radius: 16px; padding: 12px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  text-align: center; position: relative; overflow: hidden;
}
.gauge-title {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--text-soft); text-transform: uppercase; margin-bottom: 6px;
}
.gauge-wrap { position: relative; width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; }
.gauge-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge-track { fill: none; stroke: var(--track); stroke-width: 3; }
.gauge-arc {
  fill: none; stroke-width: 3; stroke-linecap: round;
  transition: stroke-dasharray .6s ease;
}
.gauge-arc.cpu { stroke: var(--pink); filter: drop-shadow(0 0 8px rgba(236, 72, 153, 0.8)); }
.gauge-arc.ram { stroke: var(--amber); filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.8)); }
.gauge-arc.disk { stroke: var(--cyan); filter: drop-shadow(0 0 8px rgba(34, 211, 238, 0.8)); }
.gauge-val {
  position: absolute; inset: 6px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
  background: url('/static/images/galaxy.jpg') no-repeat center center;
  background-size: cover;
  border-radius: 50%;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
.sparkline { width: 100%; height: 16px; margin-top: 8px; opacity: .8; }
.sparkline.cpu { color: var(--pink); }
.sparkline.ram { color: var(--amber); }
.sparkline.disk { color: var(--cyan); }

/* ---------- agent fleet cards ---------- */
.fleet-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.agent-card {
  border-radius: 16px; padding: 16px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  transition: all 0.5s cubic-bezier(0.23, 1, 0.320, 1);
  background: linear-gradient(145deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.05);
  position: relative;
  overflow: hidden;
}
.agent-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(circle at var(--mouse-x, 50%) var(--mouse-y, 50%), rgba(79, 172, 254, 0.15), transparent 40%);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 0;
}
.agent-card:hover::before { opacity: 1; }
.agent-card:hover {
  transform: translateY(-8px);
  border-color: rgba(79, 172, 254, 0.3);
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5);
}
.agent-card > * {
  position: relative;
  z-index: 1;
}
.agent-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.agent-avatar-wrap { position: relative; flex: none; }
.agent-avatar {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  background: rgba(49, 46, 129, 0.4); border: 1px solid rgba(99, 102, 241, 0.3);
}
.agent-avatar.pencil { background: rgba(131, 24, 67, 0.4); border-color: rgba(236, 72, 153, 0.3); }
.agent-status-dot {
  position: absolute; top: -4px; right: -4px; width: 12px; height: 12px;
  background: var(--emerald); border-radius: 50%; border: 2px solid var(--bg-3);
  box-shadow: 0 0 8px var(--emerald);
}
.agent-status-dot.down { background: #f87171; box-shadow: 0 0 8px #f87171; }
.agent-status-dot.restarting { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.agent-name-row { display: flex; align-items: center; gap: 8px; }
.agent-name { font-weight: 700; font-size: 14px; color: #fff; }
.status-tag {
  font-size: 10px; font-weight: 600; color: var(--emerald);
  background: rgba(6, 78, 59, 0.6); border: 1px solid rgba(52, 211, 153, 0.3);
  padding: 2px 6px; border-radius: 6px;
}
.status-tag.down { color: #fca5a5; background: rgba(127, 29, 29, 0.6); border-color: rgba(248, 113, 113, 0.3); }
.status-tag.restarting { color: var(--amber); background: rgba(120, 53, 15, 0.6); border-color: rgba(251, 191, 36, 0.3); }
.agent-meta { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.agent-meta strong { color: #e2e8f0; font-weight: 600; }
.agent-lastlog { font-size: 10px; color: var(--text-faint); margin-top: 2px; }

/* equalizer bars */
.eq { display: flex; align-items: flex-end; gap: 4px; height: 20px; flex: none; }
.eq-bar { width: 4px; height: 8px; border-radius: 99px; animation: eq-bounce 1.2s infinite ease-in-out alternate; }
.eq-bar:nth-child(1) { background: var(--cyan); animation-delay: 0.1s; }
.eq-bar:nth-child(2) { background: var(--emerald); animation-delay: 0.4s; }
.eq-bar:nth-child(3) { background: var(--pink); animation-delay: 0.2s; }
.eq-bar:nth-child(4) { background: var(--indigo); animation-delay: 0.5s; }
@keyframes eq-bounce { 0% { height: 4px; } 100% { height: 16px; } }
.agent-card.down .eq-bar { animation: none; height: 3px; opacity: .4; }

/* ---------- summary panel ---------- */
.summary-card {
  border-radius: 16px; padding: 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.sum-block { display: flex; align-items: center; gap: 12px; flex: 1; }
.sum-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.sum-icon.cyan { background: rgba(8, 51, 68, 0.8); border: 1px solid rgba(34, 211, 238, 0.3); color: var(--cyan); }
.sum-icon.purple { background: rgba(59, 7, 100, 0.8); border: 1px solid rgba(168, 85, 247, 0.3); color: var(--purple); }
.sum-icon svg { width: 20px; height: 20px; }
.sum-label { font-size: 12px; color: var(--text-soft); font-weight: 500; }
.sum-value { font-size: 14px; font-weight: 700; color: #fff; }
.sum-value .ok { color: var(--emerald); font-size: 12px; font-weight: 400; }
.sum-value .sched { color: var(--text-soft); font-size: 12px; font-weight: 400; }
.sum-divider { width: 1px; height: 32px; background: #1e293b; margin: 0 16px; }

/* ---------- other views (tables etc.) ---------- */
.view { display: none; }
.view.active { display: block; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.glass-panel {
  background: var(--glass-bg); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border); border-radius: 16px;
  box-shadow: var(--glass-shadow); padding: 16px; margin-bottom: 16px;
}
.table-card { padding: 16px; border-radius: 16px; margin-bottom: 16px; }
.table-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; color: var(--text-faint); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid #1e293b; white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid rgba(30, 41, 59, 0.6); color: var(--text-soft); }
td b { color: #e2e8f0; }
.btn {
  background: var(--glass-bg); border: 1px solid var(--glass-border); color: var(--text);
  padding: 7px 14px; border-radius: 10px; font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: border-color .2s, background .2s;
}
.btn:hover { border-color: var(--glass-border-hover); background: rgba(255,255,255,0.06); }
.btn-primary {
  background: linear-gradient(135deg, var(--rose) 0%, var(--purple) 100%); border: none; color: #fff;
  box-shadow: 0 4px 16px rgba(225, 29, 72, 0.3);
}
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; }
.gauges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-strip { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat-card { border-radius: 16px; padding: 14px; }
.stat-card .k { font-size: 10px; font-weight: 700; letter-spacing: .08em; color: var(--text-soft); text-transform: uppercase; margin-bottom: 4px; }
.stat-card .v { font-size: 18px; font-weight: 800; color: #fff; font-family: ui-monospace, monospace; }
.cron-grid { display: grid; gap: 12px; }
.cron-agent h3 { font-size: 14px; margin: 4px 0 8px; }
.cron-job { padding: 10px 12px; border-radius: 12px; background: rgba(15, 23, 42, 0.4); border: 1px solid var(--glass-border); margin-bottom: 8px; }
.jname { font-weight: 600; font-size: 12px; }
.jmeta { font-size: 11px; color: var(--text-faint); margin-top: 2px; font-family: ui-monospace, monospace; }
.two-col { display: grid; gap: 16px; }
@media (min-width: 720px) { .two-col { grid-template-columns: 1fr 1fr; } }
.stack-form label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 12px; color: var(--text-soft); }
input, select {
  width: 100%; background: rgba(15, 23, 42, 0.6); border: 1px solid var(--glass-border);
  border-radius: 10px; padding: 10px 12px; color: var(--text); font-size: 13px;
  font-family: var(--font); outline: none; margin-top: 4px; transition: border-color .2s;
}
input:focus, select:focus { border-color: rgba(168, 85, 247, 0.5); }
.more-sheet { position: fixed; inset: auto 0 0 0; z-index: 40; background: var(--glass-bg-solid); backdrop-filter: blur(20px); border-top: 1px solid var(--glass-border); border-radius: 20px 20px 0 0; padding: 16px; display: grid; gap: 4px; }
.ms-title { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.more-sheet .nav-item {
  display: flex; width: 100%; background: transparent; border: none; color: var(--text-soft);
  padding: 12px; font-size: 14px; border-radius: 10px; cursor: pointer; font-family: var(--font);
  text-align: left;
}
.more-sheet .nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }

/* ---------- flower orb ---------- */
@keyframes orb-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(225, 29, 72, 0.6), 0 0 40px rgba(168, 85, 247, 0.4); transform: scale(1); }
  50% { box-shadow: 0 0 30px rgba(225, 29, 72, 0.9), 0 0 60px rgba(168, 85, 247, 0.7); transform: scale(1.03); }
}
.flower-orb {
  background: linear-gradient(135deg, #e11d48 0%, #a855f7 100%);
  animation: orb-pulse 4s infinite ease-in-out;
}
#copilot-fab {
  position: fixed; bottom: 88px; right: 20px; z-index: 40;
  width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
  font-size: 24px; display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
#copilot-fab:hover { transform: scale(1.05); }
#copilot-fab:active { transform: scale(0.95); }

/* ---------- copilot drawer ---------- */
.copilot-drawer-wrap {
  position: fixed; bottom: 152px; right: 16px; z-index: 45;
  width: min(400px, calc(100vw - 32px)); height: min(560px, calc(100dvh - 180px));
}
.copilot-drawer {
  width: 100%; height: 100%;
  border-radius: 18px; padding: 14px; display: flex; flex-direction: column;
}
.copilot-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.copilot-title { font-weight: 800; color: var(--rose); }
.copilot-sub { font-size: 10px; color: var(--text-faint); font-family: ui-monospace, monospace; margin-top: 1px; }
.copilot-msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; padding: 2px; }
.cmsg { max-width: 85%; padding: 9px 12px; border-radius: 14px; font-size: 12px; line-height: 1.45; }
.cmsg-bot { align-self: flex-start; background: rgba(30, 41, 59, 0.7); border: 1px solid var(--glass-border); color: var(--text); border-bottom-left-radius: 4px; }
.cmsg-user { align-self: flex-end; background: linear-gradient(135deg, var(--rose), #a855f7); color: #fff; border-bottom-right-radius: 4px; }
.cmsg-error { align-self: flex-start; background: rgba(127, 29, 29, 0.6); color: #fca5a5; }
.cmsg-pending { align-self: flex-start; background: rgba(59, 7, 100, 0.6); border: 1px solid rgba(168, 85, 247, 0.4); }
.cmsg-pending .p-title { font-weight: 700; color: var(--purple); margin-bottom: 4px; }
.cmsg-pending .p-args { font-family: ui-monospace, monospace; font-size: 10px; color: var(--text-soft); margin-bottom: 8px; white-space: pre-wrap; }
.p-btns { display: flex; gap: 8px; }
.copilot-input { display: flex; gap: 8px; }
.copilot-input input { flex: 1; margin-top: 0; }
.copilot-input .btn { flex: none; }

/* ---------- bottom dock ---------- */
.mobile-nav-wrap {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
}
.mobile-nav {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
}
.mn-grid { max-width: 640px; margin: 0 auto; display: flex; align-items: stretch; justify-content: space-between; }
.mn-item {
  flex: 1; background: transparent; border: none; cursor: pointer;
  color: var(--text-soft); font-size: 11px; font-family: var(--font);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 4px 0; transition: color .2s;
}
.mn-item svg { width: 20px; height: 20px; }
.mn-item:hover { color: #fff; }
.mn-item.active { color: var(--pink); font-weight: 600; }
.mn-item.active svg { filter: drop-shadow(0 0 6px rgba(236, 72, 153, 0.8)); }

/* ---------- login ---------- */
#login-view { position: relative; z-index: 10; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 400px; border-radius: 20px; padding: 32px 28px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand-mark { filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.5)); }
.brand-name { font-size: 24px; font-weight: 800; letter-spacing: .06em; }
.brand-sub { font-size: 11px; color: var(--text-faint); letter-spacing: .05em; }
label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 14px; color: var(--text-soft); }
.login-hint { text-align: center; font-size: 11px; color: var(--text-faint); margin-top: 16px; }
.login-error { color: #fca5a5; font-size: 12px; margin-bottom: 10px; }
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--glass-bg-solid); border: 1px solid var(--glass-border);
  color: var(--text); padding: 10px 18px; border-radius: 99px; font-size: 12px;
  box-shadow: var(--glass-shadow); backdrop-filter: blur(16px);
}
#toast.err { border-color: rgba(248, 113, 113, 0.4); color: #fca5a5; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { width: 100%; max-width: 520px; max-height: 88dvh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.modal-title { font-size: 16px; font-weight: 800; }
.modal-body { overflow-y: auto; }
.agent-meta { display: grid; gap: 4px; font-size: 12px; color: var(--text-soft); margin-bottom: 10px; }
.agent-meta b { color: var(--text); }
.agent-controls { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.log-box { border-radius: 12px; overflow: hidden; background: rgba(3, 7, 18, 0.6); }
.log-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; font-size: 11px; color: var(--text-faint); border-bottom: 1px solid var(--glass-border); }
.log-view { margin: 0; padding: 10px; font-size: 10px; font-family: ui-monospace, monospace; color: #7dd3fc; height: 200px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; }
