:root {
  --bg: #0c0f14;
  --bg-2: #11161f;
  --panel: #151c27;
  --panel-2: #1b2433;
  --line: #243044;
  --text: #e6edf6;
  --muted: #8a97ab;
  --accent: #4da3ff;
  --accent-2: #6ee7b7;
  --danger: #ff6b6b;
  --lock: #f0b429;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #16213400, #0c0f14) , var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }
a { color: var(--accent); }

/* Brand */
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; letter-spacing: .02em; }
.brand-mark { color: var(--accent); transform: translateY(1px); }
.brand-name { font-size: 1.15rem; }
.brand.small .brand-name { font-size: 1rem; }
.brand-logo { width: 1.7rem; height: 1.7rem; display: block; border-radius: 6px; flex: none; }
.brand.small .brand-logo { width: 1.35rem; height: 1.35rem; }

/* ----------------------------- LOGIN ----------------------------- */
.login-view {
  min-height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1.2rem; padding: 2rem;
}
.login-card {
  width: 100%; max-width: 420px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2rem;
}
.login-card .brand { margin-bottom: 1.25rem; }
.login-card h1 { font-size: 1.35rem; margin: 0 0 .4rem; }
.login-card .sub { color: var(--muted); margin: 0 0 1.4rem; }
.login-card form { display: flex; flex-direction: column; gap: .85rem; }
.login-card label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--muted); }
.login-card input {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: .7rem .8rem; font-size: .95rem; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
#login-btn {
  margin-top: .4rem; background: var(--accent); color: #05080d; border: 0;
  border-radius: 8px; padding: .75rem; font-weight: 700; transition: filter .15s;
}
#login-btn:hover { filter: brightness(1.08); }
#login-btn:disabled { opacity: .6; cursor: progress; }
.error { color: var(--danger); min-height: 1.1em; margin: .2rem 0 0; font-size: .85rem; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 1rem; }
.hint code { background: var(--bg-2); padding: .1rem .35rem; border-radius: 5px; }
.login-foot { color: var(--muted); font-size: .78rem; }

/* ----------------------------- APP ----------------------------- */
.app-view { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .8rem;
  padding: .7rem 1.1rem; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: .85rem; }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .8rem; }
.ghost:hover { border-color: var(--accent); }

.layout { flex: 1; display: grid; grid-template-columns: 260px 1fr; min-height: 0; }
.sidebar { border-right: 1px solid var(--line); padding: 1rem .8rem; overflow: auto; }
.sidebar h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: .2rem .4rem 1rem; }
.element-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.element-list li {
  display: flex; align-items: baseline; gap: .6rem; padding: .55rem .6rem;
  border-radius: 8px; cursor: pointer; transition: background .12s;
}
.element-list li:hover { background: var(--panel); }
.element-list li.active { background: var(--panel-2); outline: 1px solid var(--line); }
.element-list .sym { font-weight: 700; color: var(--accent); width: 2.2em; }
.element-list .nm { color: var(--text); }
.element-list .cat { margin-left: auto; color: var(--muted); font-size: .72rem; }

.detail { padding: 1.4rem 1.6rem; overflow: auto; }
.empty { color: var(--muted); }
.empty .muted { display: grid; place-items: center; height: 40vh; }
/* Market overview dashboard */
.ov-head { display: flex; align-items: baseline; gap: .7rem; margin-bottom: .6rem; flex-wrap: wrap; }
.ov-head h2 { margin: 0; font-size: 1.4rem; }
.ov-movers { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .75rem; margin-bottom: 1rem; font-size: .9rem; }
.ov-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ov-table th { text-align: left; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; padding: .4rem .6rem; border-bottom: 1px solid var(--line); }
.ov-table td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ov-table tbody tr { cursor: pointer; }
.ov-table tbody tr:hover { background: var(--panel); }
.ov-unit { color: var(--muted); font-size: .76rem; }
.ov-table .pos { color: var(--accent-2); } .ov-table .neg { color: var(--danger); }
.spark { display: block; }
.detail-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: 1rem; }
.detail-head h2 { margin: 0; font-size: 1.5rem; }
.el-meta { color: var(--muted); font-size: .85rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .7rem; }
.panel-head h3 { margin: 0; font-size: .95rem; }
.scores { font-size: .78rem; color: var(--muted); }
.scores b { color: var(--accent-2); font-weight: 700; }
.muted { color: var(--muted); font-size: .8rem; }

