/* Vectorlab — design system */
:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.25);
  --shadow:    0 8px 24px rgba(0,0,0,.25);
  --shadow-lg: 0 24px 64px rgba(0,0,0,.35);

  --motion-fast: 120ms cubic-bezier(.2,.7,.2,1);
  --motion:      220ms cubic-bezier(.2,.7,.2,1);
  --motion-slow: 480ms cubic-bezier(.2,.7,.2,1);

  /* Stage palette (kept identical across themes for recognition) */
  --lab:    #fbbf24;
  --staging:#60a5fa;
  --prod:   #34d399;
  --query:  #f472b6;
  --danger: #fb7185;
}

[data-theme="dark"] {
  --bg-0: #0a0f1c;
  --bg-1: #0f1424;
  --bg-2: #141a2c;
  --bg-3: #1b2238;
  --line:  #232b46;
  --line-2:#2d3756;
  --text:  #e6ecff;
  --text-dim: #9aa6c8;
  --text-faint:#6b769a;
  --accent:#5eead4;
  --accent-2:#22d3ee;
  --accent-soft: rgba(94,234,212,.12);
  --warn: #fbbf24;
  --ok:  #34d399;
  --err: #fb7185;
  --canvas-bg: #060a16;
}
[data-theme="light"] {
  --bg-0: #f6f7fb;
  --bg-1: #ffffff;
  --bg-2: #f0f3fa;
  --bg-3: #e6ecf6;
  --line:  #dde3ef;
  --line-2:#c8d1e2;
  --text:  #0e1530;
  --text-dim: #4b557a;
  --text-faint:#7a85a3;
  --accent:#0d9488;
  --accent-2:#0891b2;
  --accent-soft: rgba(13,148,136,.10);
  --warn: #b45309;
  --ok:  #047857;
  --err: #be123c;
  --canvas-bg: #f9fafe;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: -9999px; top: 0; padding: 8px 12px; background: var(--accent);
  color: #051618; border-radius: 0 0 8px 0; z-index: 999; font-weight: 600;
}
.skip:focus { left: 0; }

/* ===== Lock screen ===== */
.lock {
  min-height: 100vh; display: grid;
  grid-template-rows: 1fr auto;
  background:
    radial-gradient(1200px 800px at 80% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 700px at -10% 110%, rgba(96,165,250,.10), transparent 60%),
    var(--bg-0);
  padding: var(--space-5);
}
.lock-card {
  width: min(560px, 100%);
  margin: auto;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  position: relative;
  overflow: hidden;
}
.lock-card::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(400px 200px at 80% 0%, var(--accent-soft), transparent 70%);
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: var(--space-5); position: relative; }
.brand-mark { color: var(--accent); }
.brand-name { font-weight: 700; letter-spacing: -0.01em; font-size: 18px; }
.brand-sub { color: var(--text-dim); font-size: 13px; }
.brand-name.small { font-size: 14px; }
.brand-mark.small { color: var(--accent); }

.lock-card h1 { margin: 0 0 var(--space-2); font-size: 22px; letter-spacing: -0.01em; }
.lock-lede { color: var(--text-dim); margin: 0 0 var(--space-5); }
.lock-form { display: grid; gap: var(--space-3); position: relative; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; }
.field input, .field select, input.big-input {
  background: var(--bg-0); color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 10px 12px;
  font: inherit;
  width: 100%;
}
.field input:focus, .field select:focus, input.big-input:focus {
  border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft);
}
.lock-row { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.lock-error { color: var(--err); min-height: 1.2em; margin: 0; font-size: 13px; }
.lock-points {
  display: grid; gap: 8px; margin-top: var(--space-5);
  color: var(--text-dim); font-size: 13px;
}
.lock-points > div { display: flex; align-items: center; gap: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.teal { background: var(--accent); }
.dot.blue { background: #60a5fa; }
.dot.amber { background: var(--lab); }
.dot.rose { background: var(--query); }

.lock-foot {
  text-align: center; color: var(--text-faint); font-size: 12px; padding-top: var(--space-4);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line-2);
  padding: 8px 14px; border-radius: var(--radius);
  cursor: pointer; font-weight: 500; font-size: 14px;
  transition: transform var(--motion-fast), background var(--motion-fast), border-color var(--motion-fast);
}
.btn:hover { background: var(--bg-3); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #051618; border-color: transparent; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: var(--err); background: transparent; }
.btn.danger:hover { background: rgba(251,113,133,.08); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  background: transparent; color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-3); }

/* ===== App shell ===== */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: 56px 1fr auto;
  grid-template-areas:
    "top top"
    "side main"
    "side foot";
  background: var(--bg-0);
}
.topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-4);
  background: linear-gradient(180deg, var(--bg-1), var(--bg-1));
  border-bottom: 1px solid var(--line);
  z-index: 20;
  position: sticky; top: 0;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--space-2); }
