:root {
  color-scheme: dark;
  --bg: #0a0d12;
  --panel: #12161f;
  --panel-raised: #171c27;
  --panel-soft: #0f131b;
  --border: #232838;
  --border-strong: #343b4e;
  --text: #e7e9ee;
  --muted: #929baa;
  --muted-2: #687284;
  --green: #35d07f;
  --green-soft: rgba(53, 208, 127, 0.12);
  --coral: #ff6b78;
  --coral-soft: rgba(255, 92, 108, 0.12);
  --amber: #f5b94d;
  --amber-soft: rgba(245, 185, 77, 0.12);
  --blue: #6c97ff;
  --blue-soft: rgba(91, 140, 255, 0.14);
  --focus: #9ab7ff;
  --radius: 14px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
  --sans: "Space Grotesk", Inter, ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    radial-gradient(circle at 80% -10%, rgba(91,140,255,.1), transparent 32rem),
    var(--bg);
  background-size: 32px 32px, 32px 32px, auto, auto;
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.skip-link { position: fixed; left: 16px; top: -80px; z-index: 1000; padding: 10px 14px; color: var(--text); background: var(--blue); border-radius: 8px; }
.skip-link:focus { top: 16px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 78px;
  padding: 14px clamp(16px, 3vw, 44px);
  border-bottom: 1px solid rgba(52, 59, 78, .8);
  background: rgba(10, 13, 18, .9);
  backdrop-filter: blur(18px);
}
.brand, .topbar-actions, .system-state, .card-head, .panel-heading, .drawer-head { display: flex; align-items: center; }
.brand { gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid rgba(108,151,255,.42); border-radius: 11px; color: var(--blue); background: var(--blue-soft); }
.brand-mark svg, .button svg, .icon-button svg, .safety-banner svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.05rem, 2vw, 1.3rem); letter-spacing: -.025em; }
h2 { font-size: 1.05rem; letter-spacing: -.01em; }
h3 { font-size: 1rem; font-weight: 600; }
.eyebrow { color: var(--muted); font-family: var(--mono); font-size: .67rem; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; }
.topbar-actions { justify-content: flex-end; gap: 10px; }
.system-state { gap: 16px; margin-right: 4px; }
.last-scan { color: var(--muted); font-size: .76rem; white-space: nowrap; }
.last-scan strong { color: var(--text); font-family: var(--mono); font-weight: 500; }

.status-pill, .bias-badge, .counter, .live-indicator { display: inline-flex; align-items: center; border-radius: 999px; font-family: var(--mono); font-size: .69rem; font-weight: 600; letter-spacing: .03em; }
.status-pill { gap: 7px; padding: 7px 10px; border: 1px solid var(--border-strong); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); }
.status-online { color: var(--green); border-color: rgba(53,208,127,.34); background: var(--green-soft); }
.status-online .status-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(53,208,127,.1); }
.status-connecting { color: var(--amber); border-color: rgba(245,185,77,.34); background: var(--amber-soft); }
.status-connecting .status-dot { background: var(--amber); }
.status-error { color: var(--coral); border-color: rgba(255,92,108,.34); background: var(--coral-soft); }

