/* Ray UI — единая дизайн-система для главной, кабинета и админки.
   Подключается первой: <link rel="stylesheet" href="/shared/ui.css">.
   Страничные styles.css содержат только layout конкретной страницы. */

/* ---------- 1. Токены ---------- */
:root {
  color-scheme: dark;

  /* фон и поверхности */
  --bg: #070b0a;
  --bg-soft: #0a1110;
  --surface: #101815;
  --surface-2: #17211d;
  --surface-3: #1e2a25;
  --line: rgba(251, 247, 238, 0.12);
  --line-strong: rgba(251, 247, 238, 0.22);

  /* текст */
  --text: #fbf7ee;
  --text-2: #aebcb3;
  --text-3: #7d8b83;
  --on-accent: #07100d;

  /* акценты и статусы */
  --accent: #2de0b5;
  --accent-2: #86caff;
  --accent-soft: rgba(45, 224, 181, 0.14);
  --ok: #2de0b5;
  --ok-soft: rgba(45, 224, 181, 0.14);
  --warn: #d8b76b;
  --warn-soft: rgba(216, 183, 107, 0.16);
  --danger: #ff8275;
  --danger-soft: rgba(255, 130, 117, 0.16);
  --info: #86caff;
  --info-soft: rgba(134, 202, 255, 0.14);
  --neutral-soft: rgba(251, 247, 238, 0.07);

  /* типографика */
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 22px;
  --fs-2xl: 28px;
  --fs-3xl: clamp(32px, 4vw, 44px);

  /* сетка */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  --shadow-accent: 0 10px 30px rgba(45, 224, 181, 0.22);
  --max: 1120px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ---------- 2. База ---------- */
*,
*::before,
*::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 50%, var(--bg) 100%);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a, button, input, select, textarea { font: inherit; }
button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
code, kbd, .mono { font-family: var(--font-mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
::selection { background: var(--accent-soft); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 3. Текстовые утилиты ---------- */
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.strong { font-weight: 600; }
.eyebrow {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--sp-3);
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.hidden, [hidden] { display: none !important; }

/* ---------- 4. Layout-утилиты ---------- */
.container { max-width: var(--max); margin: 0 auto; padding: 0 var(--sp-5); }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ---------- 5. Кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 0 var(--sp-5);
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: var(--fs-md);
  line-height: 1;
  white-space: nowrap;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease), border-color 0.15s;
  cursor: pointer;
  text-decoration: none;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.btn-primary { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: var(--on-accent); box-shadow: var(--shadow-accent); }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 14px 34px rgba(45, 224, 181, 0.32); }
.btn-secondary { background: rgba(251, 247, 238, 0.04); border-color: var(--line); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: rgba(251, 247, 238, 0.08); border-color: var(--line-strong); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: rgba(251, 247, 238, 0.06); color: var(--text); }
.btn-danger { background: var(--danger-soft); border-color: rgba(255, 130, 117, 0.35); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(255, 130, 117, 0.26); }
.btn-sm { min-height: 34px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: 8px; }
.btn-lg { min-height: 52px; padding: 0 var(--sp-8); font-size: var(--fs-lg); }
.btn-block { width: 100%; }
.btn-icon { width: 38px; min-height: 38px; padding: 0; border-radius: 9px; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--text);
  animation: ui-spin 0.7s linear infinite;
}
.btn-primary.is-loading::after { color: var(--on-accent); }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* ---------- 6. Карточки и панели ---------- */
.card {
  padding: var(--sp-6);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(251, 247, 238, 0.035), rgba(251, 247, 238, 0.01));
  border: 1px solid var(--line);
}
.card-strong { background: var(--surface-2); }
.card-accent { border-color: rgba(45, 224, 181, 0.3); background: linear-gradient(180deg, rgba(45, 224, 181, 0.08), rgba(251, 247, 238, 0.01)); }
.card-sm { padding: var(--sp-4); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card-note { color: var(--text-2); font-size: var(--fs-sm); margin-top: var(--sp-1); }
.panel { padding: var(--sp-6); border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.divider { height: 1px; background: var(--line); margin: var(--sp-5) 0; }

/* stat / KPI */
.stat { display: flex; flex-direction: column; gap: var(--sp-1); }
.stat-label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-2); }
.stat-value { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-value.accent { color: var(--accent); }
.stat-meta { font-size: var(--fs-sm); color: var(--text-2); }

/* ---------- 7. Бейджи и статусы ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  background: var(--neutral-soft);
  color: var(--text-2);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-plain::before { display: none; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent); color: var(--on-accent); }
.badge-accent::before { background: var(--on-accent); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.dot-warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.dot-danger { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }

/* ---------- 8. Формы ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.field-hint { font-size: var(--fs-xs); color: var(--text-3); }
.field-error { font-size: var(--fs-xs); color: var(--danger); }
.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(251, 247, 238, 0.04);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: rgba(251, 247, 238, 0.06); }
.input.is-invalid { border-color: var(--danger); }
.input-sm, .select-sm { min-height: 36px; padding: 6px 10px; font-size: var(--fs-sm); border-radius: 8px; }
.select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23aebcb3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.input-group { display: flex; gap: var(--sp-2); }
.input-group .input { flex: 1; min-width: 0; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { width: 40px; height: 24px; border-radius: 999px; background: var(--neutral-soft); border: 1px solid var(--line); position: relative; transition: background 0.15s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-2); transition: transform 0.15s var(--ease), background 0.15s; }
.switch input:checked + .switch-track { background: var(--accent-soft); border-color: rgba(45, 224, 181, 0.4); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* segmented (RU/EN, фильтры) */
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: rgba(251, 247, 238, 0.03); }
.segmented button, .segmented a { padding: 6px 12px; border-radius: 7px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); transition: background 0.15s, color 0.15s; }
.segmented .active { background: var(--accent); color: var(--on-accent); }