.topbar-center { color: var(--text-dim); font-size: 13px; }
.sidebar {
  grid-area: side;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  padding: var(--space-3);
  display: flex; flex-direction: column; justify-content: space-between;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar a {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-dim); text-decoration: none;
  padding: 8px 10px; border-radius: 8px;
  font-size: 14px;
  border: 1px solid transparent;
}
.sidebar a:hover { background: var(--bg-2); color: var(--text); }
.sidebar a.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--line);
}
.sidebar a .ico {
  width: 18px; text-align: center; color: var(--accent); font-size: 13px;
}
.side-foot { color: var(--text-faint); font-size: 12px; padding: var(--space-2); }
.key-status { font-family: var(--font-mono); font-size: 11px; word-break: break-all; }

.main { grid-area: main; padding: var(--space-5) clamp(var(--space-4), 4vw, var(--space-7)); max-width: 1300px; width: 100%; }
.appfoot {
  grid-area: foot; padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--line); color: var(--text-faint); font-size: 12px;
  text-align: center;
}

@media (max-width: 800px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "main" "foot";
  }
  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; width: 240px;
    transform: translateX(-100%); transition: transform var(--motion);
    z-index: 30;
  }
  .sidebar[aria-expanded="true"] { transform: translateX(0); }
  .main { padding: var(--space-4); }
}

/* ===== View head ===== */
.view-head {
  display: grid; gap: 4px; margin-bottom: var(--space-5);
  grid-template-columns: 1fr auto;
}
.view-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.01em; grid-column: 1; }
.view-head p { margin: 0; color: var(--text-dim); grid-column: 1; max-width: 70ch; }
.view-head .head-actions { grid-column: 2; grid-row: 1 / span 2; align-self: start; display: flex; gap: var(--space-2); }

/* ===== Cards ===== */
.cards { display: grid; gap: var(--space-4); margin-bottom: var(--space-5); }
.cards.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cards.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .cards.two, .cards.stats { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .cards.two, .cards.stats { grid-template-columns: 1fr; } }
.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
}
.card h2 { margin: 0 0 var(--space-3); font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); font-weight: 600; }
.stat .stat-num { font-size: 32px; font-weight: 600; letter-spacing: -0.02em; }
.stat .stat-label { color: var(--text-dim); font-size: 13px; }
.hint { color: var(--text-dim); font-size: 12px; margin: 8px 0 0; }
.dim { color: var(--text-dim); }

.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 80px 1fr 40px; gap: 8px; align-items: center; font-size: 13px; }
.bar-track { background: var(--bg-2); height: 8px; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; transition: width var(--motion); }
.bar-fill.lab { background: var(--lab); }
.bar-fill.staging { background: var(--staging); }
.bar-fill.production { background: var(--prod); }

