/* ─────────────────────────────────────────────────────────────────────────────
   SXEMA2 — дизайн-система (перенос стиля «Верстак» / StartMebel)
   Монохром: светло-серый фон, белые карточки, чёрный акцент.
   Шрифты: Onest (текст) + IBM Plex Mono (код, цифры, обозначения).
   Файлы: tokens + шрифты + база; компоненты — в admin.css / viewer.css.
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Шрифты (локальные, офлайн) ── */
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 400;
  src: url('/static/fonts/onest-cyrillic-400.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 400;
  src: url('/static/fonts/onest-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 500;
  src: url('/static/fonts/onest-cyrillic-500.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 500;
  src: url('/static/fonts/onest-latin-500.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 600;
  src: url('/static/fonts/onest-cyrillic-600.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 600;
  src: url('/static/fonts/onest-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 700;
  src: url('/static/fonts/onest-cyrillic-700.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 700;
  src: url('/static/fonts/onest-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 800;
  src: url('/static/fonts/onest-cyrillic-800.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-display: swap; font-weight: 800;
  src: url('/static/fonts/onest-latin-800.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Mono'; font-style: normal; font-display: swap; font-weight: 600;
  src: url('/static/fonts/ibm-plex-mono-cyrillic-600.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'IBM Plex Mono'; font-style: normal; font-display: swap; font-weight: 600;
  src: url('/static/fonts/ibm-plex-mono-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Токены ── */
:root {
  /* Палитра «монохром»: светло-серый фон, белые карточки, чёрный акцент */
  --paper: #ebebed;
  --paper-raised: #ffffff;
  --paper-sunken: #f3f3f5;
  --ink: #141414;
  --ink-soft: #4f4f57;
  --ink-faint: #68686f;
  --line: #ececef;
  --line-strong: #d8d8dd;

  --danger: #c03428;
  --on-danger: #ffffff;
  --warn: #7a5a12;
  --warn-bg: #f8f1de;

  /* Статусы комментариев/сообщений: оттенки серого, инверсия для «решено» */
  --st-new: #65656d;
  --st-new-bg: #f3f3f5;
  --st-work: #141414;
  --st-work-bg: #e3e3e7;
  --st-done: #5c5c64;
  --st-done-bg: #ececee;

  /* Типографика */
  --focus: #2f6feb;
  --font-display: 'Onest', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Onest', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', Consolas, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.855rem;
  --text-base: 0.94rem;
  --text-lg: 1.12rem;
  --text-xl: 1.45rem;
  --text-2xl: 1.75rem;

  /* Ритм */
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --r-pill: 999px;
  --shadow-1: 0 6px 20px rgba(20, 20, 20, 0.05), 0 1px 3px rgba(20, 20, 20, 0.04);
  --shadow-2: 0 14px 34px rgba(20, 20, 20, 0.1), 0 3px 8px rgba(20, 20, 20, 0.05);
  --shadow-3: 0 24px 60px rgba(20, 20, 20, 0.2);
  --shadow-dark: 0 12px 28px rgba(20, 20, 20, 0.22);

  --sidebar-w: 236px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* Текст и элементы на акцентной (инвертированной) поверхности */
  --on-ink: #ffffff;
  --on-ink-soft: #9c9ca1;
  --on-ink-faint: #333333;
  --muted-line: #c9c9ce;
  --muted-fill: #e4e4e8;
  --card-border: transparent;
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f5f66' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  color-scheme: light;
}

/* ── Тёмная тема ── */
[data-theme='dark'] {
  --paper: #131315;
  --paper-raised: #1d1d20;
  --paper-sunken: #26262a;
  --ink: #f2f2f3;
  --ink-soft: #a9a9b0;
  --ink-faint: #8b8b94;
  --line: #2b2b30;
  --line-strong: #3d3d44;

  --danger: #e86656;
  --on-danger: #131315;
  --warn: #e0b45f;
  --warn-bg: #33290f;

  --st-new: #8f8f96;
  --st-new-bg: #222226;
  --st-work: #f2f2f3;
  --st-work-bg: #313136;
  --st-done: #8b8b93;
  --st-done-bg: #26262a;

  --shadow-1: 0 6px 20px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 14px 34px rgba(0, 0, 0, 0.45), 0 3px 8px rgba(0, 0, 0, 0.3);
  --shadow-3: 0 24px 60px rgba(0, 0, 0, 0.6);
  --shadow-dark: 0 12px 28px rgba(0, 0, 0, 0.5);

  --on-ink: #131315;
  --on-ink-soft: #55555c;
  --on-ink-faint: #c9c9ce;
  --muted-line: #4a4a52;
  --muted-fill: #2e2e33;
  --card-border: #2e2e33;
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a9a9b0' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  color-scheme: dark;
}

/* ── База ── */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

/* Мягкие размытые пятна фона */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  z-index: -1;
  pointer-events: none;
}
body::before {
  width: 560px; height: 560px;
  background: rgba(255, 255, 255, 0.85);
  top: -160px; right: -100px;
}
body::after {
  width: 480px; height: 480px;
  background: rgba(185, 185, 192, 0.5);
  bottom: -180px; left: -90px;
}
[data-theme='dark'] body::before { background: rgba(255, 255, 255, 0.05); }
[data-theme='dark'] body::after { background: rgba(0, 0, 0, 0.35); }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
}

a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; font-size: inherit; cursor: pointer; }

input, textarea, select {
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--ink);
  background: var(--paper-raised);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(20, 20, 20, 0.1);
}
textarea { resize: vertical; min-height: 72px; }
input[readonly] { color: var(--ink-soft); }

/* Выпадающие списки — в стиле кнопок-пилюль */
select {
  appearance: none;
  -webkit-appearance: none;
  border-radius: var(--r-pill);
  padding: 8px 36px 8px 16px;
  font-weight: 600;
  cursor: pointer;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 13px;
}
select:hover { border-color: var(--ink); }

label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-soft);
}

/* Скроллбары в тон */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 6px;
  border: 2px solid var(--paper);
}
::-webkit-scrollbar-track { background: transparent; }

/* Появление страниц */
.fade-in > * { animation: rise 0.4s var(--ease) both; }
.fade-in > *:nth-child(2) { animation-delay: 0.05s; }
.fade-in > *:nth-child(3) { animation-delay: 0.1s; }
.fade-in > *:nth-child(4) { animation-delay: 0.15s; }
.fade-in > *:nth-child(5) { animation-delay: 0.2s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

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

/* ── Выпадающий список в нашем стиле ──────────────────────────────────
   Список вариантов у обычного <select> рисует операционная система, и
   настроить его нельзя. Настоящее поле прячем, а рисуем кнопку и список
   сами — см. sel.js. Кнопка стоит РЯДОМ с полем, а не вместо него,
   поэтому ей достаточно тех же правил, что и полю. */
.sel-native { display: none !important; }

.sel-btn {
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--ink);
  background: var(--paper-raised);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 8px 34px 8px 12px;
  text-align: left;
  cursor: pointer;
  position: relative;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px 18px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sel-btn:hover { border-color: var(--ink-soft); }
.sel-btn[aria-expanded="true"] { border-color: var(--ink); }
.sel-btn:disabled { opacity: 0.55; cursor: default; }
.sel-empty { color: var(--ink-soft); }

.sel-list {
  position: fixed;
  z-index: 9000;
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: min(46vh, 360px);
  overflow-y: auto;
  background: var(--paper-raised);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  font-size: var(--text-base);
  color: var(--ink);
}
.sel-opt {
  padding: 8px 12px;
  border-radius: calc(var(--r-sm) - 6px);
  cursor: pointer;
  white-space: nowrap;
}
.sel-opt.on { background: var(--ink); color: var(--paper-raised); }
.sel-opt[aria-selected="true"]:not(.on) { font-weight: 600; }
.sel-opt[aria-disabled="true"] { color: var(--ink-soft); cursor: default; }
@media (prefers-reduced-motion: reduce) { .sel-btn { transition: none; } }
