/*
  base.css — сброс, типографика по элементам, нормализация форм между браузерами.
  Подключается на всех страницах сразу после tokens.css.
*/

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

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scrollbar-gutter: stable;
  }

  html,
  body {
    margin: 0;
    padding: 0;
  }

  body {
    min-height: 100dvh;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden; /* страховка: контент нигде не должен требовать горизонтальный скролл */
  }

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

  /* Инлайн-иконки из спрайта (см. app/static/icons/sprite.svg) — единая сетка 24px, currentColor */
  .icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: inline-block;
    color: currentColor;
  }

  h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--space-3) 0;
    line-height: var(--lh-tight);
    font-weight: 700;
    text-wrap: balance;
    overflow-wrap: break-word;
  }

  h1 { font-size: var(--fs-2xl); }
  h2 { font-size: var(--fs-xl); }
  h3 { font-size: var(--fs-lg); }

  p {
    margin: 0 0 var(--space-3) 0;
    max-width: 65ch;
    overflow-wrap: break-word;
    hyphens: auto;
  }

  ul, ol {
    margin: 0 0 var(--space-3) 0;
    padding-inline-start: var(--space-5);
  }

  a {
    color: var(--color-accent);
    text-decoration-thickness: 1px;
  }

  a:hover {
    text-decoration-thickness: 2px;
  }

  small {
    font-size: var(--fs-xs);
    color: var(--color-text-muted);
  }

  code, pre, kbd {
    font-family: var(--font-mono);
    font-size: 0.92em;
  }

  hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--space-6) 0;
  }

  table {
    border-collapse: collapse;
    width: 100%;
    font-variant-numeric: tabular-nums;
  }

  /* ---------- Нормализация форм ---------- */
  input,
  textarea,
  select,
  button {
    font-family: inherit;
    font-size: var(--fs-base); /* ≥16px — iOS не зумит страницу при фокусе */
    color: inherit;
  }

  input,
  textarea,
  select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    min-height: 44px;
    width: 100%;
    color: var(--color-text);
    transition: border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
  }

  @media (prefers-reduced-motion: reduce) {
    input, textarea, select {
      transition: none;
    }
  }

  textarea {
    min-height: 44px;
    resize: vertical;
    line-height: var(--lh-normal);
  }

  input::placeholder,
  textarea::placeholder {
    color: var(--color-text-faint);
  }

  input:hover,
  textarea:hover,
  select:hover {
    border-color: var(--color-border-strong);
  }

  input:focus-visible,
  textarea:focus-visible,
  select:focus-visible,
  button:focus-visible,
  a:focus-visible,
  [tabindex]:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-color: var(--color-accent);
  }

  input:disabled,
  textarea:disabled,
  select:disabled,
  button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  /* Перекраска автозаполнения Chrome/Яндекс.Браузера под тему */
  input:-webkit-autofill,
  input:-webkit-autofill:hover,
  input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--color-text);
    box-shadow: 0 0 0 1000px var(--color-surface) inset;
    caret-color: var(--color-text);
    transition: background-color 0s;
  }

  select {
    background-image:
      linear-gradient(45deg, transparent 50%, currentColor 50%),
      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position:
      calc(100% - 20px) center,
      calc(100% - 15px) center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: var(--space-8);
    color: var(--color-text);
  }

  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    min-height: 0;
    padding: 0;
    display: inline-grid;
    place-content: center;
    border-radius: var(--radius-sm);
    accent-color: var(--color-accent);
    flex-shrink: 0;
  }

  input[type="radio"] {
    border-radius: var(--radius-pill);
  }

  input[type="file"] {
    padding: var(--space-2);
  }

  input[type="date"] {
    min-width: 0;
  }

  button {
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
  }

  /* Видно скринридеру, скрыто визуально — подписи там, где место экономится плейсхолдером */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  ::selection {
    background: var(--color-accent-soft);
    color: var(--color-text);
  }
}
