/**
 * Rufio Admin Panel - Custom Styles
 * ================================
 * Custom CSS for the admin panel UI
 */

/* ============================================================================
   Mobile foundations
   Mobile-first design tokens, reset, and scaffolding for the vet UI.
   Light theme only. Layered ON TOP of Bootstrap 5 — does not override
   Bootstrap utility classes. Target browsers: last 2 stable Chrome /
   Safari / Firefox / Edge.
   ============================================================================ */

:root {
  /* ----- Color tokens (light theme only) ----- */
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f2f5;
  --color-border: #e0e0e0;
  --color-text: #1f2330;
  --color-text-muted: #5b6275;            /* ≥ 4.5:1 on --color-bg / --color-surface */
  --color-on-primary-muted: #ffffff;      /* must hit AA ≥ 4.5:1 vs --color-primary; collapses to pure white in this palette */
  --color-primary: #5b6fdc;               /* darkened from #667eea — AA contrast with white */
  --color-primary-contrast: #ffffff;
  --color-bubble-incoming-bg: #ffffff;
  --color-bubble-incoming-text: #1f2330;
  --color-bubble-outgoing-bg: #e8edff;
  --color-bubble-outgoing-text: #1f2330;
  --color-danger: #dc3545;
  --color-success: #198754;

  /* ----- Spacing scale (0.25rem base) ----- */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 2.5rem;
  --space-8: 3rem;

  /* ----- Radius ----- */
  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-pill: 999px;

  /* ----- Shadows ----- */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.08);

  /* ----- Layout ----- */
  --app-header-h: 3.5rem;
  --composer-min-h: 3.5rem;
  --touch-target: 2.75rem;                /* 44px floor for coarse pointers */

  /* ----- Fluid type scale (clamp) ----- */
  --font-size-sm: clamp(0.8125rem, 0.78rem + 0.15vw, 0.875rem);
  --font-size-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --font-size-md: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --font-size-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.375rem);

  /* ----- Z-index (kept compatible with Bootstrap stack) ----- */
  --z-drawer: 1040;
  --z-modal: 1050;
  --z-toast: 1080;

  /* ----- Safe-area insets (iOS notch / Android gesture bar) ----- */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ----- Mobile-first reset (additive, non-destructive vs Bootstrap) ----- */
html {
  box-sizing: border-box;
  -webkit-text-size-adjust: 100%;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

body {
  overflow-wrap: break-word;
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
}

img,
svg,
video {
  max-inline-size: 100%;
  block-size: auto;
}

/* ----- iOS auto-zoom prevention: ensure form controls are ≥ 16px on phones ----- */
@media (max-width: 40rem) {
  input,
  select,
  textarea {
    font-size: max(1rem, 16px);
  }
}

/* ----- Touch-target floor for coarse pointers (WCAG 2.5.5) ----- */
@media (pointer: coarse) {
  :is(button, [role="button"], a.btn, .nav-link, .list-group-item-action) {
    min-block-size: var(--touch-target);
  }
}

/* ----- Reduced motion ----- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}


/* === END MOBILE FOUNDATIONS === */

/* Bootstrap custom property defaults (overridden at runtime by Bootstrap) */
:root {
  --bs-primary: #667eea;
}

/* ============================================
   Layout - Sidebar and Main Content
   ============================================ */

/* Push content below fixed navbar (scoped: only when a fixed-top navbar is
   actually present — leaves pages like /vet/login untouched). */
body:has(> nav.navbar.fixed-top) {
  padding-block-start: var(--app-header-h);
}

/* Sidebar styling */
.sidebar {
  position: fixed;
  top: 56px;
  bottom: 0;
  left: 0;
  z-index: 100;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.sidebar .nav-link {
  padding: 0.75rem 1rem;
  transition: background-color 0.2s;
}

.sidebar .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.sidebar .nav-link.active {
  background-color: var(--bs-primary, #667eea);
}

/* ============================================
   Cards and Components
   ============================================ */

/* Entity cards hover effect */
.entity-card {
  transition: transform 0.2s, box-shadow 0.2s;
  border: 1px solid #e0e0e0;
}

.entity-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  border-color: var(--bs-primary, #667eea);
}

/* Card header styling */
.card-header {
  background-color: #f8f9fa;
  border-bottom: 1px solid #e0e0e0;
}

/* ============================================
   Tables
   ============================================ */

/* Sticky column for wide tables */
.sticky-col {
  position: sticky;
  left: 0;
  background-color: white;
  z-index: 1;
}

/* Table hover effect */
.table-hover tbody tr:hover {
  background-color: rgba(102, 126, 234, 0.05);
}

/* ============================================
   Forms
   ============================================ */

/* Form control focus */
.form-control:focus,
.form-select:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 0.25rem rgba(102, 126, 234, 0.25);
}

/* Form check input custom color */
.form-check-input:checked {
  background-color: #667eea;
  border-color: #667eea;
}

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

/* Primary button gradient */
.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #5a6fd6 0%, #6a4190 100%);
}

/* Button group spacing */
.btn-group .btn {
  margin-right: 0;
}

/* ============================================
   Badges
   ============================================ */

/* Permission badges */
.badge {
  font-weight: 500;
}

/* ============================================
   Alerts
   ============================================ */

/* Alert styling */
.alert {
  border-radius: 8px;
}

/* ============================================
   Images
   ============================================ */

/* Image preview styling */
.image-preview {
  border: 2px solid #e0e0e0;
  transition: border-color 0.2s, opacity 0.2s;
}

.image-preview:hover {
  border-color: #667eea;
}

/* Image gallery grid */
.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 15px;
}

