:root {
  --bg: #10141a;
  --panel: #1a2029;
  --border: #2a3341;
  --text: #dbe2ec;
  --muted: #8593a5;
  --accent: #4f8ef7;
  --ok: #2e9e5b;
  --warn: #c98a1b;
  --err: #cf4a4a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.9rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

nav .brand { font-weight: 700; margin-right: 0.5rem; }
nav a { color: var(--muted); text-decoration: none; padding: 0.2rem 0; }
nav a.active, nav a:hover { color: var(--text); }
nav form.inline { margin-left: auto; }

main { max-width: 68rem; margin: 0 auto; padding: 1rem; }

h1 { font-size: 1.4rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.6rem; }
h2 .more { font-size: 0.8rem; font-weight: 400; margin-left: 0.5rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }

section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

a { color: var(--accent); }
.muted { color: var(--muted); }

.banner { border-radius: 8px; padding: 0.6rem 0.9rem; margin-bottom: 0.8rem; }
.banner.ok { background: rgba(46, 158, 91, 0.15); border: 1px solid var(--ok); }
.banner.warn { background: rgba(201, 138, 27, 0.12); border: 1px solid var(--warn); }
.banner.err { background: rgba(207, 74, 74, 0.12); border: 1px solid var(--err); }

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0.5rem 1rem;
}
.status-grid > div { display: flex; flex-direction: column; }
.status-grid .label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; }

