/*
 * Accessibility override layer on top of Bootstrap 5.3.
 *
 * Bootstrap's defaults are tuned for general audiences: 1rem text, thin box-shadow focus
 * rings, moderate contrast. This app is used by blind and low-vision people, often outdoors
 * on a phone, so the overrides below restore larger text, unmissable focus rings and bigger
 * tap targets, plus the components Bootstrap has no equivalent for.
 */

:root {
  --bs-body-font-size: 1.0625rem;
  --bs-body-line-height: 1.6;

  --app-focus: #b8460f;
  --app-live: #0a7a3f;
  --app-user-bubble: var(--bs-primary-bg-subtle);
}

[data-bs-theme="dark"] {
  --app-focus: #ffb347;
  --app-live: #4fdc95;
}

/* Unmissable focus. An outline rather than Bootstrap's box-shadow, because outlines survive
   Windows High Contrast / forced-colors mode where box-shadows are discarded. */
:focus-visible {
  outline: 4px solid var(--app-focus) !important;
  outline-offset: 3px;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
.form-range:focus-visible {
  box-shadow: none !important;
  border-color: var(--app-focus);
}

/* WCAG asks for at least 44px; Bootstrap's default controls land under that on phones. */
.btn,
.form-control,
.form-select {
  min-height: 2.75rem;
}

.btn-sm {
  min-height: 2.25rem;
}

.form-check-input[role="switch"] {
  width: 2.25rem;
  height: 1.25rem;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0.5rem;
  z-index: 1080;
}

.skip-link:focus {
  left: 0.5rem;
}

.app-tagline {
  font-size: 0.95rem;
}

.app-status {
  min-height: 2rem;
  font-weight: 700;
  color: var(--app-live);
}

.app-status[data-tone="error"] {
  color: var(--bs-danger-text-emphasis);
}

.chat-main {
  min-height: 0;
}

.transcript {
  overflow-y: auto;
  padding: 0.5rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.bubble {
  padding: 0.85rem 1.1rem;
  border-radius: 0.9rem;
  max-width: min(46rem, 92%);
  border: 2px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble.user {
  align-self: flex-end;
  background: var(--app-user-bubble);
}

.bubble.assistant {
  align-self: flex-start;
}

.bubble.error {
  align-self: flex-start;
  border-color: var(--bs-danger-border-subtle);
  background: var(--bs-danger-bg-subtle);
  color: var(--bs-danger-text-emphasis);
}

/* A text label, not colour alone, so the speaker is clear without sight or colour vision. */
.bubble .who {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  opacity: 0.75;
  margin-bottom: 0.2rem;
}

.mic-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 4.25rem;
  font-size: 1.2rem;
  font-weight: 700;
}

.mic-button[aria-pressed="true"] {
  --bs-btn-bg: var(--bs-danger);
  --bs-btn-border-color: var(--bs-danger);
  --bs-btn-hover-bg: var(--bs-danger);
  --bs-btn-hover-border-color: var(--bs-danger);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  50% { filter: brightness(1.25); }
}

.composer {
  position: sticky;
  bottom: 0;
}

kbd {
  font-size: 0.85em;
}

/*
 * High contrast. Pushes to pure black/white with heavier borders, for low vision or for
 * reading a phone screen in direct sunlight at a stop.
 */
[data-contrast="high"] {
  --bs-body-bg: #ffffff;
  --bs-body-color: #000000;
  --bs-border-color: #000000;
  --bs-secondary-bg: #ffffff;
  --bs-tertiary-bg: #ffffff;
  --app-focus: #0000ff;
  --app-live: #005a2b;
  --app-user-bubble: #e8e8e8;
}

[data-contrast="high"][data-bs-theme="dark"] {
  --bs-body-bg: #000000;
  --bs-body-color: #ffffff;
  --bs-border-color: #ffffff;
  --bs-secondary-bg: #000000;
  --bs-tertiary-bg: #000000;
  --app-focus: #ffff00;
  --app-live: #4fdc95;
  --app-user-bubble: #1a1a1a;
}

[data-contrast="high"] .bubble {
  border-width: 3px;
}

[data-contrast="high"] .text-body-secondary {
  color: var(--bs-body-color) !important;
  opacity: 1;
}

[data-contrast="high"] .btn {
  border-width: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .mic-button[aria-pressed="true"] {
    animation: none;
  }
  *,
  *::before,
  *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
