:root {
  --bg: #0c0e12; --panel: #151922; --panel2: #1c2130; --line: #262c3a;
  --fg: #e6e9ef; --dim: #8a92a6; --accent: #4da3ff;
  --purple: #b06cff; --green: #35d07f; --yellow: #ffcf3f; --red: #ff4d4d;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
}
:root[data-theme="light"] {
  --bg: #f3f5f9; --panel: #ffffff; --panel2: #eef1f7; --line: #d3d9e4;
  --fg: #16202e; --dim: #5b6675; --accent: #1f6fd6;
  --purple: #7a34cc; --green: #148a52; --yellow: #9a6b00; --red: #d02e2e;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* beat display:flex/grid on hidden elements */
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
.dim { color: var(--dim); }

/* Top bar */
#topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { cursor: pointer; color: var(--accent); font-weight: 600; white-space: nowrap; }
body[data-view="browser"] .brand { visibility: hidden; }
#topbar .meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
#mMeeting { font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px;
                font-family: var(--mono); }
#mClock { color: var(--fg); }
#mClock.tc { color: var(--yellow); font-weight: 600; }  /* projected time-certain finish */
.tod { font-size: 16px; font-weight: 600; color: var(--fg); letter-spacing: .5px;
       min-width: 72px; text-align: right; }
.pill { background: var(--panel2); border: 1px solid var(--line); border-radius: 999px;
        padding: 1px 10px; font-size: 12px; text-transform: uppercase; color: var(--dim); }

.flag { font-weight: 700; padding: 3px 12px; border-radius: 6px; letter-spacing: .5px;
        background: var(--panel2); text-transform: uppercase; font-size: 12px; }
