/* ==========================================================================
   tokens.css — 3-слойная дизайн-система «Многопрофильной ветеринарной клиники СПбГУВМ»
   Слой 1: Примитивные токены (палитра Deep Navy & White, сетка 8px, шрифты)
   Слой 2: Семантические токены (поверхности, текст, границы >=3:1 WCAG, статусы)
   Слой 3: Компонентные и системные токены (тени navy, радиусы, тайминги, фокус)
   ========================================================================== */

:root {
  /* ------------------------------------------------------------------------
     СЛОЙ 1: ПРИМИТИВНЫЕ ТОКЕНЫ (Primitive Tokens)
     ------------------------------------------------------------------------ */

  /* Фирменная палитра Deep Navy & Crisp White */
  --palette-navy-950: #0A1F44;
  --palette-navy-900: #0F2B5B;
  --palette-navy-800: #153B7A;
  --palette-blue-600: #1E56A0;
  --palette-blue-500: #2969BC;
  --palette-blue-100: #E8F0FC;

  --palette-white: #FFFFFF;
  --palette-soft-tint: #F4F7FB;
  --palette-soft-alt: #EDF2F8;

  /* Границы и нейтральные оттенки текста (проверено на WCAG AA/AAA) */
  --palette-border-subtle: #DCE4F0;
  --palette-border-control: #7589A8; /* >= 3.55:1 на #FFFFFF и >= 3.31:1 на #F4F7FB */
  --palette-text-primary: #0A1F44;   /* >= 15.8:1 на #FFFFFF */
  --palette-text-secondary: #334666; /* >= 9.3:1 на #FFFFFF */
  --palette-text-muted: #506380;     /* >= 5.9:1 на #FFFFFF (AA крупный и обычный) */
  --palette-text-on-dark: #FFFFFF;
  --palette-text-on-dark-soft: #D7E3F5; /* >= 11.4:1 на #0A1F44 */

  /* Статусные цвета (Success / Warning / Error) */
  --palette-success-fg: #0A583B;
  --palette-success-bg: #EAF7F1;
  --palette-success-border: #8CC9AF;

  --palette-warning-fg: #7C3F00;
  --palette-warning-bg: #FFF7E6;
  --palette-warning-border: #E8BA6E;

  --palette-error-fg: #991B1B;
  --palette-error-bg: #FEF2F2;
  --palette-error-border: #E5A4A4;

  /* Системный кириллический стек шрифтов (без внешних CDN / Google Fonts) */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;

  /* Базовая 8px сетка отступов */
  --space-1: 4px;   /* 0.5x для микро-интервалов */
  --space-2: 8px;   /* 1x */
  --space-3: 12px;  /* 1.5x */
  --space-4: 16px;  /* 2x */
  --space-5: 20px;  /* 2.5x */
  --space-6: 24px;  /* 3x */
  --space-8: 32px;  /* 4x */
  --space-10: 40px; /* 5x */
  --space-12: 48px; /* 6x */
  --space-16: 64px; /* 8x */
  --space-20: 80px; /* 10x */

  /* ------------------------------------------------------------------------
     СЛОЙ 2: СЕМАНТИЧЕСКИЕ ТОКЕНЫ (Semantic Tokens)
     ------------------------------------------------------------------------ */

  /* Поверхности */
  --bg-canvas: var(--palette-white);
  --bg-surface: var(--palette-white);
  --bg-soft: var(--palette-soft-tint);
  --bg-soft-hover: var(--palette-soft-alt);
  --bg-brand-soft: var(--palette-blue-100);
  --bg-navy: var(--palette-navy-950);
  --bg-navy-elevated: var(--palette-navy-900);
  --bg-navy-accent: var(--palette-navy-800);

  /* Типографика и контент */
  --text-primary: var(--palette-text-primary);
  --text-secondary: var(--palette-text-secondary);
  --text-muted: var(--palette-text-muted);
  --text-brand: var(--palette-blue-600);
  --text-on-dark: var(--palette-text-on-dark);
  --text-on-dark-muted: var(--palette-text-on-dark-soft);

  /* Действия и брендовые состояния */
  --brand-primary: var(--palette-navy-900);
  --brand-primary-hover: var(--palette-navy-800);
  --brand-primary-active: var(--palette-navy-950);
  --brand-accent: var(--palette-blue-600);
  --brand-accent-hover: var(--palette-blue-500);

  /* Границы */
  --border-subtle: var(--palette-border-subtle);
  --border-control: var(--palette-border-control);
  --border-brand: var(--palette-navy-800);
  --border-on-dark: rgba(255, 255, 255, 0.24);
  --border-on-dark-strong: rgba(255, 255, 255, 0.56);

  /* Статусы */
  --status-success-fg: var(--palette-success-fg);
  --status-success-bg: var(--palette-success-bg);
  --status-success-border: var(--palette-success-border);

  --status-warning-fg: var(--palette-warning-fg);
  --status-warning-bg: var(--palette-warning-bg);
  --status-warning-border: var(--palette-warning-border);

  --status-error-fg: var(--palette-error-fg);
  --status-error-bg: var(--palette-error-bg);
  --status-error-border: var(--palette-error-border);

  /* Двойной контур фокуса (WCAG 2.4.7 / 2.4.11) */
  --focus-inner: #FFFFFF;
  --focus-outer: #1E56A0;
  --focus-dark-inner: #0A1F44;
  --focus-dark-outer: #FFFFFF;

  /* ------------------------------------------------------------------------
     СЛОЙ 3: КОМПОНЕНТНЫЕ, ТИПОГРАФИЧЕСКИЕ И ПРОСТРАНСТВЕННЫЕ ТОКЕНЫ
     ------------------------------------------------------------------------ */

  /* Fluid-типографика на основе clamp() */
  --text-display: clamp(2rem, 1.45rem + 2.35vw, 3.25rem); /* 32px -> 52px */
  --text-h1: clamp(1.75rem, 1.35rem + 1.6vw, 2.625rem);   /* 28px -> 42px */
  --text-h2: clamp(1.45rem, 1.2rem + 1.05vw, 2.05rem);    /* 23px -> 33px */
  --text-h3: clamp(1.1875rem, 1.08rem + 0.45vw, 1.4rem);  /* 19px -> 22.4px */
  --text-h4: clamp(1.03rem, 0.98rem + 0.2vw, 1.125rem);   /* 16.5px -> 18px */
  --text-lead: clamp(1.03rem, 0.98rem + 0.25vw, 1.1875rem);
  --text-body: 1rem;     /* 16px */
  --text-sm: 0.875rem;   /* 14px */
  --text-xs: 0.78rem;    /* 12.5px */

  --leading-tight: 1.16;
  --leading-snug: 1.3;
  --leading-base: 1.58;
  --leading-relaxed: 1.68;

  /* Контейнер и шапка */
  --container-max: 1240px;
  --container-narrow: 860px;
  --container-gutter: clamp(12px, 3vw, 32px);

  --header-height: 80px;
  --header-height-scrolled: 64px;
  --header-height-mobile: 60px;

  /* Скругления */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 9999px;

  /* Тени в оттенках Deep Navy */
  --shadow-navy-xs: 0 1px 2px rgba(10, 31, 68, 0.06);
  --shadow-navy-sm: 0 4px 12px rgba(10, 31, 68, 0.08),
    0 1px 3px rgba(10, 31, 68, 0.05);
  --shadow-navy-md: 0 10px 26px rgba(10, 31, 68, 0.11),
    0 2px 6px rgba(10, 31, 68, 0.06);
  --shadow-navy-lg: 0 20px 44px rgba(10, 31, 68, 0.16),
    0 6px 14px rgba(10, 31, 68, 0.08);
  --shadow-navy-xl: 0 28px 64px rgba(10, 31, 68, 0.26);

  /* Анимации и Z-слои */
  --ease-standard: cubic-bezier(0.2, 0.8, 0.2, 1);
  --duration-fast: 150ms;
  --duration-base: 220ms;
  --duration-slow: 320ms;

  --z-base: 1;
  --z-sticky: 40;
  --z-tray: 70;
  --z-header: 90;
  --z-cookie: 95;
  --z-drawer: 120;
  --z-modal: 150;
  --z-lightbox: 170;
  --z-toast: 200;
}

