/**
 * Keyboard Navigation Styles — Linear v2.
 *
 * Focus indicators, skip link, and the "?" keyboard-help modal. Rebuilt on
 * the global design tokens (design-variables.css) so it tracks light/dark
 * automatically and matches the rest of the app: hairline borders, no
 * gradients, no shadow stacks, and — critically — focus/hover state changes
 * COLOUR ONLY, never geometry (Rule §6a). Focus RINGS (outline + a ring via
 * box-shadow) are kept: those are a11y indicators, not decoration.
 */

:root {
  --keyboard-overlay: hsl(0 0% 0% / 0.55);
  --keyboard-overlay-strong: hsl(0 0% 0% / 0.85);
}

/* ============================================
   SKIP TO CONTENT LINK
   ============================================ */
.skip-to-content {
  position: absolute;
  top: -100px;
  left: 10px;
  z-index: 10000;
  padding: 10px 18px;
  /* Own dark surface, NOT var(--brand-primary). The brand token flips with the
     theme — in dark mode it is a LIGHT purple (#8291F8), so `color: #fff` on it
     measured 2.74:1, under 4.5, on the first element every keyboard user
     reaches. A fixed dark surface is correct in both themes: 14.17:1. Matches
     the .skip-to-content in unified-design.css, which defines the same class. */
  background: hsl(217 33% 17%);
  color: hsl(210 40% 98%);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9375rem;
  transition: top 0.3s ease;
}

/* Page shells reset link colour — the marketing shell has `.mkt a { color:
   inherit }` at specificity (0,1,1), which outranks `.skip-to-content` (0,1,0),
   so the skip link inherited the page's near-black text onto its own dark
   surface: 1.20:1, an invisible label on the first thing a keyboard user
   reaches.

   Re-asserted here at (0,1,2) — `body` + `a` + class. Note the arithmetic:
   `body .skip-to-content` is only (0,1,1), because `body` is an ELEMENT
   selector, not a class — that TIES with `.mkt a` and then loses on source
   order, since marketing_v2.css loads later. Adding the `a` element selector is
   what actually wins. Specificity rather than an override flag,
   on purpose: the project ratchets those in
   tests/test_refactoring_ui_static_audit.py, and a higher-specificity selector
   is also the more robust choice, since an override flag can itself be beaten
   by another one. */
body a.skip-to-content {
  background: hsl(217 33% 17%);
  color: hsl(210 40% 98%);
}

.skip-to-content:focus {
  top: 10px;
  /* The ring must contrast with THIS element's background, not the page. It was
     var(--brand-primary) — the element's own former background colour — so the
     focus ring was invisible against itself (ratio 1.00). Now 5.02:1. */
  outline: 2px solid hsl(234 89% 74%);
  outline-offset: 2px;
}

/* ============================================
   FOCUS INDICATORS  (rings — a11y, not decoration)
   ============================================ */
body.keyboard-navigation-active *:focus {
  outline: 2px solid var(--focus-color, var(--brand-primary));
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--tint-brand-25);
  transition: outline var(--transition-fast), box-shadow var(--transition-fast);
}

body.keyboard-navigation-active button:focus,
body.keyboard-navigation-active a:focus {
  outline: 2px solid var(--focus-color, var(--brand-primary));
  outline-offset: 2px;
}

/* Product grid items — focus = a clear ring, NOT a lift (no transform / no
   shadow-on-state; that was the §6a violation in the old file). */
.product-card:focus,
.storefront-product-card:focus {
  outline: 3px solid var(--focus-color, var(--brand-primary));
  outline-offset: 2px;
}

/* ============================================
   KEYBOARD HELP MODAL
   ============================================ */
.keyboard-help-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.keyboard-help-modal.active {
  opacity: 1;
  pointer-events: all;
}

.keyboard-help-overlay {
  position: absolute;
  inset: 0;
  background: var(--keyboard-overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.keyboard-help-content {
  position: relative;
  background: var(--theme-card-bg);
  color: var(--theme-text);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: 90%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: var(--font-family);
  animation: kbdRise var(--transition-fast) ease;
}

@keyframes kbdRise {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.keyboard-help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-divider);
}

.keyboard-help-header h2 {
  margin: 0;
  font-family: var(--font-family-heading);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--theme-text);
  display: flex;
  align-items: center;
}

