/* ==========================================================================
   otks styles
   ========================================================================== */

/* --------------------------------------------------------------------------
   Fonts — local copies of the otks.systems brand faces.
   -------------------------------------------------------------------------- */

@font-face {
  font-family: "Sintesi Semi";
  src: url("/assets/fonts/SintesiSemi.otf") format("opentype");
  font-display: swap;
}
@font-face {
  font-family: "Sintesi Semi";
  src: url("/assets/fonts/SintesiSemi-Bold.otf") format("opentype");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Open Sans";
  src: url("/assets/fonts/OpenSans-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Open Sans";
  src: url("/assets/fonts/OpenSans-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

:root {
  --bg: #141414;
  --bg-elevated: #1c1c1c;
  --fg: #e5e5e3;
  --fg-muted: #c8c8c6;
  --fg-dim: #999;
  --border-subtle: #2a2a2a;
  --display: "Sintesi Semi", Arial, sans-serif;
  --body: "Open Sans", Arial, sans-serif;
}

/* --------------------------------------------------------------------------
   FrankenUI custom theme — HSL values without the hsl() wrapper, as the
   FrankenUI CDN build expects. The class is applied to <html> by the init
   script in base.html, giving it specificity to override built-in themes.
   Palette derived from the otks.systems --bg/--fg variables above.
   -------------------------------------------------------------------------- */

.uk-theme-otks {
  --background: 0 0% 8%; /* #141414 */
  --foreground: 60 4% 89%; /* #e5e5e3 */

  --muted: 0 0% 11%; /* #1c1c1c */
  --muted-foreground: 0 0% 60%; /* #999 */

  --card: 0 0% 11%;
  --card-foreground: 60 4% 89%;

  --popover: 0 0% 11%;
  --popover-foreground: 60 4% 89%;

  --border: 0 0% 16%; /* #2a2a2a */
  --input: 0 0% 16%;

  --primary: 60 4% 89%; /* otks's "primary" is the foreground tone — */
  --primary-foreground: 0 0% 8%; /* same trick as the corner button on otks.systems */

  --secondary: 0 0% 16%;
  --secondary-foreground: 60 4% 89%;

  --accent: 0 0% 60%;
  --accent-foreground: 0 0% 8%;

  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 100%;

  --ring: 60 4% 89%;
  --radius: 0.5rem;
}

/* Dark mode uses the same palette — otks is dark-first. */
.uk-theme-otks.dark {
  --background: 0 0% 8%;
  --foreground: 60 4% 89%;

  --muted: 0 0% 11%;
  --muted-foreground: 0 0% 60%;

  --card: 0 0% 11%;
  --card-foreground: 60 4% 89%;

  --popover: 0 0% 11%;
  --popover-foreground: 60 4% 89%;

  --border: 0 0% 16%;
  --input: 0 0% 16%;

  --primary: 60 4% 89%;
  --primary-foreground: 0 0% 8%;

  --secondary: 0 0% 16%;
  --secondary-foreground: 60 4% 89%;

  --accent: 0 0% 60%;
  --accent-foreground: 0 0% 8%;

  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 100%;

  --ring: 60 4% 89%;
  --radius: 0.5rem;
}

/* --------------------------------------------------------------------------
   FrankenUI Component Adjustments
   Tailwind v4 preflight resets padding/background/radius on <button> and
   <a>; we restore them so FrankenUI's classes look right.
   -------------------------------------------------------------------------- */

.uk-button {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  padding: 0 1.5rem !important;
  height: 2.5rem;
  border-radius: var(--radius, 0.5rem) !important;
  font-weight: 500;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    transform 0.2s ease;
  white-space: nowrap;
}

.uk-button-primary {
  background-color: hsl(var(--primary)) !important;
  color: hsl(var(--primary-foreground)) !important;
}

.uk-button-primary:hover {
  background-color: hsl(var(--primary)) !important;
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.uk-button-default {
  background-color: hsl(var(--secondary)) !important;
  color: hsl(var(--secondary-foreground)) !important;
  border-color: hsl(var(--secondary)) !important;
}

.uk-button-default:hover {
  background-color: hsl(var(--muted)) !important;
  color: hsl(var(--foreground)) !important;
}

.uk-button:disabled,
.uk-button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.uk-button-primary:disabled,
.uk-button-primary[disabled] {
  background-color: hsl(var(--secondary)) !important;
  color: hsl(var(--foreground)) !important;
}

.uk-button-large {
  padding: 0 2rem !important;
  height: 3rem;
  font-size: 1.125rem;
}

.uk-tab > * > a:hover {
  color: var(--fg);
}

.uk-form-label {
  color: hsl(var(--foreground)) !important;
}

/* --------------------------------------------------------------------------
   Typography — Open Sans for body, Sintesi Semi for the display wordmark
   and headings, matching otks.systems.
   -------------------------------------------------------------------------- */

* {
  font-family: var(--body);
}

.brand,
.logo-text {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--fg);
}

.brand {
  font-size: 1.75rem;
  text-decoration: none;
}

.brand:hover {
  color: #ffffff;
}

.logo-text {
  font-size: clamp(3.5rem, 10vw, 6rem);
  line-height: 1;
}

.tagline {
  font-size: clamp(14px, 2.5vw, 16px);
  letter-spacing: 0.12em;
  color: var(--fg-dim);
}

/* --------------------------------------------------------------------------
   Native form controls — opt the page into dark UA chrome so Chrome's
   datetime-local picker, calendar popup, and spin buttons render against a
   dark surface instead of the light default. Firefox does the same via
   prefers-color-scheme but Chrome only honours explicit `color-scheme`.
   -------------------------------------------------------------------------- */

html.dark {
  color-scheme: dark;
}

/* Make the calendar icon visible on dark inputs and clickable-feeling. With
   `color-scheme: dark` it's already light-on-dark, but the default opacity
   is low enough to read as decorative — bump it on hover. */
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.7;
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

/* Force every segment of the datetime edit to the foreground colour. Without
   this Chrome falls back to a near-black for the value and the placeholder
   chunks ("yyyy", "--") which is unreadable on the elevated dark surface. */
input[type="datetime-local"]::-webkit-datetime-edit,
input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper,
input[type="datetime-local"]::-webkit-datetime-edit-text,
input[type="datetime-local"]::-webkit-datetime-edit-year-field,
input[type="datetime-local"]::-webkit-datetime-edit-month-field,
input[type="datetime-local"]::-webkit-datetime-edit-day-field,
input[type="datetime-local"]::-webkit-datetime-edit-hour-field,
input[type="datetime-local"]::-webkit-datetime-edit-minute-field,
input[type="datetime-local"]::-webkit-datetime-edit-ampm-field {
  color: hsl(var(--foreground));
}

/* --------------------------------------------------------------------------
   Custom Components
   -------------------------------------------------------------------------- */

.panel-gradient {
  background: linear-gradient(135deg, var(--bg-elevated) 0%, var(--bg) 100%);
  border: 1px solid var(--border-subtle);
}

.stat-card {
  background: linear-gradient(135deg, var(--bg-elevated) 0%, var(--bg) 100%);
  border: 1px solid var(--border-subtle);
}

/* Subtle radial wash behind the hero — replaces media-hulk's red glow with a
   soft white-ish vignette that matches the otks.systems palette. */
.hero-gradient {
  background: radial-gradient(
    circle at 50% 0%,
    rgba(229, 229, 227, 0.06) 0%,
    transparent 60%
  );
}

.racing-accent {
  border-left: 3px solid var(--fg-dim);
}

.feature-card {
  transition:
    transform 0.2s ease,
    border-color 0.2s ease;
}

.feature-card:hover {
  transform: translateY(-4px);
  border-color: var(--fg-dim);
}

/* --------------------------------------------------------------------------
   Live timing board — TV-broadcast feel. High contrast, tabular monospace
   numbers, colour-coded status chips, and a soft red glow on the row that
   currently holds a live run.
   -------------------------------------------------------------------------- */

.timing-board {
  background: #000;
  border: 1px solid #1a1a1a;
  border-radius: 0.5rem;
  overflow: hidden;
}

.timing-table {
  width: 100%;
  border-collapse: collapse;
  /* `fixed` honours every column's width property and distributes any leftover
     space equally across all columns. Without it, `auto` lets the Team column
     swallow all the slack and the numeric columns bunch up on the right edge. */
  table-layout: fixed;
  /* Tabular figures keep lap-time digits aligned column-to-column even when
     the run-time font isn't naturally monospaced. */
  font-feature-settings: "tnum" 1;
}

.timing-table thead th {
  background: #0a0a0a;
  border-bottom: 1px solid #222;
  padding: 0.7rem 0.9rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #777;
}

.timing-table tbody td {
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid #141414;
  color: #fff;
  vertical-align: middle;
}

.timing-table tbody tr:last-child td {
  border-bottom: none;
}

.timing-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

/* Live row: subtle red wash + glowing left edge. Compositing on td (not tr)
   so hover still works on top. */
.timing-table tbody tr.is-live td {
  background: linear-gradient(
    90deg,
    rgba(255, 51, 51, 0.14) 0%,
    rgba(255, 51, 51, 0.04) 35%,
    transparent 70%
  );
  box-shadow: inset 3px 0 0 #ff3333;
}

.timing-table tbody tr.is-live:hover td {
  background: linear-gradient(
    90deg,
    rgba(255, 51, 51, 0.2) 0%,
    rgba(255, 51, 51, 0.06) 35%,
    transparent 70%
  );
}

/* Column sizing. Sums to less than 100% so `table-layout: fixed` distributes
   the remaining viewport width equally across all columns — giving the
   numeric columns visible breathing room instead of crowding them right. */
.timing-col-toggle {
  width: 3rem;
}
.timing-col-car {
  width: 6rem;
}
.timing-col-team {
  width: 14rem;
}
.timing-col-status {
  width: 5rem;
}
.timing-col-laps {
  width: 2.25rem;
}
.timing-col-time {
  width: 13rem;
}
.timing-col-sector {
  width: 8rem;
}
.timing-col-best {
  width: 11rem;
}
.timing-col-total {
  width: 9rem;
}
.timing-col-penalty {
  width: 4.5rem;
}
.timing-col-actions {
  width: 13rem;
}

/* Team cell may carry long uni names — ellipsis instead of forcing a column
   blow-out when `table-layout: fixed` would otherwise clip mid-word. */
.timing-col-team .team-name,
.timing-col-team .team-uni {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Car number — paddock-style white plate with bold black numerals. */
.car-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  height: 2.25rem;
  padding: 0 0.55rem;
  background: #fff;
  color: #000;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  border-radius: 3px;
}

.team-name {
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}

.team-uni {
  color: #888;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  margin-top: 0.15rem;
  text-transform: uppercase;
}

/* Status chips — coloured outline + tinted fill, broadcast palette. */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: 3px;
  border: 1px solid currentColor;
  line-height: 1;
}

.status-live {
  color: #ff3333;
  background: rgba(255, 51, 51, 0.1);
}
.status-completed {
  color: #00d084;
  background: rgba(0, 208, 132, 0.08);
}
.status-dnf {
  color: #ffb84d;
  background: rgba(255, 184, 77, 0.08);
}
.status-dq {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.06);
}

/* Pulsing dot to indicate "this is live, now". Lives inside .status-live so
   it inherits the red. */
.live-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
  animation: timing-pulse 1s ease-in-out infinite;
}

