/* ============================================================
   ShadowGrok Ops Panel — THEME v2 "Midnight Circuit"
   Complete visual overhaul layered on the base stylesheet.
   ============================================================ */

/* ---- Design tokens: dark (primary) ---- */
[data-theme=dark] {
  --bg: #05070d;
  --bg-elevated: #0a0f1a;
  --surface: rgba(16, 23, 40, 0.72);
  --surface-hover: rgba(24, 34, 58, 0.85);
  --border: rgba(94, 121, 180, 0.28);
  --border-subtle: rgba(70, 94, 148, 0.18);
  --text: #e8eefb;
  --text-muted: #7d8db0;
  --accent: #7c6cff;
  --accent-hover: #9d8bff;
  --accent-muted: rgba(124, 108, 255, 0.16);
  --success: #2ee6a8;
  --success-muted: rgba(46, 230, 168, 0.12);
  --danger: #ff5d7a;
  --danger-muted: rgba(255, 93, 122, 0.12);
  --warning: #ffc247;
  --warning-muted: rgba(255, 194, 71, 0.12);
  --info: #4dc3ff;
  --info-muted: rgba(77, 195, 255, 0.12);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  --nav-blur: rgba(5, 7, 13, 0.78);
  --grid-color: rgba(94, 121, 180, 0.22);
  --sg-glow: 0 0 0 1px rgba(124, 108, 255, 0.35), 0 0 24px rgba(124, 108, 255, 0.18);
}

/* ---- Design tokens: light ---- */
[data-theme=light] {
  --bg: #eef1f8;
  --bg-elevated: #ffffff;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-hover: #ffffff;
  --border: rgba(93, 106, 148, 0.22);
  --border-subtle: rgba(93, 106, 148, 0.12);
  --text: #131a2c;
  --text-muted: #5c688a;
  --accent: #5b48e8;
  --accent-hover: #7a68ff;
  --accent-muted: rgba(91, 72, 232, 0.1);
  --success: #0ca678;
  --success-muted: rgba(12, 166, 120, 0.1);
  --danger: #e03e5c;
  --danger-muted: rgba(224, 62, 92, 0.08);
  --warning: #d98600;
  --warning-muted: rgba(217, 134, 0, 0.1);
  --info: #0d8adf;
  --info-muted: rgba(13, 138, 223, 0.1);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 6px 28px rgba(23, 32, 64, 0.1);
  --nav-blur: rgba(255, 255, 255, 0.86);
  --grid-color: rgba(120, 138, 184, 0.28);
  --sg-glow: 0 0 0 1px rgba(91, 72, 232, 0.25), 0 0 20px rgba(91, 72, 232, 0.12);
}