/* ============================================
   JSON Display
   ============================================ */

.json-display {
  background-color: #f8f9fa;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 15px;
  max-height: 300px;
  overflow: auto;
}

.json-display pre {
  margin: 0;
  font-size: 0.875rem;
}

/* ============================================
   Utilities
   ============================================ */

/* Text truncate */
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Code styling */
code {
  background-color: #f8f9fa;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.875em;
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 767.98px) {
  .sidebar {
    position: static;
    height: auto;
  }


  .sticky-col {
    position: static;
  }
}

/* ============================================
   Animations
   ============================================ */

/* Fade in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  animation: fadeIn 0.3s ease-out;
}

/* Alert auto-dismiss animation */
.alert {
  animation: fadeIn 0.3s ease-out;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  .sidebar,
  .navbar,
  .btn,
  .btn-group {
    display: none !important;
  }

  main {
    margin: 0 !important;
    padding: 0 !important;
  }
}

/* ============================================
   Vet Chat — Conversation List
   ============================================ */

/* Conversation avatar circle */
.conversation-avatar {
  width: 2.5rem;       /* 40px */
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
  background-color: #f0f0f0;
  flex-shrink: 0;
}

/* Conversation item layout */
.conversation-item {
  padding-block: 0.625rem;
  padding-inline: 0.75rem;
  border-bottom: 1px solid #e9ecef;
  transition: background-color 0.15s;
}

.conversation-item:hover {
  background-color: rgba(102, 126, 234, 0.06);
}

.conversation-item.active {
  background-color: var(--bs-primary, #667eea);
  color: #fff;
}

.conversation-item.active .text-muted {
  color: rgba(255, 255, 255, 0.75) !important;
}

/* Message preview truncation */
.conversation-preview {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
}

/* Ensure middle section can shrink for text-truncate to work */
.conversation-info {
  min-width: 0;
}

/* Unread badge positioning */
.conversation-badge {
  font-size: 0.7rem;
  min-width: 1.25rem;
  padding-inline: 0.35rem;
}

/* Toast container z-index is inline; cursor pointer for clickable toasts */
.toast[data-conversation-id] {
  cursor: pointer;
}

/* ============================================
   Vet Chat — Responsive Adjustments
   ============================================ */

@media (max-width: 991.98px) {
  .conversation-avatar {
    width: 2rem;
    height: 2rem;
  }
}

/* ============================================================================
   Vet login page
   Mobile-first responsive layout for /vet/login. Uses the foundation tokens.
   Light theme only. Logical properties only. Layered on Bootstrap.
   ============================================================================ */

.vet-login {
  min-block-size: 100dvh;
  display: grid;
  place-items: center;
  background: var(--color-bg);
  padding-block-start: max(var(--space-5), var(--safe-top));
  padding-block-end: max(var(--space-5), var(--safe-bottom));
  padding-inline-start: max(var(--space-5), var(--safe-left));
  padding-inline-end: max(var(--space-5), var(--safe-right));
}

.vet-login__card {
  inline-size: 100%;
  max-inline-size: 24rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
  display: grid;
  gap: var(--space-4);
}

.vet-login__header {
  display: grid;
  gap: var(--space-2);
  text-align: center;
}

.vet-login__icon {
  font-size: 2.5rem;
  color: var(--color-primary);
  line-height: 1;
}

.vet-login__title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-text);
  margin: 0;
}