.keyboard-help-close {
  background: var(--theme-card-bg);
  border: 1px solid var(--border-subtle);
  color: var(--theme-text-secondary);
  /* 40x40 minimum hit area (UI_DESIGN_RULES §12). */
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.keyboard-help-close:hover {
  background: var(--theme-hover);
  border-color: var(--border-strong);
  color: var(--theme-text);
}

.keyboard-help-close:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

.keyboard-help-body {
  padding: var(--space-6);
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: var(--space-6);
}

.keyboard-help-section h3 {
  font-family: var(--font-family-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 var(--space-3);
  color: var(--theme-text-tertiary);
  border-bottom: 1px solid var(--border-divider);
  padding-bottom: var(--space-2);
}

.keyboard-shortcut {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px 0;
  border-bottom: 1px solid var(--border-divider);
}

.keyboard-shortcut:last-child { border-bottom: none; }

/* Keycaps — flat mono chips (no gradient, no skeuomorphic shadow) */
.keyboard-shortcut kbd,
.keyboard-help-footer kbd {
  background: var(--theme-bg-secondary);
  color: var(--theme-text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px 7px;
  font-family: var(--font-family-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  min-width: 26px;
  text-align: center;
  display: inline-block;
}

.keyboard-shortcut span {
  flex: 1;
  font-size: 0.875rem;
  color: var(--theme-text-secondary);
}

.keyboard-help-footer {
  padding: var(--space-4) var(--space-6);
  background: var(--theme-bg-secondary);
  border-top: 1px solid var(--border-divider);
  text-align: center;
  font-size: 0.8125rem;
  color: var(--theme-text-tertiary);
}

/* ============================================
   TABLE ROW KEYBOARD NAVIGATION
   ============================================ */
body.keyboard-navigation-active tbody tr:focus-within {
  outline: 2px solid var(--focus-color, var(--brand-primary));
  outline-offset: -2px;
  background-color: var(--tint-brand-05);
}

[data-theme="dark"] body.keyboard-navigation-active tbody tr:focus-within {
  background-color: var(--tint-brand-15);
}

body.keyboard-navigation-active tbody tr td input[type="checkbox"]:focus,
body.keyboard-navigation-active tbody tr td a:focus,
body.keyboard-navigation-active tbody tr td button:focus {
  outline: 2px solid var(--focus-color, var(--brand-primary));
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================
   GRID NAVIGATION VISUAL FEEDBACK
   ============================================ */
.product-grid,
.storefront-products-grid,
.products-grid {
  position: relative;
}

/* Navigation hint — neutral tooltip (near-black fill), not a brand gradient */
body.keyboard-navigation-active .product-grid::before,
body.keyboard-navigation-active .storefront-products-grid::before,
body.keyboard-navigation-active .products-grid::before {
  content: 'Use arrow keys to navigate';
  position: absolute;
  top: -38px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--theme-text);
  color: var(--theme-text-inverted);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}

body.keyboard-navigation-active .product-grid:focus-within::before,
body.keyboard-navigation-active .storefront-products-grid:focus-within::before,
body.keyboard-navigation-active .products-grid:focus-within::before {
  opacity: 1;
  animation: fadeInOut 3s ease;
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { opacity: 0; }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .keyboard-help-content { width: 95%; max-height: 95vh; }
  .keyboard-help-body { grid-template-columns: 1fr; padding: var(--space-5); gap: var(--space-5); }
  .keyboard-help-header { padding: var(--space-4) var(--space-5); }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .keyboard-help-modal,
  .keyboard-help-content,
  .skip-to-content,
  .product-card,
  .storefront-product-card {
    transition: none;
    animation: none;
  }
}

@media (prefers-contrast: high) {
  body.keyboard-navigation-active *:focus {
    outline-width: 3px;
    outline-color: currentColor;
  }
  .keyboard-help-overlay { background: var(--keyboard-overlay-strong); }
}
