/* ── Reset & base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --border:    #30363d;
  --text:      #c9d1d9;
  --text-dim:  #8b949e;
  --green:     #3fb950;
  --red:       #f85149;
  --blue:      #388bfd;
  --yellow:    #d29922;
  --font:      'Segoe UI', system-ui, sans-serif;
  --mono:      'Consolas', 'Courier New', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--green);
}
.version { color: var(--text-dim); font-size: 11px; margin-left: 8px; }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#api-url-label { color: var(--text-dim); font-size: 12px; }

#api-url {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 12px;
  width: 220px;
}

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
  letter-spacing: 1px;
}
.badge-green  { background: rgba(63,185,80,.2);  color: var(--green); border: 1px solid var(--green); }
.badge-red    { background: rgba(248,81,73,.2);  color: var(--red);   border: 1px solid var(--red); }
.badge-blue   { background: rgba(56,139,253,.2); color: var(--blue);  border: 1px solid var(--blue); }
.badge-offline{ background: rgba(139,148,158,.1); color: var(--text-dim); border: 1px solid var(--border); }

/* ── Account bar ───────────────────────────────────────────────── */
.account-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.account-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  border-right: 1px solid var(--border);
}
.account-stat:last-child { border-right: none; }
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.stat-value { font-size: 16px; font-family: var(--mono); font-weight: 600; margin-top: 2px; }

/* ── Layout ────────────────────────────────────────────────────── */
main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}

.col-left, .col-right { display: flex; flex-direction: column; gap: 16px; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.card h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn:active { opacity: .7; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-green { background: var(--green);  color: #000; }
.btn-red   { background: var(--red);    color: #fff; }
.btn-blue  { background: var(--blue);   color: #fff; }

.btn-row { display: flex; gap: 10px; }

/* ── Engine message ────────────────────────────────────────────── */
.engine-message {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
  min-height: 16px;
  font-family: var(--mono);
}

/* ── Tables ────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 8px;
  border-bottom: 1px solid rgba(48,54,61,.5);
  font-family: var(--mono);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.03); }

.cell-green { color: var(--green); }
.cell-red   { color: var(--red); }
.cell-dim   { color: var(--text-dim); }

/* ── Signal cells ──────────────────────────────────────────────── */
.sig-true  { color: var(--green); font-weight: 700; }
.sig-false { color: var(--text-dim); }

.trend-bar {
  display: inline-block;
  width: calc(var(--score) * 10px);
  height: 8px;
  background: var(--blue);
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 4px;
}

/* ── Form row ──────────────────────────────────────────────────── */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.form-row input,
.form-row select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
}
.form-row input { flex: 1; min-width: 120px; }

/* ── Error list ────────────────────────────────────────────────── */
.error-list {
  max-height: 180px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--red);
}
.error-list div { padding: 3px 0; border-bottom: 1px solid rgba(248,81,73,.1); }

.empty-state {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}

/* ── Account toggles ───────────────────────────────────────────── */
.accounts-list { display: flex; flex-direction: column; gap: 8px; }

.account-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.account-row.enabled  { border-color: rgba(63,185,80,.4); }
.account-row.disabled { opacity: .55; }

.account-toggle {
  width: 18px; height: 18px;
  cursor: pointer;
  accent-color: var(--green);
  flex-shrink: 0;
}

.account-info { flex: 1; }
.account-name { font-weight: 600; font-size: 13px; }
.account-type { font-size: 11px; color: var(--text-dim); margin-top: 1px; }

.account-state-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  letter-spacing: 1px;
}
.state-on  { background: rgba(63,185,80,.15); color: var(--green); }
.state-off { background: rgba(139,148,158,.1); color: var(--text-dim); }

.accounts-note {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Account gear button ───────────────────────────────────────── */
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 3px 7px;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
.btn-icon:hover { color: var(--text); border-color: var(--blue); }

/* ── Account edit panel ────────────────────────────────────────── */
.account-wrapper { display: flex; flex-direction: column; }

.account-edit-panel {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  background: var(--bg);
  padding: 14px 14px 10px;
  margin-bottom: 2px;
}

.acct-edit-form { display: flex; flex-direction: column; gap: 10px; }

.acct-edit-fields { display: flex; flex-direction: column; gap: 8px; }

.acct-field-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: 10px;
}

.acct-field-label {
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
}

.acct-field-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--mono);
  padding: 5px 8px;
  width: 100%;
}
.acct-field-input:focus {
  outline: none;
  border-color: var(--blue);
}
.acct-acct-select { font-family: var(--mono); }
.acct-field-cb { accent-color: var(--blue); width: 16px; height: 16px; cursor: pointer; }

.acct-edit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.acct-edit-hint { font-size: 11px; color: var(--text-dim); }

.acct-edit-msg { font-size: 12px; font-family: var(--mono); min-height: 16px; }

.acct-edit-loading,
.acct-edit-error {
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 0;
}
.acct-edit-error { color: var(--red); }

.device-challenge-box {
  background: rgba(210,153,34,.08);
  border: 1px solid rgba(210,153,34,.4);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.device-challenge-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--yellow);
}