.vet-login__subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin: 0;
}

.vet-login__form {
  display: grid;
  gap: var(--space-4);
}

.vet-login__field {
  display: grid;
  gap: var(--space-2);
}

.vet-login__field label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.vet-login__field .form-control {
  inline-size: 100%;
  min-block-size: var(--touch-target);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}

.vet-login__field .form-control:focus,
.vet-login__field .form-control:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-color: var(--color-primary);
  box-shadow: none;
}

.vet-login__submit {
  inline-size: 100%;
  min-block-size: var(--touch-target);
  font-weight: 600;
}

.vet-login__submit:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.vet-login__error {
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
  color: var(--color-danger);
  border: 1px solid color-mix(in srgb, var(--color-danger) 35%, transparent);
  border-radius: var(--radius-md);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  font-size: var(--font-size-sm);
}

.vet-login__footnote {
  margin: 0;
  text-align: center;
  font-size: var(--font-size-sm);
}

/* Tablet and up — slightly roomier card padding */
@media (min-width: 40rem) {
  .vet-login__card {
    padding: var(--space-7);
    gap: var(--space-5);
  }
}

/* ============================================================================
   Conversation search (vet)
   Mobile-first search bar pinned to the top of the conversation list pane.
   Additive: layered on Bootstrap's .form-control, renames nothing. Uses the
   foundation tokens, logical properties, the shared :focus-visible ring, and
   the --touch-target floor. Light theme only (matches the rest of this file —
   no prefers-color-scheme block exists project-wide).
   ============================================================================ */

.conv-search {
  display: block;
  margin-block-start: var(--space-2);
}

.conv-search__form {
  margin: 0;
}

.conv-search__input {
  inline-size: 100%;
  min-block-size: var(--touch-target);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--font-size-base);
}

.conv-search__input::placeholder {
  /* --color-text-muted is documented as ≥ 4.5:1 on --color-surface (WCAG AA) */
  color: var(--color-text-muted);
}

.conv-search__input:focus,
.conv-search__input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-color: var(--color-primary);
  box-shadow: none;
}

/* Tablet and up — align with the roomier list-pane rhythm */
@media (min-width: 40rem) {
  .conv-search {
    margin-block-start: var(--space-3);
  }
}

/* ============================================================================
   Conversation list (vet)
   Mobile-first responsive conversation list. Uses the foundation tokens.
   Light theme only. Logical properties only. Layered on Bootstrap: the
   `.list-group .list-group-flush .list-group-item .list-group-item-action`
   classes are preserved as aliases on each row so existing chrome and the
   foundation touch-target rule for `.list-group-item-action` apply
   automatically. Hover affordances are gated to fine pointers; touch users
   see the same visual state via `:focus-visible` and `[aria-current="true"]`.
   ============================================================================ */

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.conv-list > li {
  display: block;
}

.conv-item {
  inline-size: 100%;
  min-block-size: var(--touch-target);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding-block: var(--space-3);
  padding-inline: var(--space-4);
  background: var(--color-surface);
  border: 0;
  border-block-end: 1px solid var(--color-border);
  color: var(--color-text);
  text-align: start;
  cursor: pointer;
  font: inherit;
  appearance: none;
  -webkit-appearance: none;
}

/* Hover only for fine-pointer devices — coarse pointers get :focus-visible / aria-current instead */
@media (hover: hover) and (pointer: fine) {
  .conv-item:hover {
    background: var(--color-surface-alt);
  }
}

.conv-item:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
  background: var(--color-surface-alt);
}

