/* =========================================================================
   MfiSerli AI — Design System v5 «Aurora»
   Единые токены, стеклянные поверхности, аккуратная типографика.
   Подключается в index.html / messenger.html / chess.html / suite.js.
   Всё держится на CSS-переменных: темы переключаются атрибутом data-theme.
   ========================================================================= */

:root,
html[data-theme="night"] {
  color-scheme: dark;
  /* поверхности */
  --bg: #07080f;
  --bg-deep: #05060b;
  --surface: rgba(255, 255, 255, .045);
  --surface-2: rgba(255, 255, 255, .07);
  --surface-3: rgba(255, 255, 255, .1);
  --panel: #0d0f18;
  --panel2: #121520;
  --panel3: #191d2b;
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .14);
  /* текст */
  --txt: #f5f6fb;
  --txt2: #a7aec3;
  --txt3: #78819a;
  /* акценты */
  --brand: #6f5cff;
  --brand2: #a99bff;
  --brand3: #4c3bd6;
  --brand-soft: rgba(111, 92, 255, .16);
  --accent-2: #22d3ee;
  --accent-3: #f472b6;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #fb7185;
  --info: #60a5fa;
  /* геометрия и движение */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-xl: 28px;
  --dur: 180ms;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-2: 0 12px 32px -18px rgba(0, 0, 0, .8);
  --shadow-3: 0 28px 70px -32px rgba(0, 0, 0, .9);
  --glow: 0 0 0 1px var(--brand-soft), 0 18px 48px -20px rgba(111, 92, 255, .55);
  --grad-brand: linear-gradient(135deg, #6f5cff 0%, #9b7bff 48%, #22d3ee 100%);
  --grad-surface: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .02));
  --font: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --rail: 72px;
  --side: 296px;
}

