:root {
  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --ink: #1d2329;
  --muted: #66717d;
  --line: #d8d6ce;
  --blue: #225f9f;
  --green: #14784e;
  --red: #b33f36;
  --amber: #9a6a12;
  --cyan: #0d7377;
  --shadow: 0 12px 26px rgba(29, 35, 41, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

[hidden] {
  display: none !important;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
}

button:active {
  transform: translateY(1px);
}

button.buy {
  border-color: rgba(20, 120, 78, 0.25);
  background: var(--green);
  color: #fff;
}

button.sell {
  border-color: rgba(179, 63, 54, 0.25);
  background: var(--red);
  color: #fff;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

textarea {
  min-height: 156px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 2.6vw, 2rem);
  line-height: 1.1;
}

h2 {
  font-size: 1rem;
}

h3 {
  font-size: 0.92rem;
}

.auth-gate {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-card {
  display: grid;
  width: min(100%, 440px);
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-card h1 {
  text-align: center;
}

.auth-card .status {
  margin-top: 0;
  text-align: center;
}

.app-shell {
  display: none;
}

body[data-authenticated="true"] .auth-gate {
  display: none;
}

body[data-authenticated="true"] .app-shell {
  display: block;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 750;
  text-transform: uppercase;
}

td {
  font-size: 0.88rem;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 360px) minmax(320px, 520px);
  gap: 18px;
  align-items: center;
  padding: 20px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.brand {
  min-width: 0;
}

.status {
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.status.error {
  color: var(--red);
}

.auth-panel {
  min-width: 0;
}

.login-form {
  display: grid;
  gap: 10px;
}

.session-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 88px;
  gap: 10px;
  align-items: center;
}

.session-panel strong,
.session-panel span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clock {
  display: grid;
  grid-template-columns: 88px minmax(120px, 1fr);
  gap: 10px 14px;
  align-items: center;
}

.clock span {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.clock input {
  padding: 0;
}

.clock-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.readonly-clock {
  grid-template-columns: auto;
  justify-content: end;
}

.layout {
  display: grid;
  grid-template-columns: 315px minmax(460px, 1fr);
  gap: 18px;
  padding: 18px clamp(16px, 4vw, 42px) 42px;
}

.admin-layout {
  grid-template-columns: minmax(460px, 1fr) 350px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.ticket,
.impersonate,
.market,
.scoring,
.admin,
.trades {
  padding: 16px;
}

.market,
.scoring,
.admin {
  display: grid;
  align-content: start;
  gap: 14px;
}

.ticket {
  display: none;
}

body[data-page="team"][data-role="team"] .ticket {
  display: grid;
  align-content: start;
  gap: 14px;
}

.admin {
  grid-column: 2;
}

body:not([data-role="admin"]) .admin,
body:not([data-role="admin"]) .admin-only {
  display: none;
}

.trades {
  grid-column: 1 / -1;
}

/* Read-only team impersonation panel on the admin page: a full-width row
   between the Market/Admin row and the Trades table. */
.impersonate {
  display: grid;
  align-content: start;
  gap: 14px;
  grid-column: 1 / -1;
}

body:not([data-role="admin"]) .impersonate {
  display: none;
}

.section-head {
  display: flex;
  min-height: 30px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-head.compact {
  min-height: auto;
}

.pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  text-transform: none;
  vertical-align: middle;
  cursor: help;
}

.help:hover,
.help:focus {
  border-color: var(--blue);
  color: var(--blue);
  outline: none;
}

.quote-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.quote-grid span {
  color: var(--muted);
  font-size: 0.84rem;
}

.quote-grid strong {
  font-variant-numeric: tabular-nums;
}

.trade-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.speed-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: center;
}

.speed-control input[type="range"] {
  padding: 0;
}

.holdings,
.stock-score {
  display: grid;
  gap: 8px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.market-table {
  max-height: 300px;
}

.table-wrap table th,
.table-wrap table td {
  background: #fff;
}

#stocksBody tr {
  cursor: pointer;
}

#stocksBody tr.selected td {
  background: #edf5f2;
}

.chart-wrap {
  display: grid;
  gap: 10px;
  min-height: 340px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.chart-controls {
  display: grid;
  grid-template-columns: 38px 38px minmax(120px, 1fr) minmax(140px, auto) 72px;
  gap: 8px;
  align-items: center;
}

.chart-controls button {
  min-height: 34px;
  padding: 0 10px;
  font-weight: 700;
}

.chart-controls input[type="range"] {
  min-height: 34px;
  padding: 0;
}

.chart-window {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

#priceChart {
  width: 100%;
  height: 260px;
  cursor: crosshair;
}

.score-list {
  display: grid;
  gap: 10px;
}

.score-row {
  display: grid;
  gap: 6px;
}

.score-row header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
  font-weight: 750;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #ebe8df;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.muted {
  color: var(--muted);
}

.empty {
  color: var(--muted);
  text-align: center;
}

td.numeric,
th.numeric {
  text-align: right;
}

@media (max-width: 1160px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin,
  .trades {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .login-form,
  .session-panel,
  .clock,
  .clock-actions {
    grid-template-columns: 1fr;
  }

  .chart-controls {
    grid-template-columns: 38px 38px minmax(0, 1fr) 72px;
  }

  .chart-window {
    grid-column: 1 / -1;
    text-align: left;
  }

  .clock-actions {
    grid-column: auto;
  }

  th,
  td {
    padding: 9px 7px;
  }
}

/* Links */
a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}

a:hover {
  text-decoration: underline;
}

.doc-link {
  display: inline-block;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* API reference page */
.doc-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
  padding: 20px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.doc-main {
  display: grid;
  gap: 18px;
  width: min(100%, 940px);
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 42px) 64px;
}

.docs {
  padding: 20px 22px;
}

.docs h2 {
  margin: 0;
}

.docs h3 {
  margin: 20px 0 4px;
}

.docs p {
  margin: 8px 0 0;
  line-height: 1.55;
}

.docs ul {
  margin: 8px 0 0;
  padding-left: 20px;
  line-height: 1.65;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

pre {
  margin: 10px 0 0;
  padding: 12px 14px;
  overflow-x: auto;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
}

pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: 1em;
}

.endpoint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.method {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 2px 8px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.method.get {
  background: var(--blue);
}

.method.post {
  background: var(--green);
}

.endpoint .path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  font-weight: 600;
}
