:root {
  --bg: #05070c;
  --bg-2: #0a0e17;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-solid: #10131d;
  --surface-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --border-soft: rgba(255, 255, 255, 0.06);
  --text: #eef1f7;
  --text-dim: #8a92a6;
  --text-faint: #5b6275;
  --accent: #35e0a8;
  --accent-2: #2fb8e0;
  --accent-dim: #1f8a68;
  --warn: #e8b13e;
  --danger: #f2545b;
  --unknown: #7a86a0;
  --radius: 18px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, rgba(53, 224, 168, 0.08), transparent 45%),
    radial-gradient(circle at 85% 15%, rgba(47, 184, 224, 0.06), transparent 40%);
  background-attachment: fixed;
}

button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* -- shared glass surface --------------------------------------------------- */

.glass {
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* -- login screen ------------------------------------------------------- */

#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  background-image: radial-gradient(circle at 50% 20%, rgba(53, 224, 168, 0.12), transparent 55%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

#login-screen.hidden { display: none; }

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 30px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  text-align: center;
}

.brand-mark {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--accent);
}

.login-card h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.login-card p.sub { color: var(--text-dim); font-size: 13px; margin: 0 0 6px; }
.login-card form { width: 100%; display: flex; flex-direction: column; gap: 12px; }

.login-card input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 13px 15px;
  font-size: 16px;
  width: 100%;
}
.login-card input:focus { outline: none; border-color: var(--accent-dim); }

.login-error { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }

/* -- top bar / views ------------------------------------------------------ */

#topbar {
  padding: calc(10px + var(--safe-top)) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(5, 7, 12, 0.85);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 5;
}

#topbar .title { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }

.demo-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 10px 5px 8px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.demo-indicator .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px rgba(53,224,168,0.7); }
.demo-indicator .dot.warn { background: var(--warn); box-shadow: 0 0 8px rgba(232,177,62,0.7); }
.demo-indicator .dot.fail { background: var(--danger); box-shadow: 0 0 8px rgba(242,84,91,0.7); }

.status-drawer {
  position: absolute;
  top: 100%;
  right: 12px;
  z-index: 20;
  width: min(300px, 88vw);
  margin-top: 6px;
  padding: 14px;
}
.status-drawer.hidden { display: none; }

#views {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 12px 12px calc(16px + var(--safe-bottom));
  display: none;
  -webkit-overflow-scrolling: touch;
}

.view.active { display: block; }

/* -- bottom nav ------------------------------------------------------------ */

#bottom-nav {
  display: flex;
  border-top: 1px solid var(--border-soft);
  background: rgba(5, 7, 12, 0.9);
  backdrop-filter: blur(14px);
  padding-bottom: var(--safe-bottom);
}

#bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 8px 2px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  transition: color 0.15s ease;
}

#bottom-nav button.active { color: var(--accent); }
#bottom-nav button .icon { font-size: 18px; line-height: 1; }
.nav-label { letter-spacing: 0.01em; }

/* -- cards ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 15px;
  margin-bottom: 10px;
}

.card h3 { margin: 0 0 8px; font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.card .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13.5px; gap: 10px; }
.card .row .k { color: var(--text-dim); }
.card .row .v { text-align: right; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 10.5px; font-weight: 650; letter-spacing: 0.02em; }
.pill.pass { background: rgba(53,224,168,0.14); color: var(--accent); }
.pill.fail { background: rgba(242,84,91,0.14); color: var(--danger); }
.pill.unknown { background: rgba(122,134,160,0.14); color: var(--unknown); }
.pill.na { background: rgba(122,134,160,0.08); color: var(--text-dim); }
.pill.warn { background: rgba(232,177,62,0.14); color: var(--warn); }

/* -- trading card (chat) ----------------------------------------------------- */

.trading-card {
  margin-top: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  overflow: hidden;
}
.trading-card .tc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border-soft);
}
.trading-card .tc-instrument { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }
.trading-card .tc-direction { font-size: 11px; color: var(--text-dim); margin-left: 6px; }
.trading-card .tc-body { padding: 10px 14px 12px; }
.trading-card .tc-reason { font-size: 13px; color: var(--text-dim); line-height: 1.45; margin-bottom: 8px; }
.trading-card .tc-levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.trading-card .tc-level { background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; }
.trading-card .tc-level .lbl { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }
.trading-card .tc-level .val { font-size: 13.5px; font-weight: 650; margin-top: 2px; }
.trading-card .tc-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.trading-card .tc-meta .pill { font-size: 10px; }

