/**
 * Accessibility (a11y) Styles for Metablox
 * WCAG 2.1 AA Compliance
 */

/* ============================================
   Skip Links
   ============================================ */

.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #fff;
  padding: 12px 24px;
  border-radius: 0 0 8px 8px;
  z-index: 100000;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid #f37442;
  outline-offset: 2px;
}

/* ============================================
   Focus Indicators
   ============================================ */

/* Default focus style for all focusable elements */
:focus {
  outline: 2px solid #f37442;
  outline-offset: 2px;
}

/* Remove default focus for mouse users, keep for keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 3px solid #f37442;
  outline-offset: 2px;
}

/* Button focus states */
button:focus-visible,
[role="button"]:focus-visible,
.btn:focus-visible,
.big-btn:focus-visible {
  outline: 3px solid #f37442;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(243, 116, 66, 0.3);
}

/* Input focus states */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid #f37442;
  outline-offset: 0;
  border-color: #f37442;
}

/* Link focus states */
a:focus-visible {
  outline: 2px solid #f37442;
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================
   Screen Reader Only Content
   ============================================ */

.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;
}

/* Make sr-only content visible when focused (for skip links) */
.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: inherit;
}

/* ============================================
   High Contrast Mode Support
   ============================================ */

@media (prefers-contrast: high) {
  :focus,
  :focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 3px;
  }

  button,
  .btn,
  a {
    border: 2px solid currentColor;
  }
}

/* ============================================
   Reduced Motion Support
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .offline-toast {
    transition: none;
  }
}

/* ============================================
   Navigation Accessibility
   ============================================ */

/* Bottom navigation icons - ensure proper tap targets */
.bottom-nav-icon {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Menu button touch target */
.menu-btn,
.profile-menu-btn {
  min-width: 44px;
}

/* ============================================
   Form Accessibility
   ============================================ */

/* Error messages */
.error-msg {
  color: #d32f2f;
  font-size: 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.error-msg[role="alert"] {
  background: #ffebee;
  padding: 8px 12px;
  border-radius: 4px;
  border-left: 3px solid #d32f2f;
}

/* Valid/success messages */
.valid-msg {
  color: #2e7d32;
  font-size: 12px;
  margin-top: 4px;
}

.valid-msg[role="status"] {
  background: #e8f5e9;
  padding: 8px 12px;
  border-radius: 4px;
  border-left: 3px solid #2e7d32;
}

/* Required field indicator */
.required-field::after {
  content: " *";
  color: #d32f2f;
}

/* Invalid input state */
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: #d32f2f;
  background-color: #fff5f5;
}

input[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus {
  outline-color: #d32f2f;
  box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.2);
}

/* ============================================
   Color Contrast Adjustments
   ============================================ */

/* Ensure links have sufficient contrast */
a:not([class]) {
  color: #c45628;
  text-decoration: underline;
}

a:not([class]):hover {
  color: #f37442;
}

/* Placeholder text - ensure minimum contrast */
::placeholder {
  color: #6b6b6b;
  opacity: 1;
}

/* Disabled states */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled,
[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}

.big-button.disabled {
  border: none;
  outline: none;
  box-shadow: none;
}

/* ============================================
   Interactive Elements
   ============================================ */

/* Ensure clickable elements look clickable */
[role="button"],
[onclick],
[tabindex="0"] {
  cursor: pointer;
}

/* Remove pointer events from disabled elements */
[aria-disabled="true"] {
  pointer-events: none;
}

/* ============================================
   Modal Accessibility
   ============================================ */

/* Trap focus indicator for modals */
[role="dialog"],
[role="alertdialog"] {
  position: relative;
}

[role="dialog"]:focus,
[role="alertdialog"]:focus {
  outline: none;
}

/* ============================================
   Live Regions
   ============================================ */

/* Toast notifications should be announced */
[role="status"],
[role="alert"],
[aria-live] {
  /* Ensure screen readers announce these */
}

/* Loading indicators */
[aria-busy="true"] {
  cursor: wait;
}

/* ============================================
   Icon Buttons
   ============================================ */

/* Icon-only buttons need proper sizing */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.icon-button:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.icon-button:focus-visible {
  outline: 3px solid #f37442;
  outline-offset: 2px;
}

/* Material icons in buttons should not be focusable */
.icon-button .material-icons,
.icon-button .material-icons-outlined {
  pointer-events: none;
}

/* Keep memory actions above the card link and expose a full touch target. */
.memory-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  flex-shrink: 0;
}