.conv-item[aria-current="true"],
.conv-item.active {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.conv-item[aria-current="true"] .conv-item__preview,
.conv-item[aria-current="true"] .conv-item__time,
.conv-item.active .conv-item__preview,
.conv-item.active .conv-item__time {
  color: var(--color-on-primary-muted); /* AA ≥ 4.5:1 verified vs --color-primary */
}

.conv-item__avatar {
  inline-size: 2.5rem;
  block-size: 2.5rem;
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.conv-item__avatar img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
}

.conv-item__body {
  min-inline-size: 0; /* allow children to ellipsis */
  display: grid;
  gap: var(--space-1);
}

.conv-item__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  min-inline-size: 0;
}

.conv-item__name {
  font-weight: 600;
  font-size: var(--font-size-base);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-inline-size: 0;
  flex: 1 1 auto;
}

.conv-item__time {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.conv-item__preview {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
  min-inline-size: 0;
}

.conv-item__unread {
  min-inline-size: 1.5rem;
  block-size: 1.5rem;
  padding-inline: var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-size: var(--font-size-sm);
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.conv-item[aria-current="true"] .conv-item__unread,
.conv-item.active .conv-item__unread {
  background: var(--color-primary-contrast);
  color: var(--color-primary);
}

.conv-item__unread:empty,
.conv-item__unread[hidden] {
  display: none;
}

/* === END CONVERSATION LIST === */


/* ============================================================================
   Chat pane + composer
   Mobile-first chat pane shell, message bubbles, composer, and virtual-
   keyboard inset handling. Uses the foundation tokens. Light theme only.
   Logical properties only. Layered ON TOP of Bootstrap: the existing
   `<main class="col-12 col-lg-6 d-flex flex-column">` retains its Bootstrap
   classes; `display: grid` on `.chat-pane` wins by specificity / cascade
   ordering. Outgoing bubbles are right-aligned with a distinct color;
   Enter-to-send behaviour is gated by pointer type on the JS side.
   `--keyboard-inset` is set by client-side visualViewport JS.
   ============================================================================ */

/* Chat-pane shell: 3-row Grid (header / messages / composer). No magic
   numbers — height comes from the viewport minus the app header token. */
.chat-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  block-size: calc(100dvh - var(--app-header-h, 3.5rem));
  min-inline-size: 0; /* allow children to shrink for ellipsis / wrap */
}

.chat-pane__header {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  padding-block-start: max(var(--space-3), var(--safe-top));
  padding-inline-start: max(var(--space-3), var(--safe-left));
  padding-inline-end: max(var(--space-3), var(--safe-right));
  background: var(--color-surface);
  border-block-end: 1px solid var(--color-border);
}

.chat-pane__messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  min-block-size: 0; /* critical for grid flexbox scroll */
  padding-block-start: var(--space-3);
  padding-block-end: calc(var(--space-3) + var(--keyboard-inset, 0px));
  padding-inline-start: max(var(--space-4), var(--safe-left));
  padding-inline-end: max(var(--space-4), var(--safe-right));
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

@media (prefers-reduced-motion: reduce) {
  .chat-pane__messages {
    scroll-behavior: auto;
  }
}

.chat-pane__composer {
  position: sticky;
  inset-block-end: 0;
  z-index: 2;
  background: var(--color-surface);
  border-block-start: 1px solid var(--color-border);
  padding-block-start: var(--space-3);
  padding-block-end: calc(var(--space-3) + var(--safe-bottom));
  padding-inline-start: max(var(--space-3), var(--safe-left));
  padding-inline-end: max(var(--space-3), var(--safe-right));
  /* When the on-screen keyboard is open, lift composer above it. */
  transform: translateY(calc(var(--keyboard-inset, 0px) * -1));
  transition: transform 120ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .chat-pane__composer {
    transition: none;
  }
}

/* ----- Message bubbles: outgoing right-aligned with distinct color ----- */
.msg {
  max-inline-size: min(75%, 42rem);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  border-radius: var(--radius-lg);
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: var(--font-size-base);
  line-height: 1.4;
  box-shadow: var(--shadow-sm);
}

.msg--incoming {
  align-self: flex-start;
  background: var(--color-bubble-incoming-bg);
  color: var(--color-bubble-incoming-text);
  border: 1px solid var(--color-border);
  border-end-start-radius: var(--radius-sm);
}

.msg--outgoing {
  align-self: flex-end;
  background: var(--color-bubble-outgoing-bg);
  color: var(--color-bubble-outgoing-text);
  border-end-end-radius: var(--radius-sm);
}

.msg__content {
  white-space: pre-wrap;
}

.msg__meta {
  font-size: var(--font-size-sm);
  opacity: 0.75;
  margin-block-start: var(--space-1);
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.msg__attachment {
  margin-block-start: var(--space-2);
}

.msg__attachment img,
.msg__attachment video {
  max-inline-size: 100%;
  block-size: auto;
  border-radius: var(--radius-md);
  display: block;
}

.msg__attachment ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-1);
}

