:root {
  --bg: #0b1220;
  --surface: #121c2e;
  --surface-alt: #18253d;
  --border: #253552;
  --text: #eef3fb;
  --muted: #9eb0cc;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --paused: #a855f7;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

code {
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.88em;
}

/* Persistent Top Message Light Header */
.message-light-bar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: #070c16;
  border-bottom: 1px solid var(--border);
}

.ml-left, .ml-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.ml-bulb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.ml-bulb--green  { background: var(--ok);     box-shadow: 0 0 12px var(--ok); }
.ml-bulb--amber  { background: var(--warn);   box-shadow: 0 0 12px var(--warn); }
.ml-bulb--red    { background: var(--danger); box-shadow: 0 0 14px var(--danger); }
.ml-bulb--paused { background: var(--paused); box-shadow: 0 0 12px var(--paused); }

.ml-status-text {
  display: flex;
  flex-direction: column;
  font-size: 0.86rem;
}
.ml-meta { color: var(--muted); font-size: 0.78rem; }

/* Emergency Red Toggle */
.btn-emergency-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #7f1d1d;
  color: #fff;
  border: 1px solid #ef4444;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-emergency-toggle:hover { background: #b91c1c; }
.btn-emergency-toggle[data-active-mode="SYSTEM_A_CLAUDE"] {
  background: #dc2626;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.65);
}
.emergency-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fecaca;
}

/* Primary Navigation */
.ucx-topnav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.ucx-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: #fff;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
}
.ucx-brand small { color: var(--muted); font-size: 0.76rem; }

.ucx-tabs {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 6px;
}

.ucx-tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.86rem;
  cursor: pointer;
}
.ucx-tab:hover { color: var(--text); background: var(--surface-alt); }
.ucx-tab.is-active {
  background: rgba(56, 189, 248, 0.16);
  color: #e0f2fe;
  border-color: rgba(56, 189, 248, 0.5);
  font-weight: 600;
}
.tab-pill {
  font-style: normal;
  font-size: 0.68rem;
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
}

/* Sticky Return Bar */
.sticky-return-bar {
  position: sticky;
  top: 56px;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 18px;
  background: #10203a;
  border-bottom: 1px solid #2b4570;
}
.btn-return-home {
  background: #1d4ed8;
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-return-home:hover { background: #2563eb; }
.subview-crumb { font-weight: 600; color: #bae6fd; }
.subview-lock { font-size: 0.8rem; color: var(--muted); }

/* Layout & Cards */
.ucx-main { padding: 18px; max-width: 1480px; margin: 0 auto; }
.ucx-view { display: none; }
.ucx-view.is-active { display: block; }
.is-hidden { display: none !important; }

.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.grid-2-wide { display: grid; grid-template-columns: minmax(420px, 1.4fr) minmax(320px, 1fr); gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 1.05rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 0.88rem; }
.small { font-size: 0.8rem; }

.kv-list { list-style: none; padding: 0; margin: 0; }
.kv-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.88rem;
}
.kv-list li:last-child { border-bottom: none; }

.stack-form { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--muted); }
input, select {
  background: #0b1220;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

.row-actions, .toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.btn {
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}
.btn--primary { background: #0284c7; color: #fff; }
.btn--primary:hover { background: #0369a1; }
.btn--secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger-outline { background: transparent; color: #fca5a5; border-color: #ef4444; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge--ok { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.badge--warn { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.badge--info { background: rgba(56, 189, 248, 0.18); color: #7dd3fc; }
.badge--danger { background: rgba(239, 68, 68, 0.22); color: #fca5a5; }

.code-output {
  background: #070c16;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.8rem;
  overflow-x: auto;
  max-height: 360px;
  white-space: pre-wrap;
  word-break: break-word;
}

.callout {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  margin-bottom: 10px;
}
.callout--warn { border-color: var(--warn); background: rgba(245, 158, 11, 0.1); }
.callout--ok { border-color: var(--ok); background: rgba(34, 197, 94, 0.1); }
.callout--danger { border-color: var(--danger); background: rgba(239, 68, 68, 0.12); }

.stat-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-box span { color: var(--muted); font-size: 0.8rem; }

.ucx-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.86rem; }
.ucx-table th, .ucx-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
.ucx-table th { color: var(--muted); font-weight: 600; }

.konva-stage-container {
  width: 100%;
  min-height: 380px;
  background: #070c16;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.vault-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.vault-item {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.8rem;
}
.vault-hash { font-family: monospace; font-size: 0.74rem; color: var(--muted); word-break: break-all; }

.wa-result { margin-top: 10px; padding: 8px; background: #070c16; border-radius: 7px; font-size: 0.84rem; }
.wa-result a { color: #4ade80; font-weight: 600; word-break: break-all; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(3, 7, 18, 0.76);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  max-width: 460px;
  width: 100%;
  padding: 20px;
}

@media (max-width: 900px) {
  .grid-2-wide { grid-template-columns: 1fr; }
}