.activity { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 240px; overflow: auto; }
.activity li {
  display: grid; grid-template-columns: 80px 60px 1fr; gap: 8px;
  font-size: 13px; color: var(--text-dim);
  padding: 4px 0; border-bottom: 1px dashed var(--line);
}
.activity li strong { color: var(--text); }
.activity .badge { font-family: var(--font-mono); font-size: 11px; }
.badge { display: inline-block; padding: 2px 6px; border-radius: 4px; background: var(--bg-2); border: 1px solid var(--line); font-size: 11px; }
.badge.role-owner { color: var(--accent); border-color: var(--accent); }
.badge.role-researcher { color: var(--staging); border-color: var(--staging); }
.badge.role-auditor { color: var(--query); border-color: var(--query); }
.badge.role-visitor { color: var(--text-faint); }
.badge.stage-lab { color: var(--lab); border-color: rgba(251,191,36,.4); }
.badge.stage-staging { color: var(--staging); border-color: rgba(96,165,250,.4); }
.badge.stage-production { color: var(--prod); border-color: rgba(52,211,153,.4); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.deny { color: var(--err); border-color: var(--err); }

.policy-mini, .policy-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.policy-mini th, .policy-mini td, .policy-table th, .policy-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left;
}
.policy-mini th, .policy-table th { color: var(--text-dim); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.allow { color: var(--ok); }
.deny  { color: var(--err); }

.hits { list-style: none; padding: 0; margin: var(--space-3) 0 0; display: grid; gap: 6px; }
.hits li {
  display: grid; grid-template-columns: 36px 1fr 56px; gap: 8px; align-items: center;
  padding: 8px; background: var(--bg-2); border-radius: 8px; font-size: 13px;
}
.hits .score { font-family: var(--font-mono); color: var(--text-dim); font-size: 11px; text-align: right; }
.hits .rank  { font-family: var(--font-mono); color: var(--text-faint); }
.hits li.denied { opacity: .6; outline: 1px dashed var(--err); }

/* ===== Map ===== */
.map-wrap {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: auto 1fr;
  gap: var(--space-3);
  height: calc(100vh - 56px - 56px - 80px);
  min-height: 520px;
}
.map-tools {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: var(--space-3);
  background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px var(--space-3);
}
.map-search { position: relative; }
.map-search input { width: 100%; }
.map-search .kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: 11px; color: var(--text-dim);
  background: var(--bg-2); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line);
}
.map-legend { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--text-dim); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ""; width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.lg.lab::before { background: var(--lab); }
.lg.staging::before { background: var(--staging); }
.lg.prod::before { background: var(--prod); }
.lg.query::before { background: var(--query); box-shadow: 0 0 6px var(--query); }
.map-actions { display: flex; gap: 6px; }

.map-canvas-wrap {
  position: relative; background: var(--canvas-bg);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
#map-canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }
.map-hover {
  position: absolute; pointer-events: none;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; max-width: 280px;
  box-shadow: var(--shadow);
  z-index: 4;
}
.map-hover .title { font-weight: 600; margin-bottom: 4px; }
.map-hover .meta  { color: var(--text-dim); font-family: var(--font-mono); font-size: 11px; }
.map-empty {
  position: absolute; inset: 0; display: grid; place-items: center; gap: 8px;
  color: var(--text-dim); text-align: center;
}
.map-axes {
  position: absolute; left: 8px; bottom: 6px;
  color: var(--text-faint); font-size: 11px; font-family: var(--font-mono);
  pointer-events: none;
}
.map-axes span { display: block; }

.map-side {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--space-3); overflow: auto;
}
.map-side h3 { font-size: 14px; margin: 0 0 6px; }
.map-side dl { margin: 0; font-size: 13px; }
.map-side dt { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-top: 6px; }
.map-side dd { margin: 0 0 4px; word-break: break-word; }
.map-side .neighbours { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 4px; }
.map-side .neighbours li { font-size: 12px; padding: 4px 6px; background: var(--bg-2); border-radius: 6px; }

@media (max-width: 900px) {
  .map-wrap { grid-template-columns: 1fr; height: auto; }
  .map-canvas-wrap { height: 60vh; min-height: 380px; }
}

