/* Правосвод: тёмно-синий «чернильный» цвет, тёплый бумажный фон, заголовки с засечками. */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --sidebar: #efebe2;
  --text: #1a1f2b;
  --muted: #646a76;
  --border: #e2ddd1;
  --primary: #1f3a5f;
  --primary-hover: #172c48;
  --primary-soft: #e7ecf3;
  --hover: rgba(31, 58, 95, .06);
  --accent: #d9b56e;
  --danger: #b42318;
  --warn-bg: #fff6e3;
  --warn-border: #e8c47a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 28, 45, .05), 0 6px 20px rgba(20, 28, 45, .05);
  --serif: "PT Serif", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 16px/1.5 var(--sans); color: var(--text); background: var(--bg); }
h1, h2 { font-family: var(--serif); font-weight: 700; }
h1 { font-size: 34px; line-height: 1.2; margin: 0 0 10px; }
h2 { font-size: 22px; line-height: 1.3; margin: 0; }
a { color: var(--primary); }
button { font: inherit; }
.icon { width: 20px; height: 20px; flex-shrink: 0; }
.lead { color: var(--muted); margin: 0 0 28px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.badge {
  font-style: normal; font-size: 12px; line-height: 18px; padding: 0 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); white-space: nowrap;
}
.icon-button {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--muted);
  display: grid; place-items: center; cursor: pointer;
}
.icon-button:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-button:disabled { opacity: .45; cursor: default; }
.button {
  font-weight: 600; padding: 10px 20px; border-radius: 12px; border: 1px solid var(--primary);
  background: var(--primary); color: #fff; cursor: pointer;
}
.button:hover:not(:disabled) { background: var(--primary-hover); }
.button:disabled { opacity: .5; cursor: default; }

/* ---------- каркас */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 272px; flex-shrink: 0; height: 100vh; position: sticky; top: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px; padding: 18px 14px;
  background: var(--sidebar); border-right: 1px solid var(--border);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; }
