/* controls.css — buttons, the ONE tab implementation, pager, fields, forms.
 *
 * The old sheets carried four separate implementations of "underline tab"
 * (.nav-link, .seg, .seg-sm, .tab), all four of them transparent-background,
 * muted-label, active = ink + weight 650 + a 2px ::after bar. Four copies of one
 * control. `.seg` below is that control, once. The topbar's .nav-link stays in
 * chrome.css because it is a navigation landmark with different semantics, not
 * a fifth copy.
 *
 * Every interactive element defines hover, focus-visible, active and disabled,
 * and COLOUR IS NEVER THE ONLY SIGNAL — every active state also changes weight
 * or draws a rule, so it survives greyscale.
 */

/* ------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  min-height: 44px;          /* hit area, even when the label is short */
  padding: 0 var(--s-5);
  border: var(--bw-1) solid var(--ink);
  border-radius: var(--r-full);
  background: transparent;
  color: var(--ink);
  font-size: var(--t-sm);
  font-weight: 600;
  white-space: nowrap;
  transition-property: color, background-color, border-color, box-shadow, transform;
  transition-duration: var(--dur-2), var(--dur-2), var(--dur-2), var(--dur-3), var(--dur-3);
  transition-timing-function: var(--ease-out), var(--ease-out), var(--ease-out), var(--ease-out), var(--ease-spring);
}
/* Hover LIFTS (a button is a control and says so); press sinks. */
.btn:hover {
  background: var(--ink-wash);
  color: var(--ink);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}
.btn:active { transform: scale(0.97); box-shadow: none; }

/* The one filled button per view. Prussian ink on paper, lit ink at night. */
.btn[data-kind='strong'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn[data-kind='strong']:hover {
  background: color-mix(in oklab, var(--accent) 88%, var(--ink));
  color: var(--on-accent);
}
:root[data-theme='dark'] .btn[data-kind='strong']:hover {
  background: color-mix(in oklab, var(--accent) 88%, white);
  box-shadow: var(--shadow-hover), var(--glow);
}

/* Quiet: a rule-less button for secondary actions beside a strong one. */
.btn[data-kind='quiet'] { border-color: var(--rule); color: var(--ink-2); }
.btn[data-kind='quiet']:hover { border-color: var(--ink); color: var(--ink); }

.btn[data-kind='link'] {
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  color: var(--accent);
  font-weight: 600;
}
.btn[data-kind='link']:hover {
  background: none;
  box-shadow: none;
  transform: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn[data-kind='link']:active { transform: none; color: var(--accent); }

.btn[data-size='sm'] { min-height: 36px; padding: 0 var(--s-4); font-size: var(--t-xs); }

.btn[disabled], .btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

/* A trailing arrow that leans the way the button goes. */
.btn-arrow { display: inline-block; transition: transform var(--dur-3) var(--ease-spring); }
.btn:hover .btn-arrow[data-dir='down'] { transform: translateY(2px); }
.btn:hover .btn-arrow[data-dir='right'] { transform: translateX(3px); }

.btn-icon { flex: none; width: 14px; height: 14px; }

.back-link {
  display: inline-flex; align-items: center; gap: var(--s-1);
  color: var(--ink-3);
  font-size: var(--t-sm);
}
.back-link:hover { color: var(--accent); }
.back-icon { flex: none; width: 16px; height: 16px; stroke: currentColor; fill: none; }

/* --------------------------------------------------- the one segmented
 *
 * role="tablist" when it controls panels, role="group" with aria-pressed
 * buttons otherwise. The strip SCROLLS rather than wraps, for the same reason
 * the masthead does: a control strip that grows a second line moves everything
 * below it on every route. */
.seg {
  display: flex;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: var(--edge-soft);
}
.seg::-webkit-scrollbar { display: none; }

.seg-item {
  position: relative;
  flex: none;
  display: inline-flex; align-items: center;
  min-height: 44px;
  padding: 0 var(--s-3);
  color: var(--ink-2);
  font-size: var(--t-base);
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--dur-2) var(--ease-both);
}
.seg-item:hover { color: var(--ink); }
.seg-item:focus-visible { outline-offset: -1px; }

/* WEIGHT AND RULE BOTH CHANGE, so the state survives greyscale. */
.seg-item[aria-selected='true'],
.seg-item[aria-pressed='true'] { color: var(--ink); font-weight: 650; }
.seg-item[aria-selected='true']::after,
.seg-item[aria-pressed='true']::after {
  content: '';
  position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px;
  height: var(--bw-2);
  background: var(--rule-strong);
}
.seg-item[aria-disabled='true'] { opacity: 0.4; pointer-events: none; }

.seg[data-size='sm'] .seg-item {
  min-height: 32px;
  padding: 0 var(--s-2);
  font-size: var(--t-xs);
}

/* The rail is a narrow column, so a segmented control placed there stacks
 * rather than scrolls — a 152px horizontal scroller is not a control. */
.col-rail > .seg {
  flex-direction: column;
  border-bottom: none;
  border-left: var(--edge-soft);
  overflow-x: visible;
}
.col-rail > .seg .seg-item { min-height: 32px; padding-left: var(--s-3); }
.col-rail > .seg .seg-item[aria-selected='true']::after,
.col-rail > .seg .seg-item[aria-pressed='true']::after {
  left: -1px; right: auto; top: 4px; bottom: 4px;
  width: var(--bw-2); height: auto;
}

.tab-panel { margin-top: var(--s-5); }

/* --------------------------------------------------------------- pager */

.pager {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-4);
}
.pager-btn {
  min-height: 40px; min-width: 40px;
  padding: 0 var(--s-2);
  border: var(--edge-soft);
  border-radius: var(--r-2);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--t-xs);
  transition: color var(--dur-1), border-color var(--dur-1);
}
.pager-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.pager-btn:active { transform: scale(0.97); }
.pager-btn[aria-current='page'] {
  color: var(--ink);
  font-weight: 650;
  border-color: var(--rule-strong);
  border-width: var(--bw-2);
}
.pager-btn[disabled] { opacity: 0.4; pointer-events: none; }
.pager-gap { color: var(--ink-3); padding-inline: var(--s-1); }
.pager-count { margin-left: auto; color: var(--ink-3); font-size: var(--t-xs); }