/* ===== Grid lists (collections, sandboxes) ===== */
.grid-3 {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.entity-card {
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--space-4);
  display: grid; gap: 8px; cursor: pointer;
  transition: border-color var(--motion-fast), transform var(--motion-fast);
}
.entity-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.entity-card h3 { margin: 0; font-size: 16px; }
.entity-card .meta { color: var(--text-dim); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.entity-card .desc { color: var(--text-dim); font-size: 13px; }
.entity-card .row { display: flex; gap: 8px; flex-wrap: wrap; }
.entity-card .footrow { display: flex; justify-content: space-between; align-items: center; }

/* ===== Deploy pipeline ===== */
.deploy-pipeline {
  display: grid;
  grid-template-columns: 1fr 100px 1fr 100px 1fr;
  align-items: stretch;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
.stage {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--space-3); min-height: 280px; display: flex; flex-direction: column; gap: 8px;
}
.stage h2 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.stage[data-stage="lab"] { box-shadow: inset 0 -2px 0 var(--lab); }
.stage[data-stage="staging"] { box-shadow: inset 0 -2px 0 var(--staging); }
.stage[data-stage="production"] { box-shadow: inset 0 -2px 0 var(--prod); }
.stage-items { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; overflow: auto; max-height: 340px; }
.stage-items li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font-size: 13px;
}
.stage-items input[type="checkbox"] { accent-color: var(--accent); }
.stage-items .id { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }
.gate { display: grid; place-items: center; gap: 8px; }
.gate-arrow { color: var(--accent); font-size: 22px; }
.signoffs { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.signoffs li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
  background: var(--bg-2); border-radius: 8px; padding: 8px; font-size: 13px;
}
@media (max-width: 1000px) { .deploy-pipeline { grid-template-columns: 1fr; } .gate { padding: 8px; } .gate-arrow { transform: rotate(90deg); } }

/* ===== Audit ===== */
.audit-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.audit-table th, .audit-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.audit-table th { background: var(--bg-2); color: var(--text-dim); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.audit-table tr:last-child td { border-bottom: 0; }
.audit-table code { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }
.audit-status { color: var(--text-dim); margin-top: var(--space-3); font-size: 13px; }
.audit-status.ok { color: var(--ok); }
.audit-status.err { color: var(--err); }

/* ===== Policy ===== */
.check-row {
  display: grid; gap: 8px; align-items: center;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto 1fr;
  margin-top: var(--space-3);
}
.check-row select { background: var(--bg-0); color: var(--text); border: 1px solid var(--line-2); padding: 8px; border-radius: 8px; }
.check-out { font-family: var(--font-mono); font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--bg-2); border: 1px solid var(--line); min-height: 36px; display: flex; align-items: center; }
.check-out.allow { color: var(--ok); border-color: rgba(52,211,153,.4); }
.check-out.deny { color: var(--err); border-color: rgba(251,113,133,.4); }
@media (max-width: 800px) { .check-row { grid-template-columns: 1fr 1fr; } }

/* ===== Prose ===== */
.prose { max-width: 70ch; }
.prose h2 { font-size: 16px; margin-top: var(--space-5); }
.prose ul { padding-left: 20px; }
.prose li { margin-bottom: 4px; }

/* ===== Modal ===== */
.modal-back {
  position: fixed; inset: 0; background: rgba(5, 8, 18, .55);
  display: grid; place-items: center; z-index: 100; padding: var(--space-4);
  animation: fade-in var(--motion);
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: var(--radius-lg); width: min(560px, 100%);
  padding: var(--space-5); box-shadow: var(--shadow-lg); position: relative;
  animation: pop-in var(--motion);
}
.modal-x {
  position: absolute; top: 8px; right: 10px; background: transparent; border: 0;
  color: var(--text-dim); font-size: 22px; cursor: pointer;
}
.modal h2 { margin: 0 0 var(--space-3); font-size: 18px; }
.modal label { display: grid; gap: 4px; margin-bottom: var(--space-3); font-size: 13px; color: var(--text-dim); }
.modal label > span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.modal input[type=text], .modal textarea, .modal select {
  width: 100%; background: var(--bg-0); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; font: inherit;
}
.modal textarea { min-height: 100px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 80px);
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 18px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 200;
  transition: transform var(--motion), opacity var(--motion); opacity: 0;
  max-width: 90vw; text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.err { border-color: var(--err); color: var(--err); }
.toast.ok  { border-color: var(--ok); color: var(--ok); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { transform: scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