.sidebar-close { display: none; }
.brand { display: block; padding: 2px 4px; line-height: 0; }
.brand img { display: block; height: 40px; width: auto; }
.new-chat {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); font-weight: 600; text-decoration: none;
}
.new-chat:hover { border-color: var(--primary); color: var(--primary); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-soon {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-size: 15px;
}
.nav a:hover { background: var(--hover); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-soon { color: var(--muted); white-space: nowrap; }
.nav-soon em { margin-left: auto; font-style: normal; font-size: 12px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }

.saved { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.saved-tabs { display: flex; padding: 3px; border-radius: 10px; background: var(--hover); }
.saved-tabs button {
  flex: 1; border: 0; background: transparent; padding: 6px 4px; border-radius: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.saved-tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.saved-list li { display: flex; align-items: center; border-radius: 10px; }
.saved-list li:hover { background: var(--hover); }
.saved-item {
  flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: left;
  border: 0; background: none; padding: 7px 10px; color: var(--text); cursor: pointer;
}
.saved-item:disabled { opacity: .5; }
.saved-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-remove { border: 0; background: none; color: var(--muted); padding: 6px 10px; cursor: pointer; opacity: 0; font-size: 18px; line-height: 1; }
.saved-list li:hover .saved-remove, .saved-remove:focus-visible { opacity: 1; }
@media (hover: none) { .saved-remove { opacity: 1; } }
.saved-empty { margin: 2px 10px; font-size: 13px; color: var(--muted); }
.sidebar-note { margin: 0; padding: 0 6px; font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.scrim { display: none; }
.content { flex: 1; width: 100%; max-width: 880px; margin: 0 auto; padding: 56px 28px 32px; }

/* ---------- чат */
.chat { display: flex; flex-direction: column; gap: 24px; }
.welcome { text-align: center; padding-top: 5vh; }
.welcome .lead { margin: 0; }
.messages { display: none; flex-direction: column; gap: 18px; }
body.chatting .messages { display: flex; flex: 1; }
body.chatting .welcome, body.chatting .start { display: none; }
body.chatting .content { padding-top: 28px; padding-bottom: 0; }
body.chatting .chat { min-height: calc(100vh - 28px); }

.msg { display: flex; gap: 12px; align-items: flex-start; animation: appear .18s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } }
.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  max-width: 80%; padding: 10px 16px; border-radius: 18px 18px 4px 18px;
  background: var(--primary); color: #fff; white-space: pre-wrap; overflow-wrap: anywhere;
}
.avatar {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border);
}
.avatar img { width: 22px; height: 22px; }
.msg-bot .bubble {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px 18px 18px 18px; box-shadow: var(--shadow);
}
.bubble p { margin: 0; }
.msg-progress { font-size: 13px; color: var(--muted); }
.msg-question { font-size: 17px; font-weight: 600; }
.msg-hint { font-size: 15px; color: var(--muted); }
.msg-error { color: var(--danger); }
.note { padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); border: 1px solid var(--warn-border); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 15px; line-height: 1.3; text-align: left; text-decoration: none; cursor: pointer;
}
.chip:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip:disabled { opacity: .45; cursor: default; }
.chip.chosen:disabled { opacity: 1; border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip-quiet { background: transparent; color: var(--muted); }

.result-label { color: var(--muted); }
.result-amount { font-family: var(--serif); font-size: 40px; font-weight: 700; line-height: 1.1; color: var(--primary); }
.result-note { font-size: 14px; color: var(--muted); }
.facts { margin: 4px 0 0; display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 16px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.summary-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.summary { margin: 0; border-top: 1px solid var(--border); }
.summary-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.summary-row dt { font-size: 14px; color: var(--muted); }
.summary-row dd { margin: 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.summary-row dd span { font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.summary-row dd span.empty { font-weight: 400; color: var(--muted); }
.link-button {
  flex-shrink: 0; border: 0; background: none; padding: 0; cursor: pointer;
  font-size: 14px; color: var(--primary); text-decoration: underline; text-underline-offset: 3px;
}

.composer-wrap { display: flex; flex-direction: column; gap: 8px; }
body.chatting .composer-wrap {
  position: sticky; bottom: 0; z-index: 5; padding: 16px 0;
  background: linear-gradient(to bottom, rgba(246, 244, 239, 0), var(--bg) 24px);
}
.composer {
  display: flex; flex-direction: column; gap: 6px; padding: 12px 12px 10px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 8px 30px rgba(20, 28, 45, .08);
}
.composer:focus-within { border-color: var(--primary); }
.composer textarea {
  border: 0; outline: 0; resize: none; background: transparent; padding: 6px 0;
  font: inherit; font-size: 16px; color: var(--text); max-height: 200px; overflow-y: hidden;
}
.composer-row { display: flex; align-items: center; gap: 8px; margin-left: -8px; }
.composer-hint { flex: 1; font-size: 13px; color: var(--muted); }
.send {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: 12px; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--primary); color: #fff;
}
.send:hover { background: var(--primary-hover); }
.flow-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-bottom: 8px; border-bottom: 1px dashed var(--border); font-size: 13px; color: var(--muted);
}
.flow-bar button { border: 0; background: none; padding: 0; cursor: pointer; font-size: 13px; color: var(--primary); }
.disclaimer { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- стартовые действия */
.start { display: flex; flex-direction: column; gap: 18px; }
.tabs { display: flex; justify-content: center; gap: 4px; }
.tabs button {
  border: 0; background: none; padding: 6px 16px; border-radius: 999px; cursor: pointer; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.actions-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.action {
  position: relative; display: flex; flex-direction: column; gap: 6px; min-height: 140px; padding: 16px;
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; transition: border-color .15s, transform .15s;
}
a.action:hover { border-color: var(--primary); transform: translateY(-1px); }
.action-icon {
  width: 40px; height: 40px; margin-bottom: 6px; border-radius: 12px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary);
}
.action strong { font-size: 15px; line-height: 1.3; }
.action .desc { font-size: 13px; line-height: 1.35; color: var(--muted); }
.action-soon { background: transparent; box-shadow: none; }
.action-soon .action-icon { background: var(--hover); color: var(--muted); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 20px; }
.section-head a { font-size: 15px; text-decoration: none; }
.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px 14px; }
.sheet-card { display: flex; flex-direction: column; gap: 4px; color: var(--text); text-decoration: none; }
.sheet {
  position: relative; display: block; aspect-ratio: 4 / 3; margin-bottom: 6px; overflow: hidden;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
/* «шапка» документа справа сверху и строки текста внизу */
.sheet::before, .sheet::after { content: ""; position: absolute; }
.sheet::before { top: 14px; right: 14px; width: 42%; height: 23px; background: repeating-linear-gradient(to bottom, var(--border) 0 2px, transparent 2px 7px); }
.sheet::after { left: 16px; right: 16px; bottom: 12px; height: 32%; background: repeating-linear-gradient(to bottom, var(--border) 0 2px, transparent 2px 8px); }
.sheet-word {
  position: absolute; left: 0; right: 0; top: 45%; text-align: center;
  font-family: var(--serif); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--primary);
}
a.sheet-card:hover .sheet { border-color: var(--primary); transform: translateY(-1px); }
.sheet-title { font-size: 15px; font-weight: 600; line-height: 1.3; }
.sheet-meta { font-size: 13px; color: var(--muted); }
.sheet-card.soon .sheet { background: transparent; box-shadow: none; }
.sheet-card.soon .sheet-word { color: var(--muted); }
.sheet-card.soon .sheet-title { color: var(--muted); font-weight: 500; }

/* ---------- телефон и узкие окна */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; height: auto;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(20, 28, 45, .25); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(20, 28, 45, .35); }
  .sidebar-close { display: grid; }
  .topbar {
    display: flex; align-items: center; gap: 6px; padding: 8px 12px; position: sticky; top: 0; z-index: 10;
    background: var(--bg); border-bottom: 1px solid var(--border);
  }
  .topbar .brand img { height: 30px; }
  .content { padding: 24px 16px 20px; }
  body.chatting .content { padding-top: 16px; }
  body.chatting .chat { min-height: calc(100vh - 70px); }
  h1 { font-size: 26px; }
  .welcome { padding-top: 2vh; }
  .actions-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .avatar { display: none; }
  .msg-user .bubble { max-width: 90%; }
  .msg-bot .bubble { padding: 12px 14px; }
  .facts, .summary-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .facts dd { margin-bottom: 8px; }
  .composer-hint { font-size: 12px; }
}
