/* ════════════════════════════════════════════════════════════════
   cellConsultant — Neo Chinese / Shan Shui / Wukong Design System
   Свиток, туман, горы, каллиграфия, красные печати.
   ════════════════════════════════════════════════════════════════ */

/* ── Токены ───────────────────────────────────────────────────── */
:root {
  --rice-paper: #f5f0e8;
  --warm-ivory: #faf7f1;
  --ink-black: #1b1a18;
  --mountain-gray: #4a4a47;
  --mist-gray: #8a8781;
  --divider: #d8d3cb;
  --seal-red: #b43a2f;
  --seal-red-deep: #8f2c23;
  --aged-gold: #c8a56a;
  --aged-gold-soft: #d8bd8e;

  --bg: var(--rice-paper);
  --surface: var(--warm-ivory);
  --text: var(--ink-black);
  --text-2: var(--mountain-gray);
  --text-3: var(--mist-gray);
  --line: var(--divider);
  --accent: var(--seal-red);
  --gold: var(--aged-gold);

  --bubble-in: #fbf8f2;
  --bubble-out: #f3ecdd;

  --shadow-card: 0 6px 24px rgba(27, 26, 24, 0.06);
  --shadow-float: 0 12px 40px rgba(27, 26, 24, 0.12);

  --r-card: 20px;
  --r-btn: 16px;
  --r-chip: 999px;

  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 40px; --s5: 64px; --s6: 96px;

  --serif: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --brush: 'Ma Shan Zheng', 'Noto Serif SC', serif;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

:root[data-theme='dark'] {
  --bg: #11100e;
  --surface: #1b1a18;
  --text: #e8e1d5;
  --text-2: #b8b0a4;
  --text-3: #8a8781;
  --line: #2c2a26;
  --rice-paper: #11100e;
  --warm-ivory: #1b1a18;
  --bubble-in: #201e1a;
  --bubble-out: #2a2419;
  --shadow-card: 0 6px 24px rgba(0, 0, 0, 0.4);
  --shadow-float: 0 12px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
svg { vertical-align: -0.15em; }

body {
  font-family: var(--sans);
  background-color: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  /* Текстура рисовой бумаги — едва заметное зерно */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}
:root[data-theme='dark'] body { background-blend-mode: overlay; }

/* ── Слои тумана (медленное движение глубины) ─────────────────── */
.mist {
  position: fixed; inset: -20%; z-index: 0; pointer-events: none;
  background-repeat: no-repeat;
}
.mist-1 {
  background-image: radial-gradient(60% 50% at 20% 30%, rgba(200, 165, 106, 0.10), transparent 70%),
                    radial-gradient(50% 40% at 80% 20%, rgba(180, 58, 47, 0.05), transparent 70%);
  animation: drift1 90s ease-in-out infinite alternate;
}
.mist-2 {
  background-image: radial-gradient(55% 45% at 70% 80%, rgba(74, 74, 71, 0.06), transparent 70%),
                    radial-gradient(45% 35% at 30% 90%, rgba(200, 165, 106, 0.07), transparent 70%);
  animation: drift2 120s ease-in-out infinite alternate;
}
@keyframes drift1 { from { transform: translate3d(-3%, -2%, 0) scale(1.05); } to { transform: translate3d(4%, 3%, 0) scale(1.1); } }
@keyframes drift2 { from { transform: translate3d(2%, 3%, 0) scale(1.08); } to { transform: translate3d(-4%, -2%, 0) scale(1.02); } }

/* Водяной каллиграфический символ за всем интерфейсом */
.watermark {
  position: fixed; right: -4vw; bottom: -10vh; z-index: 0; pointer-events: none;
  font-family: var(--brush); font-size: 56vh; line-height: 1;
  color: var(--ink-black); opacity: 0.025; user-select: none;
}

/* ── Топбар — шапка свитка ────────────────────────────────────── */
.topbar {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: var(--s3);
  padding: 14px var(--s3);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent); opacity: 0.5;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 600; font-size: 19px; letter-spacing: 0.5px; }
.brand .seal {
  font-family: var(--brush); color: var(--rice-paper); background: var(--seal-red);
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 7px;
  font-size: 18px; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15);
}
.brand svg { color: var(--ink-black); }

