/* ==========================================================================
   DIST-17 — Base: reset, typography, primitives
   ========================================================================== */

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--c-canvas);
  color: var(--c-ink);
  font-family: var(--f-sans);
  font-size: var(--t-sm);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}
button { background: none; border: 0; cursor: pointer; }
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

svg { display: block; }

/* --- Numbers. The single highest-leverage rule in this file.
       Every financial figure uses tabular figures + mono so the decimal point
       sits in the same x-position down an entire column. ------------------ */
.num {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 1;
  letter-spacing: var(--tr-tight);
  white-space: nowrap;
}
.num--r { text-align: right; }

/* --- Micro label: the uppercase eyebrow used for column groups, panel
       captions, and every "what is this number" clarifier. ---------------- */
.eyebrow {
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--c-ink-3);
}

.muted   { color: var(--c-ink-3); }
.muted-2 { color: var(--c-ink-4); }
.strong  { font-weight: 600; }
.nowrap  { white-space: nowrap; }
.trunc   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Focus. Visible, and only for keyboard. Never removed, only replaced. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 1px;
  border-radius: var(--r-xs);
}

::selection { background: var(--c-accent-soft); color: var(--c-accent-3); }

/* --- Scrollbars: thin and neutral so dense panels don't gain visual weight */
* { scrollbar-width: thin; scrollbar-color: var(--c-line-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--c-line-3);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-pill);
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--c-ink-4); background-clip: content-box; }

/* ==========================================================================
   Controls
   ========================================================================== */

.ctl {
  height: var(--ctl-h);
  min-height: 24px;
  padding: 0 var(--s-4);
  background: var(--c-surface);
  border: 1px solid var(--c-line-2);
  border-radius: var(--r-sm);
  color: var(--c-ink);
  font-size: var(--t-sm);
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.ctl::placeholder { color: var(--c-ink-4); }
.ctl:hover { border-color: var(--c-line-3); }
.ctl:focus-visible { border-color: var(--c-accent); box-shadow: var(--ring); outline: none; }
.ctl[disabled] { background: var(--c-surface-2); color: var(--c-ink-4); cursor: not-allowed; }

textarea.ctl { height: auto; padding: var(--s-3) var(--s-4); resize: vertical; line-height: var(--lh-body); }

select.ctl {
  appearance: none;
  padding-right: var(--s-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7784' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-4) center;
  cursor: pointer;
}

/* --- Buttons */
.btn {
  height: var(--ctl-h);
  padding: 0 var(--s-5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  border: 1px solid var(--c-line-2);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-ink);
  font-size: var(--t-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover { background: var(--c-surface-2); border-color: var(--c-line-3); }
.btn:active { background: var(--c-surface-3); }
.btn[disabled] { color: var(--c-ink-4); background: var(--c-surface-2); cursor: not-allowed; }

.btn--primary {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-ink-inv);
  font-weight: 600;
}
.btn--primary:hover { background: var(--c-accent-2); border-color: var(--c-accent-2); }
.btn--primary:active { background: var(--c-accent-3); }

.btn--danger { color: var(--s-bad-text); border-color: var(--s-bad-line); background: var(--c-surface); }
.btn--danger:hover { background: var(--s-bad-bg); border-color: var(--s-bad-bar); }

.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--c-surface-3); border-color: transparent; }

.btn--sm { height: var(--ctl-h-sm); padding: 0 var(--s-4); font-size: var(--t-xs); }
.btn--icon { width: var(--ctl-h); padding: 0; }
.btn--icon.btn--sm { width: var(--ctl-h-sm); }
.btn--block { width: 100%; justify-content: center; }
.btn--lg { height: 44px; }

/* --- Segmented control */
.seg {
  display: inline-flex;
  padding: 2px;
  background: var(--c-surface-3);
  border-radius: var(--r-md);
  gap: 2px;
}
.seg__btn {
  height: calc(var(--ctl-h) - 6px);
  min-height: 24px;
  padding: 0 var(--s-4);
  border-radius: var(--r-xs);
  font-size: var(--t-xs);
  font-weight: 500;
  color: var(--c-ink-2);
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  transition: background .12s ease, color .12s ease;
}
.seg__btn:hover { color: var(--c-ink); }
.seg__btn[aria-pressed="true"] {
  background: var(--c-surface);
  color: var(--c-ink);
  font-weight: 600;
  box-shadow: var(--sh-1);
}

/* --- Checkbox / radio */
.check {
  appearance: none;
  width: 14px; height: 14px;
  border: 1px solid var(--c-line-2);
  border-radius: var(--r-xs);
  background: var(--c-surface);
  display: inline-grid; place-content: center;
  cursor: pointer;
  flex: none;
  transition: background .12s ease, border-color .12s ease;
}
.check:checked { background: var(--c-accent); border-color: var(--c-accent); }
.check:checked::after {
  content: ""; width: 8px; height: 8px;
  background: #fff;
  clip-path: polygon(13% 47%, 3% 58%, 38% 92%, 97% 22%, 86% 12%, 37% 70%);
}
.check:indeterminate { background: var(--c-accent); border-color: var(--c-accent); }
.check:indeterminate::after { content: ""; width: 8px; height: 2px; background: #fff; }
.check:hover:not(:checked) { border-color: var(--c-ink-4); }

input[type="radio"].check { border-radius: var(--r-pill); }
input[type="radio"].check:checked { background: var(--c-surface); border-width: 4px; border-color: var(--c-accent); }

/* --- Switch */
.switch {
  appearance: none;
  width: 30px; height: 17px;
  border-radius: var(--r-pill);
  background: var(--c-line-3);
  position: relative;
  cursor: pointer;
  flex: none;
  transition: background .15s ease;
}
.switch::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--sh-1);
  transition: transform .15s cubic-bezier(.32, .72, 0, 1);
}
.switch:checked { background: var(--c-accent); }
.switch:checked::after { transform: translateX(13px); }

/* --- Tooltip: CSS-only, no library */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(3px);
  background: #1b2430;
  color: #fff;
  font-size: var(--t-xs);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease .25s, transform .12s ease .25s;
  z-index: var(--z-toast);
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-tip-pos="bottom"]::after { bottom: auto; top: calc(100% + 6px); }
[data-tip-pos="left"]::after {
  bottom: auto; top: 50%; left: auto; right: calc(100% + 8px);
  transform: translateY(-50%);
}
[data-tip-pos="left"]:hover::after { transform: translateY(-50%); }

/* --- Divider */
.hr { height: 1px; background: var(--c-line); border: 0; margin: 0; }
.vr { width: 1px; align-self: stretch; background: var(--c-line); }
