/* One palette, defined on :root, re-pointed for dark. Every colour in the app is a token, so the
   dark theme is a variable swap rather than a second stylesheet. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #17202a;
  --muted: #667085;
  --accent: #1f5eff;
  --accent-contrast: #ffffff;
  --gain: #12805c;
  --loss: #c0392b;
  --warn-bg: #fff5e6;
  --warn-border: #f0b429;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319; --surface: #161b23; --surface-2: #1e2530; --border: #2a323f;
    --text: #e6e9ef; --muted: #98a2b3; --accent: #6f9bff; --accent-contrast: #0f1319;
    --gain: #3ecf8e; --loss: #ff6b5e; --warn-bg: #2b2314; --warn-border: #a67c1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.gain { color: var(--gain); } .loss { color: var(--loss); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.stack { display: grid; gap: 1rem; }

/* Layout */
.app { max-width: 1180px; margin: 0 auto; padding: 1rem; }
header.top {
  position: sticky; top: 0; z-index: 5; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: .7rem 1rem; margin-bottom: 1rem;
}
header.top .inner { max-width: 1180px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 650; letter-spacing: -.01em; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem; }
.tile .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 1.35rem; font-weight: 600; margin-top: .15rem; font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* Forms */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem .6rem; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
.field { min-width: 0; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; align-items: end; }
button {
  background: var(--accent); color: var(--accent-contrast); border: 1px solid transparent;
  border-radius: 8px; padding: .5rem .9rem; cursor: pointer; font-weight: 550; width: auto;
}
button:hover:not(:disabled) { filter: brightness(1.07); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.danger { background: transparent; color: var(--loss); border-color: var(--border); }
button.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
.table-wrap { overflow-x: auto; }
th, td { text-align: right; padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.closed td { opacity: .55; }

/* Messages */
.alert { border-radius: 8px; padding: .6rem .8rem; border: 1px solid; font-size: .9rem; }
.alert.error { background: color-mix(in srgb, var(--loss) 10%, transparent); border-color: var(--loss); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.alert.info { background: var(--surface-2); border-color: var(--border); }
.pill { display: inline-block; font-size: .74rem; padding: .1rem .45rem; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* Auth */
.auth { max-width: 400px; margin: 8vh auto; }
.auth .card { padding: 1.5rem; }
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; }
.tabs button { flex: 1; background: transparent; color: var(--muted); border: 1px solid var(--border); }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); }

/* Allocation bar */
.alloc { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.alloc span { display: block; height: 100%; }

/* Analyst */
.chat { display: grid; gap: .75rem; max-height: 460px; overflow-y: auto; }
.msg { padding: .6rem .8rem; border-radius: 10px; border: 1px solid var(--border); white-space: pre-wrap; }
.msg.user { background: var(--surface-2); }
.msg.assistant { background: var(--surface); }
