/* ── Material Design 3 base for LiveCore (replaces Bootstrap 3) ───────────────
   Tokens: SchemeTonalSpot from seed #337ab7 (the old Bootstrap primary), generated with
   @material/material-color-utilities 0.3.0, contrast level 0. Two custom colours, harmonised to
   the seed: "success" (#5cb85c) for the green "today" buttons and "selected" (#f0ad4e) for a
   driver the viewer has marked. Selected stays yellow so it is clearly distinct from the blue
   update flash, also for red-green colour-blind viewers. Every text/background pair below is at
   least 6.4:1 (WCAG AA is 4.5:1).

   The component rules keep the Bootstrap class names the views already use (btn, table,
   panel, alert, form-control, badge, …), so markup and Knockout bindings are unchanged. */

:root {
  color-scheme: light dark;

  --md-sys-color-primary: #33618d;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #d0e4ff;
  --md-sys-color-on-primary-container: #144974;
  --md-sys-color-secondary: #526070;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #d6e4f7;
  --md-sys-color-on-secondary-container: #3b4857;
  --md-sys-color-tertiary: #695779;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #f0dbff;
  --md-sys-color-on-tertiary-container: #514060;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #93000a;
  --md-sys-color-surface: #f8f9ff;
  --md-sys-color-on-surface: #191c20;
  --md-sys-color-surface-variant: #dee3eb;
  --md-sys-color-on-surface-variant: #42474e;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f2f3f9;
  --md-sys-color-surface-container: #eceef4;
  --md-sys-color-surface-container-high: #e6e8ee;
  --md-sys-color-surface-container-highest: #e0e2e8;
  --md-sys-color-outline: #73777f;
  --md-sys-color-outline-variant: #c2c7cf;
  --md-sys-color-inverse-surface: #2d3135;
  --md-sys-color-inverse-on-surface: #eff1f6;
  --md-sys-color-inverse-primary: #9ecafc;
  --md-sys-color-shadow: #000000;

  --md-custom-color-success: #006d43;
  --md-custom-color-on-success: #ffffff;
  --md-custom-color-success-container: #72fcb4;
  --md-custom-color-on-success-container: #002111;
  --md-custom-color-selected-container: #ffdf99;
  --md-custom-color-on-selected-container: #251a00;

  /* Type scale (M3 baseline). Roboto where installed (Android, ChromeOS), else the system UI font. */
  --md-ref-typeface: Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --md-sys-typescale-headline-medium: 400 28px/36px var(--md-ref-typeface);
  --md-sys-typescale-headline-small: 400 24px/32px var(--md-ref-typeface);
  --md-sys-typescale-title-large: 400 22px/28px var(--md-ref-typeface);
  --md-sys-typescale-title-medium: 500 16px/24px var(--md-ref-typeface);
  --md-sys-typescale-title-small: 500 14px/20px var(--md-ref-typeface);
  --md-sys-typescale-body-large: 400 16px/24px var(--md-ref-typeface);
  --md-sys-typescale-body-medium: 400 14px/20px var(--md-ref-typeface);
  --md-sys-typescale-label-large: 500 14px/20px var(--md-ref-typeface);
  --md-sys-typescale-label-medium: 500 12px/16px var(--md-ref-typeface);

  --md-sys-shape-corner-extra-small: 4px;
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-full: 9999px;

  --md-sys-state-hover-opacity: 0.08;
  --md-sys-state-pressed-opacity: 0.10;
}

