/* VetConsult design system — mobile-first PWA */

:root {
  /* Brand (preserved) */
  --color-primary: #0f5c4c;
  --color-primary-hover: #14705e;
  --color-primary-soft: #d7ebe4;
  --color-primary-muted: rgba(15, 92, 76, 0.12);

  /* Surfaces */
  --color-bg: #f4f1eb;
  --color-bg-accent: #eae5dc;
  --color-surface: #fffcf7;
  --color-surface-elevated: #ffffff;
  --color-ink: #1c2a24;
  --color-muted: #5a6b63;
  --color-border: #cfc6b8;
  --color-border-subtle: #e4ddd0;

  /* Status */
  --color-success: #1d6b3a;
  --color-success-bg: #e5f6ea;
  --color-warn: #8a4b12;
  --color-warn-bg: #f7ead9;
  --color-warn-border: #e2c39a;
  --color-danger: #8a1f1f;
  --color-danger-bg: #fde8e8;
  --color-info: #3d4f6f;
  --color-info-bg: #e8eef8;
  --color-info-border: #c5d0e6;

  /* Chat */
  --chat-thread-bg: #e8f0ec;
  --chat-bubble-customer: linear-gradient(160deg, #167a66, #0f5c4c);
  --chat-bubble-assistant: #e8eef8;
  --chat-bubble-vet: #f7ead9;

  /* Typography */
  --font-display: "Source Serif 4", "Georgia", serif;
  --font-body: "Figtree", "Segoe UI", system-ui, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.35rem;
  --text-2xl: 1.75rem;
  --text-3xl: clamp(1.85rem, 5vw, 2.75rem);

  /* Spacing & shape */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 999px;
  --shadow-sm: 0 1px 2px rgba(28, 42, 36, 0.06);
  --shadow-md: 0 4px 16px rgba(28, 42, 36, 0.08);
  --shadow-lg: 0 12px 32px rgba(28, 42, 36, 0.1);

  /* Layout */
  --header-h: 3.5rem;
  --bottom-nav-h: 4.25rem;
  --sidebar-w: 15rem;
  --content-max: 42rem;
  --touch-min: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #121a17;
    --color-bg-accent: #0e1512;
    --color-surface: #1a2420;
    --color-surface-elevated: #22302a;
    --color-ink: #e8f0ec;
    --color-muted: #9aada4;
    --color-border: #2f4038;
    --color-border-subtle: #26352e;
    --color-primary-soft: #1a3d34;
    --color-primary-muted: rgba(80, 180, 150, 0.15);
    --color-success-bg: #153528;
    --color-warn-bg: #2e2214;
    --color-warn-border: #5c4020;
    --color-danger-bg: #3a1a1a;
    --color-info-bg: #1c2433;
    --color-info-border: #3d4f6f;
    --chat-thread-bg: #141c19;
    --chat-bubble-assistant: #243044;
    --chat-bubble-vet: #3a2a18;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

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

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-ink);
  background:
    radial-gradient(ellipse at top left, rgba(15, 92, 76, 0.08) 0%, transparent 42%),
    linear-gradient(180deg, var(--color-bg), var(--color-bg-accent));
  background-attachment: fixed;
}

a {
  color: var(--color-primary);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

img {
  max-width: 100%;
  height: auto;
}

/* —— App shell —— */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-shell.has-bottom-nav {
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: var(--space-2);
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: var(--space-4);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--header-h);
  padding: var(--space-3) var(--space-4);
  padding-top: calc(var(--space-3) + var(--safe-top));
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--color-ink);
}

.brand-mark {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: grid;
  place-items: center;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-nav {
  display: none;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: center;
}

.header-nav a {
  text-decoration: none;
  color: var(--color-muted);
  font-weight: 500;
  min-height: var(--touch-min);
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-1);
}

.header-nav a:hover,
.header-nav a.is-active {
  color: var(--color-primary);
}

.header-nav a.is-active {
  font-weight: 600;
}

.user-chip {
  display: none;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.app-body {
  flex: 1;
  display: flex;
  width: 100%;
}

.sidebar {
  display: none;
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: var(--space-6) var(--space-4);
  border-right: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 70%, transparent);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  position: sticky;
  top: calc(var(--header-h) + var(--space-4));
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-min);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-muted);
  font-weight: 500;
}

