/* ---------------------------------------------------------------------------
   Shared component layer. Every tool builds from these; nothing here knows
   anything about the Race Split Planner specifically.
   --------------------------------------------------------------------------- */

/* --- Panels & sections ---------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.panel__body { padding: var(--s-6); }
.panel--flush .panel__body { padding: 0; }

.section { margin-top: var(--s-7); }
.section:first-child { margin-top: 0; }
.section__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s-4); flex-wrap: wrap;
  padding-bottom: var(--s-3); margin-bottom: var(--s-4);
  border-bottom: 2px solid var(--ink);
}
.section__title { font-size: var(--text-lg); letter-spacing: -0.015em; }
.section__note { font-size: var(--text-sm); color: var(--muted); }
.section__actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

.field-set { border: 0; margin: 0; padding: 0; }
.field-set + .field-set { margin-top: var(--s-6); padding-top: var(--s-6); border-top: 1px solid var(--line-2); }
.field-set__legend {
  float: left; width: 100%;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  padding: 0; margin-bottom: var(--s-4);
}
.field-set__legend + * { clear: both; }

/* --- Forms ---------------------------------------------------------------- */
.field + .field { margin-top: var(--s-4); }
.field__label { display: block; margin-bottom: var(--s-2); font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
.field__hint { margin-top: var(--s-2); font-size: var(--text-sm); color: var(--muted); }

.input, .select {
  width: 100%; padding: 9px 11px;
  font-family: var(--font-sans); font-size: var(--text-base); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-ctl); border-radius: var(--radius);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input:hover, .select:hover { border-color: var(--ink-2); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.input.num { font-family: var(--font-mono); }

.select {
  appearance: none;
  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 1.5 6 6.5 11 1.5' fill='none' stroke='%2368727C' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  padding-right: 32px; cursor: pointer;
}

/* Duration input: three fields that read as a single value. */
.duration { max-width: 340px; display: flex; align-items: stretch; border: 1px solid var(--line-ctl); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.duration:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.duration__part { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.duration__part + .duration__part { border-left: 1px solid var(--line-ctl); }
.duration__input {
  width: 100%; border: 0; background: none; text-align: center;
  padding: 10px var(--s-2) 2px;
  font: 600 var(--text-xl)/1.1 var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--ink); -moz-appearance: textfield;
}
.duration__input:focus { outline: none; }
.duration__input::-webkit-outer-spin-button,
.duration__input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.duration__unit {
  text-align: center; padding-bottom: var(--s-2);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted);
}

/* File input: a restrained drop target, not a marketing panel. */
.file-input { position: relative; }
.file-input input[type="file"] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.file-input__face {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4); border: 1px dashed var(--line-ctl); border-radius: var(--radius);
  background: var(--surface-2); color: var(--muted); font-size: var(--text-sm);
  transition: border-color 120ms ease, background-color 120ms ease;
}
.file-input:hover .file-input__face { border-color: var(--accent-line); background: var(--accent-tint); }
.file-input input[type="file"]:focus-visible + .file-input__face { outline: var(--focus); outline-offset: 2px; }
.file-input__icon { flex: none; color: var(--accent); }
.file-input__text strong { display: block; color: var(--ink); font-weight: 600; font-size: var(--text-base); }
.file-input[data-has-file="true"] .file-input__face { border-style: solid; border-color: var(--accent-line); background: var(--accent-tint); }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 9px 16px; min-height: 38px;
  font-family: var(--font-sans); font-size: var(--text-base); font-weight: 600;
  border: 1px solid transparent; border-radius: var(--radius);
  cursor: pointer; white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:disabled { cursor: not-allowed; opacity: 0.5; }

.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover:not(:disabled) { background: #000; }

.btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--line-ctl); }
.btn--secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--ink-2); }

.btn--quiet { background: none; color: var(--muted); padding-inline: var(--s-2); }
.btn--quiet:hover:not(:disabled) { color: var(--ink); background: var(--surface-2); }

.btn--sm { min-height: 30px; padding: 5px 11px; font-size: var(--text-sm); }
.btn--block { width: 100%; }

/* --- Segmented control ---------------------------------------------------- */
.segmented { display: inline-flex; padding: 2px; background: var(--surface-2); border: 1px solid var(--line-ctl); border-radius: var(--radius); }
.segmented__btn {
  padding: 5px 12px; min-height: 28px;
  font: 500 var(--text-sm)/1 var(--font-sans); color: var(--muted);
  background: none; border: 0; border-radius: var(--radius-sm); cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
.segmented__btn:hover { color: var(--ink); }
.segmented__btn[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); font-weight: 600;
  box-shadow: 0 0 0 1px var(--line);
}

