/* =========================================================================
   PULSE :: Design tokens
   Palette:  ink #0B1220 · panel #121B2E · raised #182238 · border #24304A
             text #E8ECF1 · muted #8592AB
             established #3FBF9F · disputed #E8A33D · speculative #8B85C7
             bad #E5546B · good #3FBF9F · mixed #C9A6E8
   Type:     display/data -> JetBrains Mono   body -> Inter
   Signature: the horizontal "pulse line" ECG trace connecting cause -> event -> effect
   ========================================================================= */

:root{
  --ink: #0B1220;
  --panel: #121B2E;
  --raised: #182238;
  --border: #24304A;
  --text: #E8ECF1;
  --muted: #8592AB;

  --established: #3FBF9F;
  --disputed: #E8A33D;
  --speculative: #8B85C7;

  --bad: #E5546B;
  --good: #3FBF9F;
  --mixed: #C9A6E8;
  --neutral: #8592AB;

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
::selection{ background: var(--established); color: var(--ink); }

/* ---------------------------------------------------------------- topbar */
.topbar{
  display:flex;
  align-items:baseline;
  gap:16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel), var(--ink));
}
.wordmark{ display:flex; align-items:center; gap:10px; }
.pulse-dot{
  width:10px; height:10px; border-radius:50%;
  background: var(--established);
  box-shadow: 0 0 0 0 rgba(63,191,159,0.6);
  animation: pulse-beat 1.8s infinite;
}
@keyframes pulse-beat{
  0%   { box-shadow: 0 0 0 0 rgba(63,191,159,0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(63,191,159,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,191,159,0); }
}
.wordmark-text{
  font-family: var(--mono);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.12em;
}
.tagline{
  color: var(--muted);
  font-size: 13px;
  font-family: var(--mono);
}

/* ---------------------------------------------------------------- layout */
.layout{
  display:flex;
  height: calc(100vh - 61px);
}

/* ------------------------------------------------------------------ rail */
.rail{
  width: 320px;
  flex-shrink:0;
  border-right: 1px solid var(--border);
  display:flex;
  flex-direction:column;
  background: var(--panel);
}
.rail-head{ padding: 16px; border-bottom: 1px solid var(--border); }
.search-input{
  width:100%;
  padding: 10px 12px;
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  outline: none;
}
.search-input:focus{ border-color: var(--established); }
.domain-filters{
  display:flex;
  flex-wrap: wrap;
  gap:6px;
  margin-top: 10px;
}
.chip{
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chip:hover{ border-color: var(--established); color: var(--text); }
.chip.active{ background: var(--established); border-color: var(--established); color: var(--ink); font-weight:600; }

.rail-list{ overflow-y:auto; flex:1; }
.rail-empty, .chain-empty, .detail-empty{
  padding: 24px 16px;
  color: var(--muted);
  font-size: 13px;
  font-family: var(--mono);
}

.rail-item{
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease;
}
.rail-item:hover{ background: var(--raised); }
.rail-item.active{ background: var(--raised); box-shadow: inset 3px 0 0 var(--established); }
.rail-item-date{
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.03em;
}
.rail-item-title{
  font-size: 14px;
  font-weight: 600;
  margin-top: 2px;
  line-height: 1.3;
}
.rail-item-meta{
  display:flex;
  align-items:center;
  gap:6px;
  margin-top: 6px;
}

.dot{ width:8px; height:8px; border-radius:50%; display:inline-block; }
.dot.established{ background: var(--established); }
.dot.disputed{ background: var(--disputed); }
.dot.speculative{ background: var(--speculative); }

.sev-bar{
  height:3px;
  border-radius:2px;
  background: var(--border);
  flex:1;
  overflow:hidden;
}
.sev-bar-fill{ height:100%; background: var(--disputed); }

/* ------------------------------------------------------------------ main */
.main{
  flex:1;
  display:flex;
  flex-direction:column;
  min-width:0;
}

.chain-panel{
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink:0;
}
.chain-panel-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 14px 20px 0 20px;
}
.chain-panel-head h2{
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin:0;
  font-weight: 600;
}
.legend{ display:flex; gap:14px; }
.legend-item{
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  display:flex;
  align-items:center;
  gap:5px;
}

.chain-viewport{
  padding: 20px;
  overflow-x:auto;
  min-height: 260px;
  display:flex;
  align-items:center;
}
.chain-empty{ padding:0; }

.detail-panel{
  flex:1;
  overflow-y:auto;
  padding: 24px 28px;
}
.detail-empty{ padding:0; }

/* --------------------------------------------------------------- detail */
.detail-header{ display:flex; align-items:flex-start; justify-content:space-between; gap:20px; }
.detail-title{ font-size: 22px; font-weight:700; line-height:1.25; margin:0 0 6px 0; }
.detail-date{ font-family: var(--mono); color: var(--muted); font-size:13px; }

.badge{
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.established{ background: rgba(63,191,159,0.15); color: var(--established); border:1px solid rgba(63,191,159,0.4); }
.badge.disputed{ background: rgba(232,163,61,0.15); color: var(--disputed); border:1px solid rgba(232,163,61,0.4); }
.badge.speculative{ background: rgba(139,133,199,0.15); color: var(--speculative); border:1px solid rgba(139,133,199,0.4); }

.tag-row{ display:flex; flex-wrap:wrap; gap:8px; margin: 14px 0; }
.tag{
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-summary{ font-size: 15px; line-height: 1.65; color: var(--text); margin: 16px 0; max-width: 760px; }

.stat-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(150px,1fr));
  gap: 12px;
  margin: 20px 0;
  max-width: 760px;
}
.stat-box{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.stat-label{ font-family: var(--mono); font-size: 10px; text-transform:uppercase; letter-spacing:0.06em; color: var(--muted); }
.stat-value{ font-size: 18px; font-weight: 700; margin-top: 4px; }
.stat-value.valence-good{ color: var(--good); }
.stat-value.valence-bad{ color: var(--bad); }
.stat-value.valence-mixed{ color: var(--mixed); }
.stat-value.valence-neutral{ color: var(--neutral); }

.valence-note{ font-size: 13px; color: var(--muted); margin-top: 16px; max-width: 700px; line-height:1.5; }

.section-title{
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 28px 0 12px 0;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.market-grid{ display:flex; flex-direction:column; gap: 20px; }
.market-card{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  max-width: 760px;
}
.market-card-head{ display:flex; justify-content:space-between; align-items:center; margin-bottom: 8px; }
.market-asset{ font-weight: 600; font-size: 14px; }
.market-type{ font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing:0.05em; }
.market-note{ font-size: 12px; color: var(--muted); margin-top: 8px; }
.market-chart-wrap{ height: 160px; }
.no-market-data{ color: var(--muted); font-size: 13px; font-family: var(--mono); }

/* -------------------------------------------------------- pulse line viz */
.pulse-svg{ display:block; }
.pulse-node{ cursor: pointer; }
.pulse-node-label{
  font-family: var(--mono);
  font-size: 10px;
  fill: var(--muted);
}
.pulse-node-label.root{ fill: var(--text); font-weight: 700; }
.pulse-node-date{
  font-family: var(--mono);
  font-size: 9px;
  fill: var(--muted);
}
.pulse-edge{ fill:none; stroke-width: 1.6; }

/* -------------------------------------------------------------- scroll */
::-webkit-scrollbar{ width:10px; height:10px; }
::-webkit-scrollbar-track{ background: var(--ink); }
::-webkit-scrollbar-thumb{ background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover{ background: var(--muted); }

/* ---------------------------------------------------------- topbar actions */
.topbar{ justify-content: space-between; }
.topbar-actions{ display:flex; align-items:center; gap:14px; margin-left:auto; }
.btn-add-event{
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--established);
  background: rgba(63,191,159,0.12);
  color: var(--established);
  cursor: pointer;
}
.btn-add-event:hover{ background: rgba(63,191,159,0.22); }
.logout-link{
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
}
.logout-link:hover{ color: var(--text); border-color: var(--muted); }

/* --------------------------------------------------------------- key persons */
.key-persons-list{
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 700px;
}
.key-persons-list li{
  font-size: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.key-persons-list li:last-child{ border-bottom: none; }
.source-link{ margin-top: 14px; }
.source-link a{
  font-family: var(--mono);
  font-size: 12px;
  color: var(--established);
  text-decoration: none;
}
.source-link a:hover{ text-decoration: underline; }

/* -------------------------------------------------------------- login page */
.login-body{
  display:flex;
  align-items:center;
  justify-content:center;
  min-height: 100vh;
  background: var(--ink);
}
.login-card{
  width: 340px;
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align:center;
}
.login-wordmark{ justify-content:center; margin-bottom: 8px; }
.login-tagline{ color: var(--muted); font-size: 13px; font-family: var(--mono); margin: 0 0 24px 0; }
.login-form{ display:flex; flex-direction:column; gap: 12px; }
.login-input{
  width:100%;
  padding: 12px 14px;
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 18px;
  letter-spacing: 0.3em;
  text-align:center;
  outline:none;
}
.login-input:focus{ border-color: var(--established); }
.login-button{
  padding: 12px;
  border-radius: 6px;
  border: none;
  background: var(--established);
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}
.login-button:hover{ opacity: 0.9; }
.login-error{
  margin-top: 14px;
  color: var(--bad);
  font-family: var(--mono);
  font-size: 12px;
}

/* ------------------------------------------------------------------ modal */
.modal-overlay{
  position: fixed;
  inset: 0;
  background: rgba(11,18,32,0.75);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index: 100;
  padding: 20px;
}
.modal-card{
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y:auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.modal-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-bottom: 18px;
}
.modal-head h2{ margin:0; font-size: 18px; }
.modal-close{
  background:none;
  border:none;
  color: var(--muted);
  font-size: 24px;
  cursor:pointer;
  line-height:1;
}
.modal-close:hover{ color: var(--text); }
.modal-form{ display:flex; flex-direction:column; gap: 16px; }
.form-row label{
  display:block;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}
.form-row .hint{ text-transform:none; letter-spacing:0; color: var(--muted); font-family: var(--sans); }
.form-row input[type="text"],
.form-row input[type="date"],
.form-row input[type="url"],
.form-row select,
.form-row textarea{
  width:100%;
  padding: 9px 11px;
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  outline:none;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus{ border-color: var(--established); }
.form-row-split{ display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions{
  display:flex;
  justify-content: space-between;
  align-items:center;
  margin-top: 6px;
}
.btn-ai-assist{
  background: rgba(139,133,199,0.15);
  border: 1px solid rgba(139,133,199,0.4);
  color: var(--speculative);
  padding: 9px 14px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  cursor:pointer;
}
.btn-ai-assist:hover{ background: rgba(139,133,199,0.25); }
.btn-ai-assist:disabled{ opacity:0.6; cursor:default; }
.btn-save-event{
  background: var(--established);
  border:none;
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight:700;
  font-size: 12px;
  text-transform: uppercase;
  cursor:pointer;
  margin-left:auto;
}
.btn-save-event:hover{ opacity:0.9; }

@media (max-width: 860px){
  .layout{ flex-direction: column; height:auto; }
  .rail{ width:100%; max-height: 260px; }
}
