/* UI primitive styles. Tokens only; no hard-coded theme colors. */

/* Hover wash that layers over any surface color. */
:root { --wash-hover: linear-gradient(var(--bg-hover), var(--bg-hover)); --wash-active: linear-gradient(var(--bg-active), var(--bg-active)); }

/* ---------- Button ---------- */
.btn {
  --btn-h: var(--control-md);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--btn-h);
  padding: 0 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-control);
  line-height: var(--leading-control);
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
  transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out),
    box-shadow var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out), opacity var(--dur-1) var(--ease-out);
}
.btn:active:not(:disabled) { transform: scale(var(--motion-press)); }
/* Disabled: one quiet treatment for every variant (no washed-out fills). Loading keeps the variant's look. */
.btn:disabled:not(.is-loading) { background: var(--bg-inset); background-image: none; color: var(--text-3); box-shadow: inset 0 0 0 1px var(--border); filter: none; cursor: not-allowed; }
.btn-ghost:disabled:not(.is-loading) { background: none; box-shadow: none; color: var(--text-4); }
.btn.is-loading { cursor: progress; }
.btn.is-loading > :not(.btn-spinner) { opacity: 0; transition: opacity var(--dur-1) var(--ease-out); }
.btn.is-loading > .btn-spinner { position: absolute; inset: 0; display: grid; place-items: center; animation: bramble-fade-in var(--dur-1) var(--ease-out) both; }
.btn-sm { --btn-h: var(--control-sm); padding: 0 8px; gap: 4px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-lg { --btn-h: var(--control-lg); padding: 0 16px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.btn-primary { background: var(--ink); color: var(--text-on-ink); box-shadow: 0 1px 2px rgba(16, 14, 30, .14); }
.btn-primary:hover:not(:disabled) { background: var(--ink-hover); }
.btn-accent { background: var(--accent); color: var(--text-on-accent); box-shadow: 0 1px 2px rgba(60, 30, 160, .18); }
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background-color: var(--bg-elevated); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong), 0 1px 1px rgba(16, 14, 30, .03); }
.btn-secondary:hover:not(:disabled) { background-image: var(--wash-hover); }
.btn-secondary:active:not(:disabled) { background-image: var(--wash-active); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.btn-ghost:active:not(:disabled) { background: var(--bg-active); }
.btn-danger { background: var(--danger); color: var(--text-on-danger); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.06); }
.btn .btn-kbd { margin-left: 2px; }
.btn-primary .kbd, .btn-accent .kbd, .btn-danger .kbd { background: rgba(255, 255, 255, .16); color: inherit; box-shadow: none; }

/* ---------- Icon button ---------- */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--control-md);
  height: var(--control-md);
  flex-shrink: 0;
  border-radius: var(--radius-md);
  color: var(--text-3);
  transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
}
.icon-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.icon-btn:active:not(:disabled) { background: var(--bg-active); transform: scale(var(--motion-press)); }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { background: var(--bg-active); color: var(--text); }
.icon-btn:disabled { color: var(--text-4); cursor: not-allowed; }
.icon-btn-sm { width: var(--control-sm); height: var(--control-sm); border-radius: var(--radius-sm); }
.icon-btn-lg { width: var(--control-lg); height: var(--control-lg); }
.icon-btn-secondary { background-color: var(--bg-elevated); color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
.icon-btn-secondary:hover:not(:disabled) { background-color: var(--bg-elevated); background-image: var(--wash-hover); }

/* ---------- Kbd ---------- */
.kbd-group { display: inline-flex; align-items: center; gap: 2px; }
.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: var(--radius-xs);
  font: 500 11px/1 var(--font-sans);
  color: var(--text-3);
  background: var(--bg-subtle);
  box-shadow: inset 0 0 0 1px var(--border), inset 0 -1px 0 var(--border-strong);
  font-variant-numeric: tabular-nums;
}
.kbd-sm { min-width: 16px; height: 16px; padding: 0 3px; }

