/* =========================================================
   tools-base.css — Shared design tokens & base components
   for standalone Donkey Analytics tool pages (sail_tool,
   track_editor, polar_tuner, …).  Aligns with cockpit.css.
   ========================================================= */

/* ========== Shared spacing / radius tokens ========== */
:root {
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;
  --radius-xs: 3px; --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px;
  --transition: 160ms cubic-bezier(.4,0,.2,1);
  --header-h: 52px;
}

/* ========== DARK (default) ========== */
:root, body {
  --bg:         #0b0d10;
  --bg-elev:    #12161b;
  --bg-panel:   #161b22;
  --bg-hover:   #1c222b;
  --bg-active:  #232a35;
  --line:       #222932;
  --line-strong:#2d3641;
  --ink:        #e7edf3;
  --ink-mute:   #8a95a3;
  /* Matches cockpit.css: 4.8:1 or better on every panel (#508). */
  --ink-dim:    #7d8896;
  --accent:     #29a98b;
  /* White on the green (or on --info) is under 3:1; near-black is 6.6:1. */
  --accent-ink: #0b0d10;
  --accent-soft:rgba(41,169,139,0.14);
  --info:       #56b6e2;
  --info-soft:  rgba(86,182,226,0.14);
  --pos:        #7ed3a4;
  --neg:        #ff6b7a;
  --warn:       #e09640;
  /* A chart's hover labels: a step above the panel (see cockpit.css). */
  --chart-tip:  #1c222b;
  --shadow:     0 1px 0 rgba(255,255,255,0.02) inset, 0 10px 30px rgba(0,0,0,0.5);

  --font-ui:  "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-num: "JetBrains Mono", "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  color-scheme: dark;
}

/* ========== LIGHT ========== */
body[data-mode="light"] {
  --bg:         #f2efe9;
  --bg-elev:    #fbf9f4;
  --bg-panel:   #ffffff;
  --bg-hover:   #ebe7de;
  --bg-active:  #ddd7c8;
  --line:       #ddd6c7;
  --line-strong:#a89f8a;
  --ink:        #16171a;
  --ink-mute:   #55606e;
  --ink-dim:    #606976;
  /* Dark enough for 4.5:1 on their own tints as well (see cockpit.css). */
  --accent:     #166951;
  --accent-ink: #ffffff;
  --accent-soft:rgba(22,105,81,0.14);
  --info:       #1c6486;
  --info-soft:  rgba(28,100,134,0.14);
  --pos:        #276b42;
  --neg:        #b12838;
  --warn:       #7e5617;
  --chart-tip:  #ffffff;
  --shadow:     0 1px 0 rgba(255,255,255,0.6) inset, 0 8px 24px rgba(22,23,26,0.06);
  color-scheme: light;
}

/* ========== Base resets ========== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent-soft); }

/* ========== Tab bar ========== */
nav.tabs {
  display: flex; gap: 2px;
  padding: 0 var(--space-4);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.tab {
  background: transparent; color: var(--ink-mute); border: none;
  padding: 12px 16px; cursor: pointer; font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: var(--transition);
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ========== Buttons ========== */
button, .btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--bg-panel); color: var(--ink);
  border: 1px solid var(--line-strong);
  font-weight: 500; font-size: 13px;
  cursor: pointer; transition: var(--transition);
  white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { background: var(--bg-hover); }
button:disabled, .btn:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary, .btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
button.primary:hover:not(:disabled), .btn.primary:hover { filter: brightness(1.07); }
button.ghost, .btn.ghost {
  background: transparent; border-color: transparent; color: var(--ink-mute);
}
button.ghost:hover, .btn.ghost:hover { background: var(--bg-hover); color: var(--ink); }
button.danger, .btn.danger {
  background: transparent; color: var(--neg); border-color: var(--neg);
}
button.danger:hover:not(:disabled), .btn.danger:hover {
  background: color-mix(in oklab, var(--neg) 10%, transparent);
}
button.secondary, .btn.secondary {
  background: var(--info); color: var(--accent-ink); border-color: var(--info);
}
button.secondary:hover:not(:disabled), .btn.secondary:hover { filter: brightness(1.07); }
button.close-btn, .btn.close-btn {
  background: transparent; color: var(--neg); border: 1px solid var(--neg);
  padding: 6px 14px; font-weight: 600;
}
button.close-btn:hover, .btn.close-btn:hover {
  background: color-mix(in oklab, var(--neg) 10%, transparent);
}
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.lg { padding: 12px 20px; font-size: 14px; }
.btn.block { display: flex; width: 100%; justify-content: center; }

/* ========== Inputs ========== */
input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px; color: var(--ink);
  transition: var(--transition); width: 100%;
  outline: none;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
  border-color: var(--accent); background: var(--bg-elev);
}
input[type="color"] {
  width: 36px; height: 32px; padding: 2px 3px;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer;
}