.flag.green { background: #123c25; color: var(--green); }
.flag.yellow { background: #3d3410; color: var(--yellow); }
.flag.red { background: #3d1414; color: var(--red); }
.flag.chequered, .flag.ended { background: #2a2f3d; color: var(--fg); }

/* Views */
.view { padding: 16px; }
h1 { font-size: 18px; margin: 4px 0 16px; }

/* Session browser */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
        padding: 14px; cursor: pointer; transition: border-color .12s, transform .12s; }
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card.live { border-color: #2c5; margin-bottom: 16px; max-width: 320px; }
.card-title { font-weight: 600; margin-bottom: 6px; }
.card .row2 { display: flex; justify-content: space-between; margin-top: 8px;
              font-family: var(--mono); font-size: 12px; color: var(--dim); }
.card .tag { font-size: 10px; text-transform: uppercase; color: var(--accent);
             border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; margin-left: 6px;
             vertical-align: middle; }

/* Hierarchical browser: meeting card -> session rows */
.cards { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
.card.meeting { cursor: default; }
.card.meeting:hover { transform: none; border-color: var(--line); }
.card.meeting.live { border-color: #2c5; }
.meeting-head { margin-bottom: 8px; }
.live-badge { color: var(--red); font-size: 11px; font-weight: 700; margin-left: 6px;
              letter-spacing: .3px; animation: livepulse 2s ease-in-out infinite; }
@keyframes livepulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.sessions { display: flex; flex-direction: column; gap: 4px; margin-top: 8px;
            border-top: 1px solid var(--line); padding-top: 8px; }
.session-row { display: flex; align-items: center; gap: 10px; padding: 4px 2px; border-radius: 6px; }
.session-row:hover { background: rgba(255,255,255,.03); }
.session-row.live { background: rgba(44,204,85,.08); }
.session-row .sess-name { font-weight: 600; font-size: 13px; white-space: nowrap;
                          display: flex; flex-direction: column; min-width: 0; flex: 1; }
.session-row .sess-cat { font-weight: 400; font-size: 11px; color: var(--dim);
                         overflow: hidden; text-overflow: ellipsis; }
.session-row .sess-meta { font-family: var(--mono); font-size: 11px; text-align: right;
                          line-height: 1.3; white-space: nowrap; }
.session-row .sess-actions { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.session-row.locked .sess-name { color: var(--dim); }
.lock-note { color: var(--dim); font-size: 12px; }

/* Board table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 760px; table-layout: fixed; }
th, td { padding: 6px 7px; text-align: left; white-space: nowrap;
         overflow: hidden; text-overflow: clip; }
th .resizer { position: absolute; top: 0; right: 0; width: 9px; height: 100%;
              cursor: col-resize; z-index: 2; }
th .resizer::before { content: ""; position: absolute; right: 1px; top: 22%;
              height: 56%; width: 2px; background: var(--line); }
th .resizer:hover::before { background: var(--accent); top: 0; height: 100%; }
th { position: sticky; top: 0; background: var(--panel2); color: var(--dim);
     font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--line); }
th.r, td.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { border-bottom: 1px solid var(--line); }
tbody tr:nth-child(odd) { background: rgba(255,255,255,.015); }
tbody td { font-family: var(--mono); font-size: 15px; }
td.driver { font-family: system-ui, sans-serif; }
td.pos { font-weight: 700; }
td.num { color: var(--accent); }
tr.pit { opacity: .55; }
tr.moved-up td.pos { color: var(--green); }
tr.moved-down td.pos { color: var(--red); }

tbody tr { cursor: pointer; }
tr.reference { outline: 1px solid var(--accent); background: rgba(77,163,255,.10) !important; }
tr.reference td.num { font-weight: 700; }
tr.secondary-row { background: rgba(77,163,255,.16) !important;
                   box-shadow: inset 2px 0 0 var(--accent); }
tr.secondary-row td.num { font-weight: 700; color: var(--accent); }

/* last-5-laps delta columns (race view) — narrow, so scale text to fit (no ellipsis) */
th.delta-h { color: var(--dim); border-left: 1px solid var(--line); }
td.delta { background: var(--bg); color: var(--dim); border-left: 1px solid var(--line); }
td.delta.ref-faster { background: #123c25; color: var(--green); }
/* numeric fields all share the main cell size (15px); autofit shrinks any that overflow */
th.delta-h, td.delta { font-size: 15px; padding-left: 2px; padding-right: 2px;
                       letter-spacing: -0.3px; text-overflow: clip; cursor: pointer; }
th.delta-h { font-size: 12px; }   /* headers stay at the header size */
th.delta-h:hover, td.delta:hover { background: var(--panel2); }
td.delta.pit { font-size: 13px; letter-spacing: -0.5px; }  /* pit + stint: slightly smaller */
td.delta.active-stint { color: var(--green); font-weight: 600; }  /* current stint */
td.delta.theory { font-weight: 600; }
/* BEST display: white or purple text only (green is a background, never text) */
td.delta.micro { color: var(--fg); }
td.delta.micro.ref-faster { color: var(--fg); }   /* focus faster: green bg, white text */
td.delta.sb, td.delta.micro.sb { color: var(--purple); font-weight: 600; }  /* the single best */
/* PAST mode: lap times, coloured text only (no green backgrounds) */
td.past { font-family: var(--mono); font-size: 15px; text-align: right; text-overflow: clip;
          border-left: 1px solid var(--line); padding-left: 2px; padding-right: 2px; }
td.past.green { color: var(--green); }
td.past.purple { color: var(--purple); font-weight: 600; }

.refbar { font-size: 13px; color: var(--fg); }
.refbar .dim { margin-left: 8px; }

.board-head { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.btn { background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
       border-radius: 8px; padding: 6px 14px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
body[data-view="browser"] #settingsBtn { display: none; }  /* settings only apply to the board */

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55);
                 display: flex; align-items: flex-start; justify-content: center;
                 padding: 6vh 16px; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
         width: min(720px, 96vw); max-height: 88vh; overflow: auto;
         box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between;
              padding: 12px 16px; border-bottom: 1px solid var(--line);
              font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.settings-tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--line);
                 background: var(--panel); position: sticky; top: 49px; z-index: 1; }
.settings-tab-btn { background: none; border: none; border-bottom: 2px solid transparent;
                    color: var(--dim); padding: 10px 12px; cursor: pointer; font-size: 13px; }
.settings-tab-btn:hover { color: var(--fg); }
.settings-tab-btn.active { color: var(--fg); border-bottom-color: var(--accent); }
.settings-pane { display: flex; flex-direction: column; gap: 14px; }
.mono-ip { font-family: var(--mono); font-size: 12px; }
.blocked-page { display: flex; align-items: center; justify-content: center; min-height: 100vh;
                background: var(--bg); color: var(--dim); font: 16px system-ui; text-align: center; padding: 24px; }
.settings { display: flex; flex-direction: column; gap: 14px; align-items: stretch;
            padding: 16px; min-width: 0; overflow-x: hidden; }
.settings select, .settings input { max-width: 100%; }
.settings-group { min-width: 0; }
#adminSection { min-width: 0; }
.admin-matrix { width: 100%; }   /* fit the pane, no horizontal scroll */

/* car-colours table */
.colour-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12.5px; }
.colour-table th, .colour-table td { padding: 5px 6px; text-align: left; border-bottom: 1px solid var(--line);
                                     overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.colour-table th { color: var(--dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
/* # | Team | Driver | Main | Secondary | reset */
.colour-table col.c-num   { width: 34px; }
.colour-table col.c-main,
.colour-table col.c-sec   { width: 56px; }
.colour-table col.c-reset { width: 52px; }
.colour-table th.c-main, .colour-table th.c-sec,
.colour-table td.c-main, .colour-table td.c-sec { text-align: center; }
.colour-table td.num { font-family: var(--mono); color: var(--accent); font-weight: 700; text-align: right; }
.colour-table td.team { color: var(--dim); }
.colour-table input[type=color] { width: 30px; height: 20px; padding: 0; border: 1px solid var(--line);
                                  border-radius: 4px; background: none; cursor: pointer; vertical-align: middle; }
.colour-table td.c-reset .btn.sm { padding: 2px 7px; font-size: 11px; }

/* auth */
.authbox { display: inline-flex; align-items: center; gap: 8px; font-family: system-ui, sans-serif; }
.authbox .who { color: var(--fg); font-size: 13px; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.primary { background: var(--accent); color: #06121f; border-color: var(--accent); font-weight: 600; }
.auth-modal { width: min(400px, 96vw); }
.auth-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.auth-tabs { display: flex; gap: 8px; }
.auth-tabs .tab { flex: 1; background: var(--panel2); color: var(--dim); border: 1px solid var(--line);
                  border-radius: 8px; padding: 8px; cursor: pointer; font-size: 13px; }
.auth-tabs .tab.active { color: var(--fg); border-color: var(--accent); }
#authForm { display: flex; flex-direction: column; gap: 10px; }
#authForm label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--dim); }
#authForm input { background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
                  border-radius: 8px; padding: 9px 10px; font-size: 14px; }
.auth-error { color: var(--red); font-size: 13px; min-height: 16px; }
.gbtn { display: flex; justify-content: center; min-height: 40px; }
.auth-divider { display: flex; align-items: center; color: var(--dim); font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.auth-divider span { padding: 0 10px; }
#localAuth { display: flex; flex-direction: column; gap: 12px; }

/* post-pit-stop estimate */
.pit-modal { width: min(460px, 96vw); }
.pit-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.pit-add { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pit-add select { flex: 1; min-width: 0; }
.pit-add label { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--dim); }
.pit-list { display: flex; flex-direction: column; gap: 6px; }
.pit-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.pit-row .pit-est { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--accent); }
/* ghost row in the timing table */
tr.pit-ghost { background: rgba(77,163,255,.08) !important; }
tr.pit-ghost td { color: var(--accent); font-style: italic; border-top: 1px dashed var(--accent); border-bottom: 1px dashed var(--accent); }
tr.pit-ghost td.pos, tr.pit-ghost td.num { font-style: normal; font-weight: 700; }
tr.pit-ghost td.driver { font-style: normal; }
td.pit-proj { color: var(--accent); }   /* GTN up to a projected post-pit ghost ahead */
.pit-rm { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px;
          padding: 0 2px; margin-left: 4px; opacity: .7; }
.pit-rm:hover { opacity: 1; color: var(--red); }

/* welcome modal */
.welcome-modal { width: min(460px, 96vw); }
.welcome-body { padding: 18px; }
.welcome-lede { font-size: 15px; color: var(--fg); margin: 0 0 14px; }
.welcome-points { margin: 0 0 14px; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.welcome-points li { color: var(--dim); }
.welcome-points b { color: var(--fg); }
.welcome-more { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
                padding: 10px 12px; color: var(--dim); margin: 0; }
.welcome-more b { color: var(--accent); }

/* what's-new modal */
.wn-modal { width: min(620px, 96vw); }
.wn-body { padding: 4px 18px 8px; }
.wn-release { padding: 16px 0; border-bottom: 1px solid var(--line); }
.wn-release:last-child { border-bottom: 0; }
.wn-release h2 { font-size: 18px; margin: 2px 0 4px; }
.wn-meta { font-family: var(--mono); font-size: 12px; color: var(--dim); margin: 0; }
.wn-summary { color: var(--fg); margin: 6px 0 10px; }
.wn-teaser { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.wn-teaser li { display: flex; align-items: center; gap: 8px; color: var(--dim); }
.wn-section { margin-top: 12px; }
.wn-section h3 { font-size: 14px; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wn-section p { color: var(--dim); margin: 0 0 6px; }
.wn-points { margin: 4px 0 0; padding-left: 18px; color: var(--dim); display: flex; flex-direction: column; gap: 4px; }
.wn-chip { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
           padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.wn-chip-new { color: var(--green); background: rgba(53,208,127,.14); border: 1px solid rgba(53,208,127,.4); }
.wn-chip-improved { color: var(--accent); background: rgba(77,163,255,.14); border: 1px solid rgba(77,163,255,.4); }
.wn-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 18px;
              border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }

/* gated panel placeholder */
.locked { display: flex; align-items: center; justify-content: center; min-height: 200px;
          color: var(--dim); font-size: 14px; text-align: center; padding: 24px; }

/* admin matrix */
.admin-head { font-weight: 600; color: var(--fg); border-top: 1px solid var(--line); padding-top: 12px; }
.admin-matrix { border-collapse: collapse; margin: 6px 0; }
.admin-matrix th, .admin-matrix td { padding: 4px 14px; text-align: center; font-size: 13px; border: 1px solid var(--line); }
.admin-matrix td:first-child, .admin-matrix th:first-child { text-align: left; text-transform: capitalize; }
.settings-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.settings-label { color: var(--dim); font-size: 12px; text-transform: uppercase; }
.settings-group > .settings-label:first-child { min-width: 92px; }
.user-list { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 3px 2px; }
.user-row .user-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row.disabled .user-name { color: var(--dim); text-decoration: line-through; }
.user-row .tag { font-size: 10px; }
.settings label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

#panels { display: flex; flex-direction: column; gap: 14px; }
.panel-row { display: grid; gap: 14px; align-items: start; position: relative; }
.panel-empty { border: 1px dashed var(--line); border-radius: 10px; min-height: 40px; opacity: .4; }
/* drag handle sitting over the gap between two panels */
.col-resizer { position: absolute; top: 0; bottom: 0; width: 14px; transform: translateX(-50%);
               cursor: col-resize; z-index: 4; }
.col-resizer::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
                       transform: translateX(-50%); background: transparent; transition: background .12s; }
.col-resizer:hover::before { background: var(--accent); }

/* layout editor (Settings → General) */
.settings-group-col { flex-direction: column; align-items: stretch; }
.layout-editor { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.lay-row { display: flex; gap: 8px; align-items: center; }
.lay-cells { display: grid; gap: 6px; flex: 1; min-width: 0; }
.lay-cells .lay-cell { width: 100%; min-width: 0; }
.lay-ctl { display: inline-flex; align-items: center; gap: 3px; flex-shrink: 0; }
.lay-ctl button { background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
                  border-radius: 5px; min-width: 24px; height: 26px; cursor: pointer; font-size: 13px; padding: 0 5px; }
.lay-ctl button:hover:not(:disabled) { border-color: var(--accent); }
.lay-ctl button:disabled { opacity: .35; cursor: default; }
.lay-n { font-family: var(--mono); font-size: 11px; color: var(--dim); min-width: 34px; text-align: center; }
#layAddRow { align-self: flex-start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
         overflow: hidden; min-width: 0; }
.panel-head { padding: 8px 14px; font-size: 12px; text-transform: uppercase; color: var(--dim);
              border-bottom: 1px solid var(--line); background: var(--panel2);
              display: flex; align-items: center; }
.l5ctl { margin-left: auto; display: inline-flex; align-items: center; gap: 16px; }
.l5nav { display: inline-flex; align-items: center; gap: 6px; }
.l5nav button { background: var(--panel); color: var(--fg); border: 1px solid var(--line);
                border-radius: 5px; width: 24px; height: 22px; cursor: pointer; font-size: 13px; line-height: 1; }
.l5nav button:hover { border-color: var(--accent); }
#l5range { font-family: var(--mono); font-size: 11px; color: var(--dim); min-width: 34px; text-align: center; }
#l5modeLabel { font-family: var(--mono); font-size: 11px; color: var(--fg); font-weight: 600;
               min-width: 52px; text-align: center; }
.panel-body { padding: 10px; min-width: 0; }
.panel .table-wrap { border: 0; border-radius: 0; }
#wheelView, #gapView, #stintView { display: flex; justify-content: center; }
#wheel, #gap, #stint { max-width: 100%; }

/* stint plot controls */
.stint-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px;
             border-bottom: 1px solid var(--line); }
.stint-ctl select { max-width: 46%; }
.stint-fit { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--dim); cursor: pointer; }
.stint-chips { display: flex; flex-wrap: wrap; gap: 6px; flex-basis: 100%; }
.stint-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px;
              border: 1px solid var(--line); border-radius: 999px; padding: 2px 6px 2px 8px; }
.stint-chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.stint-chip button { background: none; border: none; color: var(--dim); cursor: pointer;
                     font-size: 14px; line-height: 1; padding: 0 2px; }
.stint-chip button:hover { color: var(--red); }

/* stuck/quiet car (no timing-line crossing recently) — reuses the in-pit dimming */
tr.stuck { opacity: .5; }

.purple { color: var(--purple); font-weight: 600; }
.green  { color: var(--green); }
.yellow { color: var(--yellow); }
.best.purple { text-shadow: 0 0 6px rgba(176,108,255,.5); }

/* Transport */
.transport { display: flex; align-items: center; gap: 12px; margin-top: 14px;
             background: var(--panel); border: 1px solid var(--line);
             border-radius: 8px; padding: 10px 14px; }
.transport button { background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
             border-radius: 6px; width: 38px; height: 32px; cursor: pointer; font-size: 14px; }
.transport button:hover { border-color: var(--accent); }
.transport .time { font-family: var(--mono); color: var(--dim); min-width: 48px; text-align: center; }
#scrub { flex: 1; accent-color: var(--accent); }
select { background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
         border-radius: 6px; padding: 5px 8px; }
