/* Юрист РБ — общая дизайн-система (все страницы: лендинг, вход, чат).
   Два варианта дизайна: :root[data-design="classic"] и :root[data-design="modern"] (по умолчанию — modern),
   у каждого — светлая и тёмная схема (prefers-color-scheme). Атрибут ставит theme.js до первой отрисовки.

   Токены-контракт (оба дизайна определяют все):
     --bg --bg-elev --surface --surface-2 --text --text-muted --text-faint --border --border-strong
     --accent --accent-hover --accent-contrast --accent-soft --danger --danger-soft --warning --warning-soft
     --success --success-soft --radius-sm --radius-md --radius-lg --radius-pill --shadow-sm --shadow-md --shadow-lg
     --font-sans --font-display --font-mono --focus-ring --sidebar-bg --bubble-user-bg --bubble-user-text
     --bubble-assistant-bg --header-bg
   Типы: цвета — обычные цвета (--focus-ring — ЦВЕТ: outline: 2px solid var(--focus-ring) или
   box-shadow: 0 0 0 3px var(--focus-ring)); --shadow-* — значения box-shadow; --radius-* — длины.
   Дополнительно: --link (цвет ссылок в тексте), --accent-2 / --accent-3 (вторые цвета для градиентов),
   --overlay (затемнение под модальными окнами), --heading-weight, --heading-tracking, --ease. */

/* ===================== Токены: «Современный» (по умолчанию) ===================== */

:root,
:root[data-design="modern"] {
  color-scheme: light dark;

  --bg: #ffffff;
  --bg-elev: #f8f8fa;
  --surface: #ffffff;
  --surface-2: #f3f3f6;
  --text: #0d0d12;
  --text-muted: #55555f;
  --text-faint: #72727d;
  --border: #e6e6eb;
  --border-strong: #d2d2da;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --accent-soft: #eef0ff;
  --accent-2: #8b5cf6;
  --accent-3: #06b6d4;
  --link: #4f46e5;

  --danger: #c81e1e;
  --danger-soft: #fef1f1;
  --warning: #a14b06;
  --warning-soft: #fff7e6;
  --success: #047857;
  --success-soft: #eafaf3;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(16, 16, 28, 0.06);
  --shadow-md: 0 1px 2px rgba(16, 16, 28, 0.04), 0 6px 16px -4px rgba(16, 16, 28, 0.1);
  --shadow-lg: 0 2px 6px rgba(16, 16, 28, 0.04), 0 28px 56px -16px rgba(16, 16, 28, 0.22);

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-display: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --heading-weight: 700;
  --heading-tracking: -0.022em;

  --focus-ring: #6366f1;
  --overlay: rgba(10, 10, 18, 0.48);

  --sidebar-bg: #f7f7f9;
  --bubble-user-bg: #f0f0f4;
  --bubble-user-text: #0d0d12;
  --bubble-assistant-bg: transparent;
  --header-bg: rgba(255, 255, 255, 0.72);

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root,
  :root[data-design="modern"] {
    --bg: #0c0c10;
    --bg-elev: #131318;
    --surface: #17171d;
    --surface-2: #202028;
    --text: #ededf2;
    --text-muted: #a5a5b2;
    --text-faint: #7f7f8c;
    --border: #27272f;
    --border-strong: #3a3a45;

    --accent: #5f61ee;
    --accent-hover: #7072f2;
    --accent-contrast: #ffffff;
    --accent-soft: rgba(99, 102, 241, 0.17);
    --accent-2: #a78bfa;
    --accent-3: #22d3ee;
    --link: #a5a8ff;

    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.13);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.12);
    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.12);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 20px -6px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 30px 60px -18px rgba(0, 0, 0, 0.75);

    --focus-ring: #8b8ef8;
    --overlay: rgba(0, 0, 0, 0.62);

    --sidebar-bg: #111116;
    --bubble-user-bg: #24242d;
    --bubble-user-text: #ededf2;
    --bubble-assistant-bg: transparent;
    --header-bg: rgba(12, 12, 16, 0.7);
  }
}

/* ===================== Токены: «Классика» ===================== */