/* A11Y-004: the same photo order is available to keyboard and single taps. */
.photo-cover-choice, .photo-order-actions, .photo-upload-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--ds-ink);
  background: var(--ds-card);
}
.photo-cover-choice input[type="radio"] {
  appearance: auto;
  display: inline-block;
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--ds-brand-strong);
}
.photo-order-actions button, .photo-entry button, .photo-upload-actions button,
.moment-playback-controls button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--ds-input-border);
  border-radius: 8px;
  background: var(--ds-card);
  color: var(--ds-ink);
  font: inherit;
  padding: 8px;
  cursor: pointer;
}
.photo-order-actions [aria-disabled="true"] { opacity: .65; cursor: default; }
.photo-upload-actions input[type="file"] { display: block; max-width: 100%; }
.photo-entry:focus-within { scroll-margin-block: 80px; }
.moment-playback-controls {
  position: relative;
  z-index: 12;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  background: var(--ds-card);
  color: var(--ds-ink);
}

.photo-media-editor { padding: 8px 16px; color: var(--ds-ink); background: var(--ds-card); }
.photo-media-editor label, .photo-media-editor textarea { display: block; max-width: 100%; }
.photo-media-editor textarea { width: 100%; min-height: 80px; font: inherit; }

.story-card > .moment-playback-controls { position: absolute; bottom: 72px; left: 0; right: 0; }
.moment-transcript { position: absolute; top: 80px; z-index: 12; max-height: 50%; overflow: auto; background: var(--ds-card); color: var(--ds-ink); padding: 8px; }
.moment-transcript p { white-space: pre-wrap; }


/* Desktop memory photos: a stable preview, grouped actions and one scroll region. */
#create-memory > .memory-photo-panel {
  flex: 0 0 352px;
  width: 352px;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  border-right: 1px solid var(--ds-line);
  background: var(--ds-surface);
  color: var(--ds-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
#create-memory > .memory-story-panel { flex: 1; min-width: 0; }
.memory-photo-panel-header {
  flex: none;
  padding: 24px 24px 16px;
  background: var(--ds-card);
  border-bottom: 1px solid var(--ds-line);
}
.memory-photo-panel-header .memory-modal-header { margin: 0; }
.memory-photo-panel-hint { margin-top: 8px; color: var(--ds-ink-soft); }
.memory-photo-panel #upload-interface {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.memory-photo-panel #dropContainer {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.desktop-photo-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  box-sizing: border-box;
  scrollbar-gutter: stable;
}
.desktop-photo-list .photos-list { display: grid; gap: 12px; }
.desktop-photo-list .photo-entry {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--ds-line);
  border-radius: 16px;
  background: var(--ds-card);
  color: var(--ds-ink);
  box-sizing: border-box;
}
.desktop-photo-list .photo-card-header {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
}
.desktop-photo-list .photo-preview {
  width: 96px;
  height: 112px;
  border-radius: 8px;
  background-color: var(--ds-surface);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}
