:root {
  /* surfaces */
  --bg: #0a0b0d;
  --bg-subtle: #121417;
  --panel-bg: #0e1013;
  --panel-border: #23262b;
  --footer-bg: #060708;

  /* text */
  --text: #e8e6e1;
  --text-muted: #7d828c;
  --border: #33383f;

  /* brand — red is the identity; green/red keep up/down semantics */
  --accent: #ff5252;
  --accent-bright: #ff6b6b;
  --accent-text: #0a0b0d;
  --accent-glow: rgba(255, 82, 82, 0.25);
  --focus-ring: rgba(255, 82, 82, 0.18);

  /* semantic */
  --success: #4caf50;
  --success-glow: rgba(76, 175, 80, 0.3);
  --error: #ff5252;
  --error-glow: rgba(255, 82, 82, 0.3);

  /* secondary terminal accent — warnings / the "Actionable" flag.
     Amber so it never competes with the red brand or green/red P&L. */
  --warn: #ffb000;
  --high-bg: #1c1504;
  --high-border: var(--warn);

  /* typography */
  --font-body: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-display: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* geometry — sharp corners everywhere; badges get 2px */
  --radius: 0px;
  --statusbar-h: 28px;

  /* sidebar layout */
  --navbar-width: 232px;
  --navbar-width-min: 64px;
  --navbar-gap: 0px;
}

* { box-sizing: border-box; }

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: #4a5058; }

body {
  margin: 0;
  min-width: 1280px;
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* brand lockup: "rix|terminal" — rix in action red, pipe + terminal in
   the neutral text color (per Extras/rixterminal.png). Reused by the login
   title, sidebar wordmark, and sidebar footer. */
.wm-rix { color: var(--accent); }
.wm-sep { color: var(--text); padding: 0 0.06em; }
.wm-rest { color: var(--text); }

/* brand text renders lowercase, like typical command-line text */
h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.35rem;
  text-transform: lowercase;
  letter-spacing: 3px;
  margin: 0;
}

.view { min-height: 100vh; }

#app-view { position: relative; }

/* ---------- Login ---------- */

#login-view:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(var(--bg) 0 0) padding-box,
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(255, 255, 255, 0.008) 2px 4px);
}

.login-card {
  width: 340px;
  padding: 2rem;
  border: 1px solid var(--panel-border);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel-bg);
}

.login-card h1 { text-align: center; }

/* blinking block cursor after the wordmark */
#login-title::after {
  content: "\258C";
  color: var(--accent);
  margin-left: 2px;
  animation: cursor-blink 1.1s steps(1) infinite;
}
@keyframes cursor-blink { 50% { opacity: 0; } }

.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 0.5rem;
  margin-bottom: 1.75rem;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.9rem;
}

input:not([type="radio"]):not([type="checkbox"]), select, textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:not([type="radio"]):not([type="checkbox"]):focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

input[type="radio"], input[type="checkbox"] {
  display: inline-block;
  width: auto;
  margin: 0 0.4rem 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}

button[type="submit"], .run-card button, #run-btn {
  padding: 0.55rem 2rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.login-card button[type="submit"] { width: 100%; }

.run-card button {
  display: block;
  width: fit-content;
  min-width: 220px;
  margin: 0 auto;
}

button[type="submit"]:hover, .run-card button:hover, #run-btn:hover {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
  box-shadow: 0 0 12px var(--accent-glow);
}

button:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }

.error { color: var(--error); font-family: var(--mono); font-size: 0.8rem; margin-top: 0.8rem; margin-bottom: 0; }
.status { font-family: var(--mono); font-size: 0.8rem; color: var(--text-muted); margin-top: 0.8rem; }
.status.error { color: var(--error); }
.status.success { color: var(--success); }

/* ---------- Status bar ---------- */

#status-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--statusbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--footer-bg);
  border-bottom: 1px solid var(--panel-border);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  z-index: 2000;
  user-select: none;
}

.statusbar-group { display: flex; align-items: center; gap: 1.5rem; min-width: 0; }

#statusbar-brand { color: var(--accent); font-weight: 700; letter-spacing: 2px; text-transform: lowercase; }
#statusbar-cursor { animation: cursor-blink 1.1s steps(1) infinite; }

#statusbar-tab { color: var(--text); font-weight: 500; }
#statusbar-tab::before { content: "\258D "; color: var(--accent); }

#statusbar-session { display: flex; align-items: center; gap: 0.45rem; }