.msg__attachment a {
  color: inherit;
  text-decoration: underline;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ----- Composer form ----- */
.composer-form {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-2);
  align-items: end;
}

.composer-form__attach {
  min-block-size: var(--touch-target);
  min-inline-size: var(--touch-target);
  display: grid;
  place-items: center;
  margin: 0;
  cursor: pointer;
}

.composer-form__attach input[type="file"] {
  /* Visually hidden but keyboard-focusable through the label */
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.composer-form__attach:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.composer-form__input {
  min-block-size: var(--touch-target);
  max-block-size: 8rem;
  resize: none;
  inline-size: 100%;
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: max(1rem, 16px); /* iOS auto-zoom guard */
  line-height: 1.4;
  background: var(--color-surface);
  color: var(--color-text);
  overflow-y: auto;
}

.composer-form__input:focus,
.composer-form__input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-color: var(--color-primary);
  box-shadow: none;
}

.composer-form__send {
  min-block-size: var(--touch-target);
  min-inline-size: var(--touch-target);
  display: inline-grid;
  grid-auto-flow: column;
  place-items: center;
  gap: var(--space-1);
}

.composer-form__send:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* On very narrow phones, collapse the Send button label to icon only. */
@media (max-width: 30rem) {
  .composer-form__send span {
    /* keep accessible name via aria-label on the button */
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .composer-form__send .bi-send {
    margin-inline-end: 0 !important;
  }
}

/* === END CHAT PANE + COMPOSER === */

/* === Stacked navigation (mobile single-pane shell) === */
/* On mobile (< 64rem) the chat shell shows ONE pane at a time
   (list | chat | profile). On desktop (>= 64rem) the existing Bootstrap
   3-column row is preserved exactly. */

/* Mobile-only icon buttons in the chat header. Base styles are mobile-first;
   they are hidden on desktop further down. */
.chat-pane__back,
.chat-pane__profile-toggle {
  display: inline-grid;
  place-items: center;
  min-block-size: var(--touch-target);
  min-inline-size: var(--touch-target);
  font-size: 1.25rem;
  line-height: 1;
  text-decoration: none;
  color: var(--color-text);
}

.chat-pane__back:focus-visible,
.chat-pane__profile-toggle:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

@media (max-width: 63.999rem) {
  /* Single-pane stacked layout — override Bootstrap row on mobile. */
  .chat-shell { display: block; min-block-size: 100dvh; }

  .chat-shell__pane { display: none; }

  .chat-shell[data-view="list"]    .chat-shell__pane--list,
  .chat-shell[data-view="chat"]    .chat-shell__pane--chat,
  .chat-shell[data-view="profile"] .chat-shell__pane--profile {
    display: block;
  }

  /* Force the active pane to span full inline-size regardless of Bootstrap
     col widths — neutralises col-12/col-lg-* on small viewports. */
  .chat-shell__pane {
    flex: 0 0 100%;
    max-inline-size: 100%;
    inline-size: 100%;
  }

  /* The chat pane uses CSS Grid (3-row template defined above) for its
     internal layout — restore `display: grid` when it becomes the active
     pane on mobile so the grid-template-rows continues to apply. */
  .chat-shell[data-view="chat"] .chat-shell__pane--chat {
    display: grid;
  }
}

@media (min-width: 64rem) {
  /* Desktop: hide the mobile-only header buttons; data-view attribute is
     ignored — all three panes remain visible via the Bootstrap row/cols. */
  .chat-pane__back,
  .chat-pane__profile-toggle { display: none; }
}
/* === END STACKED NAVIGATION === */

/* ============================================================================
   Attachments
   Image / video / file attachments open in a new tab via
   <a target="_blank" rel="noopener noreferrer">. No in-app lightbox, no
   <dialog>. Mobile-first, foundation tokens, logical properties only.
   Light theme only. Overrides the earlier placeholder rules for
   `.msg__attachment` (which assumed a wrapping div + <ul> of links).
   ============================================================================ */

/* Multi-attachment vertical stack inside a message bubble. */
.msg__attachment-list {
  margin-block-start: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.msg__attachment {
  display: block;
  border-radius: var(--radius-md);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}

.msg__attachment:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Image + video previews: scale within bubble; never overflow viewport. */
.msg__attachment--image img,
.msg__attachment--video video {
  display: block;
  inline-size: 100%;
  max-inline-size: min(100%, 20rem);
  block-size: auto;
  max-block-size: 60dvh;
  object-fit: contain;
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
}

/* Video chrome: wrapper is a flex column so the "Open in new tab" link sits
   directly beneath the player without overlapping the native controls. */
.msg__attachment--video {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow: visible; /* allow the open link to be fully clickable */
}

.msg__attachment-open {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--touch-target);
  font-size: var(--font-size-sm);
  color: inherit;
  text-decoration: underline;
  padding-inline: var(--space-1);
}

.msg__attachment-open:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Generic non-media file chip: icon · name (truncates) · size/mime. */
.msg__attachment--file {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  min-block-size: var(--touch-target);
}

.msg__attachment-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
}