.badge {
  display: inline-block;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge.ok { background: rgba(46, 158, 91, 0.2); color: #5ecb8b; }
.badge.warn { background: rgba(201, 138, 27, 0.2); color: #e8b45a; }
.badge.err { background: rgba(207, 74, 74, 0.2); color: #e88; }
.badge.long { background: rgba(46, 158, 91, 0.2); color: #5ecb8b; }
.badge.short { background: rgba(207, 74, 74, 0.2); color: #e88; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
tr.row-warn td { background: rgba(201, 138, 27, 0.08); }
.zscore-note { margin: 0.8rem 0 0; font-size: 0.84rem; }
.zscore-summary strong { font-size: 0.95rem; }
.zscore-table .badge + .badge { margin-left: 0.25rem; }
.zscore-table tbody tr.zscore-ready td:last-child strong { color: #e6c67a; }
.zscore-pending-grid { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.zscore-pending { border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 0.9rem; }
.zscore-pending h3 { margin: 0 0 0.5rem; font-size: 0.92rem; }
.zscore-pending .status-grid { gap: 0.4rem 1rem; }
.zscore-pending p { margin: 0.6rem 0 0; font-size: 0.8rem; }

.pos { color: #5ecb8b; }
.neg { color: #e88; }

form label { display: block; margin: 0.5rem 0 0.15rem; font-size: 0.85rem; color: var(--muted); }
input, select, textarea {
  width: 100%;
  max-width: 22rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
button {
  margin-top: 0.6rem;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.55; cursor: wait; }
button.danger { background: var(--err); border-color: var(--err); }
button.warn { background: var(--warn); border-color: var(--warn); }
button.small { margin-top: 0; padding: 0.2rem 0.6rem; font-size: 0.8rem; }
button.link {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 400;
  cursor: pointer;
}
button.link:hover { color: var(--text); }
button.ghost { background: none; border-color: var(--border); color: var(--text); }
button.ghost:hover { filter: none; border-color: var(--muted); }

/* Inline symbol-row editing */
.row-edit td { vertical-align: top; }
.row-edit form { display: flex; gap: 0.4rem; }
.cell-input {
  width: 100%;
  min-width: 5rem;
  max-width: 9rem;
  margin: 0;
  padding: 0.25rem 0.4rem;
}
.row-actions { display: inline-flex; flex-wrap: nowrap; gap: 0.4rem; align-items: center; white-space: nowrap; }
.row-actions form { display: inline-flex; margin: 0; }
.small-link { font-size: 0.8rem; text-decoration: none; padding: 0.2rem 0.35rem; }
.cell-error { color: var(--err); font-size: 0.78rem; margin-top: 0.3rem; white-space: normal; max-width: 9rem; }
.cell-notice { color: var(--ok); font-size: 0.78rem; margin-top: 0.3rem; white-space: normal; max-width: 18rem; }

.button-link {
  display: inline-block;
  margin-top: 0.6rem;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1rem;
  margin-top: 0.8rem;
}
.form-grid form { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.8rem; }

.action-row { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-top: 0.8rem; }
.inline-form { display: flex; align-items: center; gap: 0.5rem; }
.inline-form label { margin: 0; }
.inline-form select { width: auto; }
.inline-form button { margin-top: 0; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.filter-bar label { margin: 0; }
.filter-bar select { width: auto; }
.filter-bar button { margin-top: 0; }

.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 0.8rem; }

.feed-detail { margin-top: 0.6rem; color: var(--muted); font-size: 0.85rem; }
.feed-detail ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

.login-box { max-width: 22rem; margin: 15vh auto 0; }
.login-box h1 { text-align: center; }
.login-box input { max-width: none; }
.login-box button { width: 100%; }

/* Quant Lab */
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.page-heading h1, .page-heading h2 { margin-bottom: 0.2rem; }
.page-heading p { margin-top: 0; }
.quant-summary strong { font-size: 1rem; }
.quant-note { font-size: 0.82rem; margin: 0.8rem 0 0; }
.quant-assumptions { display: grid; grid-template-columns: repeat(3, minmax(10rem, 1fr)) auto; gap: 0.7rem; align-items: end; }
.quant-assumptions label { margin: 0; }
.quant-assumptions input { max-width: none; margin-top: 0.2rem; }
.quant-assumptions button { margin: 0; }
.quant-table td { vertical-align: middle; }
.selected-row td { background: rgba(79, 142, 247, 0.08); }
.quant-empty { text-align: center; padding: 3rem 1rem; }
.quant-empty.compact { padding: 1rem; }
.quant-icon { font-size: 2.5rem; color: var(--accent); }
details { margin-top: 1rem; }
summary { cursor: pointer; color: var(--accent); margin-bottom: 0.7rem; }

@media (max-width: 760px) {
  .page-heading { display: block; }
  .quant-assumptions { grid-template-columns: 1fr; }
  .quant-assumptions button { width: 100%; }
  .quant-table table, .quant-table tbody, .quant-table tr, .quant-table td { display: block; width: 100%; }
  .quant-table thead { display: none; }
  .quant-table tr { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem; margin-bottom: 0.7rem; }
  .quant-table td { border: 0; padding: 0.25rem; white-space: normal; }
}

/* Live trading */
.live-banner { padding: .6rem .9rem; border-radius: 6px; margin-bottom: .8rem; font-size: .95rem; }
.live-banner.mode-paper { background: #14321f; color: #9fe3b6; border: 1px solid #2c6b43; }
.live-banner.mode-live { background: #3a1414; color: #ffb4b4; border: 1px solid #8d2b2b; }
.live-banner.mode-recovery { background: #3a2f10; color: #ffd98a; border: 1px solid #8d7420; }
tr.live-row { background: rgba(141, 43, 43, .12); }
.badge.book-live { background: #8d2b2b; color: #fff; }
.badge.book-shadow { background: #3f4a63; color: #cfe0ff; }
.badge.book-paper { background: #2c3a2f; color: #b9d8c2; }
.badge.warn { background: #8d7420; color: #fff5d6; }
.warn { color: #ffd98a; }
.status-grid { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; }
.status-grid dt { color: #8b97a8; }
.status-grid dd { margin: 0; }
.preflight { list-style: none; padding: 0; }
.preflight li { padding: .25rem 0; border-bottom: 1px solid #1e2530; }
.preflight li.fail strong { color: #ffb4b4; }
.preflight li.warn strong { color: #ffd98a; }
.preflight .mark { display: inline-block; width: 1.6rem; }
.actions-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem; align-items: end; }
.inline-form { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; margin: .6rem 0; }
.book-tabs { display: flex; gap: .4rem; margin-bottom: .8rem; }
.book-tabs a { padding: .3rem .8rem; border-radius: 5px; background: #1b2230; color: #9fb0c8; text-decoration: none; font-size: .9rem; }
.book-tabs a.active { background: #2c3a52; color: #e8eef7; }
