@import url('https://fonts.googleapis.com/css2?family=Titillium+Web:wght@400;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme tokens ────────────────────────────── */
:root {
  /* Light (default) */
  --bg:             #f2f2f7;
  --surface:        #ffffff;
  --border:         #d8d8e4;
  --red:            #e8002d;
  --gold:           #b8860b;
  --green:          #00875a;
  --blue:           #0050c8;
  --text:           #0f0f1a;
  --muted:          #6c6c80;
  --header-bg:      #ffffff;
  --input-bg:       #fafafa;
  --hover:          rgba(0,0,0,.04);
  --overlay-subtle: rgba(0,0,0,.04);
  --overlay-soft:   rgba(0,0,0,.07);
  --card-shadow:    0 1px 4px rgba(0,0,0,.08);
  --danger-fg:      #c0392b;
}

[data-theme="dark"] {
  --bg:             #0f0f1a;
  --surface:        #1a1a2e;
  --border:         #2a2a3e;
  --gold:           #ffd700;
  --green:          #00e676;
  --blue:           #0067ff;
  --text:           #eeeeee;
  --muted:          #888888;
  --header-bg:      #111111;
  --input-bg:       #111111;
  --hover:          rgba(255,255,255,.025);
  --overlay-subtle: rgba(255,255,255,.04);
  --overlay-soft:   rgba(255,255,255,.08);
  --card-shadow:    none;
  --danger-fg:      #ff6b6b;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Titillium Web', system-ui, sans-serif;
  min-height: 100vh;
  padding-bottom: 48px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background .2s, color .2s;
}

.container { max-width: 640px; margin: 0 auto; padding: 0 16px; }

@media (min-width: 768px) {
  .container { max-width: 860px; padding: 0 24px; }
  .page-title { font-size: 1.35em; margin: 32px 0 20px; }
}
@media (min-width: 1200px) {
  .container { max-width: 1100px; padding: 0 32px; }
  .page-title { font-size: 1.5em; }
}

/* ── Header ─────────────────────────────────── */
header {
  background: var(--header-bg);
  border-bottom: 2px solid var(--red);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--card-shadow);
}
.hdr-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  gap: 8px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: .95em;
  color: var(--red);
  letter-spacing: 1px;
  white-space: nowrap;
  text-decoration: none;
}
.logo-mark {
  height: 20px;
  width: auto;
  flex-shrink: 0;
}
nav {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }
nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: .82em;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  transition: color .15s, background .15s;
}
nav a:hover { color: var(--text); background: var(--overlay-soft); }
nav a.active { color: var(--red); background: rgba(232,0,45,.1); }

/* ── Mobile hamburger menu ───────────────────── */
.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 1.1em;
  line-height: 1;
  padding: 4px 8px;
  flex-shrink: 0;
  transition: background .15s;
}
.nav-toggle:hover { background: var(--overlay-soft); }

@media (max-width: 639px) {
  .nav-toggle { display: flex; align-items: center; margin-left: auto; }
  nav {
    display: none;
    position: absolute;
    top: 54px;
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    overflow-x: unset;
    background: var(--header-bg);
    border-bottom: 2px solid var(--red);
    padding: 8px;
    gap: 2px;
    box-shadow: 0 6px 20px rgba(0,0,0,.4);
    z-index: 101;
  }
  nav.open { display: flex; }
  nav a { font-size: .9em; padding: 11px 14px; }
}

/* ── Theme toggle ────────────────────────────── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .95em;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.theme-toggle:hover { color: var(--text); background: var(--overlay-soft); }

/* ── Page title ─────────────────────────────── */
.page-title {
  margin: 24px 0 16px;
  font-size: 1.15em;
  font-weight: 700;
  letter-spacing: .5px;
}
.section-header {
  font-size: .72em;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gold);
  margin: 28px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Cards ──────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
}

