:root {
  --bg: #0b0e14;
  --bg-2: #11151f;
  --panel: #151a26;
  --panel-2: #1a2030;
  --line: #232a3b;
  --line-2: #2d3650;
  --text: #e6eaf2;
  --muted: #8a93a8;
  --faint: #5c6577;
  --accent: #4f8cff;
  --accent-2: #6ea8ff;
  --green: #1fcf8f;
  --green-bg: rgba(31, 207, 143, .12);
  --red: #ff5470;
  --red-bg: rgba(255, 84, 112, .12);
  --amber: #ffb547;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, #15203a 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 10%, #14283a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-2); }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- buttons ---------------------------------------------------------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-color: transparent; color: #06101f; }
.btn.primary:hover { box-shadow: 0 6px 18px rgba(79, 140, 255, .35); }
.btn.ghost { background: transparent; }
.btn.warn { background: rgba(255, 181, 71, .14); border-color: rgba(255, 181, 71, .4); color: var(--amber); }
.btn.danger { background: var(--red-bg); border-color: rgba(255, 84, 112, .45); color: var(--red); }
.btn.danger:hover { background: rgba(255, 84, 112, .22); }

/* ---- login ------------------------------------------------------------ */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 32px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin: 22px 0 4px; }
.login-card form { display: grid; gap: 14px; margin-top: 18px; }
.login-card label, .form-grid label, .toggles .switch, .add-script label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; }
.login-card input, .form-grid input, .form-grid select, .add-script input {
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line-2); border-radius: 9px; padding: 10px 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 140, 255, .18); }

/* ---- brand ------------------------------------------------------------ */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #06101f; border-radius: 11px; font-size: 18px; font-weight: 800;
}
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; }

/* ---- app shell -------------------------------------------------------- */
.app { max-width: 1340px; margin: 0 auto; padding: 22px clamp(14px, 3vw, 30px) 60px; display: grid; gap: 18px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: rgba(11, 14, 20, .82); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow);
}
.status-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.top-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.top-actions form { margin: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 12px;
}
.pill b { color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 10px; }
.pill span { font-variant-numeric: tabular-nums; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 0 transparent; }
.pill.clock { font-family: var(--mono); }
.pill.live i { background: var(--green); animation: pulse 2s infinite; }
.pill.bad i { background: var(--red); }
.pill.warn i { background: var(--amber); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(31, 207, 143, .5); } 70% { box-shadow: 0 0 0 6px rgba(31, 207, 143, 0); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ---- metrics ---------------------------------------------------------- */
.metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.metric {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
}
.metric.hero { background: linear-gradient(180deg, #16203a, #121726); border-color: var(--line-2); }
.metric-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.metric-value { display: block; margin-top: 8px; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 6px; color: var(--faint); font-size: 11px; }
.metric small b { color: var(--muted); }
.pos { color: var(--green); } .neg { color: var(--red); }
.metric.hero.up { box-shadow: inset 0 0 0 1px rgba(31,207,143,.3); }
.metric.hero.down { box-shadow: inset 0 0 0 1px rgba(255,84,112,.3); }

/* ---- panels ----------------------------------------------------------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-head span { color: var(--faint); font-size: 12px; }
.total-mtm { font-size: 13px; color: var(--muted); }
.total-mtm b { font-family: var(--mono); font-size: 15px; margin-left: 6px; }
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---- entry control ---------------------------------------------------- */
.entry-control .start-form { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.select-wrap { display: grid; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; min-width: 220px; }
.select-wrap select {
  font: inherit; font-size: 15px; font-weight: 600; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 11px 14px; cursor: pointer;
}
.start-btn { font-size: 15px; padding: 11px 26px; }
.start-btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }
.start-hint { flex: 1 1 100%; margin: 4px 0 0; color: var(--faint); font-size: 12px; }

/* ---- tables ----------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; color: var(--faint); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.data-table th.num { text-align: right; }
.data-table td { padding: 10px; border-bottom: 1px solid rgba(35, 42, 59, .55); font-variant-numeric: tabular-nums; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background .15s ease; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, .02); }
.data-table .empty { text-align: center; color: var(--faint); padding: 26px; }
.positions .closed { opacity: .5; }
td.flash-up { animation: flashUp .6s ease; }
td.flash-down { animation: flashDown .6s ease; }
@keyframes flashUp { 0% { background: var(--green-bg); } 100% { background: transparent; } }
@keyframes flashDown { 0% { background: var(--red-bg); } 100% { background: transparent; } }

.tag { display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 6px; margin-right: 4px; letter-spacing: .03em; }
.tag.ce { background: rgba(79,140,255,.16); color: var(--accent-2); }
.tag.pe { background: rgba(255,181,71,.16); color: var(--amber); }
.tag.sl { background: var(--red-bg); color: var(--red); }
.tag.scale { background: var(--green-bg); color: var(--green); }
.tag.roll { background: rgba(138,147,168,.18); color: var(--muted); }
.badge-open { color: var(--green); } .badge-closed { color: var(--faint); }

/* ---- timeline --------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; display: grid; gap: 2px; }
.timeline li { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 8px 6px; border-bottom: 1px solid rgba(35,42,59,.5); font-size: 13px; }
.timeline li.empty { display: block; text-align: center; color: var(--faint); padding: 24px; }
.timeline time { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.timeline .lv-trade { color: var(--text); } .timeline .lv-trade::before { content: "● "; color: var(--accent); }
.timeline .lv-warn { color: var(--amber); } .timeline .lv-error { color: var(--red); }
.timeline .lv-info { color: var(--muted); }

/* ---- forms ------------------------------------------------------------ */
.collapsible summary { cursor: pointer; display: flex; align-items: baseline; gap: 12px; list-style: none; }
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible summary::before { content: "▸"; color: var(--faint); transition: transform .2s; }
.collapsible[open] summary::before { transform: rotate(90deg); }
.collapsible summary h2 { margin: 0; font-size: 15px; }
.collapsible summary span { color: var(--faint); font-size: 12px; }
.collapsible > form, .collapsible > .script-grid { margin-top: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.form-grid.compact { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 9px; }
.toggles { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 16px; }
.form-actions { margin-top: 16px; }

.switch { flex-direction: row; align-items: center; gap: 9px; color: var(--text); cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 38px; height: 22px; background: var(--line-2); border-radius: 999px; position: relative; transition: background .2s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch.sm span { width: 32px; height: 18px; } .switch.sm span::after { width: 13px; height: 13px; } .switch.sm input:checked + span::after { transform: translateX(14px); }

.script-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.script-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 12px; }
.script-title { display: flex; align-items: center; justify-content: space-between; }
.script-title strong { font-size: 15px; }
.add-script { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line-2); display: grid; gap: 12px; }
.add-script h3 { margin: 0; font-size: 14px; }

/* ---- toasts ----------------------------------------------------------- */
.toast-stack { position: fixed; top: 16px; right: 16px; z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: 10px; padding: 11px 15px; box-shadow: var(--shadow); animation: slideIn .25s ease; max-width: 340px; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 1080px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .metrics { grid-template-columns: 1fr; }
  .top-actions { width: 100%; }
}