/* Dark: the device setting, unless the viewer chose light on the page (theme.js sets
   data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --md-sys-color-primary: #9ecafc;
    --md-sys-color-on-primary: #003256;
    --md-sys-color-primary-container: #144974;
    --md-sys-color-on-primary-container: #d0e4ff;
    --md-sys-color-secondary: #bac8db;
    --md-sys-color-on-secondary: #243240;
    --md-sys-color-secondary-container: #3b4857;
    --md-sys-color-on-secondary-container: #d6e4f7;
    --md-sys-color-tertiary: #d5bee5;
    --md-sys-color-on-tertiary: #3a2a48;
    --md-sys-color-tertiary-container: #514060;
    --md-sys-color-on-tertiary-container: #f0dbff;
    --md-sys-color-error: #ffb4ab;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error-container: #ffdad6;
    --md-sys-color-surface: #101418;
    --md-sys-color-on-surface: #e0e2e8;
    --md-sys-color-surface-variant: #42474e;
    --md-sys-color-on-surface-variant: #c2c7cf;
    --md-sys-color-surface-container-lowest: #0b0e12;
    --md-sys-color-surface-container-low: #191c20;
    --md-sys-color-surface-container: #1d2024;
    --md-sys-color-surface-container-high: #272a2f;
    --md-sys-color-surface-container-highest: #32353a;
    --md-sys-color-outline: #8c9199;
    --md-sys-color-outline-variant: #42474e;
    --md-sys-color-inverse-surface: #e0e2e8;
    --md-sys-color-inverse-on-surface: #2d3135;
    --md-sys-color-inverse-primary: #33618d;

    --md-custom-color-success: #53df9a;
    --md-custom-color-on-success: #003921;
    --md-custom-color-success-container: #005232;
    --md-custom-color-on-success-container: #72fcb4;
    --md-custom-color-selected-container: #5a4300;
    --md-custom-color-on-selected-container: #ffdf99;
  }
}

/* Dark chosen on the page (or ?theme=dark). Same values as the block above: keep them in sync. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --md-sys-color-primary: #9ecafc;
  --md-sys-color-on-primary: #003256;
  --md-sys-color-primary-container: #144974;
  --md-sys-color-on-primary-container: #d0e4ff;
  --md-sys-color-secondary: #bac8db;
  --md-sys-color-on-secondary: #243240;
  --md-sys-color-secondary-container: #3b4857;
  --md-sys-color-on-secondary-container: #d6e4f7;
  --md-sys-color-tertiary: #d5bee5;
  --md-sys-color-on-tertiary: #3a2a48;
  --md-sys-color-tertiary-container: #514060;
  --md-sys-color-on-tertiary-container: #f0dbff;
  --md-sys-color-error: #ffb4ab;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #93000a;
  --md-sys-color-on-error-container: #ffdad6;
  --md-sys-color-surface: #101418;
  --md-sys-color-on-surface: #e0e2e8;
  --md-sys-color-surface-variant: #42474e;
  --md-sys-color-on-surface-variant: #c2c7cf;
  --md-sys-color-surface-container-lowest: #0b0e12;
  --md-sys-color-surface-container-low: #191c20;
  --md-sys-color-surface-container: #1d2024;
  --md-sys-color-surface-container-high: #272a2f;
  --md-sys-color-surface-container-highest: #32353a;
  --md-sys-color-outline: #8c9199;
  --md-sys-color-outline-variant: #42474e;
  --md-sys-color-inverse-surface: #e0e2e8;
  --md-sys-color-inverse-on-surface: #2d3135;
  --md-sys-color-inverse-primary: #33618d;

  --md-custom-color-success: #53df9a;
  --md-custom-color-on-success: #003921;
  --md-custom-color-success-container: #005232;
  --md-custom-color-on-success-container: #72fcb4;
  --md-custom-color-selected-container: #5a4300;
  --md-custom-color-on-selected-container: #ffdf99;
}

:root[data-theme="light"] { color-scheme: light; }

/* ── Base ──────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 16px 16px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-medium);
}

h1, h2, h3, h4 { margin: 16px 0 8px; color: var(--md-sys-color-on-surface); }
h1 { font: var(--md-sys-typescale-headline-medium); }
h2 { font: var(--md-sys-typescale-headline-small); }
h3 { font: var(--md-sys-typescale-title-large); }
h4 { font: var(--md-sys-typescale-title-medium); }

p, ul, ol, table, pre { margin: 0 0 12px; }
small, .small { font-size: 85%; }
strong, b { font-weight: 600; }

a { color: var(--md-sys-color-primary); text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

input[type=checkbox] {
  width: 18px;
  height: 18px;
  margin: 0;
  vertical-align: middle;
  accent-color: var(--md-sys-color-primary);
}

pre, code { font-family: ui-monospace, Consolas, "Roboto Mono", monospace; }

.text-muted { color: var(--md-sys-color-on-surface-variant); }
.text-muted a { color: inherit; }
.text-center { text-align: center; }

/* Inline SVG icons (Material Icons, Apache 2.0) */
.icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  vertical-align: middle;
  flex: none;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