:root[data-design="classic"] {
  --bg: #f6f2e9;
  --bg-elev: #fbf8f2;
  --surface: #fffdf9;
  --surface-2: #f0eadc;
  --text: #18212f;
  --text-muted: #4b5466;
  --text-faint: #646b79;
  --border: #e2d9c6;
  --border-strong: #c8bb9c;

  --accent: #1c355e;
  --accent-hover: #142a4d;
  --accent-contrast: #fffdf8;
  --accent-soft: #e6e9f0;
  --accent-2: #b38b3d;   /* золото */
  --accent-3: #8c6a24;   /* тёмное золото — для текста */
  --link: #1c4a8a;

  --danger: #a3302a;
  --danger-soft: #f8e5e1;
  --warning: #8a5a00;
  --warning-soft: #f7ecd3;
  --success: #2e6b3f;
  --success-soft: #e4efe4;

  --radius-sm: 3px;
  --radius-md: 5px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 0 rgba(24, 33, 47, 0.04), 0 1px 2px rgba(24, 33, 47, 0.06);
  --shadow-md: 0 1px 2px rgba(24, 33, 47, 0.06), 0 8px 18px -8px rgba(24, 33, 47, 0.16);
  --shadow-lg: 0 2px 4px rgba(24, 33, 47, 0.05), 0 22px 44px -18px rgba(24, 33, 47, 0.3);

  --font-sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --heading-weight: 600;
  --heading-tracking: -0.005em;

  --focus-ring: #9c7628;
  --overlay: rgba(14, 21, 34, 0.5);

  --sidebar-bg: #efe9db;
  --bubble-user-bg: #1c355e;
  --bubble-user-text: #fffdf8;
  --bubble-assistant-bg: #fffdf9;
  --header-bg: rgba(246, 242, 233, 0.94);
}

@media (prefers-color-scheme: dark) {
  :root[data-design="classic"] {
    --bg: #0e1522;
    --bg-elev: #131c2c;
    --surface: #162133;
    --surface-2: #1c293e;
    --text: #ece5d6;
    --text-muted: #b6af9f;
    --text-faint: #8f8a7b;
    --border: #253248;
    --border-strong: #364763;

    --accent: #d1ad62;
    --accent-hover: #ddbd78;
    --accent-contrast: #15110a;
    --accent-soft: rgba(209, 173, 98, 0.14);
    --accent-2: #d1ad62;
    --accent-3: #e0c486;
    --link: #e0c486;

    --danger: #f0897f;
    --danger-soft: rgba(240, 137, 127, 0.13);
    --warning: #e9b759;
    --warning-soft: rgba(233, 183, 89, 0.13);
    --success: #85c897;
    --success-soft: rgba(133, 200, 151, 0.13);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 22px -10px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.3), 0 26px 50px -20px rgba(0, 0, 0, 0.8);

    --focus-ring: #d1ad62;
    --overlay: rgba(4, 8, 14, 0.66);

    --sidebar-bg: #0b111c;
    --bubble-user-bg: #23344f;
    --bubble-user-text: #ece5d6;
    --bubble-assistant-bg: #162133;
    --header-bg: rgba(14, 21, 34, 0.92);
  }
}

/* ===================== Сброс и базовая типографика ===================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--heading-weight);
  letter-spacing: var(--heading-tracking);
  line-height: 1.2;
  text-wrap: balance;
}

p, ul, ol, dl, dd, figure, blockquote, pre, fieldset {
  margin: 0;
}

ul, ol {
  padding: 0;
}

fieldset {
  padding: 0;
  border: 0;
  min-width: 0;
}

legend {
  padding: 0;
}

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

img, video {
  height: auto;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

a {
  color: var(--link);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

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

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

b, strong {
  font-weight: 650;
}

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

[hidden] {
  display: none !important;
}

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

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Значки из /icons/sprite.svg: <svg class="icon"><use href="/icons/sprite.svg#имя"/></svg> */
.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  display: inline-block;
  vertical-align: -0.2em;
}

/* ===================== Общие классы ===================== */

.container {
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}

@media (min-width: 768px) {
  .container {
    padding-inline: 32px;
  }
}

.visually-hidden {
  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;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform 0.15s var(--ease);
}

.skip-link:focus-visible {
  transform: none;
}

