/* ============================================================
   ui-polish.css
   ------------------------------------------------------------
   Cross-cutting UX polish:
     .palette-overlay / .palette / .palette__*
     .shortcuts-overlay / .shortcuts / .shortcuts__*
     .nva-toast
     .empty-state / .empty-state__*
     .skeleton / .skeleton__*
     .sr-only, .skip-link (refined), focus-visible defaults
   ============================================================ */

/* ── Screen-reader only (used by announcer + utility) ── */
.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 default (overrides UA ring with token) ── */
:where(button, a, [role="button"], input, textarea, select):focus-visible {
  outline: 2px solid var(--color-focus, var(--color-primary, #2563eb));
  outline-offset: 2px;
  border-radius: var(--radius-sm, 6px);
}

/* ── Command palette ──────────────────────────── */
.palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: start center;
  padding: 10vh 1rem 1rem;
  z-index: 60;
  overflow: auto;
}
.palette-overlay[hidden] { display: none; }

.palette {
  width: min(640px, 100%);
  max-height: min(70vh, 560px);
  background: var(--color-surface, #fff);
  border-radius: var(--radius-lg, 14px);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.35);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid var(--color-border, #e5e7eb);
}

.palette__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
}
.palette__icon {
  font-size: 1rem;
  color: var(--color-text-muted, #6b7280);
  width: 1.4rem;
  text-align: center;
}
.palette__input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 0.95rem;
  padding: 0.25rem 0.1rem;
  color: var(--color-text, #111827);
  font-family: inherit;
}
.palette__input::placeholder {
  color: var(--color-text-muted, #9ca3af);
}
.palette__esc {
  font-size: 0.6875rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 0.35rem;
  color: var(--color-text-muted, #6b7280);
  background: var(--color-surface-alt, #fafbfc);
}

.palette__list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  overflow: auto;
  max-height: 60vh;
}
.palette__group {
  padding: 0.55rem 0.9rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted, #6b7280);
}
.palette__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  color: var(--color-text, #111827);
  line-height: 1.4;
  user-select: none;
}
.palette__item[aria-selected="true"] {
  background: color-mix(in oklab, var(--color-primary, #2563eb) 10%, #fff);
  color: var(--color-primary, #2563eb);
}
.palette__label {
  font-size: 0.875rem;
  font-weight: 600;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette__hint {
  color: var(--color-text-muted, #6b7280);
  font-size: 0.75rem;
  flex: 0 1 auto;
}
.palette__hotkey {
  font-family: var(--font-mono, ui-monospace, Menlo, monospace);
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 0.35rem;
  color: var(--color-text-muted, #6b7280);
  background: var(--color-surface-alt, #fafbfc);
  flex: 0 0 auto;
}
.palette__empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--color-text-muted, #6b7280);
  font-style: italic;
}
.palette__foot {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  padding: 0.5rem 0.9rem;
  border-top: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-surface-alt, #fafbfc);
  font-size: 0.75rem;
  color: var(--color-text-muted, #6b7280);
}
.palette__foot kbd {
  font-size: 0.6875rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 0.3rem;
  background: var(--color-surface, #fff);
  color: var(--color-text, #111827);
  margin: 0 0.1rem;
}

/* ── Shortcut help ─────────────────────────────── */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 65;
  overflow: auto;
}
.shortcuts-overlay[hidden] { display: none; }
.shortcuts {
  width: min(520px, 100%);
  background: var(--color-surface, #fff);
  border-radius: var(--radius-lg, 14px);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  border: 1px solid var(--color-border, #e5e7eb);
}
.shortcuts__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
}
.shortcuts__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-text, #111827);
}
.shortcuts__close {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
  color: var(--color-text-muted, #6b7280);
}
.shortcuts__close:hover {
  background: var(--color-surface-alt, #fafbfc);
  color: var(--color-text, #111827);
}
.shortcuts__list {
  margin: 0;
  padding: 0.5rem 0;
}
.shortcuts__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 1rem;
}
.shortcuts__row + .shortcuts__row {
  border-top: 1px dashed var(--color-border, #e5e7eb);
}
.shortcuts__row dt {
  font-weight: 600;
  color: var(--color-text, #111827);
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex: 0 0 auto;
}
.shortcuts__row dd {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted, #6b7280);
  text-align: right;
}
.shortcuts kbd {
  font-family: var(--font-mono, ui-monospace, Menlo, monospace);
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-bottom-width: 2px;
  border-radius: 0.35rem;
  background: var(--color-surface-alt, #fafbfc);
  color: var(--color-text, #111827);
  margin: 0 0.1rem;
}
.shortcuts__or {
  font-size: 0.6875rem;
  color: var(--color-text-muted, #6b7280);
  font-weight: 500;
  padding: 0 0.2rem;
}

/* ── Toast ─────────────────────────────────────── */
.nva-toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0) + 1.5rem);
  transform: translate(-50%, 1rem);
  background: var(--color-text, #111827);
  color: #fff;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 70;
  max-width: min(560px, calc(100vw - 2rem));
}
.nva-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.nva-toast[data-kind="error"]   { background: var(--color-danger, #dc2626); }
.nva-toast[data-kind="success"] { background: var(--color-success, #16a34a); }
.nva-toast[data-kind="warn"]    { background: var(--color-warning, #d97706); }

/* ── Empty state ───────────────────────────────── */
.empty-state {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1.25rem;
  border: 1px dashed var(--color-border, #e5e7eb);
  border-radius: var(--radius-lg, 14px);
  background: var(--color-surface-alt, #fafbfc);
  text-align: center;
}
.empty-state__icon {
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 0.25rem;
  filter: grayscale(0.25);
}
.empty-state__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-text, #111827);
}
.empty-state__hint {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted, #6b7280);
  max-width: 36ch;
}
.empty-state__cta {
  margin-top: 0.5rem;
}

/* ── Skeletons ─────────────────────────────────── */
@keyframes nva-skeleton-pulse {
  0%   { opacity: 0.55; }
  50%  { opacity: 0.9;  }
  100% { opacity: 0.55; }
}
.skeleton {
  display: grid;
  gap: 0.75rem;
}
.skeleton--dense { gap: 0.35rem; }
.skeleton__row,
.skeleton__card {
  display: grid;
  gap: 0.45rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 10px);
  background: var(--color-surface, #fff);
}
.skeleton__line {
  height: 0.7rem;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    color-mix(in oklab, var(--color-border, #e5e7eb) 60%, #fff) 0%,
    color-mix(in oklab, var(--color-border, #e5e7eb) 90%, #fff) 50%,
    color-mix(in oklab, var(--color-border, #e5e7eb) 60%, #fff) 100%
  );
  animation: nva-skeleton-pulse 1.4s ease-in-out infinite;
}
.skeleton__line--title { width: 55%; height: 0.9rem; }
.skeleton__line--short { width: 35%; }

/* ── Respect reduced motion everywhere ─────────── */
@media (prefers-reduced-motion: reduce) {
  .skeleton__line { animation: none; }
  .nva-toast { transition: none; }
}

/* ── Narrow screens ────────────────────────────── */
@media (max-width: 560px) {
  .palette-overlay { padding-top: 6vh; }
  .palette__foot   { flex-wrap: wrap; justify-content: flex-start; gap: 0.5rem 1rem; }
  .shortcuts__row  { flex-direction: column; align-items: flex-start; gap: 0.3rem; }
  .shortcuts__row dd { text-align: left; }
}
