:root {
  --bg: #f6f8fa; --panel: #ffffff; --ink: #1f2328; --muted: #656d76;
  --line: #d0d7de; --accent: #0969da; --accent-bg: #ddf4ff;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar nav { display: flex; gap: 4px; margin-right: auto; }
.topbar nav a {
  color: var(--ink); padding: 6px 12px; border-radius: 6px;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: var(--accent-bg); color: var(--accent); }
.user { color: var(--muted); font-size: 13px; }

.banner {
  background: #fff8c5; border-bottom: 1px solid #d4a72c;
  padding: 8px 24px; font-size: 13px;
}

main { max-width: 1080px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 0 0 20px; }
h2 { font-size: 16px; margin: 28px 0 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px;
}
.card-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 26px; font-weight: 600; margin-top: 6px; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.sparkline { display: block; margin-top: 2px; }

a.card-link { display: block; color: inherit; }
a.card-link:hover { text-decoration: none; border-color: var(--accent); }
a.card-link .card-label { font-size: 15px; text-transform: none; letter-spacing: 0;
  color: var(--ink); font-weight: 600; }
a.card-link .card-sub { margin-top: 6px; font-size: 13px; }

table { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); }
th { background: var(--bg); color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); background: var(--panel); border: 1px dashed var(--line);
  border-radius: 10px; padding: 20px; }
.crumb { margin: 0 0 8px; }
code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12px; }

.flash { max-width: 1080px; margin: 16px auto -8px; padding: 10px 16px;
  background: #dafbe1; border: 1px solid #2da44e; color: #1a7f37; border-radius: 8px; }
.alert { padding: 10px 16px; margin-bottom: 16px;
  background: #ffebe9; border: 1px solid #cf222e; color: #cf222e; border-radius: 8px; }

.form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 20px; max-width: 460px; display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
.form input, .form select { font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; font-weight: 400; }
.form .hint { color: var(--muted); font-weight: 400; font-size: 12px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }

.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; font-size: 14px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #0860ca; }

.selector-bar { display: flex; gap: 20px; align-items: flex-end; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 18px; margin-bottom: 16px; }
.selector-bar label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
.selector-bar select { font: inherit; font-weight: 400; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.chart-panel { background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px; overflow-x: auto; }

/* Scorecard: a metric at or below its null value (coin-flip hit rate, negative
   skill, non-positive correlation) reads as red so a failing model is obvious. */
.order-group { margin-bottom: 22px; }
.order-group-head { display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 8px; }
.order-symbol { font-weight: 700; font-size: 16px; margin-right: 10px; }
.btn-danger { background: #cf222e; border-color: #cf222e; color: #fff; }
.btn-danger:hover { background: #a40e26; }
.pill-planned { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.pill-placed { background: #dafbe1; border-color: #2da44e; color: #1a7f37; }
.pill-cancelled { background: #ffebe9; border-color: #cf222e; color: #cf222e; }
.pill-skipped, .pill-failed { background: #fff1e5; border-color: #bc4c00; color: #bc4c00; }

.metric-neg { color: #cf222e; font-weight: 600; }
.metric-notes { color: var(--muted); font-size: 12.5px; margin-top: 10px;
  max-width: 900px; }
.metric-notes p { margin: 0 0 8px; }
.metric-notes strong { color: var(--ink); font-weight: 600; }

table.kv { max-width: 560px; }
table.kv th { width: 220px; background: var(--panel); text-transform: none; letter-spacing: 0;
  color: var(--muted); font-weight: 600; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); background: var(--bg); }
.pill-active { background: #dafbe1; border-color: #2da44e; color: #1a7f37; }
.pill-inactive, .pill-closed { background: #ffebe9; border-color: #cf222e; color: #cf222e; }
.pill-contribution { background: #dafbe1; border-color: #2da44e; color: #1a7f37; }
.pill-withdrawal { background: #fff1e5; border-color: #bc4c00; color: #bc4c00; }
.pill-fee, .pill-charged { background: #ddf4ff; border-color: #0969da; color: #0969da; }
.pill-calculated, .pill-generated, .pill-sent { background: var(--bg); }

/* --- Sign-in page (TRADECRAFT_AUTH_MODE=oauth) -------------------------- */
.login-body { background: var(--bg); }
.login-main { max-width: 420px; margin: 0 auto; padding: 12vh 20px 24px;
  display: flex; justify-content: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px 26px 22px; width: 100%; text-align: center;
}
.login-card .brand { font-size: 18px; margin-bottom: 18px; }
.login-lead { color: var(--muted); margin: 0 0 20px; }
.login-button { display: flex; justify-content: center; min-height: 44px; }
.login-error {
  background: #ffebe9; border: 1px solid #cf222e; color: #cf222e;
  border-radius: 8px; padding: 10px 12px; margin: 0 0 18px; text-align: left;
}
.login-foot { margin: 20px 0 0; }

/* The signed-in identity in the top bar, with its sign-out control. */
.user form { display: inline; }
.user .signout {
  background: none; border: none; padding: 0 0 0 8px; margin: 0;
  color: var(--accent); font: inherit; font-size: 13px; cursor: pointer;
}
.user .signout:hover { text-decoration: underline; }