.sidebar-link:hover {
  background: var(--color-primary-muted);
  color: var(--color-primary);
}

.sidebar-link.is-active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-weight: 600;
}

.sidebar-link svg {
  flex-shrink: 0;
  opacity: 0.85;
}

.main-wrap {
  flex: 1;
  min-width: 0;
}

main.app-main {
  width: min(var(--content-max), calc(100% - 2rem));
  margin: var(--space-5) auto var(--space-8);
}

main.app-main.wide {
  width: min(56rem, calc(100% - 2rem));
}

main.chat-main {
  width: min(780px, calc(100% - 1rem));
  margin: 0.75rem auto 2rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* —— Bottom navigation (mobile) —— */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  min-height: var(--bottom-nav-h);
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: var(--touch-min);
  padding: var(--space-2) var(--space-1);
  text-decoration: none;
  color: var(--color-muted);
  font-size: 0.68rem;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav a svg {
  width: 1.4rem;
  height: 1.4rem;
}

.bottom-nav a.is-active {
  color: var(--color-primary);
  font-weight: 700;
}

.bottom-nav a.is-active svg {
  transform: translateY(-1px);
}

.bottom-nav .nav-fab {
  position: relative;
  margin-top: -0.85rem;
}

.bottom-nav .nav-fab .fab-circle {
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
}

.bottom-nav .nav-fab span:not(.fab-circle) {
  margin-top: 0.2rem;
}

.bottom-nav .nav-fab.is-active .fab-circle {
  background: var(--color-primary-hover);
}

/* —— Typography & page structure —— */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.page-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: 1.2;
}

.page-header .subtitle {
  margin: var(--space-1) 0 0;
  color: var(--color-muted);
}

.section {
  margin-bottom: var(--space-6);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 var(--space-3);
  font-size: var(--text-lg);
  font-weight: 600;
}

.section-title a {
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
}

/* —— Cards & panels —— */
.panel,
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-link:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.card-link:active {
  transform: none;
}

.card-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-body h3 {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 600;
}

.card-meta {
  margin: 0.2rem 0 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.card-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: 1fr;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: white;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--color-primary-hover);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled,
.btn.is-loading {
  opacity: 0.65;
  pointer-events: none;
}

.btn.secondary {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}

.btn.secondary:hover {
  background: var(--color-primary-muted);
}

.btn.ghost {
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
}

.btn.block {
  width: 100%;
}

.btn.sm {
  min-height: 2.25rem;
  padding: 0.4rem 0.9rem;
  font-size: var(--text-sm);
}

.btn .spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn.secondary .spinner {
  border-color: rgba(15, 92, 76, 0.25);
  border-top-color: var(--color-primary);
}

.actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-5);
}

.sticky-actions {
  position: sticky;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + var(--space-3));
  z-index: 20;
  padding: var(--space-3);
  margin: var(--space-4) calc(-1 * var(--space-1)) 0;
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.app-shell:not(.has-bottom-nav) .sticky-actions {
  bottom: var(--space-4);
}

/* —— Forms —— */
.form-row {
  margin-bottom: var(--space-4);
}

.form-row label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 600;
}

.form-row.has-error input,
.form-row.has-error textarea,
.form-row.has-error select {
  border-color: var(--color-danger);
}

.helptext {
  color: var(--color-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
}

.helptext ul {
  margin: var(--space-1) 0 0;
  padding-left: 1.2rem;
}

.errorlist {
  list-style: none;
  margin: var(--space-2) 0 0;
  padding: 0;
  color: var(--color-danger);
  font-size: var(--text-sm);
}

.errorlist li {
  margin: var(--space-1) 0;
}

input,
textarea,
select {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--color-ink);
  background: var(--color-surface-elevated);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #8bb8ab;
  box-shadow: 0 0 0 3px rgba(15, 92, 76, 0.12);
  outline: none;
}

/* —— Status badges —— */
.status,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.status::before,
.badge::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
}

.status-active,
.badge-active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.status-diagnosis_ready,
.badge-info {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.status-pending_review,
.badge-warn {
  background: var(--color-warn-bg);
  color: var(--color-warn);
}

.status-reviewed,
.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

/* —— Alerts / flash —— */
.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
}

