/* ================================================================
   Vectrax — Product Interface
   ================================================================ */
:root {
  --bg:       #0b0e14;
  --surface:  #141922;
  --surface2: #1a2030;
  --border:   #252d3a;
  --text:     #d1d5db;
  --dim:      #6b7280;
  --accent:   #4f8ff7;
  --ok:       #34d399;
  --warn:     #fbbf24;
  --err:      #f87171;
  --r:        6px;
  --font:     -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono:     'SF Mono', Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ----------------------------------------------------------------
   UTILITIES
   ---------------------------------------------------------------- */
.dim  { color: var(--dim); }
.err  { color: var(--err); }
.mono { font-family: var(--mono); font-size: 12px; }
.full { width: 100%; }

/* Tags / Badges */
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  background: var(--surface2); color: var(--dim);
}
.tag-ok     { background: #0d2b1a; color: var(--ok); }
.tag-warn   { background: #2b1d0d; color: var(--warn); }
.tag-err    { background: #2b0d0d; color: var(--err); }
.tag-dim    { background: var(--surface2); color: var(--dim); }
.tag-owner  { background: #0d2b1a; color: var(--ok); }
.tag-operator { background: #1a1a40; color: var(--accent); }
.tag-viewer { background: var(--surface2); color: var(--dim); }

/* ----------------------------------------------------------------
   BUTTONS
   ---------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 18px; border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface); color: var(--text);
  font-size: 13px; font-family: var(--font); cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--surface2); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { opacity: 0.9; }
.btn-ok  { background: var(--ok); color: #000; border-color: var(--ok); }
.btn-err { background: var(--err); color: #fff; border-color: var(--err); }
.btn-ghost { background: none; border-color: var(--border); color: var(--dim); }
.btn-ghost:hover { color: var(--text); background: var(--surface); }
.btn-sm { padding: 4px 12px; font-size: 12px; }

/* ----------------------------------------------------------------
   FIELDS
   ---------------------------------------------------------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 4px; font-weight: 500; }
.field input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--bg); color: var(--text); font-size: 14px;
  font-family: var(--font); outline: none; transition: border-color 0.2s;
}
.field input:focus { border-color: var(--accent); }

/* ================================================================
   1. LOGIN VIEW
   ================================================================ */
#view-login {
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; background: var(--bg);
}
.login-card {
  width: 380px; padding: 40px 36px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  text-align: center;
}
.login-logo {
  width: 48px; height: 48px; margin: 0 auto 12px;
  background: var(--accent); color: #fff;
  border-radius: 12px; font-size: 24px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.login-title { font-size: 22px; color: var(--text); margin-bottom: 2px; }
.login-subtitle { font-size: 13px; color: var(--dim); margin-bottom: 24px; }
.login-error {
  background: #2b0d0d; color: var(--err); border-radius: var(--r);
  padding: 8px 12px; font-size: 13px; margin-bottom: 12px; display: none;
}

/* ================================================================
   2. APP SHELL
   ================================================================ */
#view-app { display: none; height: 100vh; display: flex; flex-direction: column; }

/* Top bar */
#topbar {
  display: flex; align-items: center; height: 52px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.topbar-left  { display: flex; align-items: center; gap: 8px; }
.topbar-logo  {
  width: 28px; height: 28px; background: var(--accent); color: #fff;
  border-radius: 6px; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.topbar-name  { font-size: 15px; font-weight: 600; color: var(--text); }
.topbar-nav   { display: flex; gap: 0; margin-left: 32px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-identity { font-size: 13px; color: var(--dim); }
.topbar-identity strong { color: var(--text); }

/* Nav buttons */
.nav-btn {
  padding: 14px 18px; border: none; background: none; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--dim);
  border-bottom: 2px solid transparent; transition: all 0.2s;
}
.nav-btn:hover { color: var(--text); }
.nav-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Main panels */
.main-panel { display: none; flex: 1; overflow-y: auto; }
.main-panel.active { display: flex; flex-direction: column; }

/* ================================================================
   3. CHAT VIEW
   ================================================================ */
.chat-context {
  padding: 8px 20px; font-size: 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px; display: flex;
  flex-direction: column; gap: 8px;
}
.chat-empty { color: var(--dim); text-align: center; margin-top: 60px; }
.chat-input-bar {
  display: flex; gap: 8px; padding: 12px 20px;
  background: var(--surface); border-top: 1px solid var(--border);
}
.chat-input-bar input {
  flex: 1; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--bg); color: var(--text); font-size: 14px;
  font-family: var(--font); outline: none;
}
.chat-input-bar input:focus { border-color: var(--accent); }

/* Bubbles */
.bubble {
  max-width: 80%; padding: 10px 14px; border-radius: 10px;
  font-size: 14px; line-height: 1.5; word-break: break-word;
}
.bubble-user {
  align-self: flex-end; background: #1c2a40; color: var(--text);
  border-bottom-right-radius: 2px;
}
.bubble-sys {
  align-self: flex-start; background: var(--surface2); color: var(--text);
  border-bottom-left-radius: 2px;
}
.bubble-id { font-family: var(--mono); font-size: 11px; color: var(--dim); margin-top: 4px; }
.bubble-answer { max-width: 90%; }

/* Sovereign answer — clean, user-facing */
.sovereign-answer {
  white-space: pre-wrap; line-height: 1.6;
  font-size: 14px; color: var(--text);
}
.sovereign-confirm {
  font-size: 13px; color: var(--dim); font-style: italic;
}

/* Debug info — hidden by default, visible when debug mode is active */
.debug-info {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 12px; opacity: 0.7;
}
.tag-debug { background: #1a0d2b; color: #a78bfa; font-weight: 700; }

/* Mode badges (debug only) */
.tag-mode-memory { background: #0d2b1a; color: var(--ok); }
.tag-mode-local  { background: #1a1a40; color: var(--accent); }
.tag-mode-online { background: #2b1d0d; color: var(--warn); }
.tag-fallback { background: #2b0d2b; color: #c084fc; font-style: italic; }

/* Sources panel (debug only) */
.sources-panel {
  margin-top: 10px; padding-top: 8px;
  border-top: 1px solid var(--border);
}
.sources-title {
  font-size: 11px; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px;
}
.source-card {
  padding: 6px 10px; margin-bottom: 4px;
  background: var(--bg); border-radius: var(--r);
  border: 1px solid var(--border);
}
.source-link {
  font-size: 12px; font-weight: 600; color: var(--accent);
  text-decoration: none;
}
.source-link:hover { text-decoration: underline; }
.source-snippet {
  font-size: 11px; color: var(--dim); margin-top: 2px;
  line-height: 1.4; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* ================================================================
   4. DASHBOARD VIEW
   ================================================================ */

/* Metrics strip */
.metrics-strip {
  display: flex; gap: 0; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; flex-shrink: 0;
}
.metric {
  padding: 14px 20px; text-align: center; min-width: 100px;
  border-right: 1px solid var(--border);
}
.metric:last-child { border-right: none; }
.metric-val   { font-size: 18px; font-weight: 700; color: var(--text); }
.metric-label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* Dash nav */
.dash-nav {
  display: flex; gap: 0; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
  overflow-x: auto;
}
.dash-tab {
  padding: 10px 16px; border: none; background: none; cursor: pointer;
  font-size: 13px; color: var(--dim);
  border-bottom: 2px solid transparent; transition: all 0.2s;
}
.dash-tab:hover { color: var(--text); }
.dash-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Sections */
.dash-content { flex: 1; overflow-y: auto; padding: 20px; }
.dash-section { display: none; }
.dash-section.active { display: block; }

/* Cards (dashboard) */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px 16px; margin-bottom: 10px;
}
.card-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px;
}
.card-body { font-size: 13px; color: var(--dim); margin-bottom: 8px; line-height: 1.5; }
.card-meta {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 12px; color: var(--dim);
}
.card-evidence {
  font-size: 12px; color: var(--dim); font-style: italic;
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border);
}

/* Key-value rows */
.kv {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.kv:last-child { border-bottom: none; }

/* Layer rows */
.layer-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.layer-row:last-child { border-bottom: none; }
.layer-id { font-family: var(--mono); font-size: 12px; color: var(--dim); min-width: 24px; }

/* History rows */
.hist-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.hist-row:last-child { border-bottom: none; }
.hist-text { flex: 1; }
.hist-meta { font-size: 11px; }

/* Audit rows */
.audit-row {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.audit-row:last-child { border-bottom: none; }
.audit-ts { font-size: 11px; min-width: 130px; }

/* Proposal actions */
.prop-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ----------------------------------------------------------------
   RESPONSIVE
   ---------------------------------------------------------------- */
@media (max-width: 768px) {
  .metrics-strip { flex-wrap: wrap; }
  .metric { min-width: 80px; flex: 1; }
  .bubble { max-width: 95%; }
  .topbar-nav { margin-left: 16px; }
  .topbar-identity { display: none; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
