/* Общие стили: шрифт, цвета (светлая и тёмная тема), поля ввода, кнопки, аватары, окна */
@font-face { font-family: 'Golos Text'; font-weight: 400; font-display: swap; src: url(/fonts/golos-text-cyrillic-400-normal.woff2) format('woff2'); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Golos Text'; font-weight: 500; font-display: swap; src: url(/fonts/golos-text-cyrillic-500-normal.woff2) format('woff2'); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Golos Text'; font-weight: 600; font-display: swap; src: url(/fonts/golos-text-cyrillic-600-normal.woff2) format('woff2'); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Golos Text'; font-weight: 700; font-display: swap; src: url(/fonts/golos-text-cyrillic-700-normal.woff2) format('woff2'); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Golos Text'; font-weight: 400; font-display: swap; src: url(/fonts/golos-text-latin-400-normal.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+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Golos Text'; font-weight: 500; font-display: swap; src: url(/fonts/golos-text-latin-500-normal.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+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Golos Text'; font-weight: 600; font-display: swap; src: url(/fonts/golos-text-latin-600-normal.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+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Golos Text'; font-weight: 700; font-display: swap; src: url(/fonts/golos-text-latin-700-normal.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+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  color-scheme: light;
  --band: #1d2b4c;         /* шапки — цвет чернил накладной */
  --band-text: #ffffff;
  --band-muted: #b9c4dc;
  --ink: #1d2b4c;          /* акцентный текст и рамки */
  --ink-2: #2a3b63;
  --ink-soft: #e4e9f3;     /* мягкие кнопки, выделение */
  --ink-soft-2: #d6deec;
  --btn: #1d2b4c;
  --btn-hover: #2a3b63;
  --paper: #f2f4f7;        /* фон переписки */
  --surface: #ffffff;
  --surface-2: #f5f7fa;    /* наведение */
  --surface-3: #fafbfc;
  --signal: #f5c518;       /* сигнальный жёлтый — непрочитанное, фокус */
  --on-signal: #1d2b4c;
  --mine: #dde7f5;         /* свои сообщения */
  --text: #19212f;
  --muted: #5f6a80;
  --line: #dde2ea;
  --danger: #b8352b;
  --danger-soft: #fbe9e7;
  --ok: #24724f;
  --ok-soft: #e3f2ea;
  --warn: #9a6a00;
  --warn-soft: #fff8dc;
  --overlay: rgba(19, 27, 46, .45);
  --chip-bg: rgba(29, 43, 76, .06);
  --chip-bg-hover: rgba(29, 43, 76, .11);

  /* Цвет роли — видно, кто есть кто */
  --r-admin: #3557a6;
  --r-employee: #24724f;
  --r-supplier: #9a5d14;
  --r-point: #16707f;
  --r-counterparty: #6a4c9c;

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow: 0 1px 2px rgba(25, 33, 47, .08), 0 4px 16px rgba(25, 33, 47, .06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .22);
  --font: 'Golos Text', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Тёмная тема: автоматически по настройкам телефона/компьютера или выбранная вручную */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --band: #111a2e; --band-text: #e8edf7; --band-muted: #8f9bb8;
    --ink: #a9bff0; --ink-2: #c3d3f6; --ink-soft: #222f4a; --ink-soft-2: #2b3a5a;
    --btn: #3a5aa8; --btn-hover: #4667b8;
    --paper: #0c1220; --surface: #141c2d; --surface-2: #1a2438; --surface-3: #172033;
    --mine: #1f3560; --text: #e4e9f2; --muted: #93a0ba; --line: #263250;
    --danger: #f08070; --danger-soft: #3a1f22; --ok: #5cc996; --ok-soft: #173326; --warn: #e8c060; --warn-soft: #33290f;
    --overlay: rgba(0, 0, 0, .6); --chip-bg: rgba(169, 191, 240, .08); --chip-bg-hover: rgba(169, 191, 240, .15);
    --r-admin: #86a5f2; --r-employee: #5cc996; --r-supplier: #e5a65a; --r-point: #52c0d2; --r-counterparty: #b195ea;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --band: #111a2e; --band-text: #e8edf7; --band-muted: #8f9bb8;
  --ink: #a9bff0; --ink-2: #c3d3f6; --ink-soft: #222f4a; --ink-soft-2: #2b3a5a;
  --btn: #3a5aa8; --btn-hover: #4667b8;
  --paper: #0c1220; --surface: #141c2d; --surface-2: #1a2438; --surface-3: #172033;
  --mine: #1f3560; --text: #e4e9f2; --muted: #93a0ba; --line: #263250;
  --danger: #f08070; --danger-soft: #3a1f22; --ok: #5cc996; --ok-soft: #173326; --warn: #e8c060; --warn-soft: #33290f;
  --overlay: rgba(0, 0, 0, .6); --chip-bg: rgba(169, 191, 240, .08); --chip-bg-hover: rgba(169, 191, 240, .15);
  --r-admin: #86a5f2; --r-employee: #5cc996; --r-supplier: #e5a65a; --r-point: #52c0d2; --r-counterparty: #b195ea;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--r-admin); }
[hidden] { display: none !important; }
mark { background: rgba(245, 197, 24, .45); color: inherit; border-radius: 3px; padding: 0 1px; }

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

/* ---------- Поля формы ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-weight: 500; font-size: 14px; }
.field small { color: var(--muted); font-size: 13px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }
.input, .select, .textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface);
  font-size: 16px; /* 16px — чтобы iPhone не увеличивал страницу при вводе */
  transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(245, 197, 24, .45); }
.textarea { resize: vertical; min-height: 80px; }
.check-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; cursor: pointer; font-size: 15px; }
.check-row input { width: 20px; height: 20px; accent-color: var(--btn); margin: 0; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px;
  border: 0; border-radius: var(--radius-m);
  background: var(--btn); color: #fff;
  font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--ink-soft); color: var(--ink); }