.btn-dim {
  background: var(--border);
  color: var(--text);
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.btn-dim:hover { opacity: .8; }

/* ── TradingView ticker links ───────────────────────────────────── */
.ticker-link {
  color: var(--blue);
  text-decoration: none;
  font-family: var(--mono);
  font-weight: 600;
}
.ticker-link:hover { text-decoration: underline; opacity: .85; }

.tag-buy, .tag-sell {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 600;
  text-decoration: none;
  margin: 2px 2px;
}
.tag-buy  { background: rgba(63,185,80,.15);  color: var(--green); }
.tag-buy:hover  { background: rgba(63,185,80,.3); }
.tag-sell { background: rgba(248,81,73,.15);  color: var(--red); }
.tag-sell:hover { background: rgba(248,81,73,.3); }

/* ── Signal history ─────────────────────────────────────────────── */
.signal-history {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 340px;
  overflow-y: auto;
}

.sh-entry {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sh-ts {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}
.sh-raw { opacity: .6; }

.sh-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.sh-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 2px;
}
.buy-label  { background: rgba(63,185,80,.2);  color: var(--green); }
.sell-label { background: rgba(248,81,73,.2);  color: var(--red); }

/* ── System settings ───────────────────────────────────────────── */
.settings-tabs { display: flex; gap: 6px; margin-bottom: 14px; }

.settings-body { display: flex; flex-direction: column; gap: 6px; }

.setting-row {
  display: grid;
  grid-template-columns: 1fr 130px;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(48,54,61,.4);
}
.setting-row:last-child { border-bottom: none; }

.setting-label {
  font-size: 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 5px;
}

.setting-input { display: flex; justify-content: flex-end; }

.setting-input input[type="number"],
.setting-input select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--mono);
  padding: 4px 8px;
  width: 120px;
  text-align: right;
}
.setting-input input[type="number"]:focus,
.setting-input select:focus { outline: none; border-color: var(--blue); }

.setting-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  background: var(--border);
  border-radius: 50%;
  font-size: 10px;
  color: var(--text-dim);
  cursor: help;
  flex-shrink: 0;
}

.setting-row-full {
  grid-template-columns: 1fr;
  gap: 6px;
}
.setting-row-full .setting-label { text-align: left; }

.setting-taglist {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--mono);
  padding: 6px 8px;
  width: 100%;
  resize: vertical;
  line-height: 1.5;
}
.setting-taglist:focus { outline: none; border-color: var(--blue); }

.settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ── Instruments table ──────────────────────────────────────────── */
.instr-table { font-size: 12px; }
.instr-sym   { font-weight: 600; font-family: var(--mono); }

.instr-num-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  font-family: var(--mono);
  padding: 3px 6px;
  width: 72px;
  text-align: right;
}
.instr-num-input:focus { outline: none; border-color: var(--blue); }

/* ── Stock scanner ──────────────────────────────────────────────── */
.scanner-progress {
  margin: 10px 0 4px;
}

.progress-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
  transition: width .3s ease;
}

#scanner-pct {
  font-size: 11px;
  color: var(--text-dim);
}

.scanner-tabs {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.tab-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tab-btn:hover  { border-color: var(--blue); color: var(--text); }
.tab-btn.tab-active { border-color: var(--blue); color: var(--blue); background: rgba(56,139,253,.1); }

/* ── Trade Journal ──────────────────────────────────────────────── */
.journal-today-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  background: rgba(63,185,80,.15);
  color: var(--green);
  vertical-align: middle;
}

.journal-table-wrap {
  overflow-x: auto;
  margin-top: 10px;
  max-height: 320px;
  overflow-y: auto;
}

/* Notes compose area */
.note-compose {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.note-textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 10px;
  resize: vertical;
  width: 100%;
}
.note-textarea:focus { outline: none; border-color: var(--blue); }

.note-compose-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.note-tags-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  padding: 5px 8px;
}
.note-tags-input:focus { outline: none; border-color: var(--blue); }

/* Notes list */
.notes-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}

.note-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.note-tags {
  font-size: 10px;
  color: var(--blue);
}

.note-body {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.note-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 0 4px;
}
.note-delete:hover { color: var(--red); }

/* ── Timeline ───────────────────────────────────────────────────── */
.timeline-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 14px;
}

.timeline-date-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  padding: 4px 8px;
}
.timeline-date-input:focus { outline: none; border-color: var(--blue); }

.timeline {
  position: relative;
  padding-left: 24px;
  max-height: 480px;
  overflow-y: auto;
}

/* Vertical spine */
.timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
  border-radius: 1px;
}

.tl-entry {
  position: relative;
  margin-bottom: 18px;
}

/* Colored dot on the spine */
.tl-dot {
  position: absolute;
  left: -20px;
  top: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  flex-shrink: 0;
}

.tl-dot-long-open  { background: var(--green); }
.tl-dot-short-open { background: var(--red); }
.tl-dot-close      { background: var(--yellow); }
.tl-dot-note       { background: var(--blue); }
.tl-dot-manual     { background: #a371f7; }  /* purple for manual */

.tl-time {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: .3px;
  margin-bottom: 2px;
}

.tl-message {
  font-size: 13px;
  line-height: 1.45;
}

.tl-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 1px;
}

.tl-pnl-pos { color: var(--green); font-weight: 600; }
.tl-pnl-neg { color: var(--red);   font-weight: 600; }

.tl-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 5px;
  vertical-align: middle;
}
.tl-badge-engine { background: rgba(56,139,253,.15); color: var(--blue); }
.tl-badge-manual { background: rgba(163,113,247,.15); color: #a371f7; }
.tl-badge-note   { background: rgba(56,139,253,.1);  color: var(--blue); }

.tl-note-body {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text);
}

.tl-note-tags {
  font-size: 10px;
  color: var(--blue);
  margin-top: 2px;
}