/* ---------- Tooltip ---------- */
.tooltip {
  z-index: var(--z-tooltip);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .35);
  pointer-events: none;
  animation: bramble-fade-in var(--dur-1) var(--ease-out) both;
}
.tooltip .kbd { background: rgba(255, 255, 255, .14); color: inherit; box-shadow: none; }

/* ---------- Floating surfaces ---------- */
.popover-surface {
  z-index: var(--z-popover);
  background: var(--bg-raised);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  overflow: auto;
  outline: none;
  scrollbar-width: thin;
}
.popover-anim { animation: bramble-pop-in var(--dur-2) var(--ease-out) both; }
.popover-anim[data-state="closed"] { animation: bramble-pop-out var(--dur-1) var(--ease-in-out) both; pointer-events: none; }
.popover { padding: 4px; }

/* ---------- Menu ---------- */
.menu { min-width: 208px; max-width: 340px; padding: 4px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  line-height: 18px;
  cursor: default;
  user-select: none;
  outline: none;
}
.menu-item:focus, .menu-item.is-open { background: var(--bg-active); }
.menu-item[aria-disabled="true"] { color: var(--text-4); }
.menu-item[aria-disabled="true"] .menu-item-icon { color: var(--text-4); }
.menu-item.is-danger { color: var(--danger-ink); }
.menu-item.is-danger .menu-item-icon { color: var(--danger-ink); }
.menu-item.is-danger:focus { background: var(--danger-tint); }
.menu-item.has-description { align-items: flex-start; padding-top: 6px; padding-bottom: 6px; }
.menu-item.has-description .menu-item-icon { margin-top: 1px; }
.menu-item-icon { display: grid; place-items: center; width: 16px; height: 18px; color: var(--text-3); flex-shrink: 0; }
.menu-item-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.menu-item-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item-description { font-size: 12px; line-height: 16px; color: var(--text-3); white-space: normal; }
.menu-item-badge { margin-left: auto; flex-shrink: 0; }
.menu-item-kbd { margin-left: auto; flex-shrink: 0; }
.menu-item-kbd .kbd { background: none; box-shadow: none; color: var(--text-3); padding: 0 1px; min-width: 12px; }
.menu-item-check { display: grid; place-items: center; width: 14px; margin-left: auto; color: var(--accent-ink); flex-shrink: 0; }
.menu-item-chevron { margin-left: auto; color: var(--text-3); }
.menu-separator { height: 1px; margin: 4px -4px; background: var(--border); }
.menu-label { padding: 6px 8px 4px; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--text-3); }
.menu-submenu { z-index: calc(var(--z-popover) + 1); }

/* ---------- Select trigger ---------- */
.select-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  height: var(--control-md);
  padding: 0 8px 0 10px;
  border-radius: var(--radius-md);
  font-size: var(--text-control);
  line-height: var(--leading-control);
  font-weight: 500;
  color: var(--text);
  transition: background-color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.select-trigger:disabled { opacity: .5; }
.select-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.select-value.is-placeholder { color: var(--text-3); font-weight: 400; }
.select-icon { color: var(--text-3); }
.select-chevron { color: var(--text-3); transition: transform var(--dur-2) var(--ease-out); }
.select-trigger.is-open .select-chevron { transform: rotate(180deg); }
.select-field { min-width: 180px; justify-content: space-between; background-color: var(--bg-elevated); box-shadow: inset 0 0 0 1px var(--border-strong); }
.select-field .select-value { flex: 1; }
.select-field:hover:not(:disabled) { background-image: var(--wash-hover); }
.select-field.is-open { box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 3px var(--accent-tint); }
.select-pill { height: 28px; padding: 0 6px 0 8px; border-radius: var(--radius-sm); color: var(--text-2); }
.select-pill:hover:not(:disabled), .select-pill.is-open { background: var(--bg-hover); color: var(--text); }
.select-pill.is-open { background: var(--bg-active); }
.select-ghost { height: 24px; padding: 0 4px; border-radius: var(--radius-sm); color: var(--text-2); }
.select-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-hover); }
.select-sm { height: var(--control-sm); font-size: 12px; }
.select-menu { max-height: 420px; }