.tabs { display: flex; gap: 4px; }
.tab {
  position: relative; background: transparent; border: none; cursor: pointer;
  color: var(--text-3); font-family: var(--serif); font-size: 16px; font-weight: 500;
  padding: 8px 16px; letter-spacing: 1px; transition: color 0.3s var(--ease);
}
.tab:hover { color: var(--text-2); }
.tab.active { color: var(--text); }
.tab.active::after {
  content: ''; position: absolute; left: 14px; right: 14px; bottom: 2px; height: 2.5px;
  background: var(--seal-red); border-radius: 2px;
  /* неровный край как мазок кисти */
  clip-path: polygon(0 40%, 8% 0, 30% 60%, 55% 10%, 78% 70%, 92% 20%, 100% 55%, 100% 100%, 0 100%);
  animation: brushSwipe 0.5s var(--ease);
}
@keyframes brushSwipe { from { transform: scaleX(0); transform-origin: left; opacity: 0; } to { transform: scaleX(1); opacity: 1; } }

.channel-status { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: var(--r-chip);
  background: var(--surface); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--text-2);
}
.pill svg { width: 14px; height: 14px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-3) 20%, transparent); }
.dot.on { background: #5a9c6f; box-shadow: 0 0 0 3px rgba(90,156,111,0.2); }
.dot.off { background: var(--seal-red); box-shadow: 0 0 0 3px rgba(180,58,47,0.18); }

#theme-toggle {
  background: transparent; border: 1px solid var(--line); color: var(--text-2);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  font-family: var(--brush); font-size: 17px; transition: all 0.3s var(--ease);
}
#theme-toggle:hover { border-color: var(--gold); color: var(--gold); }

/* ── Панели вкладок (разворот свитка) ─────────────────────────── */
.tab-panel { display: none; flex: 1; overflow: hidden; position: relative; z-index: 2; }
.tab-panel.active { display: flex; animation: unroll 0.55s var(--ease); }
#tab-catalog.active, #tab-settings.active { display: block; overflow: auto; padding: var(--s4) var(--s4) var(--s5); }
@keyframes unroll {
  from { clip-path: inset(0 0 100% 0); opacity: 0.4; }
  to { clip-path: inset(0 0 0 0); opacity: 1; }
}

/* ── Инбокс: список сделок ────────────────────────────────────── */
.conv-list {
  width: 300px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}