.desktop-photo-list .photo-card-info { min-width: 0; }
.desktop-photo-list .photo-position { font-weight: 600; }
.desktop-photo-list .photo-cover-choice {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  min-height: 44px;
  padding: 0;
  cursor: pointer;
  line-height: 1.25;
}
.desktop-photo-list .photo-cover-choice input[type="radio"] {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  position: static;
  border: 0;
  border-radius: 50%;
  background: none;
}
.desktop-photo-list .photo-cover-choice input::after { content: none; }
.desktop-photo-list .photo-edit-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.desktop-photo-list .photo-entry button {
  min-height: 44px;
  margin: 0;
  padding: 4px 8px;
  font: inherit;
  line-height: 1.25;
  border-radius: 8px;
}
.desktop-photo-list .photo-edit-actions button { border-color: transparent; background: var(--ds-surface); }
.desktop-photo-list .photo-order-actions {
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 12px;
  padding: 8px 0 0;
  border-top: 1px solid var(--ds-line);
}
.desktop-photo-list .photo-order-actions[hidden] { display: none; }
.desktop-photo-list .photo-order-label { flex: 1; color: var(--ds-ink-soft); }
.desktop-photo-list .photo-order-actions button { background: transparent; border-color: transparent; }
.desktop-photo-list .photo-media-editor { margin-top: 8px; padding: 0; border-top: 1px solid var(--ds-line); }
.desktop-photo-list .photo-media-editor summary {
  min-height: 44px;
  padding: 12px 0 4px;
  box-sizing: border-box;
  cursor: pointer;
  font-weight: 500;
}
.desktop-photo-list .photo-media-fields { display: grid; gap: 12px; padding-top: 8px; }
.desktop-photo-list .photo-media-hint { margin: 0; color: var(--ds-ink-soft); }
.desktop-photo-list .photo-description-label { font-weight: 500; }
.desktop-photo-list .media-description {
  display: block;
  width: 100%;
  min-height: 96px;
  box-sizing: border-box;
  margin-top: 8px;
  padding: 12px;
  resize: vertical;
  border: 1px solid var(--ds-input-border);
  border-radius: 8px;
  background: var(--ds-card);
  color: var(--ds-ink);
  font: inherit;
  line-height: 1.5;
}
.desktop-photo-list .photo-media-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 24px;
  cursor: pointer;
}
.desktop-photo-list .photo-media-check input {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--ds-brand-strong);
}
.desktop-photo-list .photo-description-save { justify-self: start; }
.desktop-photo-list .media-save-status { margin: 0; overflow-wrap: anywhere; }
.desktop-photo-list .media-save-status:empty { display: none; }
.desktop-photo-upload {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--ds-line);
}
.desktop-photo-upload .photo-upload-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px 16px;
  box-sizing: border-box;
  border: 1px solid var(--ds-input-border);
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  background: var(--ds-card);
  color: var(--ds-ink);
  cursor: pointer;
  overflow: hidden;
}
/* Keep the native input keyboard-accessible; legacy .image-selector hides it. */
.desktop-photo-upload .photo-upload-button input[type="file"] {
  display: block !important;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.desktop-photo-upload .photo-upload-button:focus-within {
  outline: 3px solid var(--ds-brand-strong);
  outline-offset: 2px;
}
.desktop-photo-upload .photo-upload-hint { font-size: 14px; line-height: 20px; color: var(--ds-ink-soft); }
.desktop-photo-upload .upload-progress-container:empty { display: none; }
.desktop-photo-upload .upload-progress-container { max-height: 120px; overflow: auto; }
.desktop-photo-list .photo-list-empty { padding: 24px 8px; text-align: center; }
.desktop-photo-list .photo-list-empty p { color: var(--ds-ink-soft); }
@media (min-width: 813px) and (max-width: 1100px) {
  #create-memory > .memory-photo-panel { flex-basis: 320px; width: 320px; }
  .memory-photo-panel-header { padding: 16px; }
  .desktop-photo-list .photo-card-header { grid-template-columns: 80px minmax(0, 1fr); }
  .desktop-photo-list .photo-preview { width: 80px; }
}

.desktop-photo-list .photo-edit-btn { opacity: 1; }
.desktop-photo-list .photo-edit-btn:hover { color: var(--ds-ink) !important; }
@media (max-width: 812px) {
  #create-memory > .memory-photo-panel { flex: none; width: 100%; }
  .memory-photo-panel #dropContainer { display: block; overflow: visible; }
}
