:root {
  --navy: #0d2b52; --navy-2: #163d6f; --ink: #13233a; --soft: #5a6b80; --line: #dfe5ec;
  --bg: #f2f5f8; --paper: #fff; --red: #d0233f; --green: #1f8a5b; --amber: #c27a00;
  --r: 10px; --display: "Barlow Condensed", "Arial Narrow", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 Barlow, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--navy-2); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); letter-spacing: .01em; margin: 0; line-height: 1.1; }
h1 { font-size: 32px; font-weight: 800; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 18px; font-weight: 700; }
.muted { color: var(--soft); }
.small { font-size: 13px; }

/* Layout */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--navy); color: #fff; padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand img { width: 36px; height: 36px; }
.brand b { font-family: var(--display); font-size: 22px; font-weight: 800; line-height: 1; letter-spacing: .02em; }
.brand small { display: block; font-size: 12px; color: rgba(255,255,255,.65); }
.side select { width: 100%; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); color: #fff; border-radius: 8px; padding: 8px; }
.side select option { color: var(--ink); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: rgba(255,255,255,.8); text-decoration: none; padding: 9px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.on { background: #fff; color: var(--navy); font-weight: 600; }
.side .me { margin-top: auto; font-size: 13px; color: rgba(255,255,255,.7); padding: 0 6px; }
.side .me b { color: #fff; display: block; }
.side .me button { background: none; border: 0; color: rgba(255,255,255,.75); padding: 0; cursor: pointer; text-decoration: underline; }
main { padding: 26px 30px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.head p { margin: 4px 0 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* Surfaces */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid2 > .card + .card { margin-top: 0; }
.grid2 + .card, .card + .grid2 { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat b { font-family: var(--display); font-size: 30px; font-weight: 800; color: var(--navy); display: block; line-height: 1; }
.stat span { color: var(--soft); font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--soft); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.link { cursor: pointer; }
tr.link:hover td { background: #f6f9fc; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; }
.empty { padding: 26px; text-align: center; color: var(--soft); }

/* Controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 8px 13px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: #b9c4d0; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid #c9d2dc; border-radius: 8px; padding: 8px 10px; background: #fff; }
textarea { min-height: 70px; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
label.f { display: block; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--soft); margin-bottom: 4px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 17px; height: 17px; accent-color: var(--navy); }
.search { max-width: 280px; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #e8eef5; color: var(--navy); }
.pill.green { background: #dff3ea; color: var(--green); }
.pill.amber { background: #fbefd9; color: var(--amber); }
.pill.red { background: #fbe3e7; color: var(--red); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; font-weight: 600; color: var(--soft); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--navy); border-color: var(--red); }

/* Silks + drivers */
.silk { width: 26px; height: 26px; flex: none; vertical-align: middle; }
.driver { display: inline-flex; align-items: center; gap: 7px; }

/* Race card */
.race { border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); overflow: hidden; }
.race + .race { margin-top: 16px; }
.race-h { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: #f6f9fc; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.race-no { font-family: var(--display); font-weight: 800; font-size: 26px; color: #fff; background: var(--navy); border-radius: 8px; min-width: 42px; text-align: center; padding: 2px 8px; }
.place { font-family: var(--display); font-weight: 800; font-size: 20px; }
.place.p1 { color: var(--red); }
td input.mini { width: 74px; padding: 5px 7px; }
.map { height: 320px; border-radius: var(--r); border: 1px solid var(--line); }
.map.tall { height: 460px; }
.mk { background: var(--navy); color: #fff; border: 2px solid #fff; border-radius: 99px; font-weight: 700; font-size: 12px; display: grid; place-items: center; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.mk.finish { background: var(--red); }

/* Handicap log */
.log li { margin: 0 0 6px; }
.hc-big { font-family: var(--display); font-size: 44px; font-weight: 800; color: var(--navy); line-height: 1; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(160deg, var(--navy) 0%, #081a33 100%); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { color: var(--navy); margin-bottom: 18px; padding: 0; }
.login .brand small { color: var(--soft); }
.err { color: var(--red); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* Modal + toast */
.modal { position: fixed; inset: 0; background: rgba(8,20,40,.5); display: grid; place-items: center; padding: 16px; z-index: 2000; }
.modal[hidden] { display: none; }
.modal .box { background: #fff; border-radius: 14px; width: 100%; max-width: 620px; max-height: 92vh; overflow: auto; padding: 22px; }
.modal .box.wide { max-width: 860px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 3000; }
.toast.on { opacity: 1; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 18px; background: #f2f5f8; padding: 10px 12px; border-radius: 8px; user-select: all; }

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; }
  .side .club { flex: 1; min-width: 150px; }
  .nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
  .nav a { white-space: nowrap; }
  .side .me { display: none; }
  main { padding: 18px 16px 50px; }
  .form { grid-template-columns: 1fr; }
  h1 { font-size: 26px; }
}