/* ---------- Command menu / combobox ---------- */
.command-menu { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
.command-menu-search { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 16px; border-bottom: 1px solid var(--border); color: var(--text-3); flex-shrink: 0; }
.command-menu-search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; font-size: 15px; color: var(--text); }
.command-menu-search input::placeholder { color: var(--text-4); }
.command-menu-sm .command-menu-search { height: 38px; padding: 0 10px; gap: 8px; }
.command-menu-sm .command-menu-search input { font-size: 13px; }
.command-menu-list { flex: 1; min-height: 0; overflow: auto; padding: 6px; max-height: 380px; }
.command-menu-sm .command-menu-list { padding: 4px; max-height: 320px; }
.command-menu-group + .command-menu-group { margin-top: 6px; }
.command-menu-group-label { padding: 6px 8px 4px; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--text-3); }
.command-menu-item { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--text); cursor: default; user-select: none; }
.command-menu-sm .command-menu-item { min-height: 30px; padding: 5px 8px; gap: 8px; }
.command-menu-item.is-active { background: var(--bg-active); }
.command-menu-icon { display: grid; place-items: center; width: 20px; height: 20px; color: var(--text-3); flex-shrink: 0; }
.command-menu-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.command-menu-label { font-size: 13px; line-height: 18px; }
.command-menu-description { font-size: 12px; line-height: 16px; color: var(--text-3); }
.command-menu-meta { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.command-menu-badge { flex-shrink: 0; }
.command-menu-check { color: var(--accent-ink); flex-shrink: 0; }
.command-menu-empty { padding: 28px 8px; text-align: center; color: var(--text-3); font-size: 13px; }
.command-menu-footer { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); flex-shrink: 0; }
.command-menu-footer .kbd-group { margin-right: 4px; }
.combobox-popover { padding: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- Dialog & sheet ---------- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: 32px;
  background: var(--bg-overlay);
  animation: bramble-fade-in var(--dur-2) var(--ease-out) both;
}
.dialog-overlay[data-state="closed"] { animation: bramble-fade-out var(--dur-2) var(--ease-in-out) both; pointer-events: none; }
.dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100vh - 64px);
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-dialog);
  outline: none;
  overflow: hidden;
  animation: bramble-dialog-in var(--dur-3) var(--ease-out) both;
}
.dialog[data-state="closed"] { animation: bramble-dialog-out var(--dur-2) var(--ease-in-out) both; }
.dialog-sm { max-width: 420px; }
.dialog-md { max-width: 560px; }
.dialog-lg { max-width: 720px; }
.dialog-xl { max-width: 960px; }
.dialog-header { display: flex; align-items: flex-start; gap: 12px; padding: 18px 16px 0 24px; flex-shrink: 0; }
.dialog-heading { display: grid; gap: 4px; flex: 1; min-width: 0; padding-top: 3px; }
.dialog-description { font-size: 13px; line-height: 20px; color: var(--text-2); }
.dialog-body { padding: 16px 24px 24px; overflow: auto; min-height: 0; flex: 1; }
.dialog-footer { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 0 24px 20px; flex-shrink: 0; }
.sheet-overlay { position: fixed; inset: 0; z-index: var(--z-overlay); background: var(--bg-overlay); animation: bramble-fade-in var(--dur-2) var(--ease-out) both; }
.sheet-overlay[data-state="closed"] { animation: bramble-fade-out var(--dur-2) var(--ease-in-out) both; pointer-events: none; }
.sheet {
  position: absolute;
  top: 8px;
  right: 8px;
  bottom: 8px;
  max-width: calc(100vw - 16px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-dialog);
  outline: none;
  overflow: hidden;
  animation: bramble-sheet-in var(--dur-3) var(--ease-out) both;
}
.sheet[data-state="closed"] { animation: bramble-sheet-out var(--dur-2) var(--ease-in-out) both; }
.sheet-header { display: flex; align-items: flex-start; gap: 12px; padding: 16px 12px 14px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sheet-body { flex: 1; min-height: 0; overflow: auto; padding: 20px; }

/* ---------- Tabs & segmented ---------- */
.tabs { position: relative; display: flex; align-items: stretch; gap: 2px; border-bottom: 1px solid var(--border); }
.tab {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: 6px;
  height: 36px;
  padding: 0 8px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color var(--dur-1) var(--ease-out);
}
.tab:hover:not(:disabled) { color: var(--text-2); }
.tab[aria-selected="true"] { color: var(--text); }
.tab:focus-visible { outline-offset: -2px; }
.tabs-sm .tab { height: 34px; padding: 0 6px; }
.tabs-indicator {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--text);
  transition: transform var(--dur-3) var(--ease-out), width var(--dur-3) var(--ease-out);
}
.tab-badge { display: inline-grid; place-items: center; min-width: 18px; height: 16px; padding: 0 5px; border-radius: var(--radius-full); background: var(--bg-active); color: var(--text-2); font-size: 11px; line-height: 1; }
.segmented { position: relative; display: inline-flex; padding: 2px; border-radius: var(--radius-md); background: var(--bg-inset); box-shadow: inset 0 0 0 1px var(--border); }
.segmented-block { display: flex; }
.segmented-block .segment { flex: 1; }
.segment {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: calc(var(--control-md) - 4px);
  padding: 0 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2); /* text-3 on --bg-inset is 4.16:1, under the 4.5:1 floor */
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease-out);
}
.segment:hover:not(:disabled) { color: var(--text); }
.segment[aria-checked="true"] { color: var(--text); }
.segment:focus-visible { outline-offset: 0; }
.segmented-sm .segment { height: 22px; padding: 0 8px; font-size: 12px; }
.segmented-indicator {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  border-radius: 6px;
  background: var(--bg-raised);
  box-shadow: 0 1px 2px rgba(16, 14, 30, .08), 0 0 0 1px var(--border);
  transition: transform var(--dur-3) var(--ease-out), width var(--dur-3) var(--ease-out);
}

