/* vesc.tools — shared styles. Mobile-first, light/dark via tokens. */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #15181d;
  --muted: #5b6472;
  --accent: #0a7f5a;
  --accent-strong: #06654a;
  --accent-soft: #e3f4ee;
  --on-accent: #ffffff;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --info: #1d5fbf;
  --info-soft: #e7f0fd;
  --ok: #12805c;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --border: #2a313c;
    --text: #e8ebf0;
    --muted: #9aa4b2;
    --accent: #3ccf97;
    --accent-strong: #5fe0ad;
    --accent-soft: #10392b;
    --on-accent: #06281c;
    --warn: #f3c26b;
    --warn-soft: #3a2c0f;
    --danger: #ff8a7a;
    --danger-soft: #3d1714;
    --info: #8ab8ff;
    --info-soft: #14263f;
    --ok: #3ccf97;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0e1116;
  --surface: #161a21;
  --surface-2: #1d222b;
  --border: #2a313c;
  --text: #e8ebf0;
  --muted: #9aa4b2;
  --accent: #3ccf97;
  --accent-strong: #5fe0ad;
  --accent-soft: #10392b;
  --on-accent: #06281c;
  --warn: #f3c26b;
  --warn-soft: #3a2c0f;
  --danger: #ff8a7a;
  --danger-soft: #3d1714;
  --info: #8ab8ff;
  --info-soft: #14263f;
  --ok: #3ccf97;
  --shadow: none;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--sans);
  overflow-x: hidden;
}
img,
svg {
  max-width: 100%;
}
a {
  color: var(--accent);
  text-underline-offset: 2px;
}
a:hover {
  color: var(--accent-strong);
}
h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5em;
}
h1 {
  font-size: clamp(1.9rem, 5vw, 2.8rem);
  letter-spacing: -0.02em;
}
h2 {
  font-size: clamp(1.35rem, 3vw, 1.7rem);
  letter-spacing: -0.01em;
}
h3 {
  font-size: 1.1rem;
}
p {
  margin: 0 0 1em;
}
code,
kbd {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.05em 0.35em;
  overflow-wrap: anywhere;
}
.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.88rem;
}
.skip {
  position: absolute;
  left: -999px;
}
.skip:focus {
  left: 16px;
  top: 8px;
  background: var(--surface);
  padding: 6px 10px;
  z-index: 10;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- header / footer ---------- */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 60px;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}
.brand svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
}
.nav {
  display: flex;
  gap: 4px 16px;
  flex-wrap: wrap;
  margin-left: auto;
  font-size: 0.95rem;
}
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 4px 0;
}
.nav a:hover,
.nav a[aria-current='page'] {
  color: var(--text);
}
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 64px;
  padding: 28px 0 40px;
  color: var(--muted);
  font-size: 0.88rem;
}
.site-footer p {
  margin: 0 0 0.5em;
}

/* ---------- sections ---------- */
main {
  padding: 32px 0 0;
}
.hero {
  padding: 32px 0 16px;
}
.hero p.lead {
  font-size: 1.15rem;
  color: var(--muted);
  max-width: 44rem;
}
.section {
  margin-top: 48px;
}
.section > p.muted {
  max-width: 46rem;
}
.prose {
  max-width: 46rem;
}
.prose ul,
.prose ol {
  padding-left: 1.3em;
}
.prose li {
  margin: 0.25em 0;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent);
}
.btn.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.9rem;
}
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

/* ---------- cards ---------- */
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card h3 {
  margin-bottom: 0.35em;
}
.card p:last-child {
  margin-bottom: 0;
}
a.card {
  display: block;
  color: inherit;
  text-decoration: none;
}
a.card:hover {
  border-color: var(--accent);
}
.card.feature {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%);
}
.card .icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 12px;
}
.card .icon svg {
  width: 20px;
  height: 20px;
}
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  vertical-align: middle;
}
.badge.ok {
  background: var(--accent-soft);
  color: var(--ok);
  border-color: transparent;
}
.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: transparent;
}

/* ---------- callouts ---------- */
.callout {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 16px 0;
  border: 1px solid transparent;
  background: var(--info-soft);
}
.callout.warn {
  background: var(--warn-soft);
}
.callout.danger {
  background: var(--danger-soft);
}
.callout > :last-child {
  margin-bottom: 0;
}
.callout strong:first-child {
  display: block;
  margin-bottom: 2px;
}

/* ---------- steps ---------- */
ol.steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 12px 0;
}
ol.steps > li {
  counter-increment: step;
  position: relative;
  padding: 0 0 14px 42px;
}
ol.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9rem;
  display: grid;
  place-items: center;
}