/* ========== Labels ========== */
label {
  display: block; font-size: 11px; color: var(--ink-dim);
  margin: 8px 0 4px; text-transform: uppercase; letter-spacing: 0.1em;
  font-weight: 600;
}

/* ========== Section / pane headings ========== */
h1 { font-size: 18px; margin: 0 0 12px; font-weight: 600; letter-spacing: -0.01em; }
h2 {
  font-size: 10px; text-transform: uppercase; color: var(--ink-dim);
  margin: 18px 0 8px; letter-spacing: 0.14em; font-weight: 600;
}
h3 { font-size: 13px; font-weight: 600; color: var(--ink-mute); margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.05em; }

/* ========== Toolbar ========== */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 14px;
}
.toolbar.grid { gap: 10px 16px; }
.toolbar label {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink-mute); font-size: 12px;
  text-transform: none; letter-spacing: normal;
  margin: 0; font-weight: 400;
}
.toolbar input[type="number"] { width: 70px; }

/* ========== Panels (tab content areas) ========== */
.panel { display: none; padding: 18px var(--space-5); }
.panel.active { display: block; }
.pane { margin-bottom: var(--space-5); }
.pane h3 { font-size: 12px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.08em; }

/* ========== Split layout ========== */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

/* ========== Status text ========== */
.status { font-size: 12px; }
.muted  { color: var(--ink-mute); }
.dim    { color: var(--ink-dim); }

/* ========== Alert ========== */
.alert {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 12px; margin: 8px 0; border: 1px solid;
}
.alert.info, .alert-info {
  background: var(--info-soft); color: var(--info);
  border-color: color-mix(in oklab, var(--info) 30%, transparent);
}
.alert.success, .alert-success {
  background: color-mix(in oklab, var(--pos) 14%, transparent); color: var(--pos);
  border-color: color-mix(in oklab, var(--pos) 30%, transparent);
}
.alert.error, .alert-error {
  background: color-mix(in oklab, var(--neg) 14%, transparent); color: var(--neg);
  border-color: color-mix(in oklab, var(--neg) 30%, transparent);
}
.alert.warning, .alert-warning {
  background: color-mix(in oklab, var(--warn) 14%, transparent); color: var(--warn);
  border-color: color-mix(in oklab, var(--warn) 30%, transparent);
}
/* An error stays until dismissed (#518): its text and a close button. */
.alert-dismissible { display: flex; align-items: flex-start; gap: 8px; }
.alert-dismissible .alert-text { flex: 1; min-width: 0; }
.alert-dismiss {
  flex: none; margin: -3px -6px -3px 0; padding: 0 6px;
  border: 0; background: transparent; color: inherit; opacity: .7;
  font: inherit; font-size: 16px; line-height: 1.2; cursor: pointer;
  border-radius: var(--radius-sm);
}
.alert-dismiss:hover { opacity: 1; }
.alert-dismiss:focus-visible { opacity: 1; outline: 2px solid currentColor; outline-offset: 1px; }

/* ========== Toast ========== */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel); color: var(--ink);
  padding: 10px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 13px; opacity: 0; pointer-events: none;
  transition: all 0.25s ease; z-index: 1000; max-width: 480px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error   { border-color: var(--neg); color: var(--neg); }
.toast.success { border-color: var(--pos); color: var(--pos); }
/* An error toast stays until its close button is pressed (#518). */
.toast.error { display: flex; align-items: flex-start; gap: 10px; }
.toast.show.error { pointer-events: auto; }
.toast-dismiss {
  flex: none; margin: -2px -8px -2px 0; padding: 0 6px;
  border: 0; background: transparent; color: inherit; opacity: .7;
  font: inherit; font-size: 16px; line-height: 1.2; cursor: pointer;
  border-radius: var(--radius-sm);
}
.toast-dismiss:hover { opacity: 1; }
.toast-dismiss:focus-visible { opacity: 1; outline: 2px solid currentColor; outline-offset: 1px; }