.confirm-toggle {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  padding: 9px 12px;
  font-size: 12.5px;
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.confirm-list { margin-top: 6px; display: none; flex-direction: column; gap: 6px; }
.confirm-list.open { display: flex; }
.confirm-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.confirm-row .sym { font-weight: 700; margin-right: 6px; }
.confirm-row .sym.pass { color: var(--accent); }
.confirm-row .sym.fail { color: var(--danger); }
.confirm-row .sym.unknown { color: var(--unknown); }
.confirm-row .sym.na { color: var(--text-faint); }
.confirm-row .exp { color: var(--text-faint); font-size: 11px; display: block; margin-top: 2px; }

.checklist-item { border-bottom: 1px solid var(--border-soft); padding: 8px 0; }
.checklist-item:last-child { border-bottom: none; }
.checklist-item .head { display: flex; justify-content: space-between; align-items: center; }
.checklist-item .code { font-size: 13px; }
.checklist-item .reason { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* -- chat ------------------------------------------------------------------- */

#chat-view { display: flex; flex-direction: column; padding: 0; }
#chat-messages { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }

.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px 16px;
  gap: 6px;
  min-height: 40vh;
}
.welcome-mark { font-size: 11px; font-weight: 700; letter-spacing: 0.24em; color: var(--accent); margin-bottom: 4px; }
.welcome-title { font-size: 26px; font-weight: 650; letter-spacing: -0.015em; }
.welcome-tagline { font-size: 14px; color: var(--text-dim); margin: 6px 0 20px; font-style: italic; }
.welcome-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.bubble { max-width: 88%; padding: 11px 14px; border-radius: 18px; font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04140f; border-bottom-right-radius: 5px; font-weight: 500; }
.bubble.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.bubble.system { align-self: center; background: transparent; color: var(--text-faint); font-size: 11.5px; text-align: center; max-width: 96%; }
.bubble.error { border-color: rgba(242,84,91,0.4); }

.bubble .retry-row { margin-top: 8px; display: flex; }
.bubble .retry-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 20px; padding: 5px 12px; font-size: 12px; }

.quick-action-row { display: flex; gap: 6px; padding: 0 12px 8px; overflow-x: auto; scrollbar-width: none; }
.quick-action-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 20px;
  padding: 7px 13px;
  font-size: 12.5px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.chip:active { background: rgba(255,255,255,0.12); }
.chip.disabled { opacity: 0.4; }

#chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--border-soft);
  background: rgba(5,7,12,0.85);
  backdrop-filter: blur(14px);
}

#chat-input-bar textarea {
  flex: 1;
  resize: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  padding: 11px 15px;
  font-size: 15px;
  max-height: 120px;
  line-height: 1.35;
}
#chat-input-bar textarea:focus { outline: none; border-color: var(--accent-dim); }

.send-btn {
  background: var(--accent);
  color: #04140f;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.send-btn:disabled { background: var(--surface-2); color: var(--text-faint); }
.send-btn:active:not(:disabled) { transform: scale(0.92); }

.loading-dots { display: inline-flex; gap: 3px; align-items: center; }
.loading-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--text-dim); animation: pulse 1.1s infinite ease-in-out; }
.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

.confirm-buttons { display: flex; gap: 8px; margin-top: 8px; }
.confirm-buttons button { flex: 1; border-radius: 10px; padding: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13px; }
.confirm-buttons button.yes { border-color: var(--accent-dim); color: var(--accent); }
.confirm-buttons button.no { border-color: var(--danger); color: var(--danger); }

/* -- controls / buttons ------------------------------------------------------ */

.btn { border-radius: var(--radius-sm); padding: 11px 14px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13.5px; transition: transform 0.1s ease; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04140f; border: none; font-weight: 650; }
.btn.danger { border-color: rgba(242,84,91,0.5); color: var(--danger); }
.btn.small { padding: 7px 11px; font-size: 12px; }
.btn.full { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.empty-state { color: var(--text-dim); font-size: 13px; text-align: center; padding: 34px 10px; }
.loading { color: var(--text-dim); font-size: 13px; text-align: center; padding: 18px; }
.section-title { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; margin: 16px 4px 8px; font-weight: 600; }

/* -- forward-testing screen: visual, not tabular ----------------------------- */

.progress-track { background: var(--surface-2); border-radius: 20px; height: 8px; overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 20px; transition: width 0.4s ease; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 4px; }
.stat-tile { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat-tile .num { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.stat-tile .lbl { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.stat-tile .num.pos { color: var(--accent); }
.stat-tile .num.neg { color: var(--danger); }

.timeline { display: flex; flex-direction: column; gap: 6px; }
.timeline-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: none; }
.timeline-dot.pass { background: var(--accent); }
.timeline-dot.fail { background: var(--danger); }
.timeline-dot.unknown { background: var(--unknown); }
.timeline-body { flex: 1; font-size: 12.5px; }
.timeline-body .inst { font-weight: 650; }
.timeline-body .meta { color: var(--text-faint); font-size: 11px; margin-top: 1px; }

.bar-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 6px 0; }
.bar-row .bar-label { width: 76px; flex: none; color: var(--text-dim); }
.bar-row .bar-track { flex: 1; height: 7px; border-radius: 20px; background: var(--surface-2); overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 20px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.bar-row .bar-val { width: 56px; flex: none; text-align: right; color: var(--text-faint); font-size: 11px; }

/* -- history screen ----------------------------------------------------------- */

.history-msg { padding: 8px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.history-msg:last-child { border-bottom: none; }
.history-msg .who { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.history-msg .txt { color: var(--text); white-space: pre-wrap; }
.history-msg.user .who { color: var(--accent); }

/* -- responsive safety ---------------------------------------------------- */

@media (max-width: 340px) {
  .trading-card .tc-levels { grid-template-columns: 1fr 1fr; }
}