/* btn-primary = filled, btn-success = filled in the custom success colour, btn-danger =
   filled error, btn-default = outlined. State layers follow M3: the label colour at 8 %
   (hover) / 10 % (pressed). */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 24px;
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-full);
  font: var(--md-sys-typescale-label-large);
  text-align: center;
  text-decoration: none;
  white-space: normal;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-primary);
  -webkit-tap-highlight-color: transparent;
}

.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 150ms linear;
  pointer-events: none;
}

.btn:hover::after { opacity: var(--md-sys-state-hover-opacity); }
.btn:active::after { opacity: var(--md-sys-state-pressed-opacity); }

.btn-primary { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.btn-success { background: var(--md-custom-color-success); color: var(--md-custom-color-on-success); }
.btn-danger  { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }
.btn-default {
  background: transparent;
  border-color: var(--md-sys-color-outline);
  color: var(--md-sys-color-primary);
}

.btn-lg { min-height: 48px; font: var(--md-sys-typescale-title-medium); }
.btn-sm { min-height: 32px; padding: 4px 12px; }

.btn-block { display: flex; width: 100%; }
.btn-block + .btn-block { margin-top: 8px; }

/* M3 disabled: on-surface at 12 % (container) and 38 % (label). Used for "Vald klubb" and the
   empty states on the front page, so they no longer look clickable. */
.btn.disabled, .btn[disabled] {
  cursor: default;
  pointer-events: none;
  border-color: transparent;
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
}
.btn-default.disabled, .btn-default[disabled] {
  background: transparent;
  border-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
}

/* Count next to a club or heading */
.badge {
  display: inline-block;
  min-width: 24px;
  padding: 2px 8px;
  border-radius: var(--md-sys-shape-corner-full);
  font: var(--md-sys-typescale-label-medium);
  text-align: center;
  vertical-align: middle;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.badge:empty { display: none; }

/* ── Tables ────────────────────────────────────────────────────────────────── */

.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.table > thead > tr > th,
.table > tbody > tr > td,
.table > tfoot > tr > td {
  padding: 8px;
  vertical-align: top;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* Zero specificity, so a class like .rightText still wins */
:where(.table) th { text-align: left; }

.table > thead > tr > th {
  font: var(--md-sys-typescale-title-small);
  color: var(--md-sys-color-on-surface-variant);
  vertical-align: bottom;
  border-top: 0;
  border-bottom: 1px solid var(--md-sys-color-outline);
}

/* Result and goal tables: dense (as before), so as many columns as possible fit on a phone.
   The real fix for the width is breakable lap times (R1). */
.table-condensed > thead > tr > th,
.table-condensed > tbody > tr > td { padding: 1px; }

.table-striped > tbody > tr:nth-of-type(odd) > td { background: var(--md-sys-color-surface-container-low); }

.table-hover > tbody > tr:hover > td {
  background-image: linear-gradient(
    color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent),
    color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent));
}

/* A driver the viewer has selected */
.table > tbody > tr.warning > td {
  background-color: var(--md-custom-color-selected-container);
  color: var(--md-custom-color-on-selected-container);
}

/* Column widths on the admin page */
td.col-xs-1 { width: 8.33%; }
td.col-xs-2 { width: 16.67%; }
td.col-xs-3 { width: 25%; }

/* ── Panel (outlined card) ─────────────────────────────────────────────────── */

.panel {
  margin: 0 0 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
}

.panel-heading {
  padding: 12px 16px;
  font: var(--md-sys-typescale-title-medium);
}

.panel-body { padding: 0 16px 16px; }

/* ── Alerts (M3 banner-like) ───────────────────────────────────────────────── */

.alert {
  margin: 0 0 12px;
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  font: var(--md-sys-typescale-body-medium);
}
.alert-warning { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
.alert-info { background: var(--md-sys-color-surface-container-highest); color: var(--md-sys-color-on-surface); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */

.form-inline { display: flex; flex-wrap: wrap; gap: 8px; }
.form-group { display: flex; flex-wrap: wrap; gap: 8px; }

/* Outlined text field (compact) */
.form-control {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-large);
}
.form-control:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}
.form-control::placeholder { color: var(--md-sys-color-on-surface-variant); }
select.form-control option { background: var(--md-sys-color-surface-container); color: var(--md-sys-color-on-surface); }