/* --- Кнопки --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease),
    box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}

.btn:hover {
  text-decoration: none;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

.btn .icon {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}

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

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
}

.btn-lg {
  min-height: 52px;
  padding: 14px 24px;
  font-size: 16px;
}

.btn-block {
  display: flex;
  width: 100%;
}

@media (pointer: coarse) {
  .btn-sm {
    min-height: 40px;
  }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn .icon {
  width: 22px;
  height: 22px;
}

.link-btn {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
  cursor: pointer;
}

.link-btn:disabled {
  color: var(--text-faint);
  text-decoration: none;
}

/* --- Карточки, бейджи, поля --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* меньше 16px — iOS увеличивает страницу при фокусе */
  line-height: 1.4;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

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

.input:focus-visible,
.input:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* --- Модальные окна (<dialog class="modal">) — по центру на компьютере, снизу на телефоне --- */

.modal {
  width: min(640px, calc(100% - 32px));
  max-height: min(84vh, 760px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal[open] {
  display: flex;
  flex-direction: column;
  animation: modal-in 0.2s var(--ease);
}

.modal::backdrop {
  background: var(--overlay);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 14px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 18px;
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px 22px 22px;
  -webkit-overflow-scrolling: touch;
}

.modal-foot {
  padding: 12px 22px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

@media (max-width: 599px) {
  .modal {
    width: 100%;
    max-width: none;
    max-height: 88vh;
    margin: auto 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
  }

  .modal[open] {
    animation-name: sheet-in;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(40px);
    opacity: 0.4;
  }
}

/* Текст от сервера в стиле Telegram: переводы строк значимы */
.rich {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.rich blockquote {
  margin: 0.5em 0;
  padding: 0.25em 0 0.25em 0.9em;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

.rich pre {
  white-space: pre-wrap;
  padding: 0.6em 0.8em;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.rich code {
  padding: 0.05em 0.3em;
  border-radius: 4px;
  background: var(--surface-2);
}

.rich pre code {
  padding: 0;
  background: none;
}

/* ===================== «Классика»: детали общих элементов ===================== */

:root[data-design="classic"] .btn {
  letter-spacing: 0.01em;
}

:root[data-design="classic"] .btn-primary {
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

:root[data-design="classic"] .btn-secondary {
  box-shadow: none;
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

:root[data-design="classic"] .btn-secondary:hover {
  background: var(--accent-soft);
}

:root[data-design="classic"] .badge {
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--accent-2);
  color: var(--accent-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11.5px;
}

:root[data-design="classic"] .card {
  box-shadow: none;
}

:root[data-design="classic"] .modal {
  border-top: 3px solid var(--accent-2);
}

@media (prefers-color-scheme: dark) {
  :root[data-design="classic"] .btn-secondary {
    border-color: var(--accent-2);
    color: var(--accent-3);
  }
}

/* «Современный»: мягкие градиенты на главной кнопке */
:root:not([data-design="classic"]) .btn-primary {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0));
}

:root:not([data-design="classic"]) .btn-primary:hover {
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--accent) 70%, transparent);
}

/* ===================== Переключатель дизайна (рисует theme.js) ===================== */

.design-picker {
  position: fixed;
  left: var(--design-picker-left, max(12px, env(safe-area-inset-left)));
  bottom: var(--design-picker-bottom, max(12px, env(safe-area-inset-bottom)));
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: var(--shadow-md);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1;
  opacity: 0.9;
  transition: opacity 0.15s var(--ease);
}

.design-picker:hover,
.design-picker:focus-within {
  opacity: 1;
}

.design-picker-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px 0 8px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
}

.design-picker-toggle:hover {
  color: var(--text);
}

.design-picker-toggle .icon {
  width: 18px;
  height: 18px;
}

.design-picker-option {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.design-picker-option:hover {
  background: var(--surface-2);
  color: var(--text);
}

.design-picker-option[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
}

.design-picker.is-collapsed .design-picker-option {
  display: none;
}

.design-picker.is-collapsed .design-picker-toggle {
  padding: 0 8px;
}

.design-picker.is-collapsed .design-picker-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (pointer: coarse) {
  .design-picker-toggle,
  .design-picker-option {
    height: 36px;
  }
}

/* Смена дизайна — без анимаций переходов, чтобы не мигало */
.design-switching *,
.design-switching *::before,
.design-switching *::after {
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
