/* Buttons, fields, choice controls, chips, badges, avatars.

   §0.2: every button carries exactly one icon, drawn in currentColor, that
   moves on hover and keyboard focus (castomo-icons' data-motion does the
   moving). tools/check.mjs fails a template with a bare-text button. */

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--paper-2);
  --btn-fg: var(--ink);
  --btn-edge: var(--rule-strong);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-h);
  padding: 0 18px;
  border: var(--rule-w) solid var(--btn-edge);
  border-radius: var(--radius-button, 999px);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 650;
  font-size: var(--t0);
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  overflow-wrap: normal;
  user-select: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease-spring), box-shadow var(--dur) var(--ease);
}
.btn .ci { --ci-size: 18px; flex: none; }
.btn:has(.ci:first-child) { padding-inline-start: 14px; }
.btn:has(.ci:last-child):not(:has(.ci:first-child)) { padding-inline-end: 14px; }
@media (hover: hover) { .btn:hover { background: color-mix(in oklab, var(--btn-bg) 92%, var(--ink)); } }
.btn:active { transform: translateY(1px) scale(.985); }

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--on-accent);
  --btn-edge: var(--accent);
  box-shadow: 0 1px 0 color-mix(in oklab, var(--accent) 40%, transparent), 0 6px 16px -8px color-mix(in oklab, var(--accent) 70%, transparent);
}
@media (hover: hover) { .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); } }
:root[data-btn2="ghost"] .btn:not(.btn-primary, .btn-danger),
.btn-ghost { --btn-bg: transparent; --btn-edge: transparent; }
:root[data-btn2="ghost"] .btn:not(.btn-primary, .btn-danger):hover,
.btn-ghost:hover { background: var(--hover); }
:root[data-btn2="filled"] .btn:not(.btn-primary, .btn-danger, .btn-ghost) { --btn-bg: var(--field); --btn-edge: transparent; }
.btn-danger { --btn-bg: var(--bad); --btn-fg: var(--paper-2); --btn-edge: var(--bad); }
:root:is([data-theme="dark"], [data-theme="contrast-dark"]) .btn-danger { --btn-fg: var(--paper); }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .btn-danger { --btn-fg: var(--paper); } }
.btn-quiet-danger { --btn-fg: var(--bad); }

.btn-sm { min-height: 32px; padding-inline: 12px; font-size: var(--t-1); gap: 6px; }
.btn-sm .ci { --ci-size: 16px; }
/* A full-width button is sized by its card, not its words: on a phone a long label wraps
   inside the pill instead of running into (or past) its rounded ends. */
.btn-block { width: 100%; padding: 10px 22px; white-space: normal; text-align: center; text-wrap: balance; }
.btn-block:has(.ci:first-child) { padding-inline-start: 18px; }
@media (pointer: coarse) { .btn-sm { min-height: var(--target); } }

/* Icon-only: a square target with an accessible name (aria-label, always). */
.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--control-h);
  height: var(--control-h);
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-2);
  text-decoration: none;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease-spring);
}
.icon-btn .ci { --ci-size: 20px; }
@media (hover: hover) { .icon-btn:hover { background: var(--hover); color: var(--ink); } }
.icon-btn:active { transform: scale(.94); }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { background: var(--press); color: var(--ink); }
.icon-btn .dot {
  position: absolute;
  inset-block-start: 8px;
  inset-inline-end: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--paper);
}
/* An unread count on the bell: a number while it is small, "9+" after (notes-model.js). */
.icon-btn .count {
  position: absolute;
  inset-block-start: 3px;
  inset-inline-end: 1px;
  min-width: 18px;
  height: 18px;
  padding-inline: 5px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 0 0 2px var(--paper);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Busy keeps its size and says so (aria-busy + a live label), never a bare spinner. */
.btn[aria-busy="true"], .agent-mic[aria-busy="true"] { pointer-events: none; }
.btn[aria-busy="true"] .ci, .agent-mic[aria-busy="true"] .ci { animation: dk-spin .8s linear infinite; }
@keyframes dk-spin { to { transform: rotate(1turn); } }
.btn:disabled, .btn[aria-disabled="true"], .icon-btn:disabled {
  cursor: not-allowed;
  opacity: .55;
  box-shadow: none;
  transform: none;
}

.btn-row { display: flex; flex-wrap: wrap; gap: var(--s0); align-items: center; }

/* ---------- Fields ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label {
  color: var(--ink);
  font-weight: 650;
  font-size: var(--t-1);
}
.field .optional { color: var(--ink-3); font-weight: 500; }
.hint { color: var(--ink-3); font-size: var(--t-1); }
.error-text {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--bad);
  font-size: var(--t-1);
  font-weight: 600;
}
.error-text .ci { --ci-size: 16px; margin-top: 1px; }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 8px 14px;
  border: var(--rule-w) solid transparent;
  border-radius: var(--radius-control);
  background: var(--field);
  color: var(--ink);
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
:root[data-input="outline"] :is(.input, .select, .textarea) { background: var(--paper-2); border-color: var(--rule-strong); }
:root[data-input="underline"] :is(.input, .select, .textarea) { background: transparent; border-radius: 0; border-width: 0 0 2px; border-color: var(--rule-strong); padding-inline: 2px; }
:root[data-theme^="contrast"] :is(.input, .select, .textarea) { border-color: var(--ink); background: var(--paper-2); }
.textarea { min-height: 112px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); opacity: 1; }
@media (hover: hover) { :is(.input, .select, .textarea):hover { background: var(--field-hover); } }
:is(.input, .select, .textarea):focus-visible {
  outline: none;
  border-color: var(--accent-ink);
  background: var(--paper-2);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
:root[data-theme^="contrast"] :is(.input, .select, .textarea):focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
:is(.input, .select, .textarea)[aria-invalid="true"] { border-color: var(--bad); }
:is(.input, .select, .textarea):disabled { opacity: .6; cursor: not-allowed; }
.select {
  appearance: none;
  padding-inline-end: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* A field with an icon inside it (search, currency, URL). */
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap > .ci { position: absolute; inset-inline-start: 12px; --ci-size: 18px; color: var(--ink-3); pointer-events: none; }
.input-wrap > .input { padding-inline-start: 40px; }
.input-wrap > .input-suffix { position: absolute; inset-inline-end: 12px; color: var(--ink-3); font-size: var(--t-1); }

fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; color: var(--ink); font-weight: 700; }