/* What a map says with no Leaflet, or no tiles (#516). */
.map-library-missing {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; padding: 40px; text-align: center;
  color: var(--ink-mute); font-size: 14px; background: var(--bg);
}
.map-offline-note {
  background: var(--bg-panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 6px 10px; font-size: 12px;
  line-height: 1.4; max-width: 280px; box-shadow: var(--shadow);
}

/* ========== Modal ========== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-panel); border: 1px solid var(--line);
  padding: 18px 22px; border-radius: var(--radius-md);
  min-width: 320px; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; text-transform: none; letter-spacing: normal; color: var(--ink); }
.modal-card label { display: block; margin: 10px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ========== Tables (polar / data) ========== */
.scroll-x { overflow-x: auto; }
table.polar, table.data {
  border-collapse: collapse; font-size: 12px; width: max-content;
}
table.polar th, table.polar td, table.data th, table.data td {
  padding: 5px 9px; border: 1px solid var(--line); text-align: right;
  white-space: nowrap;
}
table.polar th { background: var(--bg-panel); position: sticky; top: 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); }
table.polar td.tws-col { background: var(--bg-elev); font-weight: 600; color: var(--accent); font-family: var(--font-num); }
table.polar td.cell { cursor: pointer; }
table.polar td.cell:hover { background: var(--bg-hover); }
table.polar td.empty { color: var(--ink-dim); font-style: italic; }
table.data th { background: var(--bg-panel); position: sticky; top: 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); }
table.data tr:nth-child(even) td { background: var(--bg-hover); }
table.data tr:nth-child(odd)  td { background: var(--bg-panel); }
.ratio-good { color: var(--pos); font-weight: 600; }
.ratio-bad  { color: var(--neg); font-weight: 600; }
.ratio-neutral { color: var(--ink); }

/* ========== Suggestion / diff kind colouring ========== */
.kind-added   { color: var(--pos); }
.kind-changed { color: var(--warn); }
.kind-removed { color: var(--neg); }

/* ========== Checkbox label helper ========== */
.chk { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--ink-mute); font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: normal; }

/* ========== Kbd ========== */
kbd, .kbd {
  font-family: var(--font-num); font-size: 11px;
  padding: 1px 6px; border-radius: 4px;
  background: var(--bg-hover); color: var(--ink-mute);
  border: 1px solid var(--line); line-height: 1.6;
}

/* ========== Hint text ========== */
.hint { font-size: 11px; color: var(--ink-mute); margin-top: 6px; line-height: 1.5; }
.hint kbd { background: var(--bg-panel); padding: 1px 5px; border-radius: 3px; border: 1px solid var(--line); font-size: 10px; }