.button, .icon-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  transition: border-color 180ms ease, background 180ms ease, transform 150ms ease;
  touch-action: manipulation;
}
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; font-weight: 600; font-size: .83rem; }
.button:active, .icon-button:active { transform: scale(.97); }
.button-primary { background: var(--blue); color: #071020; border-color: #81a6ff; }
.button-primary:hover { background: #82a7ff; }
.button-danger { background: var(--coral-soft); color: #ff9ba4; border-color: rgba(255,92,108,.42); }
.button-danger:hover { background: rgba(255,92,108,.2); }
.button-secondary { background: transparent; border-color: var(--border-strong); }
.button-secondary:hover, .icon-button:hover { background: rgba(255,255,255,.045); border-color: #485268; }
.icon-button { display: grid; place-items: center; width: 44px; padding: 0; background: var(--panel); border-color: var(--border); }

.page-shell { width: min(1540px, 100%); margin: 0 auto; padding: 20px clamp(16px, 3vw, 44px) 56px; }
.safety-banner { display: flex; align-items: center; gap: 13px; padding: 13px 16px; border: 1px solid rgba(108,151,255,.25); border-radius: 12px; background: rgba(91,140,255,.07); }
.safety-banner svg { flex: 0 0 auto; color: var(--blue); }
.safety-banner div { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.safety-banner strong { font-size: .82rem; }
.safety-banner span { color: var(--muted); font-size: .79rem; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 28px 0 13px; }
.section-heading h2 { margin-top: 2px; font-size: 1.3rem; }
.legend { display: flex; gap: 14px; color: var(--muted); font-family: var(--mono); font-size: .67rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2); }
.legend-dot.medium { background: var(--amber); }
.legend-dot.high { background: var(--green); }

.signal-grid { display: grid; grid-template-columns: repeat(5, minmax(215px, 1fr)); gap: 12px; }
.signal-card { min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(145deg, rgba(255,255,255,.018), transparent 46%), var(--panel); box-shadow: 0 12px 32px rgba(0,0,0,.12); }
.signal-card[data-side="BUY"] { border-top-color: rgba(53,208,127,.72); }
.signal-card[data-side="SELL"] { border-top-color: rgba(255,92,108,.72); }
.signal-card-error { border-color: rgba(255,92,108,.38); }
.card-head { justify-content: space-between; gap: 10px; }
.symbol-code { margin-bottom: 2px; color: var(--muted); font-size: .68rem; letter-spacing: .08em; }
.bias-badge { padding: 5px 8px; border: 1px solid var(--border-strong); white-space: nowrap; }
.bias-bullish { color: var(--green); border-color: rgba(53,208,127,.32); background: var(--green-soft); }
.bias-bearish { color: var(--coral); border-color: rgba(255,92,108,.32); background: var(--coral-soft); }
.bias-neutral { color: var(--muted); background: rgba(255,255,255,.03); }
.confluence { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 15px 0; }
.confluence span { height: 4px; border-radius: 6px; background: #2a3040; }
.confluence.confidence-low span:nth-child(1) { background: var(--amber); }
.confluence.confidence-medium span:nth-child(-n+2) { background: var(--amber); }
.confluence.confidence-high.buy span { background: var(--green); }
.confluence.confidence-high.sell span { background: var(--coral); }
.card-empty-state { min-height: 137px; display: grid; align-content: center; gap: 12px; color: var(--muted); font-size: .78rem; }
.skeleton-line { width: 72%; height: 7px; border-radius: 8px; background: linear-gradient(90deg, #222837, #303747, #222837); background-size: 200% 100%; animation: shimmer 1.8s ease-in-out infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.metric-list { display: grid; gap: 7px; margin: 0; }
.metric-row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .7rem; }
.metric-row dt, .metric-row dd { margin: 0; }
.metric-row dd { max-width: 58%; color: var(--text); font-family: var(--mono); font-size: .68rem; text-align: right; overflow-wrap: anywhere; }
.setup-reason { min-height: 38px; margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--border); color: var(--muted); font-size: .72rem; line-height: 1.45; }
.trade-plan { margin-top: 13px; padding: 11px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--panel-soft); }
.trade-plan-head { display: flex; justify-content: space-between; margin-bottom: 8px; font-family: var(--mono); font-size: .67rem; }
.trade-side.buy { color: var(--green); }
.trade-side.sell { color: var(--coral); }
.price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 9px; }
.price-item { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); font-family: var(--mono); font-size: .63rem; }
.price-item strong { color: var(--text); font-weight: 500; }

.lower-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(330px, .85fr); gap: 12px; margin-top: 18px; }
.panel { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.panel-heading { justify-content: space-between; padding: 15px 17px; border-bottom: 1px solid var(--border); }
.counter { min-width: 28px; justify-content: center; padding: 4px 8px; color: var(--blue); background: var(--blue-soft); }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .69rem; font-variant-numeric: tabular-nums; }
th { padding: 10px 14px; color: var(--muted); background: var(--panel-soft); font-weight: 500; text-align: left; white-space: nowrap; }
td { padding: 11px 14px; border-top: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: rgba(255,255,255,.025); }
.empty-row td { height: 108px; color: var(--muted); font-family: var(--sans); text-align: center; }
.side-buy { color: var(--green); }
.side-sell { color: var(--coral); }
.live-indicator { gap: 6px; color: var(--green); }
.live-indicator span { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.activity-log { height: 246px; margin: 0; padding: 7px 17px 12px; overflow: auto; list-style: none; font-family: var(--mono); font-size: .67rem; }
.activity-log li { display: grid; grid-template-columns: 76px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(35,40,56,.7); }
.activity-log time { color: var(--muted-2); }
.activity-log span { color: #b7bdc9; overflow-wrap: anywhere; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.62); backdrop-filter: blur(3px); }
.settings-drawer { position: fixed; inset: 0 0 0 auto; z-index: 90; width: min(470px, 100%); padding: 20px; overflow-y: auto; border-left: 1px solid var(--border-strong); background: #0d1118; box-shadow: var(--shadow); transform: translateX(104%); transition: transform 220ms ease-out; }
.settings-drawer.is-open { transform: translateX(0); }
.drawer-head { justify-content: space-between; margin-bottom: 20px; }
fieldset { display: grid; gap: 7px; margin: 0 0 15px; padding: 15px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
legend { padding: 0 7px; color: var(--text); font-weight: 600; font-size: .84rem; }
label { margin-top: 7px; color: #c8cdd7; font-size: .75rem; font-weight: 500; }
.unit { color: var(--muted); font-family: var(--mono); font-size: .65rem; font-weight: 400; }
input, select { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 9px; color: var(--text); background: #0b0f16; font-family: var(--mono); font-size: .8rem; }
input:hover, select:hover { border-color: #4b566d; }
.field-help { color: var(--muted); font-size: .69rem; line-height: 1.45; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; }
.form-error { margin: 0 0 12px; padding: 10px 12px; border: 1px solid rgba(255,92,108,.4); border-radius: 9px; color: #ff9ba4; background: var(--coral-soft); font-size: .75rem; }
.drawer-actions { position: sticky; bottom: -20px; display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; padding: 15px 0 20px; background: linear-gradient(transparent, #0d1118 22%); }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 120; max-width: 360px; padding: 12px 15px; border: 1px solid var(--border-strong); border-radius: 10px; color: var(--text); background: #191f2b; box-shadow: var(--shadow); font-size: .78rem; }

@media (max-width: 1240px) {
  .signal-grid { grid-template-columns: repeat(3, minmax(220px, 1fr)); }
  .signal-card:nth-child(n+4) { grid-column: span 1; }
}
@media (max-width: 900px) {
  .topbar { align-items: flex-start; }
  .system-state { display: none; }
  .signal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lower-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  body { font-size: 16px; }
  .topbar { min-height: auto; padding: 12px 14px; gap: 10px; }
  .brand-mark { display: none; }
  .brand .eyebrow { display: none; }
  .topbar-actions { gap: 8px; }
  .button { padding: 0 11px; }
  .button svg { display: none; }
  .page-shell { padding: 14px 12px 40px; }
  .safety-banner { align-items: flex-start; }
  .safety-banner div { display: block; }
  .safety-banner span { display: block; margin-top: 2px; }
  .section-heading { align-items: flex-start; }
  .legend { display: none; }
  .signal-grid { grid-template-columns: 1fr; }
  .signal-card { padding: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .settings-drawer { padding: 16px; }
  .table-wrap { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody { padding: 8px 12px 12px; }
  tbody tr:not(.empty-row) { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-bottom: 9px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; }
  td { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border: 0; }
  td::before { color: var(--muted); content: attr(data-label); }
  .empty-row td { display: grid; height: 92px; place-items: center; }
  .empty-row td::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition-duration: .01ms !important; }
}
