:root {
  --bg: #0b0e14;
  --bg-2: #121722;
  --panel: #151b27;
  --panel-2: #1b2331;
  --line: #263041;
  --line-2: #33405a;
  --text: #e6ebf2;
  --muted: #8894a8;
  --accent: #4da3ff;
  --accent-2: #7c8cff;
  --pos: #2ecc8f;
  --neg: #ff6b6b;
  --warn: #f6c14b;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #16203050, transparent), var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #10151f, #0d1119);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  font-size: 26px; color: var(--accent);
  filter: drop-shadow(0 0 8px #4da3ff55);
}
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }
.coverage {
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px;
  background: var(--panel);
}

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid; grid-template-columns: 340px 1fr; gap: 20px;
  padding: 20px; max-width: 1500px; margin: 0 auto; align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

/* ----------------------------------------------------------- control panel */
.panel {
  background: linear-gradient(180deg, var(--panel), #12171f);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; position: sticky; top: 78px;
}
@media (max-width: 900px) { .panel { position: static; } }

.field { margin-bottom: 16px; }
.field > label {
  display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); margin-bottom: 6px; font-weight: 600;
}
input, select, button { font-family: inherit; font-size: 14px; }
input[type=text], input[type=date], input[type=number], select {
  width: 100%; background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 11px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px #4da3ff22;
}
input[type=date] { color-scheme: dark; }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); min-height: 1em; }

/* combo / autocomplete */
.combo { position: relative; }
#ticker { text-transform: uppercase; font-family: var(--mono); letter-spacing: .5px; }
.suggest {
  list-style: none; margin: 4px 0 0; padding: 4px; position: absolute; z-index: 30;
  left: 0; right: 0; background: var(--panel-2); border: 1px solid var(--line-2);
  border-radius: 8px; max-height: 260px; overflow-y: auto;
  box-shadow: 0 12px 30px #0008;
}
.suggest li {
  padding: 7px 10px; border-radius: 6px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.suggest li.active, .suggest li:hover { background: var(--accent); color: #06101d; }
.suggest .sym { font-family: var(--mono); font-weight: 600; }
.suggest .nm { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest li.active .nm, .suggest li:hover .nm { color: #06101dcc; }

/* dates + presets */
.dates { display: flex; align-items: center; gap: 8px; }
.dates input { flex: 1; }
.dash { color: var(--muted); }
.presets { display: flex; gap: 6px; margin-top: 8px; }
.presets button {
  flex: 1; background: var(--bg-2); color: var(--muted);
  border: 1px solid var(--line-2); border-radius: 7px; padding: 6px 0; cursor: pointer;
  transition: all .12s;
}
.presets button:hover { color: var(--text); border-color: var(--accent); }
.presets button.active { background: var(--accent); color: #06101d; border-color: var(--accent); font-weight: 600; }

/* params */
.params { display: grid; gap: 12px; }
.params .field { margin-bottom: 0; }
.advanced { margin: 4px 0 16px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12px; padding: 6px 0; }
.advanced summary:hover { color: var(--text); }
.advanced .field { margin-top: 10px; margin-bottom: 10px; }

.run {
  width: 100%; padding: 12px; border: none; border-radius: 9px; cursor: pointer;
  background: linear-gradient(180deg, var(--accent), #2b7fdb); color: #04121f;
  font-weight: 700; font-size: 15px; letter-spacing: .3px;
  transition: filter .15s, transform .05s;
}
.run:hover { filter: brightness(1.08); }
.run:active { transform: translateY(1px); }
.run:disabled { opacity: .6; cursor: default; }
.form-error { color: var(--neg); font-size: 12.5px; margin: 10px 0 0; }

/* ---------------------------------------------------------------- results */
.results { min-height: 300px; position: relative; }
.placeholder {
  border: 1px dashed var(--line-2); border-radius: var(--radius);
  padding: 48px 24px; text-align: center; color: var(--text);
}
.placeholder .muted { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }

.result-head { margin-bottom: 14px; }
.result-head h2 { margin: 0 0 2px; font-size: 20px; }
.result-head .muted { font-size: 13px; }

/* metric cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: 10px; padding: 14px 15px;
}
.card .k { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.card .v { font-size: 24px; font-weight: 700; font-family: var(--mono); margin-top: 4px; letter-spacing: -.5px; }
.card .sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; min-height: 1em; }
.card.hero { border-color: var(--line-2); box-shadow: inset 0 0 0 1px #4da3ff14; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* charts */
.chart-card, .grid-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 18px;
}
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chart-head h3, .grid-card h3 { margin: 0; font-size: 14px; font-weight: 600; }
.chart-head .muted { font-weight: 400; font-size: 12px; }
.toggle { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.chart { width: 100%; }
.u-legend { font-family: var(--mono); font-size: 12px; }

/* stat grid */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-top: 12px; }
.stat { background: var(--panel); padding: 11px 13px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 16px; margin-top: 2px; }

/* trades table */
.table-wrap { max-height: 340px; overflow-y: auto; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; }
table.trades { width: 100%; border-collapse: collapse; font-size: 13px; }
.trades th, .trades td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.trades th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; z-index: 1; }
.trades td { font-family: var(--mono); }
.trades tr:last-child td { border-bottom: none; }
.trades .num { text-align: right; }
.trades tbody tr:hover { background: var(--panel-2); }

.disclaimer { font-size: 11.5px; color: var(--muted); line-height: 1.5; border-top: 1px solid var(--line); padding-top: 12px; }

/* loading */
.loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; color: var(--muted);
  background: #0b0e14cc; border-radius: var(--radius); backdrop-filter: blur(2px);
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- auth gate */
.auth-shell {
  position: fixed; inset: 0; z-index: 100; display: flex;
  align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(900px 500px at 50% -10%, #16203080, transparent), var(--bg);
}
.auth-card {
  width: 100%; max-width: 380px; text-align: center; padding: 36px 30px;
  background: linear-gradient(180deg, var(--panel), #12171f);
  border: 1px solid var(--line-2); border-radius: 16px; box-shadow: 0 24px 60px #0009;
}
.auth-logo { font-size: 40px; color: var(--accent); filter: drop-shadow(0 0 12px #4da3ff55); }
.auth-kicker { margin: 10px 0 0; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.auth-card h1 { margin: 4px 0 8px; font-size: 24px; }
.auth-copy { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.gsi-wrap { display: flex; justify-content: center; min-height: 44px; }
.auth-error { color: var(--neg); font-size: 13px; margin: 16px 0 0; line-height: 1.5; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.auth-who { font-family: var(--mono); font-size: 12px; color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signout {
  background: var(--bg-2); color: var(--muted); border: 1px solid var(--line-2);
  border-radius: 7px; padding: 6px 12px; cursor: pointer; font-size: 12.5px; transition: all .12s;
}
.signout:hover { color: var(--text); border-color: var(--neg); }
@media (max-width: 620px) { .auth-who { display: none; } }