/* ---- Typography ---- */
body,
.ops-app,
button,
input,
select,
textarea {
  font-family: "Space Grotesk", "DM Sans", system-ui, -apple-system, sans-serif;
}
.mono,
code,
pre,
.ops-cell-url {
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

/* ---- App shell: deep-space backdrop ---- */
body {
  background:
    radial-gradient(1100px 520px at 12% -8%, rgba(124, 108, 255, 0.14), transparent 60%),
    radial-gradient(900px 480px at 95% 8%, rgba(77, 195, 255, 0.1), transparent 55%),
    radial-gradient(700px 600px at 55% 115%, rgba(46, 230, 168, 0.07), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
}
[data-theme=light] body {
  background:
    radial-gradient(1000px 480px at 10% -10%, rgba(91, 72, 232, 0.09), transparent 60%),
    radial-gradient(900px 420px at 100% 0%, rgba(13, 138, 223, 0.07), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

/* ---- Topbar: glass bar ---- */
.ops-topbar {
  background: var(--nav-blur);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 10px 34px rgba(0, 0, 0, 0.32);
}
.ops-brand {
  font-weight: 700;
  letter-spacing: 0.06em;
  background: linear-gradient(100deg, var(--text) 20%, var(--accent) 55%, var(--info) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---- Sidebar ---- */
.ops-sidebar {
  background: var(--nav-blur);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-right: 1px solid var(--border-subtle);
}
.ops-nav-item {
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, color 0.18s ease;
}
.ops-nav-item:hover {
  background: var(--accent-muted);
  transform: translateX(3px);
}
.ops-nav-item.active {
  background: linear-gradient(90deg, var(--accent-muted), transparent 85%);
  border-left-color: var(--accent);
  color: var(--text);
}

/* ---- Cards: glass panels ---- */
.card {
  background: var(--surface);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.22s ease, transform 0.22s ease, box-shadow 0.22s ease;
  overflow: hidden;
  position: relative;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  pointer-events: none;
}
.card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  transform: translateY(-2px);
  box-shadow: var(--shadow), 0 0 32px rgba(124, 108, 255, 0.08);
}
.card-header { border-bottom: 1px solid var(--border-subtle); }
.card-title { font-weight: 600; letter-spacing: 0.015em; }
.card-subtitle { color: var(--text-muted); }

/* ---- Buttons ---- */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease, filter 0.15s ease;
}
.btn:active { transform: translateY(1px) scale(0.985); }
.btn:disabled { opacity: 0.45; filter: saturate(0.6); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #5b8cff 100%);
  border: none;
  color: #fff;
  box-shadow: 0 4px 18px rgba(124, 108, 255, 0.35);
}
.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 26px rgba(124, 108, 255, 0.5);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--accent-muted);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--text);
}
.btn-secondary:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-color: var(--accent);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); background: var(--accent-muted); }
.btn-danger {
  background: linear-gradient(135deg, var(--danger) 0%, #ff8a5c 100%);
  border: none;
  color: #fff;
  box-shadow: 0 4px 16px rgba(255, 93, 122, 0.3);
}
.btn-danger:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* ---- Forms ---- */
input,
select,
textarea {
  background: color-mix(in srgb, var(--bg-elevated) 82%, transparent) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text) !important;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent) !important;
  box-shadow: var(--sg-glow);
}
input::placeholder,
textarea::placeholder { color: color-mix(in srgb, var(--text-muted) 70%, transparent); }
.ops-field-label { font-weight: 500; letter-spacing: 0.02em; }
.ops-field-hint { color: var(--text-muted); }

/* ---- Metrics ---- */
.ops-metrics { gap: 14px; }
.ops-metric {
  background: linear-gradient(160deg, var(--accent-muted), transparent 65%), var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.ops-metric::after {
  content: "";
  position: absolute;
  right: -22px;
  top: -22px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-muted), transparent 70%);
}
.ops-metric:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.ops-metric-label {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  font-weight: 600;
}
.ops-metric-value {
  font-size: 1.7rem;
  font-weight: 700;
  font-family: "JetBrains Mono", monospace;
  background: linear-gradient(120deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---- Status pills ---- */
.status-pill {
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  font-weight: 600;
  letter-spacing: 0.03em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.status-pill.pill-ok { border-color: color-mix(in srgb, var(--success) 50%, transparent); box-shadow: 0 0 14px rgba(46, 230, 168, 0.18); }
.status-pill.pill-error { border-color: color-mix(in srgb, var(--danger) 50%, transparent); box-shadow: 0 0 14px rgba(255, 93, 122, 0.18); }
.status-pill.pulse .status-pill-dot { animation: sg-pulse 1.6s ease-in-out infinite; }
.status-pill-dot { width: 7px; height: 7px; border-radius: 50%; }
.pill-ok .status-pill-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.pill-error .status-pill-dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.pill-loading .status-pill-dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
@keyframes sg-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.75); }
}

