/* OANDA Desk — web port styles */
:root {
  --c-bg: rgb(18,20,25);
  --c-panel: rgb(26,29,36);
  --c-panel_alt: rgb(31,35,43);
  --c-border: rgb(44,50,61);
  --c-text: rgb(229,232,238);
  --c-muted: rgb(139,148,165);
  --c-accent: rgb(76,141,255);
  --c-accent_hi: rgb(104,161,255);
  --c-accent_lo: rgb(52,110,214);
  --c-on_accent: rgb(255,255,255);
  --c-danger: rgb(233,84,84);
  --c-danger_hi: rgb(247,108,108);
  --c-warn: rgb(232,168,56);
  --c-green: rgb(46,199,143);
  --c-red: rgb(255,106,106);
  --c-row: rgb(24,27,33);
  --c-row_alt: rgb(28,32,39);
  --c-header: rgb(34,39,48);
  --bg: var(--c-bg);
  --panel: var(--c-panel);
  --panel-alt: var(--c-panel_alt);
  --border: var(--c-border);
  --text: var(--c-text);
  --muted: var(--c-muted);
  --accent: var(--c-accent);
  --danger: var(--c-danger);
  --warn: var(--c-warn);
  --green: var(--c-green);
  --red: var(--c-red);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Segoe UI", "Inter", Calibri, "DejaVu Sans", system-ui, -apple-system, sans-serif;
  font-size: 14.5px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* scrollbars */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

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

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 6px;
  gap: 3px;
  overflow: hidden;
}

/* topbar card — 2*(19+10)+24 ≈ 82px in dearpygui */
.topbar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.topbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.topbar-row .sep { color: var(--muted); }
.topbar-row .label-muted { color: var(--muted); font-size: 12.5px; }
#statusText { font-weight: 600; }
#streamsText { color: var(--muted); font-size: 12.5px; }
#pausedText { color: var(--warn); font-size: 12.5px; font-weight: 600; }
.metric-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 48px; }
.metric-value.upl-pos { color: var(--green); }
.metric-value.upl-neg { color: var(--red); }
.metric-value.margin-warn { color: var(--warn); }
.metric-value.margin-danger { color: var(--red); }

.theme-select {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12.5px;
  cursor: pointer;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .12s, background .12s, transform .08s;
  line-height: 1;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--c-on_accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--panel-alt); color: var(--text); }
.btn-ghost:hover { background: var(--c-header); }
.btn-small { padding: 3px 8px; font-size: 12px; border-radius: 5px; }

/* main layout */
.main {
  display: flex;
  gap: 3px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.col-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 50%;
  min-width: 340px;
  min-height: 0;
}
.col-right {
  flex: 1;
  min-width: 340px;
  min-height: 0;
  display: flex;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.card-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px 6px;
  font-weight: 700;
  font-size: 13.5px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.card-header .count { color: var(--muted); font-weight: 600; font-size: 12.5px; }

/* positions card: takes remaining space minus log */
#positionsCard { flex: 1; min-height: 140px; }
#logCard { height: 148px; flex-shrink: 0; }
#ordersCard { flex: 1; min-height: 280px; width: 100%; }

.table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
  position: relative;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  position: sticky;
  top: 0;
  background: var(--c-header);
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  z-index: 1;
  white-space: nowrap;
}
thead th:last-child { text-align: center; }

tbody td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
tbody tr:nth-child(even) { background: var(--c-row_alt); }
tbody tr:nth-child(odd) { background: var(--c-row); }
tbody tr:hover { filter: brightness(1.06); }

.cell-instrument { font-weight: 600; cursor: help; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.cell-side-long { color: var(--green); font-weight: 700; font-size: 11px; }
.cell-side-short { color: var(--red); font-weight: 700; font-size: 11px; }
.cell-upl-pos { color: var(--green); font-weight: 600; }
.cell-upl-neg { color: var(--red); font-weight: 600; }
.cell-actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }

/* empty state */
.empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 18px 8px;
  font-style: italic;
}

/* paused section inside orders card */
#pausedSection {
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#pausedSection.hidden { display: none; }
#pausedSection .card-header { background: var(--c-panel_alt); }
.paused-wrap {
  flex: 1;
  overflow: auto;
  min-height: 80px;
}

/* log */
.log-body {
  padding: 6px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.45;
  overflow: auto;
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.log-line { padding: 1px 0; border-bottom: 1px dashed transparent; }
.log-line time { color: var(--muted); margin-right: 8px; }

/* tooltips */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--c-header);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre;
  font-family: ui-monospace, monospace;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  z-index: 80;
  max-width: 420px;
  display: none;
  transform: translate(10px, 10px);
}

/* modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 18px 48px rgba(0,0,0,.45);
  overflow: hidden;
}
.modal.confirm { max-width: 460px; }
.modal-head {
  padding: 14px 16px 10px;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-body label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field {
  width: 100%;
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13.5px;
  outline: none;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,141,255,.18); }
.radio-row { display: flex; gap: 14px; align-items: center; }
.radio-row label { display: flex; gap: 6px; align-items: center; font-weight: 500; color: var(--text); cursor: pointer; }
.check-row { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; line-height: 1.4; }
.check-row input { margin-top: 2px; }
.error-text { color: var(--red); font-size: 12.5px; min-height: 16px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
}
.confirm-text {
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* responsive */
@media (max-width: 900px) {
  .app { height: auto; min-height: 100vh; overflow: visible; }
  .main { flex-direction: column; overflow: visible; }
  .col-left, .col-right { width: 100%; min-width: 0; }
  #positionsCard { min-height: 240px; }
  #ordersCard { min-height: 320px; }
  #logCard { height: 180px; }
}

/* light theme tweaks */
body[data-theme="light"] .btn-ghost { background: #fff; }
body[data-theme="light"] tbody tr:hover { filter: brightness(0.98); }