/* ---------- Switch / checkbox / radio cards ---------- */
.switch {
  position: relative;
  width: 32px;
  height: 18px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  background: var(--bg-active);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  transition: background-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}
.switch[aria-checked="true"] { background: var(--accent); box-shadow: inset 0 0 0 1px transparent; }
.switch:disabled { opacity: .45; }
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--switch-thumb-off);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .22), 0 0 0 .5px rgba(0, 0, 0, .06);
  transition: transform var(--dur-3) var(--ease-spring), background-color var(--dur-2) var(--ease-out);
}
.switch[aria-checked="true"] .switch-thumb { transform: translateX(14px); background: #FFFFFF; }
.switch-sm { width: 26px; height: 16px; }
.switch-sm .switch-thumb { width: 12px; height: 12px; }
.switch-sm[aria-checked="true"] .switch-thumb { transform: translateX(10px); }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; }
.control-row.is-disabled { opacity: .55; }
.control-row-text { display: grid; gap: 2px; min-width: 0; }
.control-row-label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--text); }
.control-row-description { font-size: 12px; line-height: 16px; color: var(--text-3); }

.checkbox { position: relative; display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.checkbox.is-disabled { opacity: .5; cursor: not-allowed; }
.checkbox-input { position: absolute; top: 1px; left: 0; width: 16px; height: 16px; margin: 0; opacity: 0; cursor: inherit; }
.checkbox-box {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  flex-shrink: 0;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  color: transparent;
  transition: background-color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
}
.checkbox-box svg { transform: scale(.5); opacity: 0; transition: transform var(--dur-2) var(--ease-spring), opacity var(--dur-1) var(--ease-out); }
.checkbox-input:checked + .checkbox-box, .checkbox-input:indeterminate + .checkbox-box { background: var(--accent); box-shadow: none; color: var(--text-on-accent); }
.checkbox-input:checked + .checkbox-box svg, .checkbox-input:indeterminate + .checkbox-box svg { transform: none; opacity: 1; }
.checkbox-input:focus-visible + .checkbox-box { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.checkbox-text { display: grid; gap: 2px; }
.checkbox-label { font-size: 13px; line-height: 18px; font-weight: 500; }
.checkbox-description { font-size: 12px; line-height: 16px; color: var(--text-3); }

.radio-cards { display: grid; grid-template-columns: repeat(var(--columns, 3), minmax(0, 1fr)); gap: 8px; }
.radio-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  background-color: var(--bg-elevated);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  cursor: pointer;
  transition: box-shadow var(--dur-1) var(--ease-out), background-color var(--dur-1) var(--ease-out);
}
.radio-card:hover { background-image: var(--wash-hover); }
.radio-card.is-checked { box-shadow: inset 0 0 0 1.5px var(--accent), 0 0 0 3px var(--accent-tint); }
.radio-card.is-disabled { opacity: .5; cursor: not-allowed; }
.radio-card:has(.radio-card-input:focus-visible) { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.radio-card-input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card-preview { display: block; overflow: hidden; border-radius: var(--radius-md); }
.radio-card-body { display: grid; gap: 2px; padding-right: 18px; }
.radio-card-title { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 18px; font-weight: 500; }
.radio-card-title svg { color: var(--text-3); }
.radio-card-description { font-size: 12px; line-height: 16px; color: var(--text-3); }
.radio-card-badge { margin-left: auto; }
.radio-card-dot { position: absolute; right: 10px; bottom: 12px; width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--border-strong); transition: box-shadow var(--dur-2) var(--ease-out); }
.radio-card.is-checked .radio-card-dot { box-shadow: inset 0 0 0 4px var(--accent); }

/* ---------- Inputs ---------- */
.input {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--control-md);
  min-width: 0;
  padding: 0 10px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  transition: box-shadow var(--dur-1) var(--ease-out);
}
.input:hover:not(.is-disabled) { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--border-strong), var(--text) 12%); }
.input:focus-within { box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 3px var(--accent-tint); }
.input.is-invalid { box-shadow: inset 0 0 0 1px var(--danger); }
.input.is-invalid:focus-within { box-shadow: inset 0 0 0 1px var(--danger), 0 0 0 3px var(--danger-tint); }
.input.is-disabled { opacity: .55; }
.input-sm { height: var(--control-sm); padding: 0 8px; border-radius: var(--radius-sm); }
.input-lg { height: var(--control-lg); }
.input-lg .input-control { font-size: 14px; }
.input-control { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; font-size: 13px; color: var(--text); }
.input-control:focus-visible { outline: none; }
.input-control::placeholder, .textarea::placeholder { color: var(--text-4); }
.input-icon { color: var(--text-3); }
.input-suffix { color: var(--text-3); font-size: 12px; flex-shrink: 0; }
.search-field .input-control::-webkit-search-cancel-button { display: none; }
.search-field-clear { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--bg-active); color: var(--text-2); flex-shrink: 0; }
.search-field-clear:hover { color: var(--text); }
.textarea {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  font-size: 13px;
  line-height: 20px;
  color: var(--text);
  resize: vertical;
  outline: none;
  transition: box-shadow var(--dur-1) var(--ease-out);
}
.textarea.is-autosize { resize: none; }
.textarea:focus { box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 3px var(--accent-tint); }
.textarea.is-invalid { box-shadow: inset 0 0 0 1px var(--danger); }
.field { display: grid; gap: 6px; min-width: 0; }
.field-inline { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.field-label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--text); }
.field-description { font-size: 12px; line-height: 16px; color: var(--text-3); }
.field-error { font-size: 12px; line-height: 16px; color: var(--danger-ink); }