.synthesis { white-space: pre-wrap; line-height: 1.6; }
.synthesis.locked, .feed .locked, .chart-wrap.locked { color: var(--lock); }
.locked-box { display: flex; align-items: center; gap: .5rem; color: var(--lock); background: rgba(240,180,41,.07);
  border: 1px dashed rgba(240,180,41,.35); border-radius: 8px; padding: .7rem .9rem; font-size: .88rem; }

.chart-wrap { position: relative; min-height: 140px; }
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .7rem; }
.feed li { border-left: 2px solid var(--line); padding: .15rem 0 .15rem .8rem; }
.feed .ev-title { font-weight: 600; }
.feed .ev-meta { color: var(--muted); font-size: .78rem; margin-top: .15rem; }
.feed .ev-sum { color: var(--text); opacity: .9; margin-top: .25rem; }

/* ----------------------------- ADMIN PANEL ----------------------------- */
.admin-view { padding: 1.4rem 1.6rem; overflow: auto; max-width: 1000px; }
.admin-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.admin-head h2 { margin: 0; font-size: 1.4rem; }
.form-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.form-row input, .form-row select {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: .55rem .7rem; font-size: .9rem; outline: none;
}
.form-row input:focus, .form-row select:focus { border-color: var(--accent); }
.form-row input { min-width: 180px; }
.form-row button {
  background: var(--accent); color: #05080d; border: 0; border-radius: 8px;
  padding: .6rem .9rem; font-weight: 700;
}
.admin-msg { color: var(--muted); font-size: .82rem; margin: .6rem 0 0; min-height: 1em; }

.users-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.users-table th, .users-table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
.users-table th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.users-table td { vertical-align: middle; }
.users-table select.mini { background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: .3rem .4rem; font-size: .82rem; }
.users-table input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.row-actions { display: flex; gap: .7rem; }
.link { background: none; border: 0; color: var(--accent); padding: 0; font-size: .85rem; cursor: pointer; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }
.link:disabled { color: var(--muted); cursor: not-allowed; text-decoration: none; }
.tag-you { font-size: .68rem; color: var(--accent-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .25rem; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .9rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 20px; padding: .25rem .6rem; font-size: .82rem; }
.chip-x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .8rem; line-height: 1; }
.chip-x:hover { color: var(--danger); }

/* ---------------------- Connected sources (header dots) ---------------------- */
.sources-status { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-left: .6rem; }
.ss-label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.ss-item { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; color: var(--text); cursor: default; }
.ss-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent-2);
  box-shadow: 0 0 0 0 rgba(110,231,183,.7); animation: pulse 1.8s infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(110,231,183,.6); }
  70%  { box-shadow: 0 0 0 7px rgba(110,231,183,0); }
  100% { box-shadow: 0 0 0 0 rgba(110,231,183,0); }
}