#statusbar-session-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
#statusbar-session.open #statusbar-session-dot { background: var(--success); box-shadow: 0 0 6px var(--success-glow); }
#statusbar-session.open #statusbar-session-label { color: var(--success); }
#statusbar-session.pre #statusbar-session-dot, #statusbar-session.post #statusbar-session-dot { background: var(--warn); }
#statusbar-session.pre #statusbar-session-label, #statusbar-session.post #statusbar-session-label { color: var(--warn); }

.statusbar-clock { font-variant-numeric: tabular-nums; }

#statusbar-user { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; text-transform: lowercase; }

/* ---------- Sidebar ---------- */

#nav-toggle { display: none; }

#nav-bar {
  position: fixed;
  left: 0;
  top: var(--statusbar-h);
  height: calc(100% - var(--statusbar-h));
  width: var(--navbar-width);
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  border-radius: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  user-select: none;
}

#nav-bar:has(#nav-toggle:checked) { width: var(--navbar-width-min); }

#nav-header {
  position: relative;
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--panel-border);
}

#nav-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  text-transform: lowercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  white-space: nowrap;
  transition: opacity 0.15s;
}

label[for="nav-toggle"] {
  position: absolute;
  right: 10px;
  width: 2.5rem;
  height: 100%;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#nav-toggle-burger,
#nav-toggle-burger::before,
#nav-toggle-burger::after {
  content: "";
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-muted);
  position: absolute;
  transition: background 0.15s;
}
#nav-toggle-burger::before { top: -6px; }
#nav-toggle-burger::after { top: 6px; }
label[for="nav-toggle"]:hover #nav-toggle-burger,
label[for="nav-toggle"]:hover #nav-toggle-burger::before,
label[for="nav-toggle"]:hover #nav-toggle-burger::after { background: var(--text); }

#nav-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0;
}

.tab-btn {
  display: flex;
  align-items: center;
  width: 100%;
  height: 42px;
  padding: 0 18px 0 20px;
  border: none;
  border-left: 3px solid transparent;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn i { min-width: 28px; font-size: 0.95rem; text-align: center; }
.tab-btn span { margin-left: 12px; white-space: nowrap; font-weight: 500; transition: opacity 0.15s; }

.tab-btn kbd {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.05rem 0.35rem;
  opacity: 0.7;
  transition: opacity 0.15s, border-color 0.15s, color 0.15s;
}

.tab-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.04); }

.tab-btn.active {
  color: #fff;
  background: rgba(255, 82, 82, 0.07);
  border-left-color: var(--accent);
}
.tab-btn.active i { color: var(--accent); }
.tab-btn.active kbd { color: var(--accent); border-color: var(--accent); opacity: 1; }

#nav-footer {
  flex-shrink: 0;
  background: var(--footer-bg);
  border-top: 1px solid var(--panel-border);
  border-radius: 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

#nav-footer-titlebox { min-width: 0; overflow: hidden; }

#nav-footer-title {
  display: block;
  color: var(--text);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: lowercase;
  letter-spacing: 1px;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.nav-footer-subtitle {
  display: block;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.62rem;
  text-transform: lowercase;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.15s;
}

/* Collapsed: hide labels/wordmark/footer text/kbd hints, keep icons */
#nav-bar:has(#nav-toggle:checked) #nav-title,
#nav-bar:has(#nav-toggle:checked) .tab-btn span,
#nav-bar:has(#nav-toggle:checked) .tab-btn kbd,
#nav-bar:has(#nav-toggle:checked) #nav-footer-title,
#nav-bar:has(#nav-toggle:checked) .nav-footer-subtitle,
#nav-bar:has(#nav-toggle:checked) #signout-btn {
  opacity: 0;
  pointer-events: none;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--mono);
  cursor: pointer;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0;
  flex-shrink: 0;
  transition: opacity 0.15s, color 0.15s;
}
.link-btn:hover { color: var(--accent-bright); }

/* ---------- Main content ---------- */

#main-content {
  position: absolute;
  left: var(--navbar-width);
  width: calc(100% - var(--navbar-width));
  min-height: 100vh;
  box-sizing: border-box;
  padding: calc(var(--statusbar-h) + 1.25rem) 1.5rem 2rem;
  transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#nav-bar:has(#nav-toggle:checked) + #main-content {
  left: var(--navbar-width-min);
  width: calc(100% - var(--navbar-width-min));
}

/* ---------- Run form ---------- */