.flash.error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: color-mix(in srgb, var(--color-danger) 25%, transparent);
}

.flash.success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-color: color-mix(in srgb, var(--color-success) 25%, transparent);
}

.flash.info {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.disclaimer {
  background: var(--color-warn-bg);
  color: var(--color-warn);
  border: 1px solid var(--color-warn-border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin: var(--space-4) 0;
  font-size: var(--text-sm);
}

/* —— Empty / error states —— */
.empty-state,
.error-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
}

.empty-state-icon,
.error-state-icon {
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto var(--space-4);
  border-radius: 50%;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  display: grid;
  place-items: center;
}

.empty-state h2,
.error-state h1 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
}

.empty-state p,
.error-state p {
  margin: 0 auto var(--space-5);
  color: var(--color-muted);
  max-width: 28ch;
}

/* —— Avatar —— */
.avatar {
  flex: 0 0 auto;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: white;
  background: linear-gradient(145deg, #1a7a66, #0f5c4c);
}

.avatar.lg {
  width: 4.5rem;
  height: 4.5rem;
  font-size: 1.1rem;
}

.avatar.sm {
  width: 2rem;
  height: 2rem;
  font-size: 0.65rem;
}

.avatar.species-pas { background: linear-gradient(145deg, #2a8f7a, #0f5c4c); }
.avatar.species-macka,
.avatar.species-mačka { background: linear-gradient(145deg, #6b8cae, #3d5a80); }
.avatar.species-ptica { background: linear-gradient(145deg, #c47a2c, #8a4b12); }

/* —— Home / dashboard —— */
.hero {
  padding: var(--space-6) 0 var(--space-4);
}

.hero h1 {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  margin: 0 0 var(--space-3);
  max-width: 16ch;
  line-height: 1.15;
}

.hero p {
  color: var(--color-muted);
  font-size: var(--text-lg);
  max-width: 40ch;
  margin: 0;
}

.dashboard-greeting {
  margin-bottom: var(--space-5);
}

.dashboard-greeting h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-2xl);
}

.dashboard-greeting p {
  margin: var(--space-1) 0 0;
  color: var(--color-muted);
}

.attention-card {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-primary-soft);
  border: 1px solid color-mix(in srgb, var(--color-primary) 20%, transparent);
  margin-bottom: var(--space-5);
  text-decoration: none;
  color: inherit;
}

.attention-card strong {
  display: block;
  margin-bottom: 0.15rem;
}

.attention-card p {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: 5.5rem;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  text-decoration: none;
  color: var(--color-ink);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.quick-action:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.quick-action-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  display: grid;
  place-items: center;
}

.quick-action span {
  font-weight: 600;
  font-size: var(--text-sm);
}

.stat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-full);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-size: var(--text-sm);
  color: var(--color-muted);
}

.stat-pill strong {
  color: var(--color-ink);
}

/* —— Pet profiles —— */
.pet-card .avatar.lg {
  margin-bottom: var(--space-3);
}

.pet-fields {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.pet-field dt {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  margin: 0 0 0.15rem;
  font-weight: 600;
}

.pet-field dd {
  margin: 0;
  font-weight: 500;
}

/* —— Offline / install banners —— */
.offline-banner,
.install-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-warn-bg);
  color: var(--color-warn);
  border-bottom: 1px solid var(--color-warn-border);
  font-size: var(--text-sm);
}

.offline-banner.is-visible,
.install-banner.is-visible {
  display: flex;
}

.install-banner {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border-bottom-color: color-mix(in srgb, var(--color-primary) 25%, transparent);
}

.banner-dismiss {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  padding: 0 var(--space-2);
}

/* —— Chat (consultation) —— */
body.chat-page {
  background:
    radial-gradient(ellipse at top right, rgba(15, 92, 76, 0.12) 0%, transparent 45%),
    linear-gradient(180deg, var(--color-bg) 0%, var(--color-bg-accent) 100%);
}

body.chat-page .app-shell.has-bottom-nav {
  padding-bottom: 0;
}

body.chat-page .bottom-nav {
  display: none;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  height: min(78vh, 820px);
  min-height: 520px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  animation: chat-shell-in 0.4s ease both;
}

@keyframes chat-shell-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  backdrop-filter: blur(8px);
}