/* ---------------------- Market range selector ---------------------- */
.range-sel { display: inline-flex; gap: 2px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.range-sel button { background: transparent; color: var(--muted); border: 0; border-radius: 6px; padding: .25rem .55rem; font-size: .78rem; }
.range-sel button:hover { color: var(--text); }
.range-sel button.active { background: var(--accent); color: #05080d; font-weight: 700; }
.custom-range { display: flex; align-items: center; gap: .5rem; margin: .6rem 0 .2rem; font-size: .85rem; }
.custom-range input[type=date] { background: var(--bg-2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: .35rem .5rem; }
.mini-btn { background: var(--accent); color: #05080d; border: 0; border-radius: 6px; padding: .35rem .6rem; font-size: .8rem; font-weight: 700; }
.mini-btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }

/* ---------------------- Claims / evidence ---------------------- */
.claims { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .7rem; }
.claim { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; background: var(--bg-2); }
.claim-top { display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.ctype { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); border: 1px solid var(--line); border-radius: 4px; padding: 0 .35rem; }
.cscore { margin-left: auto; color: var(--accent-2); font-size: .78rem; }
.cstmt { line-height: 1.45; }
.cval { display: inline-block; margin-top: .3rem; background: #0c1118; border: 1px solid var(--line); border-radius: 6px; padding: .15rem .4rem; font-size: .78rem; color: var(--muted); }
.claim-foot { display: flex; align-items: center; gap: .7rem; margin-top: .5rem; flex-wrap: wrap; }
.cauthor { color: var(--muted); font-size: .74rem; }
.badge { font-size: .68rem; border-radius: 4px; padding: 0 .35rem; border: 1px solid var(--line); }
.badge.disputed { color: var(--lock); border-color: rgba(240,180,41,.4); }
.badge.superseded { color: var(--muted); }

/* provenance trigger chip */
.prov { display: inline-flex; align-items: center; gap: .35rem; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 14px; padding: .15rem .55rem; font-size: .76rem; cursor: pointer; }
.prov:hover { border-color: var(--accent); }
.prov-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.prov-dot.t5 { background: var(--accent-2); } .prov-dot.t4 { background: #4da3ff; }
.prov-dot.t3 { background: var(--lock); } .prov-dot.t2, .prov-dot.t1 { background: var(--danger); }

/* floating provenance popover */
.prov-pop { position: absolute; z-index: 50; max-width: 340px; background: #0e131b; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: .75rem .85rem; font-size: .82rem; }
.pp-head { font-weight: 700; color: var(--accent); margin-bottom: .25rem; }
.pp-title { color: var(--text); margin-bottom: .4rem; }
.pp-excerpt { color: var(--text); opacity: .92; line-height: 1.5; margin-bottom: .5rem; font-style: italic; }
.pp-link { display: inline-block; color: var(--accent); font-weight: 600; }
.pp-ref { color: var(--muted); font-size: .7rem; margin-top: .4rem; font-family: ui-monospace, monospace; }

/* ---------------------- Admin access matrix ---------------------- */
.access-tools { display: flex; gap: .6rem; align-items: center; }
.matrix-wrap { overflow-x: auto; }
.access-matrix { border-collapse: collapse; width: 100%; font-size: .85rem; }
.access-matrix th, .access-matrix td { padding: .4rem .6rem; border-bottom: 1px solid var(--line); text-align: center; }
.access-matrix th:first-child, .access-matrix td:first-child { text-align: left; white-space: nowrap; }
.access-matrix th { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.access-matrix tr.all-row td { background: rgba(77,163,255,.06); border-bottom: 1px solid var(--line); }
.access-matrix input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: .45rem .55rem; padding: .6rem .8rem; }
  /* keep the live-source indicator visible on mobile — wrap it to its own line */
  .sources-status { order: 10; width: 100%; margin-left: 0; font-size: .76rem; gap: .5rem; }
  .layout { grid-template-columns: 1fr; }
  /* Sidebar: no height cap, and the element picker becomes wrapping chips so ALL
     elements are visible/tappable (not just the first few in a short scroll box). */
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; padding: .8rem; }
  .element-list { flex-direction: row; flex-wrap: wrap; gap: .4rem; }
  .element-list li { padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 999px; }
  .element-list li .cat { display: none; }
  .detail { padding: 1rem; }
  /* Admin: let wide tables scroll horizontally instead of overflowing the screen. */
  .admin-view { padding: 1rem; }
  .users-table, .access-matrix { font-size: .8rem; }
  .users-table { display: block; overflow-x: auto; white-space: nowrap; }
  .form-row input { min-width: 0; flex: 1 1 140px; }
  .prov-pop { max-width: 88vw; }
}