/* Checkbox and radio: native, drawn larger, in the accent (accent-color on body). */
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 28px;
  cursor: pointer;
  color: var(--ink-2);
}
.check input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; cursor: pointer; }
.check b { display: block; color: var(--ink); font-weight: 650; }
@media (pointer: coarse) { .check { min-height: var(--target); align-items: center; } }

/* The switch: a checkbox with role="switch", for settings that apply at once. */
.switch {
  appearance: none;
  position: relative;
  width: 42px;
  height: 26px;
  flex: none;
  margin: 0;
  border-radius: 999px;
  background: var(--rule-strong);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  inset-block-start: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--paper-2);
  box-shadow: 0 1px 3px rgb(0 0 0 / .25);
  transition: transform var(--dur-slow) var(--ease-spring);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }
:root[dir="rtl"] .switch:checked::after { transform: translateX(-16px); }
:root[data-theme^="contrast"] .switch { outline: 2px solid var(--ink); outline-offset: 0; }
:root[data-theme^="contrast"] .switch::after { background: var(--ink); }
:root[data-theme^="contrast"] .switch:checked::after { background: var(--on-accent); }

/* The caret sits at the inline end, where padding-inline-end made room for it: the left in RTL. */
:root[dir="rtl"] .select { background-position: 15px 55%, 20px 55%; }

/* Segmented control: a radio group dressed as one pill (keyboard = arrows, natively). */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--field);
  /* The ring makes the track read as one group of choices on any card, dark included;
     inset, so it adds no size. */
  box-shadow: inset 0 0 0 var(--rule-w) var(--rule);
}
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: calc(var(--control-h) - 6px);
  padding: 0 14px;
  border-radius: var(--radius-pill);
  color: var(--ink-2);
  font-weight: 600;
  font-size: var(--t-1);
  white-space: nowrap;
  overflow-wrap: normal;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
/* An unchosen segment answers the pointer, so each reads as something to press. */
.segmented input:not(:checked):hover + span { background: var(--hover); color: var(--ink); }
.segmented input:checked + span { background: var(--segment-on); color: var(--ink); box-shadow: inset 0 0 0 var(--rule-w) var(--rule-strong), 0 1px 2px rgb(0 0 0 / .08), 0 2px 8px -2px rgb(0 0 0 / .12); }
.segmented input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
:root[data-theme^="contrast"] .segmented input:checked + span { outline: 2px solid var(--ink); }

/* A file control drawn by the kit: the native one speaks the browser's language, not the page's.
   The input stays in the label (visually hidden), so a click, a tap and the keyboard all reach it. */
.file-pick { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); min-width: 0; }
.file-pick .hint { min-width: 0; overflow-wrap: anywhere; }
.file-pick .btn:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