.chat-peer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.chat-peer-meta {
  min-width: 0;
}

.chat-peer-meta h1 {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-peer-meta p {
  margin: 0.15rem 0 0;
  color: var(--color-muted);
  font-size: 0.88rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
}

.chat-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  margin: -0.35rem 0 -0.35rem -0.5rem;
  border-radius: 50%;
  color: var(--color-ink);
  text-decoration: none;
  flex-shrink: 0;
}

.chat-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: white;
  background: linear-gradient(145deg, #1a7a66, #0f5c4c);
  box-shadow: 0 4px 12px rgba(15, 92, 76, 0.25);
}

.chat-disclaimer {
  padding: 0 1rem;
}

.chat-disclaimer .disclaimer {
  margin: 0.65rem 0 0;
  font-size: 0.82rem;
  padding: 0.55rem 0.75rem;
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.9rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background-color: var(--chat-thread-bg);
  background-image:
    radial-gradient(circle at 20% 20%, rgba(15, 92, 76, 0.05) 0 1px, transparent 1.5px),
    radial-gradient(circle at 80% 40%, rgba(28, 42, 36, 0.04) 0 1px, transparent 1.5px);
  background-size: 18px 18px, 22px 22px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat-system {
  align-self: center;
  max-width: 85%;
  margin: 0.35rem 0;
  text-align: center;
}

.chat-system span {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-full);
  background: rgba(28, 42, 36, 0.08);
  color: var(--color-muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

@media (prefers-color-scheme: dark) {
  .chat-system span {
    background: rgba(255, 255, 255, 0.08);
  }
}

.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  max-width: min(82%, 520px);
  animation: bubble-in 0.25s ease both;
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.chat-row.customer {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-row.assistant,
.chat-row.veterinarian {
  align-self: flex-start;
}

.chat-row .chat-avatar {
  width: 30px;
  height: 30px;
  font-size: 0.62rem;
  box-shadow: none;
}

.chat-avatar.customer {
  background: linear-gradient(145deg, #2a8f7a, #0f5c4c);
}

.chat-avatar.assistant {
  background: linear-gradient(145deg, #5b6e8c, #3d4f6f);
}

.chat-avatar.veterinarian {
  background: linear-gradient(145deg, #c47a2c, #8a4b12);
}

.chat-bubble {
  position: relative;
  padding: 0.55rem 0.85rem 0.4rem;
  border-radius: 18px;
  line-height: 1.45;
  box-shadow: var(--shadow-sm);
}

.chat-sender-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 0.2rem;
}

.chat-row.assistant .chat-bubble {
  background: var(--chat-bubble-assistant);
  color: var(--color-ink);
  border: 1px solid var(--color-info-border);
  border-bottom-left-radius: 6px;
}

.chat-row.assistant .chat-sender-label {
  color: var(--color-info);
}

.chat-row.customer .chat-bubble {
  background: var(--chat-bubble-customer);
  color: #f4fffb;
  border-bottom-right-radius: 6px;
}

.chat-row.customer .chat-sender-label {
  color: rgba(244, 255, 251, 0.85);
  text-align: right;
}

.chat-row.veterinarian .chat-bubble {
  background: var(--chat-bubble-vet);
  color: var(--color-ink);
  border: 1px solid var(--color-warn-border);
  border-bottom-left-radius: 6px;
}

.chat-row.veterinarian .chat-sender-label {
  color: var(--color-warn);
}

.chat-bubble-text {
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.chat-bubble time {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  opacity: 0.7;
  text-align: right;
}

.chat-row.assistant .chat-bubble time,
.chat-row.veterinarian .chat-bubble time {
  color: var(--color-muted);
  opacity: 1;
}

.chat-composer {
  padding: 0.75rem 0.85rem calc(0.9rem + var(--safe-bottom));
  border-top: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 96%, transparent);
}

.chat-compose-form {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  background: var(--color-surface-elevated);
  border: 1.5px solid var(--color-border);
  border-radius: 24px;
  padding: 0.35rem 0.4rem 0.35rem 0.9rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-compose-form:focus-within {
  border-color: #8bb8ab;
  box-shadow: 0 0 0 3px rgba(15, 92, 76, 0.12);
}

.chat-compose-form.is-submitting {
  opacity: 0.7;
  pointer-events: none;
}

.chat-input {
  flex: 1;
  width: auto !important;
  min-height: auto !important;
  border: none !important;
  outline: none;
  resize: none;
  padding: 0.55rem 0 !important;
  max-height: 140px;
  background: transparent !important;
  box-shadow: none !important;
  line-height: 1.4;
  field-sizing: content;
}

.chat-send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.chat-send:hover {
  background: var(--color-primary-hover);
  transform: scale(1.04);
}

.chat-send:active {
  transform: scale(0.96);
}

.chat-send:disabled {
  opacity: 0.55;
  pointer-events: none;
}

.chat-summary-btn {
  white-space: nowrap;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  min-height: 2.25rem;
}

.chat-aside {
  display: grid;
  gap: 0.75rem;
}

.chat-card h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

.chat-summary-mobile {
  display: none;
  margin-bottom: 0.55rem;
}

.chat-typing {
  display: none;
  align-self: flex-start;
  padding: 0.65rem 1rem;
  border-radius: 18px;
  background: var(--chat-bubble-assistant);
  border: 1px solid var(--color-info-border);
  gap: 0.3rem;
}

.chat-typing.is-visible {
  display: inline-flex;
}

.chat-typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--color-info);
  animation: typing-dot 1.2s ease infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-dot {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* —— Auth pages —— */
.auth-card {
  max-width: 26rem;
  margin: var(--space-6) auto;
}

.auth-card h1 {
  margin-top: 0;
  font-family: var(--font-display);
}

.auth-footer {
  margin-top: var(--space-5);
  text-align: center;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

/* —— Skeleton loaders —— */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-border-subtle) 25%,
    var(--color-surface) 50%,
    var(--color-border-subtle) 75%
  );
  background-size: 200% 100%;
  animation: skeleton 1.2s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-line {
  height: 0.85rem;
  margin-bottom: var(--space-2);
}

.skeleton-line.w60 { width: 60%; }
.skeleton-line.w80 { width: 80%; }
.skeleton-card {
  height: 4.5rem;
}

/* —— Profile sheet —— */
.profile-panel {
  display: grid;
  gap: var(--space-4);
}

.profile-identity {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.profile-identity h2 {
  margin: 0;
  font-size: var(--text-xl);
}

.profile-identity p {
  margin: 0.15rem 0 0;
  color: var(--color-muted);
}

/* —— Responsive: tablet+ —— */
@media (min-width: 768px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .quick-actions {
    grid-template-columns: repeat(4, 1fr);
  }

  .header-nav {
    display: flex;
  }

  .user-chip {
    display: inline;
  }

  .bottom-nav {
    display: none;
  }

  .app-shell.has-bottom-nav {
    padding-bottom: 0;
  }

  .sticky-actions {
    bottom: var(--space-4);
  }

  body.chat-page .bottom-nav {
    display: none;
  }
}

@media (min-width: 1024px) {
  .sidebar {
    display: block;
  }

  .header-nav {
    display: none;
  }

  main.app-main {
    width: min(48rem, calc(100% - 3rem));
    margin-left: var(--space-8);
    margin-right: auto;
  }

  main.app-main.wide {
    width: min(56rem, calc(100% - 3rem));
  }
}

@media (max-width: 640px) {
  main.chat-main {
    width: 100%;
    margin: 0;
  }

  .chat-shell {
    height: calc(100dvh - var(--header-h) - var(--safe-top));
    min-height: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  body.chat-page .site-header {
    display: none;
  }

  body.chat-page .chat-shell {
    height: 100dvh;
  }

  .chat-back {
    display: grid;
  }

  .chat-row {
    max-width: 90%;
  }

  .chat-top-action {
    display: none;
  }

  .chat-summary-mobile {
    display: block;
  }
}

/* Legacy table → prefer cards, keep tables usable on desktop */
table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

@media (max-width: 640px) {
  .table-wrap {
    display: none;
  }
}

@media (min-width: 641px) {
  .mobile-only-list {
    display: none;
  }
}