/* ---------- 9. Таблицы ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(251, 247, 238, 0.02); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 12px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.table th { position: sticky; top: 0; z-index: 1; background: var(--surface); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: rgba(251, 247, 238, 0.03); }
.table tr.is-clickable { cursor: pointer; }
.table tr.is-clickable:hover td { background: var(--accent-soft); }
.table td .sub { display: block; font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.table .right { text-align: right; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 10. Навигация ---------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a, .tabs button { padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); white-space: nowrap; }
.tabs .active { color: var(--text); border-bottom-color: var(--accent); }

.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-list a, .nav-list button {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px;
  font-size: var(--fs-md); font-weight: 500; color: var(--text-2);
  transition: background 0.15s, color 0.15s;
  text-align: left; width: 100%;
}
.nav-list a:hover, .nav-list button:hover { background: rgba(251, 247, 238, 0.05); color: var(--text); }
.nav-list .active { background: var(--accent-soft); color: var(--text); }
.nav-list .count { margin-left: auto; font-size: var(--fs-xs); color: var(--text-3); }

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; }
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--text-2); letter-spacing: 0.06em; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); font-weight: 700; flex: none; }

.pagination { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); }
.pagination .btn { min-width: 36px; }

/* ---------- 11. Обратная связь ---------- */
.alert { display: flex; gap: 12px; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--line); background: rgba(251, 247, 238, 0.04); font-size: var(--fs-sm); }
.alert-ok { border-color: rgba(45, 224, 181, 0.35); background: var(--ok-soft); }
.alert-warn { border-color: rgba(216, 183, 107, 0.4); background: var(--warn-soft); }
.alert-danger { border-color: rgba(255, 130, 117, 0.4); background: var(--danger-soft); }
.alert-info { border-color: rgba(134, 202, 255, 0.35); background: var(--info-soft); }
.alert strong { display: block; margin-bottom: 2px; }

.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px)); }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: var(--fs-sm); animation: ui-toast-in 0.2s var(--ease); }
.toast-ok { border-color: rgba(45, 224, 181, 0.5); }
.toast-danger { border-color: rgba(255, 130, 117, 0.5); }
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-2); padding: var(--sp-10) var(--sp-5); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--text-2); }
.empty h3 { color: var(--text); font-size: var(--fs-lg); }
.empty .btn { margin-top: var(--sp-2); }

.skeleton { position: relative; overflow: hidden; background: rgba(251, 247, 238, 0.06); border-radius: 8px; min-height: 14px; }
.skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(251, 247, 238, 0.08), transparent); animation: ui-shimmer 1.2s infinite; }
@keyframes ui-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.progress { height: 8px; border-radius: 999px; background: rgba(251, 247, 238, 0.08); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.3s var(--ease); }
.progress.warn > span { background: var(--warn); }
.progress.danger > span { background: var(--danger); }

/* ---------- 12. Модалка ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: var(--sp-5); background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(6px); animation: ui-fade 0.15s; }
.modal { width: min(520px, 100%); max-height: 90vh; overflow: auto; padding: var(--sp-6); border-radius: var(--radius-lg); background: var(--surface-2); border: 1px solid var(--line-strong); box-shadow: var(--shadow); animation: ui-toast-in 0.2s var(--ease); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-6); flex-wrap: wrap; }
@keyframes ui-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 13. Прочее ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: var(--fs-sm); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }
.qr { display: inline-block; padding: 12px; background: #fff; border-radius: 12px; line-height: 0; }
.qr img, .qr svg { width: 200px; height: 200px; display: block; }
.code-block { padding: 12px 14px; border-radius: 10px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); font-family: var(--font-mono); font-size: var(--fs-xs); line-height: 1.6; overflow: auto; white-space: pre; }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(251, 247, 238, 0.04); font-size: var(--fs-sm); }
.chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

@media (max-width: 640px) {
  .btn { min-height: 46px; }
  .card, .panel { padding: var(--sp-4); border-radius: var(--radius); }
  .modal { padding: var(--sp-5); }
  .toast-host { right: 12px; left: 12px; bottom: 12px; max-width: none; }
}