/* ---------- tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.93rem;
}
th,
td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: var(--surface-2);
  font-weight: 600;
}
tr:last-child td {
  border-bottom: 0;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin: 24px 0 20px;
  overflow-x: auto;
}
.tabs button {
  font: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 10px 6px;
  margin-right: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button[aria-selected='true'] {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.subtabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 16px;
}
.subtabs button {
  font: inherit;
  font-size: 0.92rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}
.subtabs button[aria-selected='true'] {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
[hidden] {
  display: none !important;
}

/* ---------- forms ---------- */
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
.field label {
  font-weight: 600;
  font-size: 0.92rem;
}
.input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.input.mono {
  font-family: var(--mono);
}
.copy-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.copy-row .input {
  flex: 1;
  min-width: 0;
}
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  font-size: 0.95rem;
  margin: 8px 0 12px;
}
.kv dt {
  color: var(--muted);
}
.kv dd {
  margin: 0;
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

/* ---------- status / dashboard ---------- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.on {
  background: var(--ok);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.dot.wait {
  background: var(--warn);
}
.dot.off {
  background: var(--danger);
}
.tiles {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-width: 0;
}
.tile .label {
  font-size: 0.8rem;
  color: var(--muted);
}
.tile .value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile .unit {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 3px;
}
.cells {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
}
.cell {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  text-align: center;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
}
.cell b {
  display: block;
  font-size: 0.95rem;
}
.cell.low {
  border-color: var(--danger);
  background: var(--danger-soft);
}
.cell.bal {
  border-color: var(--info);
}
.log {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

form.is-connected .field,
form.is-connected > p.muted,
form.is-connected > h2 {
  display: none;
}

.share-grid {
  display: grid;
  gap: 28px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: 'one' 'two' 'three';
}
.area-one {
  grid-area: one;
}
.area-two {
  grid-area: two;
}
.area-three {
  grid-area: three;
}

@media (min-width: 760px) {
  .share-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: 'one two' 'three two';
    align-items: start;
  }
  .two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
  }
}

/* ---------- utilities (no inline styles: CSP style-src 'self') ---------- */
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mt-28 { margin-top: 28px; }
.mb-0 { margin-bottom: 0; }
.mw-560 { max-width: 560px; }
.fw-500 { font-weight: 500; }

/* Mockup of VESC Tool mobile's "TCP Hub (Internet Bridge)" box. Always dark, like the app. */
.app-mock {
  --app-bg: #2b2b2b;
  --app-line: #4a4a4a;
  --app-text: #e9e9e9;
  --app-dim: #b5b5b5;
  --app-btn: #3c3c3c;
  --app-hi: #e8692f;
  margin: 20px 0;
  max-width: 460px;
}
.app-mock-title {
  background: var(--app-bg);
  color: var(--app-text);
  padding: 14px 16px 8px;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 1.05rem;
}
.app-mock-box {
  background: var(--app-bg);
  color: var(--app-text);
  padding: 4px 12px 14px;
  border-radius: 0 0 var(--radius) var(--radius);
  display: grid;
  gap: 10px;
  font-size: .95rem;
}
.app-mock-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border: 1px solid var(--app-line);
  border-radius: 6px;
  outline: 2px solid var(--app-hi);
  outline-offset: 2px;
}
.app-mock-tick {
  width: 20px;
  height: 20px;
  border: 2px solid var(--app-dim);
  border-radius: 3px;
  flex: none;
}
.app-mock-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--app-dim);
}
.app-mock-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 2px solid #8a8a8a;
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--app-text);
  font-family: var(--mono);
  font-size: .85rem;
  overflow-wrap: anywhere;
}
.app-mock-field.is-set { border-color: var(--app-hi); }
.app-mock-port {
  display: flex;
  justify-content: space-between;
  color: var(--app-text);
  padding: 0 8px;
  font-size: 1.05rem;
}
.app-mock-btns {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
  margin-top: 4px;
}
.app-mock-btns span {
  background: var(--app-btn);
  color: var(--app-dim);
  text-align: center;
  text-transform: uppercase;
  font-size: .78rem;
  font-weight: 600;
  padding: 10px 4px;
  border-radius: 3px;
  opacity: .55;
}
.app-mock .mark,
.mock-legend .mark {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e8692f;
  color: #fff;
  font: 700 .75rem/1 var(--sans);
}
.app-mock-check .mark { margin-left: auto; }
.app-mock figcaption { margin-top: 12px; }
.mock-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.mock-legend li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.mock-legend li > div {
  display: flex;
  flex-wrap: wrap;
  column-gap: 12px;
  row-gap: 2px;
  min-width: 0;
}
.mock-legend strong { flex-basis: 100%; }
.mock-legend code { overflow-wrap: anywhere; }

/* Choose-your-own share code form */
.code-form { margin: 0 0 8px; }
.code-form .field span { line-height: 1.4; }
.form-err { color: var(--danger); margin: 0 0 4px; }
.form-err:empty { display: none; }

/* Troubleshooting disclosure on the share tab */
.trouble {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 10px 14px;
  margin: 20px 0;
}
.trouble summary { cursor: pointer; font-weight: 600; }
.trouble ul { margin: 10px 0 2px; padding-left: 18px; display: grid; gap: 8px; }
.mock-legend li .muted { flex-basis: 100%; }