@keyframes timing-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

/* Lap time — the headline value on every row. Big, monospace, slightly
   condensed letter spacing so two-decimal-place numbers don't get loose. */
.lap-time {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.4rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.02em;
  line-height: 1;
}

.lap-time-live {
  color: #ff3333;
}

/* Session best / personal best — broadcast purple. */
.lap-time-best {
  color: #c569ff;
}

/* Penalty-adjusted Total — amber tint so the operator can see the figure isn't
   a pure on-track time. Same palette as the DNF chip for visual consistency. */
.lap-time-penalty {
  color: #ffb84d;
}

.lap-time-small {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 500;
  color: #e5e5e3;
  letter-spacing: -0.01em;
}

.lap-label {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 600;
  color: #888;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.laps-count {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
}

.sector-time {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  color: #c8c8c6;
  letter-spacing: -0.01em;
}

/* Per-row action buttons — kept small but high-contrast so they're usable
   from across a paddock garage at a glance. */
.timing-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  height: 2rem;
  padding: 0 0.6rem;
  background: rgba(255, 255, 255, 0.05);
  color: #e5e5e3;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.timing-action:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: #444;
  color: #fff;
}

.timing-action-danger:hover {
  background: rgba(255, 51, 51, 0.15);
  border-color: #ff3333;
  color: #ff5555;
}