.msg__attachment-name {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-base);
}

.msg__attachment-meta {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* Outgoing bubble: chip surface must remain readable on the bubble color. */
.msg--outgoing .msg__attachment--file {
  background: color-mix(in srgb, var(--color-bubble-outgoing-bg) 85%, white 15%);
  border-color: color-mix(in srgb, var(--color-bubble-outgoing-bg) 70%, black 30%);
}

.msg--outgoing .msg__attachment-meta {
  color: var(--color-text-muted);
}

/* === END ATTACHMENTS === */


/* ============================================================================
   Accessibility polish
   Final accessibility sweep. WCAG 2.1 AA baseline. Most a11y is handled
   inline in the components above (real labels, role="log" + aria-live on
   #messageList, aria-current on conversation rows, inert on inactive panes,
   focus management on view change, hover gated to fine pointers, ≥ 44px
   touch targets, reduced-motion honoured). This section adds:
     1. A globally visible `:focus-visible` ring (Bootstrap strips outlines
        on .btn / .btn-link — re-instate without using `!important`).
     2. A skip link that jumps to the message log (first focusable element
        in <body> per WCAG 2.4.1 Bypass Blocks).
   Light theme only. Logical properties only. No new deps.
   Bootstrap's `.visually-hidden` already loaded — not redefined here.
   ============================================================================ */

/* 1. Baseline focus ring for every interactive element. `:where()` keeps
   specificity at 0 so per-component focus rules still win when they need
   tighter offsets / colors. */
:where(a, button, input, textarea, select, summary, [role="button"], [tabindex]):focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Bootstrap `.btn` strips the native outline and uses a box-shadow ring that
   is invisible against our dark navbar / primary background. Re-instate the
   token-based outline and suppress the BS box-shadow on keyboard focus. */
.btn:focus-visible,
.btn-close:focus-visible,
.btn-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  box-shadow: none;
}

/* Dark backgrounds (navbar, primary buttons) need a high-contrast ring. */
.navbar-dark .btn:focus-visible,
.bg-dark .btn:focus-visible,
.btn-primary:focus-visible {
  outline-color: var(--color-primary-contrast);
}

/* 2. Skip link — visually hidden until focused, then slides into view at the
   top-inline-start corner. Sits above all overlays via --z-toast. */
.skip-link {
  position: absolute;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--space-2);
  z-index: var(--z-toast);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform 120ms ease-out;
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
  outline: 2px solid var(--color-primary-contrast);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .skip-link {
    transition: none;
  }
}

/* === END A11Y POLISH === */


/* ============================================================================
   QA fixes & misc utilities
   Light theme only. Logical properties only. No `!important`, no new deps.
   ============================================================================ */

/* Profile card avatar (ported from the previously-inline <style> block in
   chat.ejs). Uses logical properties (was width/height). */