/* ---------- Badge / avatar / status ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  line-height: 14px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-sm { height: 18px; padding: 0 4px; }
.badge-neutral { background: var(--bg-subtle); color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border); }
.badge-accent { background: var(--accent-tint); color: var(--accent-ink); }
.badge-success { background: var(--success-tint); color: var(--success-ink); }
.badge-warning { background: var(--warning-tint); color: var(--warning-ink); }
.badge-danger { background: var(--danger-tint); color: var(--danger-ink); }
.badge-info { background: var(--info-tint); color: var(--info-ink); }
.badge-outline { box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text-2); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.avatar { display: inline-grid; place-items: center; flex-shrink: 0; overflow: hidden; border-radius: 50%; background: var(--accent-tint-2); color: var(--accent-ink); font-weight: 600; line-height: 1; letter-spacing: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.status-dot { display: inline-block; width: 8px; height: 8px; flex-shrink: 0; border-radius: 50%; background: transparent; }
.status-running { background: var(--accent); --pulse-color: var(--accent-tint-2); animation: bramble-pulse 1.8s var(--ease-out) infinite; }
.status-approval { background: var(--warning); }
.status-error { background: var(--danger); }
.status-unread { width: 6px; height: 6px; background: var(--accent); }
.status-idle { box-shadow: inset 0 0 0 1.25px var(--text-4); width: 6px; height: 6px; }
.status-done { background: var(--success); }

/* ---------- Skeleton / spinner / meter ---------- */
.skeleton {
  display: block;
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--bg-active) 37%, var(--bg-subtle) 63%);
  background-size: 400% 100%;
  animation: bramble-skeleton 1.4s ease infinite;
}
.skeleton-lines { display: grid; width: 100%; }
.spinner { display: inline-grid; place-items: center; flex-shrink: 0; color: currentColor; }
.spinner svg { animation: bramble-spin .8s linear infinite; }
.meter-wrap { display: grid; gap: 6px; min-width: 0; }
.meter-labels { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; line-height: 16px; color: var(--text-3); }
.meter { position: relative; height: 4px; overflow: hidden; border-radius: var(--radius-full); background: var(--bg-active); }
.meter-sm { height: 3px; }
.meter-lg { height: 6px; }
.meter-fill { position: absolute; inset: 0; transform-origin: left center; border-radius: inherit; background: var(--accent); transition: transform var(--dur-3) var(--ease-out); }
.meter-success .meter-fill { background: var(--success); }
.meter-warning .meter-fill { background: var(--warning); }
.meter-danger .meter-fill { background: var(--danger); }
.progress { position: relative; height: 2px; overflow: hidden; border-radius: var(--radius-full); background: var(--bg-active); }
.progress-fill { position: absolute; inset: 0; transform-origin: left center; background: var(--accent); transition: transform var(--dur-3) var(--ease-out); }
.progress.is-indeterminate .progress-fill { width: 40%; background: var(--berry-gradient); animation: bramble-indeterminate 1.2s var(--ease-in-out) infinite; }
@keyframes bramble-indeterminate { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* ---------- Empty state ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 40px 24px; }
.empty-state-sm { padding: 20px 12px; gap: 4px; }
.empty-state-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  border-radius: var(--radius-lg);
  color: var(--text-2);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-1);
}
.empty-state-sm .empty-state-icon { width: 32px; height: 32px; border-radius: var(--radius-md); margin-bottom: 4px; }
.empty-state-title { font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: -0.006em; color: var(--text); }
.empty-state-description { max-width: 40ch; font-size: 13px; line-height: 20px; color: var(--text-2); text-wrap: pretty; }
.empty-state-sm .empty-state-title { font-size: 13px; line-height: 18px; }
.empty-state-sm .empty-state-description { font-size: 12px; line-height: 18px; color: var(--text-3); }
.empty-state-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }

