:root {
  color-scheme: light;
  --ground: #e9edec;
  --surface: #f8faf9;
  --ink: #14211e;
  --muted: #4c5b57;
  --line: #cdd5d2;
  --action: #2134b8;
  --action-dark: #18268a;
  --up: #0a5a38;
  --up-tint: #cfeadc;
  --up-solid: #0a6b43;
  --down: #8f1d15;
  --down-tint: #f6d9d4;
  --down-solid: #a6241b;
  --wait-tint: #dde2e0;
  --warn: #6b4e00;
  --warn-tint: #f6e8bd;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}

.top, main, footer, .alert { max-width: 1360px; margin-inline: auto; padding-inline: 24px; }

.top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: end;
  gap: 16px 48px;
  padding-block: 28px 20px;
}

h1 { margin: 0; font-size: 1.75rem; line-height: 1.1; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 1.1rem; }

.mode { margin: 6px 0 0; color: var(--muted); }
.mode strong { background: var(--warn-tint); color: var(--warn); padding: 1px 7px; border-radius: 3px; font-weight: 600; }

.summary { display: flex; flex-wrap: wrap; margin: 0; }
.summary div { padding: 0 24px; border-left: 1px solid var(--line); }
.summary div:first-child { padding-left: 0; border-left: 0; }
.summary dt { color: var(--muted); font-size: 0.82rem; }
.summary dd { margin: 0; font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.summary .main dd { font-size: 1.75rem; line-height: 1.1; }

.alert { margin-bottom: 16px; }
.alert span { display: block; padding: 10px 14px; background: var(--down-tint); color: var(--down); border-radius: 4px; }

main section { margin-bottom: 36px; }
main h2 { margin-bottom: 10px; }

.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; margin-bottom: 12px; }
.bar h2 { margin: 0; }
.add { display: flex; align-items: center; gap: 8px; }
.add label { color: var(--muted); font-size: 0.88rem; }
.run { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.run p { margin: 0; color: var(--muted); font-size: 0.88rem; text-align: right; }

input {
  width: 170px;
  padding: 7px 10px;
  border: 1px solid #7f8d89;
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
input::placeholder { color: #5c6a66; }

button { font: inherit; cursor: pointer; border-radius: 4px; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.primary { padding: 9px 18px; border: 0; background: var(--action); color: #fff; font-weight: 600; white-space: nowrap; }
.primary:hover:not(:disabled) { background: var(--action-dark); }
.ghost { padding: 6px 12px; border: 1px solid #7f8d89; background: transparent; color: var(--ink); white-space: nowrap; }
.ghost:hover:not(:disabled) { background: var(--wait-tint); }
.link { padding: 0; border: 0; background: none; color: var(--action); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-size: 0.82rem; font-weight: 600; text-align: left; white-space: nowrap; }
.plain th, .plain td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); }
.num { text-align: right; }
.plain .num:last-child { padding-right: 0; }

.matrix { border-collapse: separate; border-spacing: 3px; margin-inline: -3px; width: calc(100% + 6px); min-width: 1020px; }
.matrix th { padding: 4px 8px; }
.matrix td { padding: 0; height: 52px; }
.matrix th:first-child, .matrix td.stock { position: sticky; left: 0; background: var(--ground); z-index: 1; }

.stock { padding-right: 12px !important; min-width: 190px; }
.stock b { display: block; font-size: 0.98rem; line-height: 1.2; }
.stock small, .price small { color: var(--muted); font-size: 0.8rem; }
.price { padding-inline: 8px !important; text-align: right; white-space: nowrap; }
.price span { display: block; font-weight: 600; }

.vote {
  display: flex;
  height: 100%;
  min-width: 96px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
  border-radius: 3px;
  font-weight: 600;
}
.vote small { font-size: 0.85rem; font-weight: 500; }
.vote.BUY { background: var(--up-tint); color: var(--up); }
.vote.SELL { background: var(--down-tint); color: var(--down); }
.vote.HOLD { background: var(--wait-tint); color: #36433f; }
.vote.fail { background: var(--warn-tint); color: var(--warn); font-weight: 500; }

.decision { display: flex; flex-direction: column; justify-content: center; height: 100%; min-width: 132px; padding: 0 10px; border-radius: 3px; font-weight: 700; }
.decision small { font-size: 0.78rem; font-weight: 400; }
.decision.BUY { background: var(--up-solid); color: #fff; }
.decision.SELL { background: var(--down-solid); color: #fff; }
.decision.HOLD { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

.exec { padding-inline: 8px !important; color: var(--muted); font-size: 0.85rem; min-width: 150px; }
.tools { padding-left: 6px !important; white-space: nowrap; }
.tools button + button { margin-left: 4px; }
.tools .ghost { padding: 4px 8px; font-size: 0.82rem; }
.empty-row { padding-inline: 10px !important; color: var(--muted); }

.detail td { height: auto; padding: 6px 0 18px; }
.reasons { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 28px; padding: 14px 16px; background: var(--surface); border-radius: 3px; position: sticky; left: 0; max-width: min(1300px, calc(100vw - 48px)); }
.reasons h3 { margin: 0 0 4px; font-size: 0.95rem; }
.reasons h3 small { color: var(--muted); font-weight: 400; }
.reasons p { margin: 0 0 6px; }
.reasons .risk { color: var(--muted); font-size: 0.9rem; }
.reasons ul { margin: 0; padding: 0; list-style: none; font-size: 0.85rem; }
.reasons li { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a { color: var(--action); }
.detail-foot { grid-column: 1 / -1; margin: 0; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; }

.note { margin: 10px 0 0; color: var(--muted); font-size: 0.86rem; max-width: 95ch; }
.empty { margin: 0; padding: 14px 0; color: var(--muted); }
.gain { color: var(--up); }
.loss { color: var(--down); }
.base td { color: var(--muted); }
.lead td { font-weight: 600; }

.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 0 48px; }

footer { padding-block: 0 32px; color: var(--muted); font-size: 0.82rem; }

.logout { margin-left: 10px; font-size: 0.88rem; }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px 16px; }
.login { width: min(100%, 360px); }
.login h1 { margin-bottom: 20px; }
.login form { display: grid; gap: 6px; }
.login label { font-weight: 600; font-size: 0.92rem; }
.login input { width: 100%; margin-bottom: 10px; }
.login .primary { margin-top: 12px; }
.hint { margin: -6px 0 12px; color: var(--muted); font-size: 0.84rem; }
.login-error { margin: 10px 0 0; padding: 9px 12px; background: var(--down-tint); color: var(--down); border-radius: 4px; }
.cf-turnstile { min-height: 65px; }

@media (max-width: 640px) {
  .top, main, footer, .alert { padding-inline: 16px; }
  .summary { gap: 12px 0; }
  .summary div { padding: 0 16px 0 0; border-left: 0; min-width: 45%; }
  .run { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .run p { order: 2; text-align: left; }
  .run .primary { width: 100%; }
  .add { width: 100%; flex-wrap: wrap; }
  .add label { width: 100%; }
  .add input { flex: 1; width: auto; min-width: 0; }
  .stock { min-width: 128px; }
  .reasons { max-width: calc(100vw - 32px); }
}