.timing-action-finish:hover {
  background: rgba(0, 208, 132, 0.15);
  border-color: #00d084;
  color: #00d084;
}

/* Penalty counter — a tiny [−] N [+] cluster with an optional `+Xs` cost annotation
   that appears as soon as the count is non-zero. Buttons share the `.timing-action`
   skeleton via styling here so they look like the other row-level controls. */
.penalty-counter {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* The two step buttons stack vertically next to the count. Sharing edges (top
   button rounds the top, bottom button rounds the bottom) so the pair reads as
   a single spinner widget rather than two loose buttons. */
.penalty-steps {
  display: inline-flex;
  flex-direction: column;
  /* negative margin between buttons collapses to a single shared border line */
}

.penalty-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 0.95rem;
  padding: 0;
  background: rgba(255, 255, 255, 0.05);
  color: #e5e5e3;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  border: 1px solid #2a2a2a;
  border-radius: 0;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.penalty-step-up {
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
}

.penalty-step-down {
  border-top-width: 0;
  border-bottom-left-radius: 3px;
  border-bottom-right-radius: 3px;
}

.penalty-step:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: #444;
  color: #fff;
  /* keep this button's border on top of the sibling's when the merged edge gets
     highlighted, otherwise hover looks asymmetric */
  position: relative;
  z-index: 1;
}