/* ---------- Divider / card / key-value / scroll ---------- */
.divider { background: var(--border); flex-shrink: 0; }
.divider-horizontal { height: 1px; width: 100%; }
.divider-vertical { width: 1px; align-self: stretch; min-height: 16px; }
.divider-label { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-3); }
.divider-label::before, .divider-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.card { background: var(--bg-elevated); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.card-pad-sm { padding: 12px; }
.card-pad-md { padding: 16px; }
.card-pad-lg { padding: 20px; }
.card-pad-none { padding: 0; }
.card.is-interactive { cursor: pointer; transition: box-shadow var(--dur-1) var(--ease-out), background-color var(--dur-1) var(--ease-out); }
.card.is-interactive:hover { background-image: var(--wash-hover); }
.card.is-selected { box-shadow: inset 0 0 0 1.5px var(--accent), 0 0 0 3px var(--accent-tint); }
.key-value { display: grid; margin: 0; }
.key-value-row { display: grid; grid-template-columns: minmax(84px, 112px) minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 5px 0; }
.key-value.is-dense .key-value-row { padding: 3px 0; }
.key-value dt { font-size: 12px; line-height: 18px; color: var(--text-3); }
.key-value dd { margin: 0; font-size: 13px; line-height: 18px; color: var(--text); }
.key-value dd.t-mono { font-size: 12px; }
.scroll-area { min-height: 0; }

/* ---------- Toast ---------- */
.toast-viewport { position: fixed; right: 16px; bottom: 16px; z-index: var(--z-toast); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
/* While a dialog or sheet is open, lift toasts above its footer so they never cover the primary action. */
body:has([role="dialog"][aria-modal="true"]) .toast-viewport { bottom: 80px; }
.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 360px;
  max-width: calc(100vw - 32px);
  padding: 12px 10px 12px 14px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  animation: bramble-toast-in var(--dur-3) var(--ease-out) both;
}
.toast[data-state="closed"] { animation: bramble-toast-out var(--dur-2) var(--ease-in-out) both; }
.toast-icon { margin-top: 2px; color: var(--text-3); flex-shrink: 0; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }
.toast-text { flex: 1; min-width: 0; }
.toast-title { font-size: 13px; line-height: 20px; font-weight: 500; overflow-wrap: anywhere; }
.toast-description { margin-top: 2px; font-size: 12px; line-height: 16px; color: var(--text-2); overflow-wrap: anywhere; }
.toast-action { height: 24px; padding: 0 8px; margin-top: -1px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; color: var(--accent-ink); background: var(--accent-tint); flex-shrink: 0; transition: background-color var(--dur-1) var(--ease-out); }
.toast-action:hover { background: var(--accent-tint-2); }
.toast-close { display: grid; place-items: center; width: 22px; height: 22px; margin-top: -1px; border-radius: var(--radius-sm); color: var(--text-3); flex-shrink: 0; }
.toast-close:hover { background: var(--bg-hover); color: var(--text); }
.toast-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--border-strong); transform-origin: left center; animation-name: bramble-progress; animation-timing-function: linear; animation-fill-mode: forwards; }