/* -------------------------------------------------------------- fields */

.form { display: grid; gap: var(--s-5); max-width: var(--w-text); }
.form-row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-end; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

.field { display: grid; gap: var(--s-1); min-width: 0; }
.field-label { font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); }
.field-hint { font-size: var(--t-2xs); color: var(--ink-3); text-wrap: pretty; }

.field-input {
  width: 100%;
  min-height: 40px;
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  border: var(--edge);
  border-radius: var(--r-2);
  color: var(--ink);
  font-size: var(--t-sm);
  /* The focused rule is an INSET SHADOW, not a border-width change: animating
   * border-width reflows the field and everything after it. */
  transition-property: border-color, box-shadow;
  transition-duration: var(--dur-2);
  transition-timing-function: var(--ease-snap);
}
.field-input:hover { border-color: var(--ink-3); }
.field-input:focus { outline: none; }
.field-input:focus-visible {
  border-color: var(--accent);
  box-shadow: inset 0 -2px 0 -1px var(--accent);
}
.field-input::placeholder { color: var(--ink-3); }
.field-input[disabled] { opacity: 0.5; pointer-events: none; }

textarea.field-input { min-height: 7rem; resize: vertical; line-height: var(--lh-normal); }

.field-counter {
  justify-self: end;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--t-3xs);
  color: var(--ink-3);
}
.field-counter[data-over='true'] { color: var(--danger); }

/* ------------------------------------------------------------ copy button */

.copy {
  display: inline-flex; align-items: center; gap: var(--s-1);
  min-height: 32px;
  padding: 0 var(--s-2);
  border: var(--edge-soft);
  border-radius: var(--r-2);
  color: var(--ink-3);
  font-size: var(--t-xs);
  transition: color var(--dur-1), border-color var(--dur-1);
}
.copy:hover { color: var(--ink); border-color: var(--ink-3); }
.copy[data-done='true'] { color: var(--live); border-color: var(--live-quiet); }

/* ---------------------------------------------------------- toggle pill
 *
 * A filter: a button with aria-pressed, in a role="group" row (.toggles). A
 * pill because it is physically one — the one radius the broadsheet allows.
 * Pressed = ink fill AND a weight change, so it survives greyscale. The count
 * is set in the measurement face because it is one. */
.toggles {
  display: flex; flex-wrap: wrap;
  gap: var(--s-2);
}
.toggle {
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: 40px;
  padding: 0 var(--s-4);
  border: var(--edge);
  border-radius: var(--r-full);
  color: var(--ink-2);
  font-size: var(--t-sm);
  font-weight: 520;
  white-space: nowrap;
  transition: color var(--dur-1), background-color var(--dur-2) var(--ease-out), border-color var(--dur-1);
}
.toggle:hover { color: var(--ink); border-color: var(--ink); }
.toggle[aria-pressed='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
  font-weight: 650;
}
.toggle-n {
  font-family: var(--font-mono);
  font-size: var(--t-2xs);
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.toggle[aria-pressed='true'] .toggle-n { color: inherit; }