.penalty-step:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.penalty-count {
  display: inline-block;
  min-width: 1.25rem;
  text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
}

/* Penalty-icon header — slightly dimmed and bigger than text headers so the icon
   reads as the column identity. Includes the inline traffic-cone SVG so it scales
   the same as the sibling FA `<i>` icons. */
.timing-col-penalty {
  text-align: center;
}
.timing-table thead th.timing-col-penalty i,
.timing-table thead th.timing-col-penalty .penalty-icon {
  color: #999;
  font-size: 0.9rem;
}
.penalty-icon {
  display: inline-block;
  /* Our SVG fills its viewBox edge-to-edge, while the FA icons next to it carry
     ~15% built-in padding. Sizing at 0.75em here matches the visual weight of
     `fa-route` rendered at the same font-size. */
  height: 1em;
  width: 1em;
  vertical-align: -0.05em;
}

/* Expand chevron */
.timing-expand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  background: transparent;
  border: none;
  color: #666;
  cursor: pointer;
  transition: color 0.15s;
}

.timing-expand:hover {
  color: #fff;
}

.timing-expand .expand-icon {
  transition: transform 0.2s ease;
}

/* History sub-row — inset and slightly dimmed so it reads as "drill-down" */
.timing-history > td {
  padding: 0 !important;
  background: #060606;
  border-bottom: 1px solid #141414;
}

.timing-history-inner {
  padding: 0.85rem 1rem 1.1rem 3rem;
}

.timing-history-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #666;
}

.timing-history-total {
  display: inline-flex;
  align-items: baseline;
  gap: 0.6rem;
}

.timing-history-table {
  width: 100%;
  border-collapse: collapse;
  font-feature-settings: "tnum" 1;
}

.timing-history-table th {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #555;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid #1a1a1a;
}

.timing-history-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid #101010;
}

.timing-history-table tr:last-child td {
  border-bottom: none;
}