/* ── Tables ─────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: .9em; }
th {
  text-align: left;
  color: var(--muted);
  font-size: .72em;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
th.c { text-align: center; }
th.r { text-align: right; }
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
td.c { text-align: center; }
td.r { text-align: right; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--hover); }

/* ── Rank cell ──────────────────────────────── */
.pos { font-weight: 700; color: var(--muted); font-size: 1em; }
.pos.gold { color: var(--gold); }
.pos.silver { color: #c0c0c0; }
.pos.bronze { color: #cd7f32; }

/* ── Player dot ─────────────────────────────── */
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Team badge ─────────────────────────────── */
.team-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 5px;
  border-radius: 20px;
  font-weight: 600;
  font-size: .85em;
}
.team-bar {
  width: 4px;
  height: 18px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Constructor team display ───────────────── */
.ctor-team {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ctor-emblem {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1.5px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .62em;
  letter-spacing: .5px;
  flex-shrink: 0;
  overflow: hidden;
  text-transform: uppercase;
}
.ctor-emblem img {
  width: 100%; height: 100%;
  object-fit: contain;
  padding: 5px;
  filter: brightness(1.1);
}
.ctor-name {
  font-weight: 600;
  font-size: .9em;
  line-height: 1.2;
}
.ctor-code {
  font-size: .72em;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  display: none;
}
@media (min-width: 768px) {
  .ctor-emblem { width: 44px; height: 44px; font-size: .72em; }
  .ctor-name { font-size: 1em; }
  .ctor-code { display: block; }
}
@media (min-width: 1200px) {
  .ctor-emblem { width: 52px; height: 52px; font-size: .8em; border-radius: 10px; }
  .ctor-name { font-size: 1.1em; }
}


/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  font-family: inherit;
  font-size: .88em;
  font-weight: 700;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity .15s, transform .1s;
  line-height: 1;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: var(--red);  color: #fff; }
.btn-secondary { background: var(--overlay-soft); color: var(--text); border: 1px solid var(--border); }
.btn-green    { background: var(--green); color: #fff; }
.btn-blue     { background: var(--blue);  color: #fff; }
.btn-danger   { background: rgba(232,0,45,.12); color: var(--danger-fg); border: 1px solid rgba(232,0,45,.25); }
.btn-sm { padding: 7px 14px; font-size: .8em; }
.btn-xs { padding: 5px 10px; font-size: .75em; }
.btn-full { width: 100%; display: flex; }

/* ── Forms ───────────────────────────────────── */
.form-group { margin-bottom: 14px; }
label {
  display: block;
  font-size: .78em;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  margin-bottom: 5px;
}
input[type=text], input[type=password], input[type=number],
input[type=date], input[type=email], select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: .92em;
  outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
select option { background: var(--surface); color: var(--text); }
textarea { resize: vertical; min-height: 80px; }

/* ── Alerts ─────────────────────────────────── */
.alert { padding: 12px 14px; border-radius: 8px; font-size: .88em; margin-bottom: 12px; line-height: 1.5; }
.alert-error   { background: rgba(232,0,45,.08);   border: 1px solid rgba(232,0,45,.25);   color: var(--danger-fg); }
.alert-success { background: rgba(0,135,90,.08);   border: 1px solid rgba(0,135,90,.25);   color: var(--green); }
.alert-info    { background: var(--overlay-subtle); border: 1px solid var(--border);        color: var(--muted); }
.alert-warning { background: rgba(184,134,11,.08); border: 1px solid rgba(184,134,11,.25); color: var(--gold); }

/* ── Loading ─────────────────────────────────── */
.loading { text-align: center; padding: 40px 20px; color: var(--muted); font-size: .9em; }
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Badges ──────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .72em;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.badge-pending   { background: rgba(184,134,11,.12); color: var(--gold); }
.badge-approved  { background: rgba(0,135,90,.1);    color: var(--green); }
.badge-rejected  { background: rgba(232,0,45,.1);    color: var(--danger-fg); }
.badge-superseded { background: var(--overlay-subtle); color: var(--muted); }
.badge-completed { background: rgba(0,135,90,.1);    color: var(--green); }
.badge-scheduled { background: var(--overlay-subtle); color: var(--muted); }

/* ── Chart ───────────────────────────────────── */
.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px 0; }
.chart-wrap { position: relative; height: 260px; min-width: 320px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: .78em; }
.legend-item { display: flex; align-items: center; gap: 6px; }

/* ── Predictions rank list ──────────────────── */
.pred-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.pred-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  user-select: none;
  cursor: grab;
  box-shadow: var(--card-shadow);
}
.pred-item.drag-over { border-color: var(--red); background: rgba(232,0,45,.07); }
@keyframes touch-charge {
  from { border-color: var(--border); box-shadow: 0 0 0 0 rgba(232,0,45,0); }
  to   { border-color: var(--red);    box-shadow: 0 0 0 3px rgba(232,0,45,.35); }
}
.pred-item.touch-pressing { animation: touch-charge 450ms ease-out forwards; }
.pred-item.touch-ghost {
  position: fixed; z-index: 1000; pointer-events: none; list-style: none;
  opacity: .92; transform: scale(1.04) rotate(1.5deg);
  box-shadow: 0 12px 36px rgba(0,0,0,.65);
}
.pred-placeholder {
  list-style: none; border-radius: 8px; border: 2px dashed var(--red);
  background: rgba(232,0,45,.06);
}
.swap-hint-inline {
  font-size: 1.15em;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  display: none;
}
@media (orientation: portrait) and (max-width: 639px) {
  .swap-hint-above { display: none; }
  .swap-hint-inline { display: inline; }
}
.pred-rank {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8em;
  flex-shrink: 0;
}
.pred-emblem {
  width: 30px; height: 30px;
  border-radius: 6px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.pred-emblem img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.pred-emblem-code { font-size: .55em; font-weight: 800; color: #fff; letter-spacing: .3px; text-transform: uppercase; }
.pred-name { flex: 1; font-weight: 600; font-size: .92em; }
.move-btns { display: flex; flex-direction: column; gap: 1px; }
.move-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 22px; height: 18px;
  border-radius: 3px;
  cursor: pointer;
  font-size: .6em;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .1s;
}
.move-btn:hover { background: var(--overlay-soft); color: var(--text); }

/* ── Gap / score ─────────────────────────────── */
.gap { color: var(--muted); font-size: .85em; }
.pts { font-weight: 700; }

/* ── Sessions list ───────────────────────────── */
.sessions-grid {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.sessions-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
@media (max-width: 767px) {
  .sessions-grid { flex-direction: column; }
}
.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--sc-accent, var(--border));
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
}
.session-meta { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.session-meta-top { display: flex; align-items: center; gap: 8px; }
.session-round {
  font-size: .72em; font-weight: 800; letter-spacing: .5px;
  color: var(--muted); text-transform: uppercase; white-space: nowrap;
}
.session-loc { font-weight: 700; font-size: .95em; }
.session-date { font-size: .78em; color: var(--muted); margin-left: auto; white-space: nowrap; }

/* Podium */
.podium { margin: 0 0 10px; display: flex; flex-direction: column; gap: 5px; }
.podium-row {
  display: flex; align-items: center; gap: 8px;
  font-size: .82em;
}
.podium-pos {
  width: 20px; text-align: right;
  font-weight: 800; font-size: .85em;
  color: var(--muted); flex-shrink: 0;
}
.podium-bar { width: 3px; height: 18px; border-radius: 2px; flex-shrink: 0; }
.podium-driver { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-team { font-size: .85em; color: var(--muted); white-space: nowrap; }

/* Recap collapse */
.recap-text {
  font-size: .82em;
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-wrap;
}
.recap-text.collapsed {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
}
.recap-toggle {
  background: none; border: none; padding: 0;
  color: var(--blue); font-size: .78em; font-weight: 600;
  cursor: pointer; margin-top: 6px; text-align: left;
  font-family: inherit;
}
.recap-toggle:hover { text-decoration: underline; }

/* ── Admin tabs ──────────────────────────────── */
.tab-bar { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: .85em;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--red); border-bottom-color: var(--red); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Misc ───────────────────────────────────── */
.row { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.text-muted { color: var(--muted); font-size: .85em; }
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.mt24 { margin-top: 24px; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Footer ─────────────────────────────────── */
footer { text-align: center; margin-top: 48px; padding: 16px 0; border-top: 1px solid var(--border); }
footer a { color: var(--muted); text-decoration: none; font-size: .8em; }
footer a:hover { color: var(--text); }
