/* ============================================================
   AI-Twins Design System v1 — единые токены и компоненты.
   Подключается ПОСЛЕ сброса на каждой странице (через base.html).
   Принципы: светлая поверхность, один фиолетовый акцент, воздух,
   подписи у всего (никаких голых эмодзи), мягкие тени, бесшовные
   переходы (fade страниц, hover-lift, фокус-кольца).
   ============================================================ */

:root {
  /* Палитра */
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafbfe;
  --text: #191c26;
  --text-2: #5b6170;
  --muted: #9096a5;
  --border: #e7e9f2;
  --brand: #6455e0;
  --brand-strong: #5243cc;
  --brand-soft: #eeecfc;
  --success: #178a50;
  --success-soft: #e7f6ee;
  --warning: #b45309;
  --warning-soft: #fdf3e3;
  --danger: #d33131;
  --danger-soft: #fdecec;
  --info: #2563eb;
  --info-soft: #e9f0fe;

  /* Геометрия */
  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 18px;
  --shadow-1: 0 1px 2px rgba(20, 22, 40, .05), 0 4px 16px rgba(20, 22, 40, .06);
  --shadow-2: 0 4px 12px rgba(20, 22, 40, .08), 0 12px 32px rgba(20, 22, 40, .10);
  --header-h: 64px;
  --content-w: 1120px;

  /* Типографика */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body.app {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Появление страницы (бесшовный переход) ---------- */
.app main.page {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 28px 24px 64px;
  animation: page-in .28s ease both;
}
@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .app main.page { animation: none; }
}

/* ---------- Шапка ---------- */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-header .inner {
  max-width: var(--content-w);
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex; align-items: center; gap: 20px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 17px; color: var(--text);
  text-decoration: none; letter-spacing: -.2px; white-space: nowrap;
}
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #7c6cf0, #5243cc);
  display: grid; place-items: center;
  color: #fff; font-size: 15px; font-weight: 800;
}

.main-nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  padding: 8px 13px; border-radius: 10px;
  color: var(--text-2); text-decoration: none;
  font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.main-nav a:hover { background: var(--brand-soft); color: var(--brand-strong); }
.main-nav a.active { background: var(--brand); color: #fff; }

/* Меню пользователя */
.user-menu { position: relative; margin-left: auto; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--surface);
  cursor: pointer; font: inherit; font-weight: 600; font-size: 14px; color: var(--text);
  transition: box-shadow .15s ease;
}
.user-chip:hover { box-shadow: var(--shadow-1); }
.user-chip .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #7c6cf0, #5243cc);
  color: #fff; display: grid; place-items: center; font-size: 14px; font-weight: 700;
}
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 210px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); padding: 6px;
  opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
.user-menu.open .user-dropdown { opacity: 1; transform: none; pointer-events: auto; }
.user-dropdown a, .user-dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; background: none; border-radius: var(--radius-s);
  font: inherit; font-size: 14px; font-weight: 500; color: var(--text);
  text-decoration: none; cursor: pointer;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--surface-2); }
.user-dropdown .danger { color: var(--danger); }
.user-dropdown .divider { height: 1px; background: var(--border); margin: 6px 4px; }

/* ---------- Заголовки страниц ---------- */
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -.4px; }
.page-head .sub { color: var(--text-2); margin-top: 4px; max-width: 640px; }
.page-head .actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 22px;
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 16px; }
.card h2 { font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.card .hint { color: var(--muted); font-size: 13px; }

.card.clickable {
  cursor: pointer; text-decoration: none; color: inherit; display: block;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.card.clickable:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: #d9dcf0;
}

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }

/* Фичекарта (иконка + заголовок + описание + стрелка) */
.feature-card { display: flex; flex-direction: column; gap: 10px; min-height: 148px; }
.feature-card .icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 21px;
  background: var(--brand-soft);
}
.feature-card h3 { font-size: 15.5px; font-weight: 700; }
.feature-card p { color: var(--text-2); font-size: 13.5px; flex: 1; }
.feature-card .go { color: var(--brand); font-weight: 700; font-size: 13.5px; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
  text-decoration: none; transition: background .15s, box-shadow .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); box-shadow: 0 6px 16px rgba(100, 85, 224, .3); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); box-shadow: var(--shadow-1); }
.btn-ghost { background: transparent; color: var(--brand); }
.btn-ghost:hover { background: var(--brand-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }

/* ---------- Бейджи ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .1px;
}
.badge-brand   { background: var(--brand-soft);   color: var(--brand-strong); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-muted   { background: #eef0f6;             color: var(--text-2); }

/* ---------- Формы ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; padding: 10px 13px;
  border: 1px solid var(--border); border-radius: 10px;
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, textarea.input:focus, select.input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(100, 85, 224, .15);
}
textarea.input { resize: vertical; min-height: 84px; }

/* ---------- Прогресс и бары ---------- */
.bar-track {
  height: 8px; border-radius: 999px; background: #edeef6; overflow: hidden;
}
.bar-fill {
  height: 100%; border-radius: 999px; background: var(--brand);
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}
.bar-fill.success { background: var(--success); }
.bar-fill.warning { background: #eab308; }

/* ---------- Таблицы ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; padding: 10px 12px; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }

/* ---------- Тосты ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  padding: 11px 20px; border-radius: 12px; color: #fff;
  font-size: 14px; font-weight: 600; z-index: 1000;
  box-shadow: var(--shadow-2); animation: toast-in .22s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Модалка ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(18, 20, 33, .45);
  display: grid; place-items: center; z-index: 200;
  animation: fade-in .18s ease;
}
.modal {
  width: min(560px, calc(100vw - 32px)); max-height: 84vh; overflow: auto;
  background: var(--surface); border-radius: var(--radius-l);
  padding: 24px; box-shadow: var(--shadow-2);
  animation: modal-in .2s ease;
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ---------- Пустые состояния ---------- */
.empty {
  text-align: center; padding: 48px 24px; color: var(--text-2);
}
.empty .icon { font-size: 40px; margin-bottom: 10px; }
.empty .btn { margin-top: 16px; }

/* ---------- Skeleton-загрузка ---------- */
.skeleton {
  background: linear-gradient(90deg, #eef0f6 25%, #f7f8fc 50%, #eef0f6 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
  border-radius: var(--radius-s); color: transparent !important;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Печать ---------- */
@media print {
  .app-header, .no-print { display: none !important; }
  body.app { background: #fff; }
  .app main.page { animation: none; padding: 0; max-width: none; }
  .card { box-shadow: none; border-color: #ddd; break-inside: avoid; }
  /* Свёрнутые details (формулы «Как посчитано» и т.п.) печатаются раскрытыми. */
  details:not([open]) > *:not(summary) { display: block !important; }
}
