/* ============================================================
   NEXUS — Amber Obsidian Autumn
   Токены строго по docs/STYLE.md и docs/DESIGN.md.
   ============================================================ */

:root {
  --obsidian: #1D1816;
  --flame: #DC3C0C;
  --ember: #691F0C;
  --parchment: #D3C0B2;
  --ash: #7A7A78;
  --paper: #E1E1E1;
  --radius: 15px;
  --font-display: "Fraunces", serif;
  --font-ui: "Nunito Sans", sans-serif;

  --header-h: 72px;
  --tabs-h: 48px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--obsidian);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[x-cloak] { display: none !important; }

button { font-family: inherit; }

/* ---------- Шапка ---------- */

.app-header {
  height: var(--header-h);
  background: var(--paper);
  display: flex;
  align-items: center;
  padding: 0 32px;
}

.logo {
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100;
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.35em;
  color: var(--obsidian);
}

/* ---------- Экран входа ---------- */

.auth-body {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 12vh;
  gap: 40px;
}

.auth-title {
  margin: 0;
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100;
  font-weight: 500;
  font-size: 44px;
  letter-spacing: 0.12em;
  color: var(--paper);
  text-align: center;
}

.auth-card {
  width: 360px;
  max-width: calc(100vw - 48px);
  background: var(--parchment);
  border-radius: var(--radius);
  padding: 28px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-note {
  margin: 0;
  font-size: 14px;
  color: var(--obsidian);
  opacity: 0.75;
  text-align: center;
}

.auth-error {
  margin: 0;
  font-size: 13px;
  color: var(--flame);
}

/* ---------- Поля и кнопки ---------- */

.input {
  width: 100%;
  /* тон между --paper и --parchment (DESIGN.md §2) */
  background: color-mix(in srgb, var(--paper) 55%, var(--parchment));
  color: var(--obsidian);
  border: none;
  border-radius: var(--radius);
  padding: 14px 18px;
  font-family: var(--font-ui);
  font-size: 15px;
  outline: none;
}

.input::placeholder { color: var(--ash); }

.input:focus-visible { box-shadow: 0 0 0 2px var(--ember); }

.input--code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 24px;
  letter-spacing: 0.5em;
  text-align: center;
}

.btn {
  background: var(--ember);
  color: var(--paper);
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 120ms ease;
}

.btn:hover { filter: brightness(1.15); }
.btn:active { filter: brightness(0.95); }

.btn--block { width: 100%; }

.btn--sm {
  padding: 8px 14px;
  font-size: 13px;
}

.btn--ghost {
  background: transparent;
  color: var(--ember);
  box-shadow: inset 0 0 0 2px var(--ember);
}

/* ---------- Каркас приложения ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.tabs {
  height: var(--tabs-h);
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 12px;
  overflow-x: auto;
}

.tab {
  background: var(--ash);
  color: rgba(29, 24, 22, 0.62);
  border: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0 28px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.tab--active {
  background: var(--parchment);
  color: var(--obsidian);
}

.panel {
  flex: 1;
  margin: 0 12px 12px;
  background: var(--parchment);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 24px;
  overflow-y: auto;
}

.tab-pane { height: 100%; }

/* ---------- Сетка виджетов ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  align-items: start;
}

.grid--main { grid-template-columns: 1.1fr 1.3fr 1fr; }

.grid--single { grid-template-columns: 1fr; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.widget {
  background: var(--paper);
  color: var(--obsidian);
  border-radius: var(--radius);
  padding: 20px;
}

.widget--wide { grid-column: 1 / -1; }

.widget__title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100;
  font-weight: 600;
  font-size: 22px;
}

.widget__subtitle {
  margin: 14px 0 6px;
  font-weight: 700;
  font-size: 15px;
}

.widget__number {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100;
  font-weight: 600;
  font-size: 26px;
}

.widget__number--sm { font-size: 22px; }

.widget__muted {
  margin: 0;
  font-size: 14px;
  color: var(--ash);
}

.widget__muted + .widget__muted { margin-top: 2px; }

.widget__image {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: var(--radius);
}

.widget .btn { margin-top: 14px; }

/* ---------- Кольцевой прогресс ---------- */

