/* Avatar (shared IconButton-style atom — web/js/atoms/avatar.js) */
.avatar-wrap { display: inline-flex; position: relative; flex-shrink: 0; }
.avatar-initials, .avatar-photo { border-radius: 50%; }
.avatar-initials {
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}
.avatar-photo { object-fit: cover; display: block; }

/* Badge */
.badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 100px;
  font-size: 12px; font-weight: 600;
}
.badge.green { background: rgba(52,199,89,0.15); color: #34C759; }
.badge.orange { background: rgba(255,149,0,0.15); color: #FF9500; }
.badge.red { background: rgba(255,59,48,0.15); color: #FF3B30; }
.badge.blue { background: rgba(0,122,255,0.15); color: #007AFF; }
.badge.purple { background: rgba(175,82,222,0.15); color: #AF52DE; }
.badge.gray { background: rgba(142,142,147,0.15); color: var(--text2); }

/* ── Buttons ──────────────────────────────────────────────────────────
   Sizes:    .btn-xs (28px), .btn-sm (32px), .btn (36px / default),
             .btn-lg (44px), .btn-xl (52px)
   Variants: .btn-primary, .btn-secondary, .btn-ghost, .btn-danger
   States:   .is-loading, [disabled], aria-disabled
   Mobile:   on touch devices, .btn auto-bumps to ≥44px height (iOS comfort) */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap-min);
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-decoration: none;   /* `<a class="btn">` must not show the default link underline */
  transition: background var(--transition-fast),
              color var(--transition-fast),
              border-color var(--transition-fast),
              box-shadow var(--transition-fast),
              transform 80ms var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { text-decoration: none; }
.btn[disabled], .btn[aria-disabled="true"], .btn.is-disabled {
  background: var(--disabled-bg) !important;
  color: var(--disabled-fg) !important;
  border-color: transparent !important;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none !important;
  transform: none !important;
}
.btn.is-loading {
  color: transparent !important;
  pointer-events: none;
  cursor: wait;
}
.btn.is-loading::after {
  content: ''; position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.65s linear infinite;
  color: var(--text);
}
.btn-primary.is-loading::after,
.btn-danger.is-loading::after { color: #fff; }

/* Variants */
.btn-primary {
  background: var(--accent-bg);
  color: #fff;
  font-weight: var(--weight-bold);  /* AA contrast for white-on-accent at any size */
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.btn-secondary {
  background: var(--input-bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-danger {
  background: rgba(255,59,48,0.12);
  color: var(--red);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
.btn-success {
  background: rgba(52,199,89,0.14);
  color: var(--green-text);
}

/* Hover only on devices that actually have hover */
@media (hover: hover) {
  .btn-primary:hover:not([disabled]):not(.is-loading) {
    background: var(--accent-bg-hover);
    box-shadow: 0 2px 6px rgba(0,122,255,0.28);
  }
  .btn-secondary:hover:not([disabled]):not(.is-loading) { background: var(--hover-bg); }
  .btn-danger:hover:not([disabled]):not(.is-loading)    { background: rgba(255,59,48,0.20); }
  .btn-ghost:hover:not([disabled]):not(.is-loading)     { background: var(--hover-bg); }
  .btn-success:hover:not([disabled]):not(.is-loading)   { background: rgba(52,199,89,0.22); }
}
.btn-primary:active:not([disabled]):not(.is-loading)   { background: #004fb0; color: #fff; }
.btn-secondary:active:not([disabled]):not(.is-loading) { background: var(--press-bg); }
.btn-ghost:active:not([disabled]):not(.is-loading)     { background: var(--hover-bg); }

/* Sizes — keep existing .btn-sm and .btn-xs hooks usable everywhere */
.btn-xs { min-height: 28px; padding: 4px 10px; font-size: var(--text-xs); border-radius: var(--radius-xs); gap: 4px; }
.btn-sm { min-height: 32px; padding: 6px 12px; font-size: var(--text-sm); gap: 4px; }
.btn-lg { min-height: 44px; padding: 12px 22px; font-size: var(--text-md); }
.btn-xl { min-height: 52px; padding: 16px 28px; font-size: var(--text-lg); }
.btn-block { display: flex; width: 100%; }

/* Icon-button variant: square hit zone, ≥36px on touch */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: var(--tap-min); min-height: var(--tap-min);
  padding: 6px 10px;
  background: var(--input-bg); color: var(--text2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  font-family: inherit;
  transition: background var(--transition-fast), color var(--transition-fast),
              transform 80ms var(--ease-out);
}
@media (hover: hover) {
  .btn-icon:hover:not([disabled]) { background: var(--hover-bg); color: var(--text); }
}
.btn-icon:active:not([disabled]) { background: var(--press-bg); }
.btn-icon[disabled], .btn-icon.is-disabled {
  background: var(--disabled-bg); color: var(--disabled-fg); cursor: not-allowed;
}

/* Bare icon-only chips — no surface, just hit zone (used in card overflow) */
.btn-iconbare {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap-min); height: var(--tap-min);
  padding: 0;
  background: transparent; color: var(--text2);
  border: 0; border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
@media (hover: hover) {
  .btn-iconbare:hover:not([disabled]) { background: var(--hover-bg); color: var(--text); }
}
.btn-iconbare:active:not([disabled]) { background: var(--press-bg); }
.btn-iconbare svg { width: var(--icon-md); height: var(--icon-md); }

/* Selected / toggle state — pressed treatment matches draw.css's prior
   .draw-tool-btn.active, now generalized. Repeated as an explicit :hover
   override too: the plain :hover rules above are `.btn-icon:hover:not(...)`
   (specificity 0,3,0), which would otherwise beat a bare
   `[aria-pressed="true"]` (0,2,0) and make a selected control look
   unselected the moment the pointer sits over it. */
.btn-icon[aria-pressed="true"], .btn-icon.is-selected,
.btn-iconbare[aria-pressed="true"], .btn-iconbare.is-selected {
  background: var(--accent);
  color: #fff;
}
.btn-icon[aria-pressed="true"]:hover:not([disabled]), .btn-icon.is-selected:hover:not([disabled]),
.btn-iconbare[aria-pressed="true"]:hover:not([disabled]), .btn-iconbare.is-selected:hover:not([disabled]) {
  background: var(--accent);
  color: #fff;
}

/* Loading state — icon is swapped for the spinner glyph by the caller;
   this just disables interaction and marks the a11y state. */
.btn-icon.is-loading, .btn-iconbare.is-loading {
  pointer-events: none;
  opacity: .7;
}

.close-btn { /* marker only — sizing/state come from .btn-icon/.btn-iconbare */ }

/* ── Toast ────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: max(16px, calc(var(--safe-bottom) + 12px));
  right:  max(16px, calc(var(--safe-right)  + 12px));
  left:   auto;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
}
/* Keep toasts (Saved, Undo…) above an open on-screen keyboard. */
html.kb-open .toast-container { bottom: calc(var(--kb-inset, 0px) + 12px); }
.toast {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  padding: 12px 14px 12px 16px;
  min-width: 260px;
  max-width: min(420px, calc(100vw - 32px));
  display: flex; align-items: flex-start; gap: 12px;
  transform: translateX(120%);
  opacity: 0;
  transition: transform var(--transition-slow) var(--ease-spring),
              opacity var(--transition-base);
  border-left: 3px solid var(--accent);
  pointer-events: auto;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.error   { border-left-color: var(--error); }
.toast.info    { border-left-color: var(--info); }

.toast-icon {
  flex-shrink: 0;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.toast.success .toast-icon { color: var(--success); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.error   .toast-icon { color: var(--error); }
.toast-icon svg { width: 22px; height: 22px; }

.toast-body { flex: 1; min-width: 0; }
.toast-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text);
  line-height: var(--leading-snug);
}
.toast-msg {
  font-size: var(--text-sm);
  color: var(--text2);
  margin-top: 2px;
  line-height: var(--leading-snug);
  word-wrap: break-word;
}
/* Sizing/color/hover/press now come from .btn-iconbare (shared IconButton
   foundation) — only the toast-specific offset stays here. */
.toast-close {
  flex-shrink: 0;
  margin: -2px -2px 0 0;
}

/* Dedup count badge — appears on a toast that's been re-fired */
.toast-count {
  position: absolute;
  top: -6px; right: -6px;
  font-size: 10px;
  font-weight: var(--weight-bold);
  background: var(--accent-bg);
  color: #fff;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
  border: 2px solid var(--card);
  pointer-events: none;
}
.toast { position: relative; }
@keyframes toast-bump-anim {
  0%   { transform: translateX(0) scale(1); }
  40%  { transform: translateX(0) scale(1.04); }
  100% { transform: translateX(0) scale(1); }
}
.toast.toast-bumped { animation: toast-bump-anim 0.32s var(--ease-out); }

@media (max-width: 699px) {
  .toast-container {
    left: max(12px, var(--safe-left));
    right: max(12px, var(--safe-right));
    max-width: none;
  }
  /* Slide up from below on mobile so the toast doesn't clip the right edge
     when the viewport is narrow — a single transform with translateY is more
     forgiving than translateX(120%) which can leave a horizontal scrollbar. */
  .toast {
    min-width: 0;
    max-width: 100%;
    transform: translateY(140%);
  }
  .toast.show { transform: translateY(0); }
}

/* Info icon tooltip */
.info-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; background: var(--text3);
  color: var(--card); font-size: 11px; font-weight: 700; cursor: help;
  margin-left: 6px; position: relative; transition: all 0.2s ease;
}
.info-icon:hover,
.info-icon.tooltip-open { background: var(--accent); transform: scale(1.1); }
/* Tooltip content is read by JS portal — hidden from normal flow */
.info-icon .info-tooltip { display: none; }

/* Tooltip portal — appended to <body>, never clipped by overflow */
.tooltip-portal {
  position: fixed; pointer-events: none; z-index: 9999;
  transform: translateX(-50%);
  background: var(--text); color: var(--card);
  padding: 8px 12px; border-radius: 8px;
  font-size: 12px; font-weight: 400; line-height: 1.5;
  max-width: 220px; text-align: left; white-space: normal;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  opacity: 0; transition: opacity 0.15s;
}
.tooltip-portal.visible { opacity: 1; }

/* ── Form inputs ──────────────────────────────────────────────────────
   Sizes:    .input-sm (32px), .input (36px / default), .input-lg (44px)
   States:   :focus, :disabled, .is-error, .is-success, [readonly]
   Helpers:  .input-label, .input-help, .input-error-text */
.input {
  width: 100%;
  min-height: var(--tap-min);
  padding: 9px 12px;
  font-size: var(--text-base);
  font-family: inherit;
  line-height: var(--leading-snug);
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast),
              background var(--transition-fast);
}
.input:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
  background: var(--bg-elev, var(--card));
}
.input::placeholder { color: var(--text3); }
.input:disabled, .input.is-disabled {
  background: var(--disabled-bg);
  color: var(--disabled-fg);
  cursor: not-allowed;
  border-color: transparent;
}
.input[readonly] {
  background: var(--disabled-bg);
  cursor: default;
}
.input.is-error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(255,59,48,0.18);
}
.input.is-success {
  border-color: var(--success);
}

select.input {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 32px; cursor: pointer;
}
textarea.input {
  resize: vertical;
  line-height: var(--leading-normal);
  min-height: 80px;
}

/* Sizes */
.input-sm { min-height: 32px; padding: 6px 10px; font-size: var(--text-sm); }
select.input.input-sm { padding-right: 28px; background-position: right 8px center; }
.input-lg { min-height: 44px; padding: 11px 14px; font-size: var(--text-md); }

/* Form helpers */
.input-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
  margin-bottom: 6px;
}
.input-label .req { color: var(--error); margin-left: 2px; }
.input-help {
  font-size: var(--text-xs);
  color: var(--text2);
  margin-top: 4px;
  line-height: var(--leading-snug);
}
.input-error-text {
  font-size: var(--text-xs);
  color: var(--error);
  margin-top: 4px;
  line-height: var(--leading-snug);
  display: flex; align-items: center; gap: 4px;
}
.input-group {
  display: flex; flex-direction: column; gap: 4px;
}

/* Native checkbox / radio polish — token-aware sizing */
input[type="checkbox"], input[type="radio"] {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
/* An unchecked native box renders as a bright white square on a dark
   surface unless the control itself is told the scheme — the loudest thing
   in every list row that carries one (Git, Notes selection). */
[data-theme="dark"] input[type="checkbox"], [data-theme="dark"] input[type="radio"] { color-scheme: dark; }

/* One checkbox, drawn from tokens, in every theme and browser. The native
   box looked different per theme and per engine (a pale system square in
   light, a grey one in dark, Safari's own rounding on iPad) beside the
   app's own selected-card outline. Size still comes from each component's
   width/height; this only draws the box and the tick. */
input[type="checkbox"] {
  -webkit-appearance: none; appearance: none; margin: 0; flex: none;
  display: inline-grid; place-content: center; vertical-align: middle;
  border: 1.5px solid color-mix(in srgb, var(--text3) 75%, transparent);
  border-radius: 5px; background: var(--input-bg, var(--card));
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
input[type="checkbox"]::before {
  content: ""; width: 62%; height: 62%;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background: #fff; transform: scale(0); transition: transform 0.12s ease;
}
input[type="checkbox"]:checked,
input[type="checkbox"]:indeterminate { background: var(--accent-bg, var(--accent)); border-color: var(--accent-bg, var(--accent)); }
input[type="checkbox"]:checked::before { transform: scale(1); }
input[type="checkbox"]:indeterminate::before { clip-path: inset(40% 10% 40% 10%); transform: scale(1); }
input[type="checkbox"]:hover:not(:disabled) { border-color: var(--accent); }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="checkbox"]:disabled { opacity: 0.5; cursor: default; }
@media (max-width: 699px) {
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }
}

/* Segmented button group (for Type / Priority pickers) */
.seg-group { display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn {
  flex: 1; padding: 7px 0; font-size: 13px; font-weight: 500; font-family: inherit;
  background: var(--input-bg); color: var(--text2); border: none; border-right: 1px solid var(--border);
  cursor: pointer; transition: background 0.12s, color 0.12s; text-align: center;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--hover-bg); color: var(--text); }
/* TASK-031: --accent (#007AFF) is tuned for borders/icons/focus rings per
   its own variables.css comment, not as a white-text button fill — axe
   measured 4.01:1 here (need 4.5:1), on every seg-btn toggle across the app.
   --accent-bg is the token this codebase already keeps for exactly that
   ("primary button bg — same as light, white text passes AA"). */
.seg-btn.active { background: var(--accent-bg); color: #fff; font-weight: 600; }
.seg-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.seg-btn:disabled:hover { background: var(--input-bg); color: var(--text2); }

/* ── Empty state ──────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--text2);
  gap: var(--space-3);
  max-width: 520px;
  margin: 0 auto;
}
.empty-state .es-icon {
  width: 72px; height: 72px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, rgba(var(--accent-rgb),0.10), rgba(var(--accent-rgb),0.02));
  border-radius: var(--radius-lg);
  color: var(--accent);
  margin-bottom: var(--space-2);
}
.empty-state .es-icon svg { width: 36px; height: 36px; opacity: 1; margin: 0; }
.empty-state .es-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--text);
  letter-spacing: var(--tracking-tight);
}
.empty-state .es-desc {
  font-size: var(--text-base);
  color: var(--text2);
  line-height: var(--leading-relaxed);
  max-width: 440px;
}
.empty-state .es-actions {
  display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: center;
  margin-top: var(--space-3);
}
/* Legacy empty-state markup (just <p> + optional svg) keeps working */
.empty-state > svg:first-child {
  width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.3;
}
.empty-state > p { font-size: var(--text-md); }

/* Tone modifiers for feedbackStateHtml() (web/js/atoms/emptyState.js) — AA-safe
   `--*-text` foreground tokens only, never the vivid fill tokens as text/icon
   color (see docs/design-system.md §1). `tone: 'neutral'` (the default) omits
   this class entirely and keeps the base `.es-icon` accent color. */
.es-tone-info    .es-icon { color: var(--accent-text); }
.es-tone-warn    .es-icon { color: var(--orange-text); }
.es-tone-danger  .es-icon { color: var(--red-text); }
.es-tone-success .es-icon { color: var(--green-text); }

/* ── Skeleton loaders (app-wide) ────────────────────────────────────────
   Use these any time a view fetches data. Render a skeleton that
   matches the final layout's dimensions so the page doesn't jump when
   data arrives. See docs in CLAUDE.md → "UI: Loading states".
   ────────────────────────────────────────────────────────────────────── */
.skel {
  background: linear-gradient(90deg,
    var(--input-bg) 25%,
    var(--hover-bg) 50%,
    var(--input-bg) 75%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
  display: block;
}
@keyframes skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
/* Shape variants */
.skel-block { display: block; }
.skel-inline { display: inline-block; }
.skel-pill   { display: inline-block; height: 30px; border-radius: 999px; }
.skel-chip   { display: inline-block; height: 24px; border-radius: 999px; }
.skel-chart  { width: 100%; height: 180px; border-radius: 8px; }
.skel-row    { height: 14px; border-radius: 4px; }
.skel-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
/* Stop shimmer motion for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .skel { animation: none; background: var(--input-bg); }
}

/* Canonical indeterminate spinner — the shared primitive new call sites
   should use instead of a bespoke per-view spinner class. Slows rather than
   freezes under reduced motion (unlike a shimmer/fill, an indeterminate
   spinner has no "final state" to snap to). */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .65s linear infinite;
}
.spinner-sm { width: 14px; height: 14px; }
.spinner-lg { width: 20px; height: 20px; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.4s; } }

/* Loading spinner item */
.rn-item-loading {
  padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 4px;
  background: var(--accent); color: #fff; display: flex; align-items: center; gap: 10px;
}
.rn-item-loading .rn-spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0;
}
.rn-item-loading .rn-item-version { font-size: 15px; font-weight: 600; }
.rn-item-loading .rn-item-meta { font-size: 12px; color: rgba(255,255,255,0.7); margin-top: 2px; }