/* The drop zone component (dropzone.js): the `.dropzone` look (40-content.css), its list and live line. */
.dropzone-field { display: grid; gap: var(--s1); min-width: 0; }
.dropzone-field .dropzone { cursor: pointer; }
.dropzone-field .dropzone:hover { border-color: var(--ink-3); }
.dropzone-field .dropzone:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.dropzone-label { color: var(--ink); }
.dropzone-label:empty { display: none; }
.dropzone .btn .ci { --ci-size: 16px; color: inherit; }
.dropzone-choose { pointer-events: none; }
.dropzone-list { display: grid; gap: 6px; list-style: none; }
.dropzone-file { display: flex; align-items: center; gap: var(--s1); padding-block: 6px; padding-inline: 8px 6px; border: var(--rule-w) solid var(--rule); border-radius: var(--radius-control); background: var(--paper); }
.dropzone-thumb { display: grid; place-items: center; inline-size: 40px; block-size: 40px; border-radius: 10px; background: var(--field); color: var(--ink-3); object-fit: cover; flex: none; }
.dropzone-thumb .ci { --ci-size: 20px; }
.dropzone-file-words { display: grid; min-width: 0; flex: 1; }
.dropzone-file-name { color: var(--ink); overflow-wrap: anywhere; }
.dropzone-file-size { font-size: var(--t-2); color: var(--ink-3); }
.dropzone-live:empty { display: none; }

/* ---------- Chips (filters) ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: var(--rule-w) solid var(--rule);
  border-radius: var(--radius-pill);
  background: var(--paper-2);
  color: var(--ink-2);
  font-weight: 600;
  font-size: var(--t-1);
  white-space: nowrap;
  overflow-wrap: normal;
}
.chip .ci { --ci-size: 16px; }
button.chip { cursor: pointer; }
@media (hover: hover) { button.chip:hover { border-color: var(--rule-strong); color: var(--ink); } }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
@media (pointer: coarse) { .chip { min-height: 40px; } }

/* ---------- Badges: status is a word and a shape, never colour alone ---------- */
.badge {
  --tone: var(--ink-3);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-block: 2px;
  padding-inline: 8px 9px;
  border-radius: var(--radius-pill);
  background: color-mix(in oklab, var(--tone) 12%, transparent);
  color: color-mix(in oklab, var(--tone) 84%, var(--ink));
  font-size: var(--t-1);
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
  overflow-wrap: normal;
}
.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tone);
  flex: none;
}
.badge[data-tone="ok"] { --tone: var(--ok); }
.badge[data-tone="warn"] { --tone: var(--warn); }
.badge[data-tone="bad"] { --tone: var(--bad); }
.badge[data-tone="info"] { --tone: var(--info); }
.badge[data-tone="accent"] { --tone: var(--accent-ink); }
/* Warn and bad differ in shape as well as hue: a square and a diamond. */
.badge[data-tone="warn"]::before { border-radius: 2px; }
.badge[data-tone="bad"]::before { border-radius: 1px; transform: rotate(45deg) scale(.9); }
/* Sample: example content, not the person's own (GUIDELINES §6). Its shape is its own: a dashed
   outline and a hollow dot, no fill, so it reads as "not real" in greyscale and in every mode. */
.badge[data-tone="sample"] {
  --tone: var(--ink-3);
  background: transparent;
  outline: 1.5px dashed var(--tone);
  outline-offset: -1.5px;
  color: var(--ink-2);
}
.badge[data-tone="sample"]::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--tone); }
.badge[data-live]::before { animation: dk-live 1.6s var(--ease) infinite; }
@keyframes dk-live { 50% { box-shadow: 0 0 0 5px color-mix(in oklab, var(--tone) 22%, transparent); } }
:root[data-theme^="contrast"] .badge { background: transparent; outline: 2px solid currentColor; outline-offset: -2px; color: var(--ink); }
:root[data-theme^="contrast"] .badge[data-tone="sample"] { outline-style: dashed; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 6px;
  background: var(--field);
  color: var(--ink-2);
  font-size: var(--t-1);
  font-weight: 600;
}

/* ---------- Avatars ---------- */
.avatar {
  --size: 32px;
  display: inline-grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  flex: none;
  border-radius: 50%;
  background: color-mix(in oklab, var(--hue, var(--accent-ink)) 16%, var(--paper-2));
  color: color-mix(in oklab, var(--hue, var(--accent-ink)) 80%, var(--ink));
  font-size: calc(var(--size) * .38);
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
:root[data-theme^="contrast"] .avatar { background: var(--paper-2); color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.avatar-lg { --size: 56px; }
.avatar-sm { --size: 24px; }
/* Nobody: an empty dashed circle the size of a person (the people picker's "Unassigned"). */
.avatar-none { background: transparent; border: 1.5px dashed var(--ink-3); }
:root[data-theme^="contrast"] .avatar-none { box-shadow: none; border-color: var(--ink); }
.avatars { display: flex; }
.avatars .avatar { box-shadow: 0 0 0 2px var(--paper-2); }
.avatars .avatar + .avatar { margin-inline-start: -8px; }