/* --- Metrics: the primary readout ----------------------------------------- */
.metrics {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden;
  background: var(--line-2); gap: 1px;
}
.metric { background: var(--surface); padding: var(--s-4) var(--s-5); min-width: 0; }
.metric__label {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--muted); margin-bottom: var(--s-2);
  display: flex; align-items: center; gap: var(--s-1);
}
.metric__value {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.02em;
  line-height: 1.1; color: var(--ink); overflow-wrap: anywhere;
}
.metric__unit { font-size: var(--text-sm); font-weight: 500; color: var(--muted); margin-left: 2px; letter-spacing: 0; }
.metric__sub { margin-top: var(--s-2); font-size: var(--text-sm); color: var(--muted); }
.metric--primary { background: var(--ink); }
.metric--primary .metric__label { color: #94A3AE; }
.metric--primary .metric__value { color: #fff; }
.metric--primary .metric__unit, .metric--primary .metric__sub { color: #A9B4BD; }
.metric--sm .metric__value { font-size: var(--text-xl); }

.metric__note { border: 0; background: none; padding: 0; cursor: help; color: var(--faint); line-height: 0; }

/* --- Data table ----------------------------------------------------------- */
.table-scroll { overflow: auto; max-height: 70vh; border-radius: var(--radius-lg); border: 1px solid var(--line); background: var(--surface); }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-base); }
.data-table th, .data-table td { padding: 9px var(--s-4); text-align: left; white-space: nowrap; }
.data-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); border-bottom: 2px solid var(--ink-2);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-2);
}
.data-table tbody td { border-bottom: 1px solid var(--line-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table .cell-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.data-table .cell-key { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--muted); width: 1%; }
.data-table .cell-strong { font-weight: 600; color: var(--ink); }
.data-table tr[data-included="false"] td:not(.cell-check) { color: var(--faint); }
.data-table .cell-check { width: 1%; text-align: center; }
.data-table .th-short { display: none; }
.data-table .th-check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font: inherit; text-transform: none; letter-spacing: 0.08em; }
.val-up { color: var(--climb); }
.val-down { color: var(--descent); }

input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.table-foot {
  display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5);
  padding-top: var(--s-3); font-size: var(--text-sm); color: var(--muted);
}

/* --- States --------------------------------------------------------------- */
.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: var(--s-9) var(--s-6); min-height: 260px;
  border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface);
}
.state__icon { color: var(--faint); margin-bottom: var(--s-4); }
.state__title { font-size: var(--text-md); font-weight: 600; }
.state__body { margin-top: var(--s-2); font-size: var(--text-sm); color: var(--muted); max-width: 40ch; }

.state--error { border-color: #E9C9C6; background: var(--danger-tint); text-align: left;
  align-items: flex-start; justify-content: flex-start;
  min-height: 0; padding: var(--s-4) var(--s-5); flex-direction: row; gap: var(--s-3); }
.state--error .state__body { max-width: 60ch; }
.state__hint { margin: var(--s-2) 0 0; font-family: var(--font-mono); font-size: var(--text-xs); color: #A0625D; }
.state--error .state__icon { color: var(--danger); margin: 2px 0 0; }
.state--error .state__title { color: var(--danger); }
.state--error .state__body { color: #7C3A35; }

.skeleton { background: var(--line-2); border-radius: var(--radius-sm); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.skeleton-stack { display: grid; gap: var(--s-3); }

.spinner {
  width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin 620ms linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Tool directory rows -------------------------------------------------- */
.tool-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.tool-list > li + li { border-top: 1px solid var(--line-2); }

.tool-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--s-4);
  padding: var(--s-5); color: inherit; transition: background-color 120ms ease; }
.tool-row:hover { background: var(--surface-2); text-decoration: none; }
.tool-row:hover .tool-row__name { color: var(--accent); }
.tool-row__mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 1px solid var(--line); border-radius: var(--radius); color: var(--accent); background: var(--surface);
}
.tool-row__name { display: block; font-size: var(--text-md); font-weight: 600; letter-spacing: -0.012em; transition: color 120ms ease; }
.tool-row__tagline { display: block; margin-top: 3px; font-size: var(--text-sm); color: var(--muted); }
.tool-row__meta { display: flex; align-items: center; gap: var(--s-4); font-size: var(--text-sm); color: var(--muted); }
.tool-row__input { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: 0.02em; }
.tool-row__chev { color: var(--faint); flex: none; }

.tool-row--pending { padding: var(--s-5); display: flex; align-items: center; gap: var(--s-4); background: var(--surface-2); }
.tool-row--pending .tool-row__mark { border-style: dashed; color: var(--faint); background: none; }
.tool-row--pending .tool-row__name { display: block; color: var(--muted); font-weight: 500; }

/* --- Misc ----------------------------------------------------------------- */
.tag {
  display: inline-flex; align-items: center; padding: 2px 7px;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.04em;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 3px;
}
.tag--live { color: var(--accent); background: var(--accent-tint); border-color: var(--accent-line); }

.disclosure { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.disclosure > summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); cursor: pointer; list-style: none;
  font-size: var(--text-md); font-weight: 600;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after {
  content: ""; width: 9px; height: 9px; flex: none;
  border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px); transition: transform 140ms ease;
}
.disclosure[open] > summary::after { transform: rotate(-135deg) translate(-3px, -3px); }
.disclosure__body { padding: 0 var(--s-5) var(--s-5); border-top: 1px solid var(--line-2); padding-top: var(--s-5); }