/* ==========================================================================
   Базовый сброс и глобальные стандарты доступности
   ========================================================================== */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--leading-base);
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  overflow-x: clip;
  display: flex;
  flex-direction: column;
  text-rendering: optimizeLegibility;
}

main {
  flex: 1 0 auto;
  min-width: 0;
}

img,
picture,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

img {
  height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--text-brand);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

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

h1,
h2,
h3,
h4,
p,
ul,
ol,
dl,
dd,
figure,
blockquote {
  margin: 0;
}

ul,
ol {
  padding: 0;
}

/* Табличное выравнивание цифр (цены, телефоны, даты, счётчики) */
.tabular-nums {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* Скрытие только визуально — доступно для скринридеров */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Базовый контейнер */
.container {
  width: 100%;
  max-width: calc(var(--container-max) + 2 * var(--container-gutter));
  margin-inline: auto;
  padding-inline: var(--container-gutter);
}

.container--narrow {
  max-width: calc(var(--container-narrow) + 2 * var(--container-gutter));
}

/* Двойное кольцо :focus-visible (чётко заметно и на белом, и на тёмном фоне) */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-outer);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--focus-inner), 0 0 0 6px var(--focus-outer);
}

:where(.section--navy, .site-footer, .mobile-drawer, .btn--primary, .btn--on-dark-outline) :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible,
.btn--primary:focus-visible,
.btn--on-dark:focus-visible,
.btn--on-dark-outline:focus-visible {
  outline: 2px solid var(--focus-dark-outer);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--focus-dark-inner), 0 0 0 6px var(--focus-dark-outer);
}

/* Безопасный плавный скролл с учётом закреплённой шапки */
[id] {
  scroll-margin-top: calc(var(--header-height) + var(--space-6));
}

/* --------------------------------------------------------------------------
   Режим сниженного движения (prefers-reduced-motion)
   -------------------------------------------------------------------------- */
@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;
    scroll-behavior: auto !important;
  }
}

/* --------------------------------------------------------------------------
   Режим повышенного контраста Windows / Forced Colors
   -------------------------------------------------------------------------- */
@media (forced-colors: active) {
  :root {
    --shadow-navy-xs: none;
    --shadow-navy-sm: none;
    --shadow-navy-md: none;
    --shadow-navy-lg: none;
    --shadow-navy-xl: none;
  }

  .btn,
  .badge,
  .pill,
  .input,
  .select,
  .textarea,
  .doctor-card,
  .service-card,
  .review-card,
  .modal,
  .site-header,
  .estimate-tray,
  .callout {
    border: 1px solid CanvasText !important;
  }

  .btn--primary,
  .pill.is-active,
  .pill[aria-pressed="true"] {
    background-color: Highlight !important;
    color: HighlightText !important;
    forced-color-adjust: none;
  }

  :where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid Highlight !important;
    outline-offset: 2px !important;
    box-shadow: none !important;
  }
}