html[data-theme="graphite"] {
  color-scheme: dark;
  --bg: #0b0c0f; --bg-deep: #08090b;
  --surface: rgba(255, 255, 255, .04); --surface-2: rgba(255, 255, 255, .065); --surface-3: rgba(255, 255, 255, .095);
  --panel: #14161b; --panel2: #1a1d24; --panel3: #22262f;
  --line: rgba(255, 255, 255, .075); --line-strong: rgba(255, 255, 255, .13);
  --brand: #7f8a9c; --brand2: #b9c4d4; --brand3: #5d6878;
  --brand-soft: rgba(150, 165, 190, .16); --accent-2: #8fa3b8; --accent-3: #c0a0b0;
  --grad-brand: linear-gradient(135deg, #7f8a9c, #c3ccd8);
}

html[data-theme="ocean"] {
  color-scheme: dark;
  --bg: #04121a; --bg-deep: #020c12;
  --panel: #081c27; --panel2: #0c2734; --panel3: #113243;
  --line: rgba(120, 200, 235, .13); --line-strong: rgba(120, 200, 235, .22);
  --txt: #e8f6fb; --txt2: #9fc4d4; --txt3: #7796a6;
  --brand: #22b8e6; --brand2: #7fe3ff; --brand3: #1387ad;
  --brand-soft: rgba(34, 184, 230, .16); --accent-2: #2dd4bf; --accent-3: #818cf8;
  --grad-brand: linear-gradient(135deg, #22b8e6, #7fe3ff 55%, #2dd4bf);
}

html[data-theme="sand"] {
  color-scheme: light;
  --bg: #faf6f0; --bg-deep: #f2ece2;
  --surface: rgba(255, 255, 255, .75); --surface-2: rgba(255, 255, 255, .9); --surface-3: #ffffff;
  --panel: #ffffff; --panel2: #f6f1e9; --panel3: #ece4d7;
  --line: rgba(90, 70, 50, .14); --line-strong: rgba(90, 70, 50, .24);
  --txt: #231f1a; --txt2: #5f574c; --txt3: #7b7365;
  --brand: #b0602f; --brand2: #8f4a20; --brand3: #8a4a22;
  --brand-soft: rgba(176, 96, 47, .12); --accent-2: #2f7d63; --accent-3: #9c5ba8;
  --ok: #1f7a52; --warn: #8a5f16; --err: #b23a44;
  --grad-brand: linear-gradient(135deg, #b0602f, #d98a4e 60%, #e8b878);
  --shadow-2: 0 12px 30px -20px rgba(90, 70, 50, .5);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6fa; --bg-deep: #eceef5;
  --surface: rgba(255, 255, 255, .8); --surface-2: #ffffff; --surface-3: #ffffff;
  --panel: #ffffff; --panel2: #f2f4fa; --panel3: #e8ecf6;
  --line: rgba(22, 30, 50, .1); --line-strong: rgba(22, 30, 50, .18);
  --txt: #12151d; --txt2: #4d5768; --txt3: #697388;
  --brand: #5b46e0; --brand2: #7360f0; --brand3: #4331b8;
  --brand-soft: rgba(91, 70, 224, .1); --accent-2: #0e9aa7; --accent-3: #c2367f;
  --grad-brand: linear-gradient(135deg, #5b46e0, #8b6bff 55%, #0e9aa7);
  --shadow-2: 0 12px 30px -22px rgba(20, 30, 60, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- фон-«аврора» ---------- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(58% 46% at 12% -6%, rgba(111, 92, 255, .22), transparent 70%),
    radial-gradient(46% 38% at 92% 4%, rgba(34, 211, 238, .16), transparent 72%),
    radial-gradient(52% 44% at 50% 110%, rgba(244, 114, 182, .12), transparent 70%);
  opacity: .9;
}
html[data-theme="light"] body::before,
html[data-theme="sand"] body::before { opacity: .5; }

/* ---------- типографика ---------- */
h1, h2, h3, h4 { margin: 0; font-weight: 660; letter-spacing: -.015em; line-height: 1.2; }
h1 { font-size: clamp(30px, 4vw, 46px); }
h2 { font-size: clamp(22px, 2.6vw, 30px); }
h3 { font-size: 17px; }
p { margin: 0 0 12px; color: var(--txt2); }
a { color: var(--brand2); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: 12.5px; color: var(--txt3); }
code, kbd { font-family: var(--mono); font-size: .92em; }
kbd {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 6px; color: var(--txt2);
}

/* ---------- карточки и поверхности ---------- */
.ds-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.ds-glass {
  background: var(--grad-surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}
.ds-hairline { height: 1px; background: var(--line); border: 0; margin: 18px 0; }

/* ---------- кнопки ---------- */
.ds-btn,
.btn, button.pbtn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--txt);
  cursor: pointer;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  text-decoration: none;
}
.ds-btn:hover, .btn:hover { background: var(--surface-3); border-color: var(--line-strong); transform: translateY(-1px); }
.ds-btn:active, .btn:active { transform: translateY(0) scale(.99); }
.ds-btn:focus-visible, .btn:focus-visible, a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--brand2);
  outline-offset: 2px;
}
.ds-btn[disabled], .ds-btn.is-disabled { opacity: .5; cursor: not-allowed; transform: none; }

.ds-btn-primary {
  background: var(--grad-brand);
  border: 0;
  color: #fff;
  box-shadow: var(--glow);
}
html[data-theme="sand"] .ds-btn-primary,
html[data-theme="light"] .ds-btn-primary { color: #fff; }
.ds-btn-primary:hover { filter: brightness(1.06); }

.ds-btn-ghost { background: transparent; border-color: transparent; color: var(--txt2); }
.ds-btn-ghost:hover { background: var(--surface-2); color: var(--txt); }

.ds-btn-danger { border-color: rgba(251, 113, 133, .4); color: var(--err); background: rgba(251, 113, 133, .08); }
.ds-btn-danger:hover { background: rgba(251, 113, 133, .16); }

.ds-icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--txt2);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.ds-icon-btn:hover { background: var(--surface-2); color: var(--txt); }

/* ---------- поля ввода ---------- */
.ds-input, .ds-textarea, .ds-select,
input[type="text"], input[type="password"], input[type="search"], textarea, select {
  font: inherit;
  font-size: 14px;
  width: 100%;
  color: var(--txt);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.ds-input::placeholder, textarea::placeholder { color: var(--txt3); }
.ds-input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--brand-soft);
  outline: none;
}

/* ---------- чипы, бейджи, статусы ---------- */
.ds-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--txt2);
}
.ds-chip.on { background: var(--brand-soft); border-color: transparent; color: var(--brand2); }
.ds-chip.ok { color: var(--ok); background: rgba(52, 211, 153, .12); border-color: transparent; }
.ds-chip.warn { color: var(--warn); background: rgba(251, 191, 36, .12); border-color: transparent; }
.ds-chip.err { color: var(--err); background: rgba(251, 113, 133, .12); border-color: transparent; }
.ds-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--txt3); }
.ds-dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .18); }
.ds-dot.away { background: var(--warn); }

/* ---------- скелетоны и спиннеры ---------- */
@keyframes ds-shimmer { 0% { background-position: -220px 0; } 100% { background-position: 320px 0; } }
.ds-skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-3) 40%, var(--surface) 80%);
  background-size: 340px 100%;
  animation: ds-shimmer 1.4s infinite linear;
}
@keyframes ds-spin { to { transform: rotate(360deg); } }
.ds-spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--brand2);
  animation: ds-spin .8s linear infinite;
}

/* ---------- тултипы (просто через title + подсказка-элемент) ---------- */
.ds-tip { position: relative; }
.ds-tip::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: calc(100% + 8px);
  transform: translate(-50%, 4px);
  background: var(--panel3);
  color: var(--txt);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  z-index: 60;
}
.ds-tip:hover::after { opacity: 1; transform: translate(-50%, 0); }

/* ---------- доступность ---------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- скроллбары ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--txt3); background-clip: content-box; }