/* ========== Scrollbars ========== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }


/* ========== Accessibility (#464) ========== */
/* Out of sight but still read out, and still clickable by script. */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}
/* Every control shows where the keyboard is; inputs keep their border. */
:where(a, button, summary, [tabindex], [role="button"], [role="tab"]):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
/* A table row's name as a button: the keyboard's stop for the row. */
.row-link {
  display: inline; margin: 0; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.row-link:hover:not(:disabled) { background: none; text-decoration: underline; text-underline-offset: 2px; }
/* A label dressed as a button round a visually hidden file input: the
   input takes the focus, the label shows it. */
label.btn:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Chart hover labels: ink on --chart-tip, not Plotly's series-coloured
   boxes and text, which fall far under 4.5:1. The reasons are spelt out
   in cockpit.css; these rules are kept in step with it. */
.js-plotly-plot .hoverlayer .hovertext path,
.js-plotly-plot .hoverlayer .hovertext rect,
.js-plotly-plot .hoverlayer .axistext path,
.js-plotly-plot .hoverlayer .legend rect.bg {
  fill: var(--chart-tip) !important;
  fill-opacity: 1 !important;
}
.js-plotly-plot .hoverlayer .axistext path,
.js-plotly-plot .hoverlayer .legend rect.bg { stroke: var(--line-strong) !important; }
.js-plotly-plot .hoverlayer text { fill: var(--ink) !important; }
.js-plotly-plot .hoverlayer .hovertext text.name { fill: var(--ink-mute) !important; }
/* Leaflet's attribution on the Course Builder and Track Editor maps: its
   links were told apart by colour alone, and its #0078a8 on an 80% white
   box over the dark theme's panel was about 3.3:1. Opaque white, with
   underlined links 7.5:1 on it. */
.leaflet-container .leaflet-control-attribution { background: #ffffff; color: #333333; }
.leaflet-container .leaflet-control-attribution a { color: #005b80; text-decoration: underline; }

/* ========== Shared tool header (templates/_tool_header.html) ========== */
[hidden] { display: none !important; }
.tool-topbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-4); height: var(--header-h); min-height: var(--header-h);
  background: var(--bg-elev); border-bottom: 1px solid var(--line);
  flex-shrink: 0; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
}
.tool-topbar h1 { font-size: 15px; margin: 0; font-weight: 600; white-space: nowrap; letter-spacing: -0.01em; }
.tool-topbar .spacer { flex: 1 1 auto; }
.tool-topbar select { width: auto; max-width: 320px; }
.tool-topbar .status { white-space: nowrap; }
.tool-brand {
  display: flex; align-items: center; height: 100%; flex-shrink: 0;
  padding-right: var(--space-3); border-right: 1px solid var(--line);
}
.tool-brand .brand-glyph { width: 24px; height: 24px; border-radius: 6px; object-fit: cover; display: block; }
.tool-context {
  font-size: 12px; color: var(--ink-mute); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 320px;
  padding-left: var(--space-2); border-left: 1px solid var(--line);
}
.tool-note {
  font-size: 9px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 3px; color: var(--warn);
  border: 1px solid color-mix(in oklab, var(--warn) 50%, transparent);
}
.tool-back { white-space: nowrap; flex-shrink: 0; }
.theme-toggle { flex-shrink: 0; }
.theme-toggle .theme-icon { display: block; }
body[data-mode="dark"] .theme-toggle .theme-icon-sun { display: none; }
body[data-mode="light"] .theme-toggle .theme-icon-moon { display: none; }

/* A tab that needs something loaded first stays visible but inert. */
.tab[disabled] { color: var(--ink-dim); cursor: not-allowed; opacity: 1; background: transparent; }

/* Secondary controls fold away under a one-line summary. */
details.fold {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0 10px; margin-top: 10px; background: var(--bg);
}
details.fold > summary {
  cursor: pointer; font-size: 12px; color: var(--ink-mute); padding: 8px 0;
  list-style: none; user-select: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: '›'; display: inline-block; margin-right: 6px; transition: transform 120ms; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > .fold-body { padding: 0 0 10px; }

/* Filter and search boxes are type="search" so browsers and password managers
   do not mistake them for a username field and autofill the signed-in address.
   Strip the native decorations that type brings so they still look like the
   rest of the app. */
input[type="search"] { -webkit-appearance: none; appearance: none; }
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration { -webkit-appearance: none; appearance: none; display: none; }

/* The links to the privacy notice, terms and cookie notice, and the
   company's details, at the foot of the sign-in, billing, account and
   legal pages (templates/_legal_footer.html). */
.legal-footer {
  margin-top: var(--space-6); padding-top: var(--space-4);
  border-top: 1px solid var(--line);
  font-size: 12px; line-height: 1.5; color: var(--ink-dim); text-align: center;
}
.legal-footer nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 14px; }
.legal-footer a { color: var(--ink-mute); text-decoration: none; }
.legal-footer a:hover { color: var(--ink); text-decoration: underline; }
.legal-footer p { margin: 6px 0 0; color: var(--ink-dim); font-size: 11px; }
.legal-footer.page-foot {
  max-width: 760px; margin: 0 auto; padding: var(--space-4) var(--space-4) var(--space-8);
}

/* The price facts and the two boxes on the billing page's confirmation
   step (templates/_contract_terms.html). */
.contract {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; margin: 0 0 var(--space-3); font-size: 13px; line-height: 1.5;
}
.contract-facts { margin: 0 0 10px; padding-left: 1.1em; color: var(--ink-mute); }
.contract-facts li { margin-bottom: 3px; }
.contract-facts strong { color: var(--ink); font-weight: 600; }
.contract a { color: var(--accent); }
.contract-check {
  display: flex; gap: 10px; align-items: flex-start; margin: 8px 0 0;
  color: var(--ink); cursor: pointer;
  /* A sentence to read, not a field caption: none of `label`'s capitals. */
  font-size: 13px; font-weight: 400; text-transform: none; letter-spacing: normal;
}
.contract-check input { margin: 2px 0 0; width: 16px; height: 16px; flex: none; accent-color: var(--accent); }
