/*
  Визуальный язык "ЗАСТУП": острые прямые углы (никаких скруглений), плотный
  жирный Archivo, тёплый кремовый фон и чёрный текст с ярко-красным акцентом,
  толстые 2px разделители вместо привычных теней. Токены и часть компонентных
  классов (.btn, .card, .tag, .input, .dialog, .hr) взяты из дизайн-системы
  "Modernist", присланной пользователем как эталон.
*/
@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;600;800&display=swap');

:root {
  --color-bg: #f3f2f2;
  --color-surface: #eae9e9;
  --color-text: #201e1d;
  --color-accent: #ec3013;
  --color-accent-2: #e15b47;
  --color-divider: rgba(32, 30, 29, 0.4);
  --color-divider-thin: rgba(32, 30, 29, 0.16);

  --color-neutral-100: #f8f4f4;
  --color-neutral-800: #444141;

  --color-accent-100: #fff2ef;
  --color-accent-600: #dd2b0f;
  --color-accent-700: #ae1800;
  --color-accent-800: #7c1405;

  --font-heading: "Archivo", system-ui, sans-serif;
  --font-body: "Archivo", system-ui, sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;

  --radius: 0px;

  --shadow-sm: 0 1px 2px rgba(32, 30, 29, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; position: relative; overflow: hidden; }

.hidden { display: none !important; }

.divider { background: var(--color-divider); height: 1px; flex-shrink: 0; }
.divider.thick { height: 2px; }
.hr { height: 2px; border: 0; margin: var(--space-4) 0; background: var(--color-divider); flex-shrink: 0; }

/* ---------- screens / tabs ---------- */

.screen {
  position: absolute; inset: 0; bottom: 74px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
}
.screen.active { display: flex; }

.scrollArea { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.sectionPad { padding: var(--space-4); }
.sectionPad.topPad { padding-bottom: var(--space-2); }

.sectionLabel { font-size: 13px; opacity: .65; margin: 0 0 10px; }

.screenTitle { margin: 0 0 8px; }
.screenHint { font-size: 13px; opacity: .65; margin: 0 0 12px; line-height: 1.5; }

/* ---------- topbar (Главная) ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px var(--space-4) var(--space-3);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brandDot { width: 10px; height: 10px; background: var(--color-accent); flex-shrink: 0; }
.brandWord { font-family: var(--font-heading); font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }

.iconBtn {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-surface); color: var(--color-text);
  border: none; cursor: pointer;
}
.iconBtn:active { background: var(--color-accent-100); color: var(--color-accent-700); }

/* ---------- category rows ---------- */

.rowList { display: flex; flex-direction: column; }
.rowItem {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--color-divider-thin);
  cursor: pointer; background: none; border-left: none; border-right: none; border-top: none;
  text-align: left; width: 100%; font: inherit; color: inherit;
}
.rowItem:last-child { border-bottom: none; }
.rowIcon {
  width: 38px; height: 38px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-surface); color: var(--color-accent-700);
}
.rowLabel { flex: 1; font-size: 14.5px; }
.rowChevron { opacity: .4; flex-shrink: 0; }

/* ---------- cards ---------- */

.card {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3); background: var(--color-surface);
  margin-bottom: var(--space-2);
}
.card.cardAccent { border: 2px solid var(--color-accent); }
.card-kicker { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--color-accent); }
.card-title { font-family: var(--font-heading); font-weight: 800; font-size: 15px; line-height: 1.2; }
.card-body { margin: 0; font-size: 13px; opacity: .8; }
.card-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: rgba(32,30,29,.5); }
.card-row { flex-direction: row; align-items: center; gap: var(--space-3); }

/* ---------- tags ---------- */

.tag {
  display: inline-flex; align-items: center; font-size: 11px;
  letter-spacing: .02em; padding: 3px 10px;
}
.tag-accent { background: var(--color-accent-100); color: var(--color-accent-800); }
.tag-neutral { background: var(--color-neutral-100); color: var(--color-neutral-800); }
.tag-outline { border: 1px solid var(--color-accent); color: var(--color-accent); }

/* ---------- buttons / inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; text-decoration: none;
  font-family: var(--font-heading); font-weight: 800; font-size: 14px; line-height: 1.2;
  color: var(--color-text); background: transparent; border: 1px solid transparent;
  padding: var(--space-2) calc(var(--space-3) * 1.2);
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--color-accent); color: var(--color-bg); }
.btn-primary:active { background: var(--color-accent-700); }
.btn-secondary { border-color: var(--color-divider); }
.btn-secondary:active { background: rgba(32,30,29,.1); }
.btn-ghost { color: var(--color-accent); padding-inline: var(--space-1); }
.btn-ghost:active { background: rgba(236,48,19,.14); }
.btn-icon { width: 40px; height: 40px; padding: 0; flex-shrink: 0; }
.btn-block { width: 100%; margin-top: var(--space-1); }

.input {
  width: 100%; min-height: 40px; padding: 8px 12px; font: inherit; font-size: 14px;
  color: var(--color-text); caret-color: var(--color-accent);
  background: var(--color-surface); border: 1px solid var(--color-divider-thin);
}
.input:focus { outline: none; border-color: var(--color-accent); }

/* ---------- Главная: недавние обращения ---------- */

#recentList .emptyHint { font-size: 13px; opacity: .55; }

/* ---------- Шаблоны ---------- */