.widget--ring { text-align: center; }

.ring {
  position: relative;
  width: 150px;
  margin: 0 auto;
}

.ring svg { display: block; width: 100%; height: auto; }

.ring__track {
  fill: none;
  stroke: color-mix(in srgb, var(--ash) 30%, transparent);
  stroke-width: 10;
}

.ring__arc {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.ring__label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.ring__value {
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100;
  font-weight: 600;
  font-size: 24px;
}

.ring__target {
  font-size: 13px;
  color: var(--ash);
}

/* ---------- Списки, бары, чипсы, спарклайн ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.list__item {
  padding: 10px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--ash) 25%, transparent);
}

.list__item:first-child { padding-top: 0; }
.list__item:last-child { border-bottom: none; padding-bottom: 0; }

.list__item--row,
.list__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.list__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.list__meta {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ash);
}

.link { color: inherit; text-decoration-color: var(--ember); }

.bar {
  margin-top: 8px;
  height: 8px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--ash) 25%, transparent);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  border-radius: var(--radius);
  background: var(--ember);
}

.bar__fill--over { background: var(--flame); }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }

.chip {
  background: var(--parchment);
  color: var(--obsidian);
  border: none;
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.chip--active {
  background: var(--ember);
  color: var(--paper);
}

.chip--static { cursor: default; }

.sparkline {
  display: block;
  width: 100%;
  height: 48px;
  margin-bottom: 8px;
}

.sparkline__line {
  fill: none;
  stroke: var(--ember);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.form-row .btn { margin-top: 0; flex-shrink: 0; }

/* ---------- Флами ---------- */

.flami-zone {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 60;
}

.flami {
  display: block;
  width: 64px;
  height: 72px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.flami__svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.flami__body { fill: var(--flame); }

.flami--idle .flami__svg { animation: flami-idle 4s ease-in-out infinite; }
.flami--thinking .flami__svg { animation: flami-thinking 1.4s ease-in-out infinite; }
.flami--proposal .flami__svg { animation: flami-proposal 1s ease-in-out infinite; }
.flami--speaking .flami__svg { animation: flami-speaking 0.7s ease-in-out infinite; }

@keyframes flami-idle {
  0%, 100% { filter: drop-shadow(0 0 5px rgba(220, 60, 12, 0.35)); transform: scale(1); }
  50%      { filter: drop-shadow(0 0 11px rgba(220, 60, 12, 0.55)); transform: scale(1.025); }
}

@keyframes flami-thinking {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(220, 60, 12, 0.55)); transform: scale(1); }
  50%      { filter: drop-shadow(0 0 16px rgba(220, 60, 12, 0.85)); transform: scale(1.05); }
}

@keyframes flami-proposal {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(220, 60, 12, 0.7)); transform: scale(1.02); }
  50%      { filter: drop-shadow(0 0 22px rgba(220, 60, 12, 1)); transform: scale(1.08); }
}

@keyframes flami-speaking {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(220, 60, 12, 0.5)); transform: scale(1); }
  30%      { filter: drop-shadow(0 0 18px rgba(220, 60, 12, 0.95)); transform: scale(1.07); }
  60%      { filter: drop-shadow(0 0 8px rgba(220, 60, 12, 0.6)); transform: scale(1.01); }
}

/* Речевой пузырь */

.flami-bubble {
  position: absolute;
  right: 8px;
  bottom: 84px;
  width: max-content;
  background: var(--paper);
  color: var(--obsidian);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 15px;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.flami-bubble::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--paper);
  border-radius: 0 0 4px 0;
  transform: rotate(45deg);
}

.flami-bubble p { margin: 0; }
.flami-bubble p + p { margin-top: 2px; }

/* ---------- Тосты proposed_action ---------- */

.toast-stack {
  position: fixed;
  right: 110px;
  bottom: 36px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 380px;
}

.toast {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--parchment);
  color: var(--obsidian);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.toast__dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--flame);
}

.toast__text { margin: 0; font-size: 14px; font-weight: 600; }

.toast__draft {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--ash);
}

.toast__actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.toast__actions .btn { margin-top: 0; }

