@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg: #f2f7f9;
  --panel: #ffffff;
  --panel-2: #eaf3f5;
  --border: #d8e5ea;
  --text: #0c1c2b;
  --muted: #5c7488;
  --accent: #10b981;
  --accent-strong: #0d9668;
  --accent-dim: #cdf0e2;
  --on-accent: #ffffff;
  --green: #10b981;
  --red: #d1493f;
  --blue: #2f8fd6;
  --cyan: #22b8d6;
  --radius: 6px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --display: 'Space Grotesk', sans-serif;
}

html[data-theme="dark"] {
  --bg: #0a1420;
  --panel: #0f1e2e;
  --panel-2: #142838;
  --border: #1f3448;
  --text: #eaf3f7;
  --muted: #86a0b5;
  --accent: #22d3a8;
  --accent-strong: #4fe8c2;
  --accent-dim: #123a30;
  --on-accent: #052018;
  --green: #22d3a8;
  --red: #ff7a70;
  --blue: #5fb0f5;
  --cyan: #3fd3e8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  transition: background .15s ease, color .15s ease;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }

.mono-nums { font-variant-numeric: tabular-nums; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  text-decoration: none;
}

.brand img.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: block;
}

.brand .brand-word { display: inline-flex; align-items: baseline; }
.brand .brand-word .up {
  background: linear-gradient(120deg, var(--cyan), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand .brand-tag {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  margin-left: 2px;
  display: none;
}
@media (min-width: 640px) {
  .brand .brand-tag { display: block; }
}

.topbar nav { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.topbar .muted { color: var(--muted); }

.btn {
  font-family: var(--mono);
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: var(--accent); background: var(--accent-dim); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { border-color: #e3b3ae; color: var(--red); }
html[data-theme="dark"] .btn-danger { border-color: #5a2a2a; }
.btn-danger:hover { background: rgba(209,73,63,0.1); border-color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border-radius: 50%; }

/* ---------- Layout ---------- */
.container { max-width: 1160px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-head p { color: var(--muted); margin: 4px 0 0; font-size: 13px; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 2px rgba(16,36,26,0.04);
}

.bot-card { display: flex; flex-direction: column; gap: 10px; }
.bot-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bot-card-head h3 { font-size: 16px; }
.bot-card .desc { color: var(--muted); font-size: 12.5px; line-height: 1.5; min-height: 32px; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 8px; border-radius: 20px; border: 1px solid var(--border);
  color: var(--muted);
}
.status .led { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.running { color: var(--green); border-color: var(--accent-dim); background: var(--accent-dim); }
.status.running .led { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 1.4s infinite; }
.status.error { color: var(--red); border-color: #f0cac6; }
html[data-theme="dark"] .status.error { border-color: #4a1f1f; }
.status.error .led { background: var(--red); }
.status.stopped .led { background: var(--muted); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); padding: 2px 7px; border-radius: 20px; }

.stat-row { display: flex; gap: 18px; margin-top: 4px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat .value { font-size: 17px; font-weight: 600; }
.value.pos { color: var(--green); }
.value.neg { color: var(--red); }

/* ---------- Forms ---------- */
.form-panel { max-width: 420px; margin: 80px auto; }
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  font-family: var(--mono);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 10px;
  border-radius: var(--radius);
  font-size: 13.5px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.error-msg { color: var(--red); font-size: 12.5px; margin-top: 6px; min-height: 16px; }
.hint { color: var(--muted); font-size: 11.5px; margin-top: -2px; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 18px 0; padding: 14px 16px; }
legend { font-family: var(--display); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 6px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 10.5px; letter-spacing: .05em; }
tr:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }

.pill-pos { color: var(--green); }
.pill-neg { color: var(--red); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  font-family: var(--mono); font-size: 13px; padding: 10px 16px; background: none; border: none;
  border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer;
}
.tab-btn.active { color: var(--accent-strong); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Misc ---------- */
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 10px; }
.empty { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,20,15,.45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 20px; z-index: 50; overflow-y: auto; }
html[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,.65); }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 560px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.hidden { display: none !important; }
.access-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.access-list li { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; font-size: 12.5px; gap: 8px; flex-wrap: wrap; }
.log-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; font-size: 11.5px; line-height: 1.6; max-height: 320px; overflow-y: auto; white-space: pre-wrap; color: var(--text); }
canvas { max-width: 100%; }
.breadcrumb { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.filter-bar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar .field { margin-bottom: 0; min-width: 140px; }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 12px; margin-bottom: 20px; }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel-2); cursor: pointer;
  font-size: 15px;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---------- Watermark: large centered mark behind specific content areas
   (equity chart, trade history, home dashboard) -- NOT a full-page tile.
   Apply the .wtu-content-watermark class to any position:static container;
   this rule adds the positioning itself, so no other CSS needs to change. ---------- */
/* ---------- Watermark: large centered mark behind specific content areas
   (equity chart, trade history, home dashboard) -- NOT a full-page tile.
   Implemented as the element's own background-image (an inline SVG data
   URI) rather than a positioned ::before -- this covers the box exactly as
   drawn regardless of whether the element's height is explicit or sized by
   its own content (a chart, a table, a card with real content all resize
   naturally), with no absolute-positioning/height edge cases involved. */
.wtu-content-watermark {
  background-repeat: no-repeat;
  background-position: center;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='440' height='130'><text x='50%25' y='50%25' text-anchor='middle' dominant-baseline='middle' font-family='Space Grotesk, sans-serif' font-weight='700' font-size='42' letter-spacing='2' fill='%2310b981' fill-opacity='0.16'>WINTRADEUP</text></svg>");
}
html[data-theme="dark"] .wtu-content-watermark {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='440' height='130'><text x='50%25' y='50%25' text-anchor='middle' dominant-baseline='middle' font-family='Space Grotesk, sans-serif' font-weight='700' font-size='42' letter-spacing='2' fill='%2322d3a8' fill-opacity='0.22'>WINTRADEUP</text></svg>");
}
/* Compact variant for narrower containers (e.g. individual strategy cards)
   where the default large mark would overflow. */
.wtu-content-watermark.wtu-wm-sm {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='230' height='70'><text x='50%25' y='50%25' text-anchor='middle' dominant-baseline='middle' font-family='Space Grotesk, sans-serif' font-weight='700' font-size='16' letter-spacing='1' fill='%2310b981' fill-opacity='0.16'>WINTRADEUP</text></svg>");
}
html[data-theme="dark"] .wtu-content-watermark.wtu-wm-sm {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='230' height='70'><text x='50%25' y='50%25' text-anchor='middle' dominant-baseline='middle' font-family='Space Grotesk, sans-serif' font-weight='700' font-size='16' letter-spacing='1' fill='%2322d3a8' fill-opacity='0.22'>WINTRADEUP</text></svg>");
}

/* ---------- Strategy card extras: token countdown, last error, heartbeat, open position ---------- */
.token-countdown { font-family: var(--mono); }
.token-countdown.warn { color: var(--red); font-weight: 600; }
.card-error-detail { font-size: 12px; color: var(--red); margin-top: 4px; word-break: break-word; }
.card-heartbeat { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.card-heartbeat.stale { color: var(--red); }
.open-position-line {
  font-size: 12.5px; margin-top: 8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2);
}
.open-position-line .label { color: var(--muted); margin-right: 4px; }