/* ---------- Code & diff ---------- */
.code-block { margin: 12px 0; overflow: hidden; border-radius: var(--radius-lg); background: var(--code-bg); box-shadow: inset 0 0 0 1px var(--border); }
.code-block-header { display: flex; align-items: center; justify-content: space-between; height: 32px; padding: 0 6px 0 12px; border-bottom: 1px solid var(--border); }
.code-block-language { font: 500 11px/14px var(--font-mono); color: var(--text-3); }
.code-block-pre { margin: 0; padding: 10px 12px; overflow: auto; font: 12px/19px var(--font-mono); white-space: pre; tab-size: 2; color: var(--text); }
.code-block-pre.is-wrapped { white-space: pre-wrap; overflow-wrap: anywhere; }
.code-block-pre code { font: inherit; }
.copy-button { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 6px; border-radius: var(--radius-sm); font-size: 12px; color: var(--text-3); transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out); }
.copy-button:hover { background: var(--bg-hover); color: var(--text); }
.copy-button.is-copied { color: var(--success-ink); }
.diff-view { overflow: hidden; border-radius: var(--radius-lg); background: var(--bg-elevated); box-shadow: inset 0 0 0 1px var(--border); }
.diff-header { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--bg-subtle); font-size: 12px; color: var(--text-3); }
.diff-path { flex: 1; font-family: var(--font-mono); color: var(--text); }
.diff-stat { display: inline-flex; gap: 6px; font-family: var(--font-mono); }
.diff-stat-add { color: var(--diff-add-text); }
.diff-stat-del { color: var(--diff-del-text); }
.diff-body { overflow: auto; padding: 4px 0; font: 12px/19px var(--font-mono); }
.diff-row { display: grid; grid-template-columns: 38px 38px 16px auto; min-width: 100%; width: max-content; }
.diff-no { padding: 0 6px; text-align: right; color: var(--text-3); opacity: .7; user-select: none; }
.diff-sign { text-align: center; user-select: none; }
.diff-text { padding-right: 16px; white-space: pre; }
.diff-add { background: var(--diff-add); }
.diff-add .diff-sign { color: var(--diff-add-text); }
.diff-del { background: var(--diff-del); }
.diff-del .diff-sign { color: var(--diff-del-text); }
.diff-hunk { background: var(--info-tint); color: var(--text-3); }