.run-card {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  background: var(--panel-bg);
  margin-bottom: 1.25rem;
}

.field-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.field-row[hidden] { display: none; }

.field-row label { flex: 1; min-width: 160px; }

/* ---------- Result ---------- */

.result-panel {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel-bg);
  overflow: hidden;
}

.result-meta {
  padding: 0.5rem 1.25rem;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--panel-border);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.markdown {
  padding: 1.1rem 1.4rem;
  line-height: 1.5;
  overflow-x: auto;
}

.markdown h1, .markdown h2 {
  font-family: var(--font-display);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.markdown h1 { font-size: 1.1rem; border-bottom: 1px solid var(--panel-border); padding-bottom: 0.4rem; }
.markdown h2 { font-size: 0.92rem; margin-top: 1.5rem; }
.markdown h2::before { content: "\258D "; color: var(--accent); }
.markdown h3 {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 1.25rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.markdown code { font-family: var(--mono); background: var(--bg-subtle); padding: 0.1em 0.35em; border-radius: 2px; font-size: 0.85em; }
.markdown pre {
  background: var(--bg-subtle);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.5;
}
.markdown pre code { background: none; padding: 0; border-radius: 0; font-size: inherit; }
.markdown a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted var(--accent); }
.markdown a:hover { color: var(--accent-bright); border-bottom-style: solid; }
.markdown ul { padding-left: 1.2rem; }
.markdown li { margin-bottom: 0.45rem; }

.markdown table { border-collapse: collapse; width: 100%; font-size: 0.78rem; font-family: var(--mono); }
.markdown th, .markdown td { border: 1px solid var(--panel-border); padding: 0.3rem 0.5rem; text-align: right; }
.markdown th:first-child, .markdown td:first-child { text-align: left; }
.markdown th {
  background: var(--bg-subtle);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.markdown tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* High-priority section: find the <h2> containing "Actionable" and
   style it and its following list distinctly via a wrapper class added
   in JS (see app.js highlightHighPriority). Amber flag — the terminal's
   warning color — so it stands apart from the red brand chrome. */
.markdown .high-priority-block {
  background: var(--high-bg);
  border: 1px solid var(--high-border);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 0.25rem 1rem 1rem;
  margin: 0.75rem 0 1.25rem;
}
.markdown .high-priority-block h2 { margin-top: 0.75rem; color: var(--warn); }
.markdown .high-priority-block h2::before { color: var(--warn); }

/* ---------- History ---------- */

.history-list { display: flex; flex-direction: column; gap: 0.35rem; }

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.9rem;
  background: var(--bg-subtle);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: border-color 0.15s, background 0.15s;
}

.history-item:hover { border-color: var(--accent); border-left-color: var(--accent); }

.history-item span:first-child { font-family: var(--mono); }

.history-item .badges { display: flex; gap: 0.5rem; align-items: center; color: var(--text-muted); font-family: var(--mono); font-size: 0.72rem; }

.badge {
  padding: 0.1rem 0.45rem;
  border-radius: 2px;
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge.error { color: var(--error); border-color: var(--error); }

.empty-state { color: var(--text-muted); font-family: var(--mono); font-size: 0.8rem; text-align: center; padding: 2rem 0; }

.history-section { margin-top: 1.5rem; }

.history-heading {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin: 0 0 0.6rem;
}
.history-heading::before { content: "\258D "; color: var(--accent); }

/* Watchlist rows reuse .history-item but aren't themselves clickable —
   only the remove button is interactive. */
.history-item:has(.remove-btn) { cursor: default; }

.remove-btn {
  background: transparent;
  border: 1px solid var(--error);
  border-radius: var(--radius);
  color: var(--error);
  font-family: var(--mono);
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
  padding: 0.2rem 0.45rem;
  transition: background 0.15s, color 0.15s;
}

.remove-btn:hover {
  background: var(--error);
  color: var(--accent-text);
}

/* Overrides the generic input rule's display:block/width:100%/margin-top
   (same specificity, wins on source order) so the catalyst date picker
   sits inline in the watchlist row's .badges flex row instead of
   stacking as a full-width block. */
input[type="date"].catalyst-input {
  display: inline-block;
  width: auto;
  margin-top: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 0.1rem 0.3rem;
}

/* ---------- Terminal-style monospace for data entry ---------- */

#quote-result-text,
#quote-ticker-input,
#watchlist-ticker-input,
#ncav-tickers-input,
#tender-tickers-input {
  font-family: var(--mono);
}