.profile-card img {
  inline-size: 6rem;
  block-size: 6rem;
  border-radius: 50%;
  object-fit: cover;
}

/* Profile pane uses the existing `.chat-pane__back` class (which the
   stacked-navigation rules already hide on desktop). This selector is
   purely defensive: explicitly hide the profile-header copy on desktop
   in case a future change scopes `.chat-pane__back` more tightly. */
@media (min-width: 64rem) {
  .chat-profile__header .chat-pane__back { display: none; }
}

/* Selected-attachment chip (filename + size + remove). */
.composer-form__chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  max-inline-size: 100%;
  background: var(--color-surface);
  margin-block-end: var(--space-2);
}

.composer-form__chip[hidden] { display: none; }

.composer-form__chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
  min-inline-size: 0;
}

.composer-form__chip-size {
  color: var(--color-text-muted);
  flex: 0 0 auto;
  font-size: var(--font-size-sm);
}

.composer-form__chip-remove {
  min-block-size: var(--touch-target);
  min-inline-size: var(--touch-target);
  display: inline-grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--color-text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}


.composer-form__chip-remove:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Toast container: safe-area padding, inline-size cap on narrow viewports,
   larger close-button hit area. Specificity `#id.class` wins over
   Bootstrap's `.toast-container` defaults without `!important`. */
#toastContainer.toast-container {
  padding-block-start: max(var(--space-4), var(--safe-top));
  padding-inline-end: max(var(--space-4), var(--safe-right));
  inline-size: min(24rem, calc(100% - var(--space-4)));
}

.toast .btn-close {
  min-block-size: var(--touch-target);
  min-inline-size: var(--touch-target);
}

/* === END QA FIXES === */

/* ============================================================================
   User profile info + Pets (collapsible)
   Mobile-first, light theme only, logical properties only. Reuses the
   foundation design tokens (colors, spacing, radii, shadows, type, touch
   target). Built for the markup in views/vet/chat.ejs and the per-pet
   <details class="pet-card"> cards emitted by public/js/vet-chat.js.
   Collapsibles use the native <details>/<summary> element (free a11y /
   keyboard support); the chevron transition is disabled under
   prefers-reduced-motion. No `!important`, no new dependencies, no dark mode.
   ============================================================================ */

/* ----- Expanded profile info rows (country / language / phone / timezone /
   joined) — a tidy stack of muted small-print rows consistent with the
   existing centered profile card. ----- */
.profile-card__info {
  display: grid;
  gap: var(--space-2);
  margin-block-start: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* Rows toggled off by JS (e.g. null phone) collapse out of the grid gap. */
.profile-card__info > [hidden] {
  display: none;
}

/* Phone `tel:` anchor — inherit the muted row color, primary on interaction. */
.profile-card__info a {
  color: var(--color-primary);
  text-decoration: none;
}

@media (hover: hover) and (pointer: fine) {
  .profile-card__info a:hover {
    text-decoration: underline;
  }
}

.profile-card__info a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ----- Outer pets collapsible ----- */
.pet-collapse {
  margin-block-start: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  overflow: hidden;
}

/* Tappable summary row: ≥ 44px touch target, no native marker, chevron at
   the inline-end edge. */
.pet-collapse__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-block-size: var(--touch-target);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  cursor: pointer;
  font-weight: 600;
  font-size: var(--font-size-md);
  color: var(--color-text);
  list-style: none;
  user-select: none;
}

.pet-collapse__summary::-webkit-details-marker {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .pet-collapse__summary:hover {
    background: var(--color-surface-alt);
  }
}

.pet-collapse__summary:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.pet-collapse__count {
  color: var(--color-text-muted);
  font-weight: 400;
}

/* Chevron rotates to point up when the section is open. */
.pet-collapse__chevron {
  flex: 0 0 auto;
  color: var(--color-text-muted);
  transition: transform 0.2s ease;
}

.pet-collapse[open] .pet-collapse__chevron {
  transform: rotate(180deg);
}

.pet-collapse__panel {
  padding-block: var(--space-2) var(--space-3);
  padding-inline: var(--space-3);
  border-block-start: 1px solid var(--color-border);
}