/* ---------- Resize handle ---------- */
.resize-handle { position: absolute; top: 0; bottom: 0; z-index: var(--z-chrome); width: 9px; cursor: col-resize; touch-action: none; }
.resize-handle-right { right: -5px; }
.resize-handle-left { left: -5px; }
.resize-handle::after { content: ""; position: absolute; top: 0; bottom: 0; left: 4px; width: 1px; background: transparent; transition: background-color var(--dur-1) var(--ease-out); }
.resize-handle:hover::after, .resize-handle:focus-visible::after { background: var(--accent); }
.resize-handle:focus-visible { outline: none; }
:root[data-resizing] * { cursor: col-resize !important; user-select: none !important; }

/* ---------- Marks ---------- */
.provider-mark { flex-shrink: 0; }
.provider-mark-codex { color: var(--provider-codex); }
.provider-mark-claude { color: var(--provider-claude); }
.provider-mark-demo { color: var(--text-3); }
.vendor-mark {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 28%;
  background: var(--bg-subtle);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  color: var(--text);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.vendor-mark-bramble, .vendor-mark-bramble-cloud { background: var(--berry-gradient); box-shadow: none; color: #FFFFFF; }
.vendor-mark-fal { background: #18171D; color: #FFFFFF; box-shadow: none; }
.vendor-mark-google { background: var(--bg-elevated); color: var(--info); }
.vendor-mark-higgsfield { background: var(--bg-elevated); color: var(--text); }
:root[data-theme="dark"] .vendor-mark-fal { background: #EDEDF1; color: #111114; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .vendor-mark-fal { background: #EDEDF1; color: #111114; } }
.bramble-mark { flex-shrink: 0; color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .skeleton, .status-running, .progress.is-indeterminate .progress-fill { animation: none; }
  .spinner svg { animation-duration: 1.6s; }
}
:root[data-reduce-motion="true"] .skeleton, :root[data-reduce-motion="true"] .status-running, :root[data-reduce-motion="true"] .progress.is-indeterminate .progress-fill { animation: none; }