@media (max-width: 720px) {
  .panel__body { padding: var(--s-4); }
  .metrics { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .metric { padding: var(--s-3) var(--s-4); }
  .metric__value { font-size: var(--text-xl); }
  .data-table { font-size: var(--text-sm); }
  .data-table th, .data-table td { padding: 10px 7px; }
  .table-scroll { max-height: none; }
  /* Keep the whole row -- including the include toggle -- reachable without
     horizontal scrolling on a phone. */
  .data-table .th-long { display: none; }
  .data-table .th-short { display: inline; }
  .data-table .th-check .th-check__text { display: none; }
  /* The analytical columns may scroll sideways, but the include toggle is a
     control, not data -- it stays pinned and reachable. */
  .data-table .cell-check { position: sticky; right: 0; z-index: 1; background: var(--surface); }
  .data-table thead .cell-check { z-index: 3; }
  .data-table tbody tr:hover .cell-check { background: var(--surface-2); }
  .data-table .cell-check::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px;
    transform: translateX(-100%);
    background: linear-gradient(to right, rgba(18,23,28,0), rgba(18,23,28,0.07));
  }
  .tool-row { grid-template-columns: auto 1fr; gap: var(--s-3); padding: var(--s-4); }
  .tool-row__meta { display: none; }
  .tool-row__chev { display: none; }
  .btn { min-height: 42px; }
  .segmented__btn { min-height: 34px; padding-inline: var(--s-3); }
}

/* Fixed four-across metric grid for a tool's primary readout. */
.metrics--quad { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .metrics--quad { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .metrics--quad { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Radio group rendered as a segmented control. Native radios keep arrow-key
   navigation and screen-reader semantics; only the presentation changes. */
.seg-radio { max-width: 380px; display: flex; padding: 2px; background: var(--surface-2); border: 1px solid var(--line-ctl); border-radius: var(--radius); }
.seg-radio__option { position: relative; flex: 1; display: flex; min-width: 0; }
.seg-radio input { position: absolute; opacity: 0; pointer-events: none; }
.seg-radio__face {
  flex: 1; text-align: center; padding: 7px var(--s-2); min-height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-sm); font-weight: 500; color: var(--muted);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
.seg-radio__face:hover { color: var(--ink); }
.seg-radio input:checked + .seg-radio__face {
  background: var(--surface); color: var(--ink); font-weight: 600;
  box-shadow: 0 0 0 1px var(--line);
}
.seg-radio input:focus-visible + .seg-radio__face { outline: var(--focus); outline-offset: 1px; }


/* --- Compact utility forms ------------------------------------------------ */
/* A value paired with its unit selector, sized so the number stays readable. */
.input-row { display: flex; gap: var(--s-2); }
.input-row .input { flex: 1 1 40%; min-width: 0; }
.input-row .select { flex: 1 1 60%; min-width: 0; }

/* A small self-contained calculator: fields across, action at the end. */
.util-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s-4); align-items: end; }
.util-grid .field + .field { margin-top: 0; }
.util-grid__action { display: flex; align-items: flex-end; }

.util-result {
  display: flex; align-items: baseline; gap: var(--s-3); flex-wrap: wrap;
  margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--line-2);
}
.util-result__label {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--muted);
}
.util-result__value { font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }

@media (max-width: 720px) {
  .util-grid { grid-template-columns: 1fr; gap: var(--s-4); }
}