.conv-list-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line);
  font-family: var(--serif); font-weight: 600; font-size: 17px; letter-spacing: 1px;
}
#conversations { list-style: none; margin: 0; padding: var(--s1); overflow: auto; }
.conv-item {
  padding: 14px 16px; margin-bottom: 6px; border-radius: 14px; cursor: pointer;
  position: relative; transition: background 0.3s var(--ease);
  animation: inkIn 0.5s var(--ease) both;
}
.conv-item:hover { background: var(--surface); }
.conv-item.active { background: var(--surface); box-shadow: var(--shadow-card); }
.conv-item.active::before {
  content: ''; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px;
  background: var(--seal-red); border-radius: 3px;
}
.conv-item .title { font-weight: 600; color: var(--text); font-size: 15px; }
.conv-item .meta { color: var(--text-3); font-size: 12px; margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.conv-item .meta svg { width: 14px; height: 14px; color: var(--text-3); }

/* Бейджи статусов — оттиск печати */
.badge {
  padding: 2px 10px; border-radius: 6px; font-size: 11px; letter-spacing: 0.5px;
  font-family: var(--serif); border: 1px solid currentColor; opacity: 0.92;
}
.badge.status-new { color: var(--text-3); }
.badge.status-sourcing { color: var(--gold); }
.badge.status-quoted, .badge.status-confirming { color: var(--seal-red); }
.badge.status-confirmed, .badge.status-done, .badge.status-contract { color: #5a9c6f; }
.badge.status-lost { color: var(--text-3); text-decoration: line-through; }

/* ── Окно диалога ─────────────────────────────────────────────── */
.conv-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.conv-header {
  padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s2);
  background: color-mix(in srgb, var(--surface) 50%, transparent);
}
.conv-header h2 { margin: 0; font-family: var(--serif); font-size: 21px; font-weight: 600; }
.conv-header select { margin-left: auto; }

.bridge { flex: 1; display: flex; overflow: hidden; }
.column { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.column:first-child { border-right: 1px solid var(--line); }
.column-head {
  padding: 12px var(--s2); font-family: var(--serif); font-weight: 600; font-size: 14px;
  border-bottom: 1px solid var(--line); color: var(--text-2);
  display: flex; align-items: center; gap: 8px; letter-spacing: 0.5px;
}
.column-head svg { width: 16px; height: 16px; }
.messages { flex: 1; overflow: auto; padding: var(--s3); display: flex; flex-direction: column; gap: 10px; }
.msg {
  max-width: 82%; padding: 10px 14px; border-radius: 16px;
  background: var(--bubble-in); border: 1px solid var(--line); line-height: 1.55;
  animation: inkIn 0.5s var(--ease) both; box-shadow: var(--shadow-card);
}
.msg.out { align-self: flex-end; background: var(--bubble-out); border-color: color-mix(in srgb, var(--gold) 30%, var(--line)); }
.msg .who { font-size: 11px; color: var(--text-3); margin-bottom: 3px; font-family: var(--serif); }
.msg .att { font-size: 11px; color: var(--gold); margin-top: 5px; }

.composer { display: flex; gap: 8px; padding: var(--s2); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; height: 46px; }

/* ── Панель агентов ───────────────────────────────────────────── */
.agent-panel {
  width: 360px; border-left: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 50%, transparent);
  padding: var(--s3); overflow: auto; display: flex; flex-direction: column; gap: var(--s2);
}
.agent-panel h3 { margin: 0 0 4px; font-family: var(--serif); font-size: 16px; font-weight: 600; letter-spacing: 0.5px; }
.agent-actions { display: flex; flex-direction: column; gap: 10px; }
.agent-result {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: var(--s2); min-height: 90px; white-space: pre-wrap; font-size: 14px; line-height: 1.65;
  box-shadow: var(--shadow-card); position: relative;
}
.agent-result.loading { color: var(--text-3); display: grid; place-items: center; }
.agent-result.loading::after {
  content: ''; width: 38px; height: 38px; border-radius: 50%;
  border: 2.5px solid transparent; border-top-color: var(--seal-red); border-right-color: var(--gold);
  animation: inkspin 1.1s linear infinite;
}
@keyframes inkspin { to { transform: rotate(360deg); } }
.agent-result-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.agent-panel textarea { height: 96px; resize: vertical; }

/* ── Каталог ──────────────────────────────────────────────────── */
.catalog-head { display: flex; justify-content: space-between; align-items: center; max-width: 1040px; }
.catalog-head h2, #tab-settings h2 { font-family: var(--serif); font-weight: 600; font-size: 28px; letter-spacing: 1px; }
.catalog-table {
  width: 100%; max-width: 1040px; border-collapse: separate; border-spacing: 0; margin-top: var(--s3);
  background: var(--surface); border-radius: var(--r-card); overflow: hidden; box-shadow: var(--shadow-card);
}
.catalog-table th, .catalog-table td { text-align: left; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.catalog-table th { color: var(--text-3); font-family: var(--serif); font-weight: 600; font-size: 13px; letter-spacing: 1px; }
.catalog-table tr:last-child td { border-bottom: none; }
.catalog-table tbody tr { transition: background 0.25s var(--ease); }
.catalog-table tbody tr:hover { background: color-mix(in srgb, var(--gold) 6%, transparent); }

/* ── Настройки ────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: var(--s3); margin-bottom: var(--s3); max-width: 760px; box-shadow: var(--shadow-card);
  animation: inkIn 0.5s var(--ease) both;
}
.card h3 { margin-top: 0; font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: 0.5px; }
.provider-row { display: grid; grid-template-columns: 100px 1fr 1fr; gap: 12px; align-items: center; margin-bottom: 12px; }
.provider-row .pname { font-family: var(--serif); font-weight: 600; }

/* Пайплайны подключения каналов */
.channel-block { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.channel-line { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.channel-line b { font-family: var(--serif); font-weight: 600; }
.ch-detail { color: var(--text-3); font-size: 13px; margin-left: 4px; }
.ch-form { display: flex; gap: 8px; align-items: center; }
.ch-form input { flex: 1; }
.ch-hint { font-size: 12.5px; color: var(--text-3); line-height: 1.5; }
.wa-qr { margin: 4px 0; }
.wa-qr img { border-radius: 12px; border: 1px solid var(--line); background: #fff; padding: 8px; }

/* ── Формы ────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; margin: 10px 0; }
.field span { font-size: 12.5px; color: var(--text-3); }
input, textarea, select {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 11px; padding: 11px 13px; font-size: 14px; font-family: inherit;
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent);
}
::placeholder { color: var(--text-3); }

/* ── Кнопки ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--seal-red); color: var(--rice-paper); border: none;
  padding: 13px 18px; border-radius: var(--r-btn); cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: var(--sans); letter-spacing: 0.3px;
  text-align: left; position: relative; overflow: hidden;
  box-shadow: 0 4px 14px rgba(180, 58, 47, 0.22);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease), filter 0.18s var(--ease);
}
.btn svg { width: 17px; height: 17px; flex-shrink: 0; }
.btn:hover { filter: brightness(1.05); box-shadow: 0 6px 18px rgba(180, 58, 47, 0.3); }
/* Нажатие — печать прижимается к бумаге */
.btn:active { transform: translateY(1px) scale(0.985); box-shadow: inset 0 2px 8px rgba(0,0,0,0.25); }
.btn:disabled { background: var(--line); color: var(--text-3); box-shadow: none; cursor: default; filter: none; }

/* Вторичная — золотая рамка */
.btn-mini {
  background: transparent; border: 1px solid var(--line); color: var(--text-2);
  padding: 7px 12px; border-radius: 9px; cursor: pointer; font-size: 12.5px; font-family: var(--sans);
  display: inline-flex; align-items: center; gap: 6px; transition: all 0.25s var(--ease);
}
.btn-mini svg { width: 14px; height: 14px; }
.btn-mini:hover { border-color: var(--gold); color: var(--gold); }

.conv-list-head .btn-mini, #new-conv {
  width: 30px; height: 30px; justify-content: center; padding: 0; border-radius: 8px;
  border-color: var(--gold); color: var(--gold); font-size: 16px;
}

/* ── Пустые состояния ─────────────────────────────────────────── */
.empty-state {
  margin: auto; color: var(--text-3); padding: var(--s5) var(--s4); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: var(--s2); max-width: 360px;
}
.empty-state .glyph { font-family: var(--brush); font-size: 96px; color: var(--ink-black); opacity: 0.10; line-height: 1; }
.empty-state .line { font-family: var(--serif); font-size: 17px; color: var(--text-2); letter-spacing: 1px; }
.empty-state .sub { font-size: 13px; color: var(--text-3); }

/* ── Тост — бумажный листок с печатью ─────────────────────────── */
.toast {
  position: fixed; bottom: var(--s4); left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  padding: 13px 22px 13px 18px; border-radius: 12px; z-index: 100; box-shadow: var(--shadow-float);
  font-size: 14px; border-left: 3px solid var(--gold); max-width: 80vw;
  animation: inkIn 0.4s var(--ease);
}
.toast.err { border-left-color: var(--seal-red); }

/* ── Печать-штамп (подтверждение действия) ────────────────────── */
.stamp-overlay {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; pointer-events: none;
}
.stamp {
  font-family: var(--brush); font-size: 120px; color: var(--seal-red);
  width: 180px; height: 180px; display: grid; place-items: center;
  border: 6px solid var(--seal-red); border-radius: 24px;
  box-shadow: inset 0 0 0 3px rgba(180,58,47,0.4);
  animation: stampIn 0.7s var(--ease) forwards;
  opacity: 0;
}
@keyframes stampIn {
  0% { opacity: 0; transform: scale(1.6) rotate(-12deg); }
  35% { opacity: 0.95; transform: scale(0.92) rotate(-6deg); }
  50% { transform: scale(1) rotate(-7deg); }
  80% { opacity: 0.95; }
  100% { opacity: 0; transform: scale(1.05) rotate(-7deg); }
}

/* ── Появление кистью ─────────────────────────────────────────── */
@keyframes inkIn {
  from { opacity: 0; filter: blur(5px); transform: translateY(7px); }
  to { opacity: 1; filter: blur(0); transform: none; }
}

/* ── Скроллбары ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--mist-gray) 40%, transparent); border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--gold) 60%, transparent); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

hr { border: none; border-top: 1px solid var(--line); margin: var(--s2) 0; }
.hint { color: #5a9c6f; font-size: 13px; margin-left: 12px; font-family: var(--serif); }

/* ── Адаптив: нижняя «бронзовая табличка» на узких экранах ─────── */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: var(--s2); padding-bottom: 60px; }
  .channel-status { order: 3; width: 100%; }
  .tabs {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 8px env(safe-area-inset-right) calc(8px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
    box-shadow: 0 -6px 24px rgba(27,26,24,0.08);
    background-image: linear-gradient(180deg, color-mix(in srgb, var(--gold) 8%, transparent), transparent);
  }
  .tab.active::after { bottom: -6px; }
  .conv-view, .agent-panel { display: none; }
  .conv-list { width: 100%; }
  .bridge { flex-direction: column; }
  .column:first-child { border-right: none; border-bottom: 1px solid var(--line); }
}