.toast-enter,
.toast-leave { transition: transform 200ms ease, opacity 200ms ease; }
.toast-enter-start,
.toast-leave-end { transform: translateY(12px); opacity: 0; }
.toast-enter-end,
.toast-leave-start { transform: translateY(0); opacity: 1; }

/* ---------- Панель Флами ---------- */

.flami-panel {
  position: fixed;
  top: calc(var(--header-h) + var(--tabs-h));
  right: 0;
  bottom: 0;
  z-index: 50;
  width: 440px;
  max-width: 100vw;
  display: flex;
  background: var(--parchment);
  border-radius: var(--radius) 0 0 var(--radius);
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.45);
  visibility: hidden;
  transform: translateX(105%);
  transition: transform 200ms ease, visibility 0s 200ms;
}

.flami-panel--open {
  visibility: visible;
  transform: translateX(0);
  transition: transform 200ms ease;
}

.flami-panel__rail {
  flex-shrink: 0;
  width: 108px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 0 16px 10px;
  background: var(--obsidian);
  border-radius: var(--radius) 0 0 var(--radius);
}

.rail-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  background: none;
  border: none;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--ash);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.rail-tab__icon { width: 22px; height: 22px; }

.rail-tab--active {
  background: var(--parchment);
  color: var(--flame);
}

.rail-logout {
  margin-top: auto;
  padding-top: 12px;
}

.rail-tab--action { width: 100%; }

.rail-tab--action:hover { color: var(--flame); }

.flami-panel__content {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 20px;
  color: var(--obsidian);
}

.flami-panel__close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius);
  background: none;
  color: var(--ash);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.flami-panel__close:hover { color: var(--obsidian); }

/* Чат */

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 14px;
}

.chat__log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}

.chat__msg {
  max-width: 85%;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
}

.chat__msg p { margin: 0; }

.chat__msg--agent {
  align-self: flex-start;
  background: var(--paper);
}

.chat__msg--user {
  align-self: flex-end;
  background: var(--ember);
  color: var(--paper);
}

.chat__source {
  margin-top: 6px !important;
  font-size: 12px;
  color: var(--ash);
}

.chat__error {
  color: var(--flame);
}

.chat__warning {
  margin-top: 6px !important;
  font-size: 12px;
  color: var(--ember);
}

.chat__form {
  display: flex;
  gap: 10px;
}

.chat__form .btn { flex-shrink: 0; }

/* Хранилище памяти */

.vault {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 16px;
}

.vault__filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.vault__groups {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-right: 4px;
}

.vault__group-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100;
  font-weight: 600;
  font-size: 18px;
}

.vault__empty {
  margin: 0;
  font-size: 13px;
  color: var(--ash);
}

.fact {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.fact__value { margin: 0; font-size: 14px; font-weight: 700; }

.fact__meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ash);
}

/* Данные: импорт и смена датасета */

.datasets {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 16px;
}

.dataset-upload {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dataset-upload__hint {
  margin: 0;
  font-size: 13px;
  color: var(--ash);
}

.dataset-upload .input[type="file"] {
  font-size: 13px;
  padding: 10px 12px;
}

.dataset-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dataset {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--paper);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.dataset__name {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  word-break: break-word;
}

.dataset__meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ash);
}

.dataset-empty {
  margin: 0;
  font-size: 13px;
  color: var(--ash);
}

.dataset-status {
  margin: 0;
  font-size: 13px;
}

.dataset-status--ok {
  color: var(--ember);
  font-weight: 700;
}

.dataset-status--error {
  color: var(--flame);
}

.dataset-status__meta {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ash);
}

/* ---------- Движение: reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .flami--idle .flami__svg,
  .flami--thinking .flami__svg,
  .flami--proposal .flami__svg,
  .flami--speaking .flami__svg {
    animation: none;
    filter: drop-shadow(0 0 10px rgba(220, 60, 12, 0.6));
  }

  .flami-panel,
  .toast-enter,
  .toast-leave { transition: none; }
}

/* ---------- Узкие экраны ---------- */

@media (max-width: 900px) {
  .grid,
  .grid--main { grid-template-columns: 1fr; }

  .flami-panel { width: 100vw; }

  .toast-stack {
    right: 16px;
    left: 16px;
    max-width: none;
  }
}