/* ----- Pet list + empty / loading states ----- */
.pet-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.pet-list:empty {
  display: none;
}

.pet-list__empty,
.pet-list__loading {
  margin-block: var(--space-2) 0;
  padding-block: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  text-align: center;
}

.pet-list__empty[hidden],
.pet-list__loading[hidden] {
  display: none;
}

/* Loading state: a calm pulsing placeholder bar that respects reduced motion
   (see the dedicated media block below). */
.pet-list__loading {
  block-size: 3rem;
  border-radius: var(--radius-md);
  background: linear-gradient(
    90deg,
    var(--color-surface-alt) 25%,
    var(--color-border) 37%,
    var(--color-surface-alt) 63%
  );
  background-size: 400% 100%;
  animation: pet-skeleton-shimmer 1.4s ease infinite;
}

@keyframes pet-skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ----- Per-pet collapsible card (<details class="pet-card">) ----- */
.pet-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* At-a-glance row: avatar + name/badge + meta, with a CSS-drawn chevron at the
   inline-end edge. ≥ 44px touch target. */
.pet-card__summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-block-size: var(--touch-target);
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.pet-card__summary::-webkit-details-marker {
  display: none;
}

/* CSS-drawn chevron (no icon-font dependency); rotates when the card opens. */
.pet-card__summary::after {
  content: "";
  flex: 0 0 auto;
  inline-size: 0.5rem;
  block-size: 0.5rem;
  margin-inline-start: auto;
  border-inline-end: 2px solid var(--color-text-muted);
  border-block-end: 2px solid var(--color-text-muted);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.pet-card[open] .pet-card__summary::after {
  transform: rotate(-135deg);
}

@media (hover: hover) and (pointer: fine) {
  .pet-card__summary:hover {
    background: var(--color-surface-alt);
  }
}

.pet-card__summary:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.pet-card__avatar {
  flex: 0 0 auto;
  inline-size: 2.75rem;
  block-size: 2.75rem;
  border-radius: var(--radius-pill);
  object-fit: cover;
  background: var(--color-surface-alt);
}

.pet-card__text {
  display: grid;
  gap: var(--space-1);
  min-inline-size: 0; /* allow the meta line to ellipsis */
  flex: 1 1 auto;
}

.pet-card__name-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-inline-size: 0;
}

.pet-card__name {
  font-weight: 600;
  font-size: var(--font-size-base);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-inline-size: 0;
}

/* Owner / co-owner pill. */
.pet-card__badge {
  flex: 0 0 auto;
  padding-block: var(--space-1);
  padding-inline: var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: 1.1;
  white-space: nowrap;
}

.pet-card__badge--owner {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.pet-card__badge--coowner {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
}

.pet-card__meta {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-inline-size: 0;
}

/* Expanded detail body: label/value rows in a two-column grid that wraps to a
   single column on the narrowest screens. */
.pet-card__body {
  display: grid;
  gap: var(--space-2);
  padding-block: var(--space-2) var(--space-3);
  padding-inline: var(--space-3);
  border-block-start: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
}

.pet-card__detail {
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1fr;
  gap: var(--space-1) var(--space-2);
  align-items: baseline;
}

.pet-card__detail-label {
  color: var(--color-text-muted);
  font-weight: 500;
}

.pet-card__detail-value {
  color: var(--color-text);
  overflow-wrap: anywhere;
}

/* ----- Profile pane scroll: keep a long pet list inside the pane rather than
   stretching the layout. On mobile the active pane is `display: block`; on
   desktop it is a Bootstrap column. In both cases allow vertical scroll within
   the available height budget without breaking the three-pane shell. ----- */
.chat-shell__pane--profile {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 63.999rem) {
  .chat-shell[data-view="profile"] .chat-shell__pane--profile {
    max-block-size: calc(100dvh - var(--app-header-h));
  }
}

/* ----- Reduced-motion: disable chevron rotation transitions and the skeleton
   shimmer (the global foundation rule already neutralises these; this is an
   explicit, intent-revealing safeguard for the new markup). ----- */
@media (prefers-reduced-motion: reduce) {
  .pet-collapse__chevron,
  .pet-card__summary::after {
    transition: none;
  }

  .pet-list__loading {
    animation: none;
  }
}

/* === END PROFILE + PETS === */