.btn.secondary:hover { background: var(--ink-soft-2); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.danger:hover { filter: brightness(.97); }
.btn.danger-solid { background: #c0392b; color: #fff; }
.btn.danger-solid:hover { background: #a93226; }
.btn.ok { background: #24724f; color: #fff; }
.btn.ok:hover { background: #1d5f41; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--ink-soft); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: var(--radius-s); }
.btn.block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:hover { background: var(--chip-bg-hover); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn svg, .btn svg { width: 22px; height: 22px; flex: none; }
.btn.small svg { width: 18px; height: 18px; }

.alert { padding: 12px 14px; border-radius: var(--radius-m); font-size: 14px; margin-bottom: 16px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--ink-soft); color: var(--ink); }
.alert.success { background: var(--ok-soft); color: var(--ok); }

/* ---------- Аватар с цветом роли ---------- */
.avatar {
  --c: var(--r-counterparty); --c-rgb: 106, 76, 156;
  position: relative;
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(var(--c-rgb), .15);
  color: var(--c);
  font-weight: 700; font-size: 15px; letter-spacing: .02em;
}
.avatar img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar svg { width: 55%; height: 55%; }
.avatar.xs { width: 24px; height: 24px; font-size: 10px; }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.xl { width: 96px; height: 96px; font-size: 32px; }
.avatar.online::after {
  content: ''; position: absolute; right: 0; bottom: 0; z-index: 1;
  width: 12px; height: 12px; border-radius: 50%;
  background: #2fb36d; border: 2px solid var(--surface);
}
.avatar.sm.online::after { width: 10px; height: 10px; }
.avatar.group { --c: var(--ink); --c-rgb: 29, 43, 76; background: var(--ink-soft); }
.avatar.support { background: var(--signal); color: var(--on-signal); }
.avatar.announce { background: var(--btn); color: #fff; }

.role-tag {
  --c: var(--r-counterparty); --c-rgb: 106, 76, 156;
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(var(--c-rgb), .13);
  color: var(--c);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}

/* Цвет по роли — после .avatar и .role-tag, чтобы переопределять их значение по умолчанию */
[data-role="admin"]        { --c: var(--r-admin);        --c-rgb: 53, 87, 166; }
[data-role="employee"]     { --c: var(--r-employee);     --c-rgb: 36, 114, 79; }
[data-role="supplier"]     { --c: var(--r-supplier);     --c-rgb: 154, 93, 20; }
[data-role="point"]        { --c: var(--r-point);        --c-rgb: 22, 112, 127; }
[data-role="counterparty"] { --c: var(--r-counterparty); --c-rgb: 106, 76, 156; }

.badge {
  display: inline-grid; place-items: center;
  min-width: 22px; height: 22px; padding: 0 7px;
  border-radius: 999px;
  background: var(--signal); color: var(--on-signal);
  font-size: 12px; font-weight: 700; line-height: 1;
}
.badge.muted { background: var(--line); color: var(--muted); }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--chip-bg); color: var(--muted);
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.tag svg { width: 14px; height: 14px; }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.ink { background: var(--ink-soft); color: var(--ink); }

/* Значок типа файла */
.ext {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 44px; border-radius: 6px;
  background: #1d2b4c; color: #fff; font-size: 10.5px; font-weight: 700; letter-spacing: .03em;
}
.ext[data-kind="doc"] { background: #2b5797; }
.ext[data-kind="sheet"] { background: #1e7145; }
.ext[data-kind="pdf"] { background: #b8352b; }
.ext[data-kind="archive"] { background: #7a5c12; }
.ext[data-kind="image"] { background: #6a4c9c; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 300;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: var(--radius-m);
  background: #1d2b4c; color: #fff; font-size: 14px;
  box-shadow: var(--shadow-lg);
}
.toast.error { background: #b8352b; }
.toast.clickable { cursor: pointer; }
@media (max-width: 760px) { .toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }

/* ---------- Модальные окна ---------- */
.modal-backdrop {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: var(--overlay);
}
.modal {
  width: min(520px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--surface); border-radius: var(--radius-l);
  box-shadow: var(--shadow-lg);
}
.modal.wide { width: min(720px, 100%); }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 22px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal header h2 { margin: 0; font-size: 19px; }
.modal .modal-body { padding: 8px 22px 22px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.confirm-text { margin: 0 0 16px; }
@media (max-width: 600px) {
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal, .modal.wide { width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: var(--radius-l) var(--radius-l) 0 0; padding-bottom: env(safe-area-inset-bottom); }
}

/* Выбор людей */
.pick-list { max-height: 50vh; overflow-y: auto; margin: 0 -22px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.pick { display: flex; align-items: center; gap: 12px; padding: 8px 22px; cursor: pointer; }
.pick:hover { background: var(--surface-2); }
.pick input { width: 20px; height: 20px; accent-color: var(--btn); flex: none; margin: 0; }
.pick .body { min-width: 0; flex: 1; }
.pick .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-empty { padding: 28px 22px; color: var(--muted); text-align: center; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
