/* ==========================================================================
   iya.ru — base layer
   Reset, global element styles, typography, focus and a11y primitives.
   Depends on: tokens.css. Overrides live in components.css / utilities.css.
   ========================================================================== */

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  /* Sticky header offset for in-page anchors. */
  scroll-padding-block-start: calc(var(--header-height) + var(--space-4));
}

body {
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-normal);
  color: var(--text);
  background-color: var(--bg);
  font-feature-settings: 'cv02' 1, 'cv03' 1, 'cv04' 1, 'cv11' 1, 'ss01' 1;
  font-variation-settings: 'opsz' 16;
  transition: background-color var(--duration-base) var(--ease-out),
    color var(--duration-base) var(--ease-out);
}

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

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

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

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

ul[class],
ol[class] {
  list-style: none;
  padding: 0;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--text-link-hover);
}

/* Only show the focus ring for keyboard users. */
:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

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

mark {
  background: var(--mark-bg);
  color: inherit;
  padding: 0 0.15em;
  border-radius: 2px;
}

hr {
  border: 0;
  border-block-start: 1px solid var(--border);
  margin-block: var(--space-6);
}

/* --- typography ---------------------------------------------------------- */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-3xl);
  letter-spacing: var(--tracking-tighter);
  font-weight: var(--weight-bold);
}

h2 {
  font-size: var(--text-2xl);
}

h3 {
  font-size: var(--text-xl);
}

h4 {
  font-size: var(--text-lg);
}

h5 {
  font-size: var(--text-md);
}

h6 {
  font-size: var(--text-base);
}

.display {
  font-size: var(--text-4xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tighter);
  line-height: var(--leading-none);
}

.display-xl {
  font-size: var(--text-5xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.045em;
  line-height: 0.98;
}

.lead {
  font-size: var(--text-lg);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  text-wrap: pretty;
}

.small {
  font-size: var(--text-sm);
}

.tiny {
  font-size: var(--text-xs);
}

.muted {
  color: var(--text-muted);
}

.faint {
  color: var(--text-faint);
}

.secondary {
  color: var(--text-secondary);
}

.strong,
b,
strong {
  font-weight: var(--weight-semibold);
}

.mono,
code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-feature-settings: 'zero' 1, 'ss01' 1;
}

code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.14em 0.38em;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-subtle);
  word-break: break-word;
}

pre {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  overflow-x: auto;
  line-height: var(--leading-relaxed);
  tab-size: 2;
}

pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: var(--text-sm);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.1em 0.4em;
  font-size: var(--text-xs);
  line-height: 1.4;
  text-align: center;
  color: var(--text-secondary);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-block-end-width: 2px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
}

blockquote {
  border-inline-start: 3px solid var(--accent-border);
  padding-inline-start: var(--space-4);
  color: var(--text-secondary);
  font-style: normal;
}

/* Numeric alignment in tables and metric read-outs. */
.numeric,
.tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

/* --- lists --------------------------------------------------------------- */
.prose ul,
.prose ol {
  padding-inline-start: 1.35em;
  margin-block: var(--space-3);
}

.prose ul {
  list-style: disc;
}

.prose ol {
  list-style: decimal;
}

.prose li + li {
  margin-block-start: var(--space-1-5);
}

.prose li::marker {
  color: var(--text-faint);
}

/* --- prose (long-form content: docs, pages, messages) -------------------- */
.prose {
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  max-width: 72ch;
}

.prose > * + * {
  margin-block-start: var(--space-4);
}

.prose h2,
.prose h3,
.prose h4 {
  color: var(--text);
  margin-block-start: var(--space-8);
  scroll-margin-block-start: calc(var(--header-height) + var(--space-4));
}

.prose h2 {
  font-size: var(--text-xl);
  letter-spacing: var(--tracking-tight);
}

.prose h3 {
  font-size: var(--text-lg);
}

.prose a {
  text-decoration: underline;
  text-decoration-color: var(--accent-border);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.prose a:hover {
  text-decoration-color: currentColor;
}

.prose strong {
  color: var(--text);
}

.prose img {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

/* --- tables -------------------------------------------------------------- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
}

caption {
  caption-side: bottom;
  text-align: start;
  padding-block: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

th,
td {
  text-align: start;
  padding: var(--space-2-5) var(--space-3);
  border-block-end: 1px solid var(--border-subtle);
  vertical-align: middle;
}

thead th {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: var(--tracking-wide);
  background: var(--surface-2);
  border-block-end: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
}

tbody tr {
  transition: background-color var(--duration-fast) var(--ease-out);
}

tbody tr:hover {
  background: var(--surface-hover);
}

tbody tr:last-child td {
  border-block-end: 0;
}

tfoot td {
  font-weight: var(--weight-semibold);
  border-block-start: 1px solid var(--border);
  color: var(--text);
}

td.num,
th.num {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

/* --- forms (base; components.css refines) -------------------------------- */
fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

legend {
  font-weight: var(--weight-semibold);
  padding-block-end: var(--space-2);
}

label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

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

input[type='search']::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

/* --- icons --------------------------------------------------------------- */
.icon {
  flex: none;
  display: inline-block;
  vertical-align: -0.15em;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.icon-lg {
  width: 24px;
  height: 24px;
}

.icon-xl {
  width: 32px;
  height: 32px;
}

.icon-muted {
  color: var(--text-faint);
}

/* Mirror directional icons in RTL without touching markup. */
[dir='rtl'] .icon-flip {
  transform: scaleX(-1);
}

/* --- a11y primitives ----------------------------------------------------- */
.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--space-2);
  z-index: var(--z-tooltip);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-inverse);
  color: var(--text-inverse);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transform: translateY(-160%);
  transition: transform var(--duration-fast) var(--ease-out);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

[hidden] {
  display: none !important;
}

[aria-busy='true'] {
  cursor: progress;
}

/* --- scrollbars ---------------------------------------------------------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: content-box;
}

/* --- print --------------------------------------------------------------- */
@media print {
  :root {
    --bg: #fff;
    --text: #000;
    --text-secondary: #222;
    --border: #ccc;
  }

  .no-print,
  .app-sidebar,
  .app-header,
  .toasts,
  .theme-toggle,
  .lang-switcher {
    display: none !important;
  }

  body {
    font-size: 11pt;
  }

  a[href^='http']::after {
    content: ' (' attr(href) ')';
    font-size: 0.85em;
    color: #555;
  }

  .card,
  .panel {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }

  h1,
  h2,
  h3 {
    break-after: avoid;
  }
}