/* ---- Tables ---- */
.ops-table-wrap {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: auto;
  background: color-mix(in srgb, var(--bg-elevated) 55%, transparent);
}
.ops-table { border-collapse: separate; border-spacing: 0; }
.ops-table thead th {
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  position: sticky;
  top: 0;
  z-index: 2;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.ops-table tbody tr { transition: background 0.14s ease; }
.ops-table tbody tr:nth-child(even) { background: rgba(124, 108, 255, 0.035); }
.ops-table tbody tr:hover { background: var(--accent-muted); }
.ops-row-selected,
.ops-table tbody tr.ops-row-selected {
  background: var(--accent-muted) !important;
  box-shadow: inset 2px 0 0 var(--accent);
}
.ops-cell-url { font-size: 0.82rem; }

/* ---- Tabs ---- */
.ops-tabs {
  background: color-mix(in srgb, var(--bg-elevated) 70%, transparent);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}
.ops-tab {
  border-radius: 999px;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
  font-weight: 500;
}
.ops-tab.active {
  background: linear-gradient(135deg, var(--accent), #5b8cff);
  color: #fff;
  box-shadow: 0 3px 14px rgba(124, 108, 255, 0.35);
}
.ops-tab:not(.active):hover { background: var(--accent-muted); }

/* ---- Worker cards ---- */
.ops-worker-grid { gap: 12px; }
.ops-worker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  position: relative;
  overflow: hidden;
}
.ops-worker-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  opacity: 0.6;
}
.ops-worker-card.proxy::before { background: var(--info); }
.ops-worker-card.c2::before { background: var(--danger); }
.ops-worker-card.other::before { background: var(--text-muted); }
.ops-worker-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: var(--shadow);
}
.ops-worker-card.active {
  border-color: var(--accent);
  box-shadow: var(--sg-glow);
}

/* ---- Toasts ---- */
.toast-container { z-index: 1000; }
.toast {
  border-radius: var(--radius-sm);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: sg-toast-in 0.32s cubic-bezier(0.21, 1.02, 0.73, 1);
  overflow: hidden;
  position: relative;
}
.toast::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
}
.toast-success { background: color-mix(in srgb, var(--success-muted) 70%, var(--bg-elevated)); }
.toast-success::before { background: var(--success); }
.toast-error { background: color-mix(in srgb, var(--danger-muted) 70%, var(--bg-elevated)); }
.toast-error::before { background: var(--danger); }
.toast-info { background: color-mix(in srgb, var(--info-muted) 70%, var(--bg-elevated)); }
.toast-info::before { background: var(--info); }
@keyframes sg-toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Rows / events / errors ---- */
.ops-row,
.ops-event-row,
.ops-error-row {
  border-radius: var(--radius-sm);
  transition: background 0.14s ease, transform 0.14s ease;
}
.ops-row:hover,
.ops-event-row:hover,
.ops-error-row:hover { background: var(--accent-muted); }
.ops-error-row { border-left: 2px solid var(--danger); padding-left: 10px; }
.ops-event-row { border-left: 2px solid var(--border); padding-left: 10px; }
.ops-muted { color: var(--text-muted); }

/* ---- Outputs & code ---- */
.ops-output {
  background: color-mix(in srgb, #000 35%, var(--bg-elevated));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--success);
}

/* ---- Page header ---- */
.page-header { margin-bottom: 22px; }
.page-header h1 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(110deg, var(--text) 30%, var(--accent) 75%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.page-lead { color: var(--text-muted); }

/* ---- Empty states / status messages ---- */
.ops-empty,
.empty-state { color: var(--text-muted); font-style: italic; opacity: 0.85; }
.status-message { letter-spacing: 0.01em; }

/* ---- Connection popover ---- */
.ops-connection-panel {
  background: var(--nav-blur);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: sg-toast-in 0.25s ease;
}

/* ---- Vault / filter ---- */
.ops-vault-filter,
.search-input,
.sort-select {
  border-radius: 999px !important;
}

/* ---- Scrollbars ---- */
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--accent) 55%, transparent) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--accent); background-clip: padding-box; }

/* ---- Selection ---- */
::selection { background: var(--accent-muted); color: var(--text); }

/* ---- Focus visibility (a11y) ---- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