.tplCard {
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--color-surface); padding: var(--space-3); margin-bottom: var(--space-2);
}
.tplIcon {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-bg); color: var(--color-accent-700);
}
.tplInfo { flex: 1; min-width: 0; }
.tplTitle { font-family: var(--font-heading); font-weight: 800; font-size: 14px; line-height: 1.3; }
.tplMeta { font-size: 11px; color: rgba(32,30,29,.5); margin-top: 3px; }

/* ---------- История ---------- */

.histItem {
  padding: 14px var(--space-4); border-bottom: 1px solid var(--color-divider-thin);
  display: flex; flex-direction: column; gap: 6px;
}
.histTop { display: flex; justify-content: space-between; align-items: center; }
.histDate { font-size: 11px; opacity: .55; }
.histTitle { font-size: 14.5px; display: flex; align-items: center; gap: 10px; justify-content: space-between; }
#historyList .emptyHint { padding: var(--space-4); font-size: 13px; opacity: .55; }

/* ---------- Профиль ---------- */

.profileRow { display: flex; align-items: center; gap: 12px; padding: 8px 0 var(--space-2); }
.avatar {
  width: 52px; height: 52px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-accent); color: var(--color-bg);
  font-family: var(--font-heading); font-weight: 800; font-size: 17px;
}
.profileName { font-family: var(--font-heading); font-weight: 800; font-size: 16px; }
.tierList { display: flex; flex-direction: column; }
.settingsRow {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 0; border-bottom: 1px solid var(--color-divider-thin);
  font-size: 14.5px; cursor: pointer;
}

/* ---------- нижняя навигация ---------- */

#tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; border-top: 2px solid var(--color-divider);
  background: var(--color-bg);
  padding: 8px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabBtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer; color: rgba(32,30,29,.45);
  padding: 4px 0; font-family: var(--font-body);
}
.tabBtn span { font-size: 10px; }
.tabBtn.active { color: var(--color-accent-700); }

/* ---------- чат (оверлей) ---------- */

#screen-chat {
  position: absolute; inset: 0; z-index: 10;
  display: none; flex-direction: column;
  background: var(--color-bg);
  padding-top: env(safe-area-inset-top);
}
#screen-chat.open { display: flex; }

.chatHeader {
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--space-4) var(--space-2);
  flex-shrink: 0;
}
.chatHeaderText { flex: 1; min-width: 0; }
#chatTitle { font-family: var(--font-heading); font-weight: 800; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chatSubtitle { font-size: 11px; opacity: .55; margin-top: 1px; }

.disclaimerBar { padding: 0 var(--space-4) var(--space-2); flex-shrink: 0; }

#feed {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px var(--space-4) 6px;
  display: flex; flex-direction: column; gap: 10px;
}

.bubbleRow { display: flex; flex-direction: column; max-width: 82%; }
.bubbleRow.user { align-self: flex-end; align-items: flex-end; }
.bubbleRow.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 13px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word;
  font-size: 14px;
}
.bubbleRow.user .bubble { background: var(--color-accent); color: var(--color-bg); }
.bubbleRow.assistant .bubble { background: var(--color-surface); color: var(--color-text); }
.bubbleTime { font-size: 10px; opacity: .5; margin: 3px 2px 0; }
.toggleBtn { margin-top: 4px; padding: 4px 8px; font-size: 11px; font-weight: 700; }
.bubble.errorText { background: var(--color-accent-100); color: var(--color-accent-800); }

#typingIndicator { padding: 0 var(--space-4) 4px; flex-shrink: 0; }
.typingBubble {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--color-surface); padding: 10px 14px; opacity: .7;
}
.typingBubble span { width: 5px; height: 5px; background: var(--color-text); animation: typing-bounce 1.1s infinite ease-in-out; }
.typingBubble span:nth-child(2) { animation-delay: .15s; }
.typingBubble span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- документ-карточка в чате ---------- */

.docCard {
  align-self: flex-start; display: flex; align-items: center; gap: 10px;
  background: var(--color-surface); padding: 10px 12px; max-width: 84%; font-size: 14px;
}
.docIcon {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-accent); color: var(--color-bg); font-size: 16px;
}
.docInfo { flex: 1; min-width: 0; }
.docTitle { font-weight: 700; font-size: 13.5px; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docHint { font-size: 12px; opacity: .55; }
.docCard button {
  background: var(--color-accent); color: var(--color-bg); border: none;
  padding: 8px 12px; font-size: 12.5px; font-weight: 800; font-family: var(--font-heading);
  cursor: pointer; flex-shrink: 0;
}
.docCard button:active { background: var(--color-accent-700); }

/* ---------- быстрые чипы ---------- */

#quickChips {
  display: flex; gap: 8px; padding: 0 var(--space-4) 8px; overflow-x: auto; flex-shrink: 0;
}
#quickChips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; cursor: pointer; flex-shrink: 0; padding: 6px 12px; font-size: 12px; }
.chip:active { background: var(--color-accent-100); }

/* ---------- composer ---------- */

#composer {
  display: flex; align-items: center; gap: 8px;
  padding: 8px var(--space-3) calc(10px + env(safe-area-inset-bottom));
  border-top: 2px solid var(--color-divider); flex-shrink: 0;
}
#messageInput { flex: 1; }

/* ---------- диалог ---------- */

.dialog-backdrop {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: var(--space-4); background: rgba(45, 43, 43, .5);
}
.dialog {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-4); background: var(--color-surface); box-shadow: 0 12px 32px rgba(45,43,43,.22);
}
.dialog-title { font-family: var(--font-heading); font-weight: 800; font-size: 18px; }
.dialog-body { font-size: 14px; opacity: .85; line-height: 1.5; white-space: pre-line; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-1); }
