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

[hidden] {
  display: none !important;
}

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --glass: rgba(255, 255, 255, 0.4);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --border: #e6e6e2;
  --text: #1a1a18;
  --text-dim: #78786f;
  --accent: #2f6fed;
  --accent-soft: #eaf1ff;
  --danger: #d64545;
  --ok: #2f9e5f;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.05), 0 10px 30px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", sans-serif;
  --sidebar-w: 264px;
}

html[data-theme="dark"] {
  --bg: #0b0d11;
  --surface: #161a21;
  --glass: rgba(16, 20, 27, 0.32);
  --glass-strong: rgba(16, 20, 27, 0.8);
  --border: #262c35;
  --text: #f3f3ef;
  --text-dim: #9a9aa2;
  --accent: #3b82f6;
  --accent-soft: #17233a;
  --danger: #f07171;
  --ok: #4ec27f;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 12px 34px rgba(0,0,0,.55);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.6), 0 2px 10px rgba(0,0,0,.5);
}

html[data-incognito="true"] {
  --bg: #1c1c1f;
  --surface: #2a2a2e;
  --glass: rgba(28, 28, 32, 0.5);
  --glass-strong: rgba(28, 28, 32, 0.85);
  --border: #3a3a40;
  --text: #dcdcdc;
  --text-dim: #8f8f96;
  --accent: #8a8a92;
  --accent-soft: #33333a;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 12px 34px rgba(0,0,0,.5);
}

html, body {
  height: 100%;
}

html {
  background: var(--bg);
}

body {
  font-family: var(--font);
  color: var(--text);
  background: transparent;
  -webkit-font-smoothing: antialiased;
}

#bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.auth {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--glass-strong);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  padding: 36px 30px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.auth-logo {
  font-size: 34px;
}

.auth-sub {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 18px;
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}

.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter .18s, transform .08s;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(.985); }
.btn-primary:disabled { opacity: .55; cursor: default; }

.btn-primary.small {
  padding: 10px 14px;
  font-size: 14px;
  flex-shrink: 0;
}

.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .18s;
}

.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); }
.btn-ghost:disabled { opacity: .45; cursor: default; }

.link {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 14px 4px 4px;
}

.auth-err {
  font-size: 13px;
  color: var(--danger);
  text-align: center;
  padding: 2px;
}

.auth-credit {
  margin-top: 10px;
}

.app {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(120deg, var(--accent), #7aa8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  padding: 4px 6px 6px;
}

.new-chat {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  transition: background .18s;
}

.new-chat:hover { background: var(--accent-soft); }

.proj-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  transition: background .18s;
}

.proj-btn:hover { background: var(--accent-soft); }

.proj-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background .18s;
}

.proj-btn.on .proj-dot { background: var(--accent); }

.proj-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.proj-caret {
  color: var(--text-dim);
  font-size: 16px;
}

.history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px -4px;
  padding: 0 4px;
}

.chat-row {
  display: flex;
  align-items: center;
  border-radius: 8px;
}

.chat-row:hover { background: var(--accent-soft); }
.chat-row.active { background: var(--accent-soft); }

.chat-item {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 4px 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-del {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 6px;
  opacity: 0;
  flex-shrink: 0;
  transition: opacity .15s, color .15s;
}

.chat-row:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); }

.side-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
}

.user-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 10px;
  flex-shrink: 0;
  transition: background .2s, color .2s;
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.icon-btn svg { display: block; }

#themeToggle .icon-moon { display: none; }
html[data-theme="dark"] #themeToggle .icon-sun { display: none; }
html[data-theme="dark"] #themeToggle .icon-moon { display: block; }

.credit {
  font-size: 12px;
  color: var(--text-dim);
  opacity: 0.6;
  letter-spacing: 0.3px;
  padding: 2px 6px;
  text-align: center;
}

.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
}

.spacer { flex: 1; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 5px 12px;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.incognito-label {
  display: none;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

html[data-incognito="true"] .incognito-label { display: inline; }

.incognito-toggle {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 10px;
  flex-shrink: 0;
  transition: background .2s, color .2s;
}

.incognito-toggle:hover {
  background: var(--accent-soft);
  color: var(--text);
}

html[data-incognito="true"] .incognito-toggle {
  background: var(--surface);
  color: var(--text);
}

.incognito-toggle svg { display: block; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
}

.bubble {
  max-width: 760px;
  margin: 0 auto 20px;
  padding: 14px 18px;
  line-height: 1.65;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.bubble.user { background: var(--accent-soft); }

.bubble.assistant { white-space: normal; }

.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }

.md p { margin: 0 0 12px; }

.md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 20px 0 10px;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.2px;
}

.md h2 { font-size: 21px; }
.md h3 { font-size: 18px; }
.md h4 { font-size: 16px; }
.md h5, .md h6 { font-size: 15px; color: var(--text-dim); }

.md ul, .md ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.md li { margin: 4px 0; }
.md li::marker { color: var(--text-dim); }

.md blockquote {
  margin: 0 0 12px;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  color: var(--text-dim);
}

.md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.md a { color: var(--accent); }

.md strong { font-weight: 650; }

.md code {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 6px;
}

.code-wrap {
  margin: 0 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px 7px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
}

.code-lang {
  font-size: 11.5px;
  color: var(--text-dim);
  letter-spacing: 0.4px;
  text-transform: lowercase;
}

.code-copy {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}

.code-copy:hover {
  background: var(--surface);
  color: var(--accent);
}

.code-wrap pre {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
}

.code-wrap code {
  background: transparent;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  color: var(--text);
}

.table-wrap {
  margin: 0 0 14px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.md table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

.md th, .md td {
  padding: 9px 13px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.md th {
  background: var(--accent-soft);
  font-weight: 600;
}

.md tr:last-child td { border-bottom: none; }

.think {
  margin: 0 0 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: transparent;
}

.think summary {
  cursor: pointer;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-dim);
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 7px;
}

.think summary::-webkit-details-marker { display: none; }

.think summary::before {
  content: "›";
  display: inline-block;
  font-size: 15px;
  transition: transform .18s;
}

.think[open] summary::before { transform: rotate(90deg); }

.think summary:hover { color: var(--text); }

.think-body {
  padding: 2px 14px 12px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-dim);
  border-top: 1px dashed var(--border);
  margin-top: 2px;
  padding-top: 12px;
  max-height: 420px;
  overflow-y: auto;
}

.think-body p { margin: 0 0 9px; }

.bubble.system {
  max-width: 760px;
  font-size: 13px;
  color: var(--text-dim);
  background: transparent;
  border: 1px dashed var(--border);
  padding: 10px 14px;
}

.sources {
  max-width: 760px;
  margin: -12px auto 20px;
  padding: 0 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-chip {
  font-size: 11.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}

.composer {
  flex-wrap: wrap;
  flex-shrink: 0;
  max-width: 760px;
  width: 100%;
  margin: 0 auto 20px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  position: relative;
  z-index: 5;
  background: var(--glass-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 8px 8px 10px;
  box-shadow: var(--shadow);
}

.input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  max-height: 200px;
  padding: 7px 2px;
}

.attach, .send {
  border: none;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .18s, filter .18s;
}

.attach {
  background: transparent;
  color: var(--text-dim);
}

.attach:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.send {
  background: var(--accent);
  color: #fff;
}

.send:hover { filter: brightness(1.1); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 860px;
  max-height: 82vh;
  background: var(--glass-strong);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  font-size: 17px;
  font-weight: 600;
}

.modal-body {
  display: flex;
  min-height: 0;
  flex: 1;
}

.col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px;
  gap: 10px;
}

.col-proj {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.col-docs { flex: 1; }

.row-form {
  display: flex;
  gap: 8px;
}

.list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 120px;
}

.proj-row, .doc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  padding: 8px 10px;
  transition: background .15s;
}

.proj-row:hover, .doc-row:hover { background: var(--accent-soft); }
.proj-row.active { background: var(--accent-soft); }

.row-main {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  padding: 0;
}

.row-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-del {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color .15s;
}

.row-del:hover { color: var(--danger); }

.badge {
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.wait { color: var(--accent); border-color: var(--accent); }
.badge.err { color: var(--danger); border-color: var(--danger); }

.docs-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.docs-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint {
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.empty {
  font-size: 13px;
  color: var(--text-dim);
  padding: 12px 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}



.doc-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface);
  cursor: pointer;
  transition: transform .14s, box-shadow .14s, border-color .14s;
}

.doc-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.doc-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  background: var(--accent-soft);
}

.doc-icon.scan { background: color-mix(in srgb, var(--accent) 18%, transparent); }

.doc-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  margin: 7px 0 0 44px;
}

.doc-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 9px 0 0 44px;
}

.badge.scan  { color: var(--accent); border-color: var(--accent); }
.badge.txt   { color: var(--text-dim); }
.badge.stamp { color: #b0812f; border-color: #b0812f; }


.doc-card.processing { cursor: default; }
.doc-card.processing:hover { transform: none; box-shadow: none; border-color: var(--border); }

.proc-step {
  font-size: 12.5px;
  color: var(--accent);
  margin: 9px 0 0 44px;
}

.shimmer {
  height: 4px;
  border-radius: 3px;
  margin: 10px 0 2px;
  background: linear-gradient(90deg, var(--border) 0%, var(--accent) 50%, var(--border) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

#docList.drag {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  border-radius: 12px;
  background: var(--accent-soft);
}



.docview {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 20px;
  animation: dvfade .18s ease;
}

@keyframes dvfade { from { opacity: 0; } to { opacity: 1; } }

.docview-card {
  width: 100%;
  max-width: 1120px;
  height: 88vh;
  background: var(--glass-strong);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: dvup .22s cubic-bezier(0.2, 0.7, 0.2, 1);
}

@keyframes dvup { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }

.docview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.docview-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.docview-badges { flex: 1; }
.docview-badges .doc-badges { margin: 0; }

.docview-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.docview-text {
  flex: 1;
  overflow-y: auto;
  padding: 26px 30px;
  line-height: 1.7;
  font-size: 15px;
  white-space: normal;
  color: var(--text);
}

.docview-text .empty { color: var(--text-dim); }

mark.lowconf {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
  text-decoration: underline wavy var(--danger);
  text-underline-offset: 3px;
  cursor: help;
}

.trunc {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--text-dim);
  font-style: italic;
}

.docview-side {
  width: 320px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface);
}

.side-h {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.outline { margin-top: 12px; font-size: 13.5px; }
.outline:empty { display: none; }

.uncertain {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.uw {
  font-size: 12px;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 6px;
  padding: 2px 7px;
  text-decoration: underline wavy;
  text-underline-offset: 2px;
}

.stampinfo {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

@media (max-width: 720px) {
  .docview-body { flex-direction: column; }
  .docview-side { width: auto; border-left: none; border-top: 1px solid var(--border); }
}



.doc-search {
  width: 100%;
  padding: 9px 12px;
  margin-bottom: 10px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}
.doc-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}


.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 26px 18px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  color: var(--text-dim);
  background: var(--glass);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  transition: border-color .2s ease, background .2s ease, transform .2s ease, color .2s ease;
}
.dropzone.over {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: scale(1.015);
}
.dropzone.over svg { animation: dropBounce .7s ease-in-out infinite; }
@keyframes dropBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}


.upload-progress {
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  animation: fadeSlide .25s ease both;
}
.up-name {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 550;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.up-track {
  height: 5px;
  overflow: hidden;
  background: var(--border);
  border-radius: 99px;
}
.up-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #7aa5ff);
  border-radius: 99px;
  transition: width .45s cubic-bezier(.4, 0, .2, 1);
}
.up-bar.pulse { animation: barPulse 1.1s ease-in-out infinite; }
@keyframes barPulse { 50% { opacity: .55; } }

.up-steps {
  display: flex;
  gap: 14px;
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--text-dim);
}
.up-step { position: relative; padding-left: 14px; transition: color .2s ease; }
.up-step::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 7px;
  height: 7px;
  background: var(--border);
  border-radius: 50%;
  transform: translateY(-50%);
  transition: background .2s ease, box-shadow .2s ease;
}
.up-step.active { color: var(--accent); }
.up-step.active::before {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.up-step.done { color: var(--ok); }
.up-step.done::before { background: var(--ok); }


.list .doc-card { animation: fadeSlide .28s ease both; }
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}


.text-find {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: auto;
}
.find-field {
  width: 190px;
  padding: 7px 11px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--glass-strong);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  transition: width .22s ease, border-color .18s ease;
}
.find-field:focus {
  width: 240px;
  border-color: var(--accent);
}
.find-count {
  min-width: 46px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.find-nav { padding: 5px; }


mark.find-hit {
  padding: 1px 2px;
  color: inherit;
  background: rgba(250, 204, 21, .38);
  border-radius: 3px;
}
mark.find-hit.current {
  background: var(--accent);
  color: #fff;
  animation: hitPop .3s ease;
}
@keyframes hitPop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}


.outline .jump {
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: color .16s ease, border-color .16s ease;
}
.outline .jump:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}


.ask-sel {
  position: fixed;
  z-index: 60;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 8px 13px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: #fff;
  cursor: pointer;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  animation: askPop .16s ease both;
}
.ask-sel:hover { filter: brightness(1.08); }
@keyframes askPop {
  from { opacity: 0; transform: translateY(4px) scale(.96); }
  to   { opacity: 1; transform: none; }
}


.skeleton { display: flex; flex-direction: column; gap: 11px; padding: 8px 0; }
.skeleton i {
  display: block;
  height: 13px;
  background: linear-gradient(90deg, var(--border) 25%, var(--glass-strong) 50%, var(--border) 75%);
  background-size: 400% 100%;
  border-radius: 6px;
  animation: shimmer 1.3s linear infinite;
}
.skeleton i:nth-child(3n) { width: 72%; }
.skeleton i:nth-child(4n) { width: 88%; }
@keyframes shimmer {
  from { background-position: 100% 0; }
  to   { background-position: 0 0; }
}


@media (prefers-reduced-motion: reduce) {
  .dropzone, .up-bar, .list .doc-card, .ask-sel, .skeleton i, mark.find-hit.current {
    animation: none !important;
    transition: none !important;
  }
}



.desk-btn {
  margin-top: 6px;
  text-decoration: none;
  color: var(--text);
}
.desk-btn svg { flex: none; color: var(--text-dim); }
.desk-btn:hover svg { color: var(--accent); }



.net-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}
.net-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  padding: 34px 46px;
  text-align: center;
  background: var(--glass-strong);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
}
.net-spin {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: netSpin .8s linear infinite;
}
.net-spin.stopped { animation: none; border-top-color: var(--danger); }
@keyframes netSpin { to { transform: rotate(360deg); } }
.net-title { font-size: 15px; font-weight: 600; color: var(--text); }
.net-sub { max-width: 320px; font-size: 13px; line-height: 1.5; color: var(--text-dim); }
.net-retry { margin-top: 6px; padding: 9px 22px; }


.net-banner {
  position: fixed;
  top: 14px;
  left: 50%;
  z-index: 65;
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 9px 16px;
  font-size: 13px;
  color: #fff;
  background: var(--danger);
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
  transform: translateX(-50%);
  animation: bannerIn .2s ease both;
}
@keyframes bannerIn {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to   { opacity: 1; transform: translateX(-50%); }
}





.burger,
.chat-top-title { display: none; }

.nav-scrim {
  position: fixed;
  inset: 0;
  z-index: 44;
  display: none;
  background: rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .24s ease;
}


@media (max-width: 768px) {

  
  html, body { overflow-x: hidden; }

  
  .app {
    position: fixed;
    top: var(--vvtop, 0px);
    right: 0;
    left: 0;
    height: var(--vvh, 100dvh);
  }

  
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 45;
    width: min(86vw, 320px);
    
    background: var(--surface);
    backdrop-filter: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: var(--shadow-lg);
    
    transform: translateX(-101%);
    transition: transform .26s cubic-bezier(.2, .7, .2, 1);
    overscroll-behavior: contain;
    padding:
      calc(12px + env(safe-area-inset-top))
      14px
      calc(10px + env(safe-area-inset-bottom))
      calc(14px + env(safe-area-inset-left));
  }

  .app.nav-open .sidebar { transform: none; }

  .nav-scrim { display: block; }
  .app.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }

  
  .app.nav-open .chat-top,
  .app.nav-open .composer {
    backdrop-filter: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  
  .chat-top {
    gap: 2px;
    padding: 5px 6px 5px 4px;
    padding-top: calc(5px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
    background: var(--glass-strong);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  .burger { display: flex; }

  
  .chat-top .chip,
  .chat-top .spacer { display: none; }

  
  html[data-incognito="true"] .incognito-label { display: none; }

  .chat-top-title {
    display: block;
    flex: 1;
    min-width: 0;
    padding: 0 2px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  
  .icon-btn,
  .incognito-toggle,
  .attach,
  .send {
    width: 44px;
    height: 44px;
  }

  .icon-btn svg,
  .incognito-toggle svg,
  .attach svg,
  .send svg {
    width: 22px;
    height: 22px;
  }

  .btn-primary { min-height: 46px; }
  .btn-ghost { min-height: 40px; padding: 9px 14px; font-size: 14px; }

  .new-chat,
  .proj-btn {
    min-height: 46px;
    font-size: 15px;
  }

  .chat-row { border-radius: 10px; }

  .chat-item {
    min-height: 44px;
    padding: 11px 4px 11px 12px;
    font-size: 15px;
  }

  
  .chat-del,
  .row-del {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    opacity: 1;
  }

  .side-bottom { gap: 4px; padding-top: 4px; }

  
  .messages { padding: 10px 0 2px; }

  .bubble {
    max-width: none;
    margin: 0 8px 12px;
    padding: 12px 14px;
    font-size: 16px;
    line-height: 1.6;
  }

  .bubble.system {
    max-width: none;
    font-size: 13.5px;
  }

  .sources {
    max-width: none;
    margin: -6px 8px 12px;
    padding: 0 6px;
  }

  .md h2 { font-size: 19px; }
  .md h3 { font-size: 17px; }
  .md ul, .md ol { padding-left: 20px; }
  .code-wrap code { font-size: 12.5px; }

  
  .composer {
    max-width: none;
    width: auto;
    margin: 0 8px calc(6px + env(safe-area-inset-bottom));
    padding: 5px 5px 5px 8px;
    gap: 3px;
    border-radius: 22px;
  }

  
  .input {
    font-size: 16px;
    min-height: 44px;
    max-height: 38dvh;
  }

  .field,
  .doc-search,
  .find-field,
  #newProjName,
  #textSearch {
    font-size: 16px;
  }

  .field { padding: 13px 14px; }

  
  .auth {
    height: auto;
    min-height: 100dvh;
    padding: calc(18px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
  }

  .auth-card {
    padding: 28px 20px 18px;
    border-radius: 18px;
  }

  .auth-logo { font-size: 30px; }
  .link { padding: 16px 8px 6px; }

  
  .net-screen {
    padding: 20px calc(16px + env(safe-area-inset-left)) 20px calc(16px + env(safe-area-inset-right));
  }

  .net-card {
    width: 100%;
    max-width: 360px;
    padding: 26px 20px;
  }

  .net-sub { max-width: none; }

  
  .net-banner {
    top: calc(8px + env(safe-area-inset-top));
    right: 10px;
    left: 10px;
    justify-content: center;
    text-align: center;
    transform: none;
    animation: none;
  }

  .toast {
    bottom: calc(16px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
  }

  
  .modal { padding: 0; }

  .modal-card {
    max-width: none;
    max-height: none;
    height: var(--vvh, 100dvh);
    border: none;
    border-radius: 0;
  }

  .modal-head { padding: calc(10px + env(safe-area-inset-top)) 8px 10px 16px; }

  
  .modal-body {
    flex-direction: column;
    overflow-y: auto;
  }

  .col { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }

  .col-proj {
    width: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .list {
    flex: none;
    min-height: 0;
    overflow: visible;
  }

  .proj-row, .doc-row { min-height: 48px; }
  .docs-head { flex-wrap: wrap; }
  .docs-title { flex: 1 1 100%; }

  
  .docview { padding: 0; }

  .docview-card {
    height: var(--vvh, 100dvh);
    border: none;
    border-radius: 0;
  }

  .docview-head {
    flex-wrap: wrap;
    padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
  }

  .docview-title { max-width: none; flex: 1; }

  .text-find {
    order: 5;
    width: 100%;
    margin-left: 0;
  }

  
  .find-field,
  .find-field:focus {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .docview-text {
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    font-size: 16px;
  }

  .docview-side {
    width: auto;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  }

  
  .ask-sel { padding: 11px 15px; font-size: 14px; }
}


@media (min-width: 769px) and (max-width: 1100px) {
  :root { --sidebar-w: 216px; }

  .sidebar { padding: 12px; gap: 8px; }
  .messages { padding: 18px 14px; }
  .composer { width: calc(100% - 28px); }
  .chip { max-width: 200px; }
}


@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .nav-scrim {
    transition: none !important;
  }
}



.chat-group {
  padding: 12px 12px 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .03em;
  text-transform: uppercase;
}

.chat-pin { margin-right: 5px; font-size: 11px; }

.chat-more {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--text-dim);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
}

.chat-row:hover .chat-more,
.chat-row.active .chat-more { opacity: 1; }
.chat-more:hover { color: var(--text); background: var(--surface); }

.chat-rename {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 7px;
}

.chat-menu {
  position: fixed;
  z-index: 60;
  min-width: 176px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}

.chat-menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 13.4px;
  color: var(--text);
  text-align: left;
  background: none;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.chat-menu-item:hover { background: var(--bg); }
.chat-menu-item.danger { color: var(--danger); }


.stop-gen {
  position: absolute;
  bottom: 92px;
  left: 50%;
  z-index: 20;
  display: inline-flex;
  gap: 7px;
  align-items: center;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transform: translateX(-50%);
}

.stop-gen:hover { border-color: var(--accent); }

.stop-square {
  width: 9px;
  height: 9px;
  background: var(--danger);
  border-radius: 2px;
}





.chat { position: relative; }

.art-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 104px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100% - 24px));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}

.art-panel-head {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  align-items: center;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--border);
}

.art-panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
}


.art-close {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-left: auto;
  padding: 0;
  color: var(--text-dim);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.art-close:hover { color: var(--text); background: var(--bg); }
.art-close:active { transform: scale(.94); }

.art-list {
  flex: 1;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.art-empty {
  padding: 20px 14px;
  font-size: 13.2px;
  line-height: 1.6;
  color: var(--text-dim);
  text-align: left;
}



.art-card {
  margin-bottom: 10px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.art-card:last-child { margin-bottom: 0; }


.art-card.draft {
  border-color: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 12%, transparent);
}

.art-head { display: flex; gap: 9px; align-items: flex-start; }

.art-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  background: var(--ok);
  border-radius: 50%;
}

.art-dot.wait { background: var(--warn); }

.art-title {
  flex: 1;
  min-width: 0;
  padding: 0;
  font: inherit;
  font-size: 13.8px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  text-align: left;
  overflow-wrap: anywhere;
  background: none;
  border: 0;
  cursor: pointer;
}

.art-title:hover { color: var(--accent); }

.art-kind,
.art-filed {
  margin: 4px 0 0 17px;
  font-size: 12px;
  color: var(--text-dim);
}



.art-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 12px;
  font: inherit;
  font-size: 12.8px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .08s;
}

.art-btn:hover { background: var(--bg); border-color: var(--text-dim); }
.art-btn:active { transform: scale(.97); }

.art-btn.primary {
  color: #fff;
  background: var(--accent);
  border-color: transparent;
}

.art-btn.primary:hover { filter: brightness(1.07); background: var(--accent); }

.art-actions,
.art-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.art-actions { margin: 11px 0 0 17px; }
.art-tools { margin-bottom: 10px; }



.art-body { margin-top: 12px; }

.art-load {
  padding: 8px 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.art-sec {
  margin-bottom: 6px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.art-sec > summary {
  padding: 8px 10px;
  font-size: 12.8px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
}

.art-sec > summary:hover { background: var(--bg); }
.art-sec > summary::-webkit-details-marker { display: none; }
.art-sec > summary::before { content: "▸"; margin-right: 6px; color: var(--text-dim); }
.art-sec[open] > summary::before { content: "▾"; }

.art-sec-body {
  padding: 2px 10px 10px;
  font-size: 12.7px;
  line-height: 1.62;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-top: 1px solid var(--border);
}



@media (max-width: 720px) {
  .art-panel {
    top: 8px;
    right: 8px;
    left: 8px;
    bottom: 96px;
    width: auto;
  }
}




.art-toggle {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--text-dim);
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s, color .12s, transform .08s;
}

.art-toggle:hover {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.art-toggle:active { transform: scale(.95); }


.art-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  color: #fff;
  text-align: center;
  background: var(--warn);
  border: 2px solid var(--bg);
  border-radius: 999px;
}

.sources { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 4px; }
.sources-label { font-size: 12px; opacity: .6; }
.source-link { font-size: 13px; color: #2563eb; text-decoration: none; border: 1px solid rgba(37,99,235,.3); border-radius: 12px; padding: 3px 10px; cursor: pointer; background: rgba(37,99,235,.06); }
.source-link:hover { background: rgba(37,99,235,.14); text-decoration: underline; }
.lawdoc-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 9999; align-items: center; justify-content: center; }
.lawdoc-panel { background: #fff; color: #1a1a1a; width: min(820px, 92vw); max-height: 88vh; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 12px 48px rgba(0,0,0,.35); }
.lawdoc-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid #eee; }
.lawdoc-title { font-weight: 600; font-size: 15px; padding-right: 12px; }
.lawdoc-close { border: none; background: none; font-size: 18px; cursor: pointer; color: #666; line-height: 1; }
.lawdoc-body { padding: 24px 30px; overflow-y: auto; line-height: 1.6; }
.lawdoc-body .d-doc { max-width: 720px; margin: 0 auto; }
.lawdoc-body .d-head { font-size: 13px; color: #666; margin: 2px 0; }
.lawdoc-body .d-head-gap { margin-top: 10px; }
.lawdoc-body .d-title { font-size: 18px; font-weight: 700; margin: 16px 0 14px; text-align: center; }
.lawdoc-body .d-subtitle { font-weight: 600; margin: 14px 0 8px; }
.lawdoc-body .d-par { margin: 10px 0; }
.lawdoc-body .d-item { margin: 6px 0 6px 18px; }
.lawdoc-body .d-sign { margin: 12px 0; color: #333; }

.pending { display: flex; align-items: center; gap: 10px; padding: 6px 0 2px; color: #6b7280; font-size: 13px; }
.pending-dots { display: inline-flex; gap: 4px; }
.pending-dots i { width: 6px; height: 6px; border-radius: 50%; background: #9ca3af; display: block; animation: eazyblink 1.2s infinite ease-in-out; }
.pending-dots i:nth-child(2) { animation-delay: .18s; }
.pending-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes eazyblink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.msg-actions { display: flex; gap: 8px; margin: 6px 0 2px; opacity: 0; transition: opacity .15s; }
.bubble.assistant:hover .msg-actions { opacity: 1; }
.msg-copy { border: 1px solid rgba(0,0,0,.12); background: transparent; color: #6b7280; font-size: 12px; padding: 3px 10px; border-radius: 8px; cursor: pointer; }
.msg-copy:hover { background: rgba(0,0,0,.05); color: #111827; }

.sources { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; max-width: 760px; margin: 8px auto 18px; padding: 0 18px; }
.sources-label { font-size: 12px; color: #6b7280; }
.source-link { font-size: 13px; color: #2563eb; text-decoration: none; border: 1px solid rgba(37,99,235,.28); border-radius: 12px; padding: 3px 10px; cursor: pointer; background: rgba(37,99,235,.06); }
.source-link:hover { background: rgba(37,99,235,.14); }

.lawdoc-panel { width: min(880px, 94vw); max-height: 90vh; }
.lawdoc-head { position: sticky; top: 0; background: #fff; z-index: 2; }
.lawdoc-body { padding: 28px 34px; }
.lawdoc-body .d-doc { max-width: 720px; margin: 0 auto; }
.lawdoc-body .d-head { font-size: 13px; color: #6b7280; margin: 2px 0; text-align: left; }
.lawdoc-body .d-head-gap { margin-top: 10px; }
.lawdoc-body .d-title { font-size: 19px; font-weight: 700; margin: 18px 0 16px; text-align: center; line-height: 1.35; }
.lawdoc-body .d-subtitle { font-weight: 600; margin: 16px 0 8px; }
.lawdoc-body .d-par { margin: 11px 0; text-align: left; }
.lawdoc-body .d-item { margin: 7px 0 7px 20px; }
.lawdoc-body .d-sign { margin: 14px 0; color: #374151; }

@media (max-width: 640px) {
  .lawdoc-body { padding: 18px 16px; }
  .sources { padding: 0 12px; }
  .msg-actions { opacity: 1; }
}

.modepick {
  position: relative;
  display: flex;
  align-items: center;
}

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font: 500 13px/1 var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}

.mode-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.mode-btn.on {
  color: var(--accent);
  border-color: var(--accent);
}

.mode-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 268px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
}

.mode-opt {
  display: block;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: 400 13px/1.35 var(--font);
  color: var(--text);
}

.mode-opt:hover {
  background: var(--accent-soft);
}

.mode-opt.sel {
  background: var(--accent-soft);
}

.mode-opt.sel .mode-opt-name::after {
  content: "✓";
  margin-left: 7px;
  color: var(--accent);
}

.mode-opt-name {
  display: block;
  font-weight: 600;
  color: var(--text);
}

.mode-opt-desc {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-dim);
}

@media (max-width: 620px) {
  .mode-btn span { display: none; }
  .mode-btn { padding: 0 9px; }
  .mode-menu { right: -40px; min-width: 240px; }
}

.pending.thinker {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}

.thinker-orb {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  position: relative;
}

.thinker-orb canvas {
  width: 46px;
  height: 46px;
  display: block;
}

.thinker-orb.fallback::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: eazySpin .9s linear infinite;
}

@keyframes eazySpin { to { transform: rotate(360deg); } }

.thinker-body {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 340px;
}

.thinker-body .pending-text {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 7px;
}

.thinker-bar {
  height: 3px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.thinker-bar i {
  display: block;
  height: 100%;
  width: 2%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), #7aa5ff);
  transition: width .35s cubic-bezier(.4,0,.2,1);
}

.doc-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 7px 9px;
  margin-bottom: 6px;
  border-radius: 9px;
  font-size: 12.5px;
  line-height: 1.4;
  background: var(--bg);
  border: 1px solid var(--border);
}

.doc-note-tag {
  flex: 0 0 auto;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.doc-note-bad { border-color: var(--danger); }
.doc-note-bad .doc-note-tag { background: var(--danger); color: #fff; }
.doc-note-fix .doc-note-tag { background: var(--ok); color: #fff; }
.doc-note-tip .doc-note-tag { background: var(--border); color: var(--text-dim); }


.img-chips {
  flex: 1 0 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 2px 8px;
}
.img-chips[hidden] { display: none; }
.img-chip {
  position: relative;
  width: 62px;
  height: 62px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--glass);
}
.img-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-chip-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .62);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  cursor: pointer;
}
.img-chip-x:hover { background: rgba(0, 0, 0, .85); }

.bubble-imgs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.bubble-imgs img {
  max-width: 260px;
  max-height: 260px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  display: block;
}
.img-zoom {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: rgba(0, 0, 0, .82);
  cursor: zoom-out;
}
.img-zoom[hidden] { display: none; }
.img-zoom img { max-width: 100%; max-height: 100%; border-radius: 12px; }


.retry-box { max-width: 760px; margin: 6px auto 18px; }
.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--glass);
  color: var(--text);
  font: 13px/1 inherit;
  font-weight: 600;
  cursor: pointer;
}
.retry-btn:hover { border-color: var(--accent); color: var(--accent); }

.stop-gen {
  width: 40px;
  height: 40px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
}
.stop-gen .stop-square { margin: 0; }


/* ─── Фон и оформление ─────────────────────────────────────── */

:root {
  color-scheme: light;
  --accent-2: #7aa8ff;
  --warn: #c98a1b;
  --ring: rgba(47, 111, 237, .30);
  --veil: rgba(20, 24, 34, .07);
  --grain: .030;
  --scroll-thumb: rgba(0, 0, 0, .20);
  --scroll-thumb-h: rgba(0, 0, 0, .34);
  --text-dim: #6b6b62;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --accent-2: #8ab4ff;
  --warn: #e0a83c;
  --ring: rgba(59, 130, 246, .42);
  --veil: rgba(0, 0, 0, .40);
  --grain: .042;
  --scroll-thumb: rgba(255, 255, 255, .16);
  --scroll-thumb-h: rgba(255, 255, 255, .30);
}

html[data-incognito="true"] {
  color-scheme: dark;
  --accent-2: #b6b6be;
  --warn: #cfa75a;
  --ring: rgba(160, 160, 170, .38);
  --veil: rgba(0, 0, 0, .34);
  --grain: .038;
  --scroll-thumb: rgba(255, 255, 255, .15);
  --scroll-thumb-h: rgba(255, 255, 255, .28);
}

body {
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* canvas — заменяемый элемент: без явных размеров он берёт размер своего буфера, а не вьюпорта */
#bg {
  z-index: -2;
  display: block;
  width: 100%;
  height: 100%;
  opacity: .6;
}

/* Вуаль и зерно поверх холста, но под содержимым. :has ограничивает их страницей чата. */
body:has(#bg)::before,
body:has(#bg)::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

/* Зерно снимает полосатость мягких градиентов и даёт бумажную фактуру. */
body:has(#bg)::before {
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

body:has(#bg)::after {
  background: radial-gradient(135% 100% at 50% -12%, transparent 44%, var(--veil) 100%);
}

.logo {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
}


/* ─── Типографика ──────────────────────────────────────────── */

.md h2, .md h3, .md h4, .md h5, .md h6 {
  margin-top: 22px;
  text-wrap: balance;
}

.md p, .md li {
  text-wrap: pretty;
}

.md li { margin: 5px 0; }

.md ul, .md ol { margin-bottom: 14px; }

.md a {
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

.md a:hover { text-decoration-thickness: 2px; }

.md code {
  font-variant-ligatures: none;
  overflow-wrap: anywhere;
}

.code-wrap pre { tab-size: 2; }

.md blockquote { border-radius: 0 10px 10px 0; }

.bubble.user {
  border: 1px solid var(--border);
  border-color: color-mix(in srgb, var(--accent) 16%, transparent);
}

.row-sub,
.doc-sub,
.badge,
.up-step,
.art-kind { font-variant-numeric: tabular-nums; }

.credit {
  opacity: .72;
  user-select: none;
}

.chat-group,
.docs-title,
.side-h { text-wrap: balance; }


/* ─── Фокус и наведение ────────────────────────────────────── */

a:focus-visible,
button:focus-visible,
summary:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible { outline: none; }

.field:focus,
.doc-search:focus {
  box-shadow: 0 0 0 3px var(--ring);
}

.find-field:focus {
  box-shadow: 0 0 0 3px var(--ring);
}

.composer {
  transition: border-color .18s ease, box-shadow .18s ease;
}

.composer:focus-within {
  border-color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  box-shadow: var(--shadow), 0 0 0 3px var(--ring);
}

.btn-ghost:hover:not(:disabled) { border-color: var(--accent); }
.btn-ghost:active:not(:disabled) { transform: scale(.98); }

.new-chat:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.new-chat:active,
.proj-btn:active { transform: scale(.99); }

.new-chat,
.proj-btn { transition: background .18s, border-color .18s, transform .08s; }

.icon-btn:active,
.incognito-toggle:active,
.attach:active,
.send:active { transform: scale(.94); }

.icon-btn,
.incognito-toggle { transition: background .2s, color .2s, transform .08s; }

.link:hover { text-decoration: underline; text-underline-offset: 2px; }

.chat-row { transition: background .15s; }

.source-chip { transition: border-color .15s, color .15s; }
.source-chip:hover { border-color: var(--accent); color: var(--accent); }

.chat-del:focus-visible,
.row-del:focus-visible { opacity: 1; }

::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }


/* ─── Полосы прокрутки ─────────────────────────────────────── */

.messages,
.history,
.list,
.think-body,
.art-list,
.modal-body,
.mode-menu,
.docview-text,
.docview-side,
.outline {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}

.messages::-webkit-scrollbar,
.history::-webkit-scrollbar,
.list::-webkit-scrollbar,
.think-body::-webkit-scrollbar,
.art-list::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.docview-text::-webkit-scrollbar,
.docview-side::-webkit-scrollbar { width: 10px; height: 10px; }

.messages::-webkit-scrollbar-thumb,
.history::-webkit-scrollbar-thumb,
.list::-webkit-scrollbar-thumb,
.think-body::-webkit-scrollbar-thumb,
.art-list::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.docview-text::-webkit-scrollbar-thumb,
.docview-side::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  background-clip: padding-box;
  border: 3px solid transparent;
  border-radius: 999px;
}

.messages::-webkit-scrollbar-thumb:hover,
.history::-webkit-scrollbar-thumb:hover,
.list::-webkit-scrollbar-thumb:hover,
.docview-text::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-h);
  background-clip: padding-box;
}

.messages,
.history,
.art-list,
.think-body { overscroll-behavior: contain; }


/* ─── Контраст: цвета вместо жёстко зашитых ────────────────── */

.pending { color: var(--text-dim); }
.pending-dots i { background: var(--text-dim); }

.msg-copy {
  border: 1px solid var(--border);
  color: var(--text-dim);
  transition: background .15s, color .15s, border-color .15s;
}

.msg-copy:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.sources-label { color: var(--text-dim); }

.source-link {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
  transition: background .15s, border-color .15s;
}

.source-link:hover {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: var(--accent);
  text-decoration: none;
}

.badge.stamp { color: var(--warn); border-color: var(--warn); }


/* ─── Узкий экран ──────────────────────────────────────────── */

@media (max-width: 768px) {
  .modal-head h2 { font-size: 16px; }
  .hint { font-size: 12px; }
}

@media (hover: none) {
  .doc-card:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--border);
  }
  .msg-actions { opacity: 1; }
  .chat-row:hover { background: transparent; }
  .chat-row.active { background: var(--accent-soft); }
}


/* ─── Меньше движения ──────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .pending-dots i,
  .shimmer,
  .net-spin,
  .list .doc-card,
  .net-banner,
  .thinker-orb.fallback::after {
    animation: none !important;
  }

  .btn-primary,
  .btn-ghost,
  .new-chat,
  .proj-btn,
  .icon-btn,
  .incognito-toggle,
  .attach,
  .send,
  .doc-card,
  .composer,
  .find-field,
  .msg-copy,
  .source-link,
  .art-toggle {
    transition: none !important;
  }

  .btn-primary:active,
  .btn-ghost:active,
  .new-chat:active,
  .proj-btn:active,
  .icon-btn:active,
  .incognito-toggle:active,
  .attach:active,
  .send:active,
  .art-toggle:active { transform: none; }
}


.send { position: relative; transition: background .18s, transform .12s; }
.send .send-ico { transition: opacity .16s, transform .16s; }
.send-stop {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 13px;
  height: 13px;
  margin: -6.5px 0 0 -6.5px;
  border-radius: 3.5px;
  background: currentColor;
  opacity: 0;
  transform: scale(.6);
  transition: opacity .16s, transform .16s;
  pointer-events: none;
}
.send.stopping .send-ico { opacity: 0; transform: scale(.7); }
.send.stopping .send-stop { opacity: 1; transform: scale(1); }
.send.stopping { background: var(--danger, #e5484d); }
.send:active { transform: scale(.94); }
@media (prefers-reduced-motion: reduce) {
  .send, .send .send-ico, .send-stop { transition: none; }
}


.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 58vh;
  padding: 24px 20px 8px;
  text-align: center;
  animation: hero-in .5s ease both;
}
.hero[hidden] { display: none; }
@keyframes hero-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.hero-mark { line-height: 0; animation: hero-float 9s ease-in-out infinite; }
@keyframes hero-float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-7px) rotate(2deg); }
}
.hero-title {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.4px;
  color: var(--text);
}
.hero-sub {
  margin: 0;
  max-width: 460px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text-dim);
}
.hero-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  max-width: 640px;
}
.hero-chip {
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--glass);
  color: var(--text-dim);
  font: 13px/1.3 inherit;
  cursor: pointer;
  transition: border-color .16s, color .16s, transform .12s;
}
.hero-chip:hover { border-color: var(--accent); color: var(--text); }
.hero-chip:active { transform: translateY(1px); }
@media (prefers-reduced-motion: reduce) {
  .hero, .hero-mark { animation: none; }
}
@media (max-width: 560px) {
  .hero { min-height: 46vh; }
  .hero-title { font-size: 25px; }
  .hero-chip { font-size: 12.5px; padding: 8px 12px; }
}


.hero {
  position: absolute;
  inset: 0 0 104px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
  z-index: 1;
}
.hero > * { pointer-events: auto; }
.hero[hidden] { display: none; }
.hero-mark { display: block; }
.hero-title {
  margin: 4px 0 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--text);
}
.hero-sub { margin: 0; max-width: 440px; font-size: 14.5px; line-height: 1.55; color: var(--text-dim); }


.hero-title {
  font-family: "Snell Roundhand", "Apple Chancery", "Segoe Script", "Brush Script MT",
               "Lucida Handwriting", cursive;
  font-style: italic;
  font-size: 58px;
  font-weight: 500;
  letter-spacing: 1px;
  line-height: 1.1;
  margin: 10px 0 2px;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--text) 96%, transparent),
    color-mix(in srgb, var(--accent) 62%, var(--text)));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .04);
}
@supports not (background-clip: text) {
  .hero-title { color: var(--text); background: none; }
}
@media (max-width: 560px) {
  .hero-title { font-size: 44px; }
}


/* каллиграфическая подпись Eazy: заставка и боковая панель */
.hero-title, .logo, .auth-logo {
  font-family: "Snell Roundhand", "Apple Chancery", "Segoe Script", "Brush Script MT",
               "Lucida Handwriting", cursive;
  font-style: italic;
  font-weight: 500;
  letter-spacing: .5px;
  background-image: linear-gradient(
    100deg,
    color-mix(in srgb, var(--text) 92%, transparent) 0%,
    color-mix(in srgb, var(--text) 92%, transparent) 38%,
    color-mix(in srgb, var(--accent) 85%, #fff) 50%,
    color-mix(in srgb, var(--text) 92%, transparent) 62%,
    color-mix(in srgb, var(--text) 92%, transparent) 100%
  );
  background-size: 260% 100%;
  background-position: 120% 0;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: eazy-shine 7s ease-in-out infinite;
  overflow: visible;
}

@keyframes eazy-shine {
  0%, 62%  { background-position: 130% 0; }
  100%     { background-position: -30% 0; }
}

.hero-title {
  font-size: 62px;
  line-height: 1.42;
  margin: 6px 0 0;
  padding: 0 12px 10px;
}

.logo, .auth-logo {
  font-size: 30px;
  line-height: 1.5;
  padding: 2px 4px 6px;
  letter-spacing: 0;
}

@supports not ((background-clip: text) or (-webkit-background-clip: text)) {
  .hero-title, .logo, .auth-logo { color: var(--text); background: none; animation: none; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-title, .logo, .auth-logo { animation: none; background-position: 50% 0; }
}

@media (max-width: 560px) {
  .hero-title { font-size: 46px; }
}


.art-holes {
  margin: 0 0 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
}
.art-field {
  display: inline;
  padding: 1px 5px;
  margin: 0 1px;
  border-bottom: 1.5px dashed var(--accent);
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: .93em;
  cursor: text;
}
.art-field:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.art-field:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.art-field.filled {
  border-bottom-style: solid;
  border-bottom-color: var(--ok, #2e8b57);
  background: transparent;
  color: var(--text);
  font-weight: 600;
}
.art-field-in {
  min-width: 90px;
  padding: 1px 4px;
  border: 0;
  border-bottom: 1px solid var(--accent);
  background: transparent;
  color: var(--text);
  font: inherit;
}
.art-field-in:focus { outline: none; }

.cut-note {
  color: var(--muted);
  font-size: 13px;
  margin-right: 10px;
}

/* ---------- индикатор работы: стол с бумагами ---------- */
.pending.thinker { display: flex; align-items: center; gap: 14px; padding: 6px 0; }
.desk { position: relative; width: 78px; height: 66px; flex: 0 0 78px; }
.desk-card {
  position: absolute; left: 16px; top: 5px; width: 46px; height: 56px;
  border-radius: 5px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.desk-card.back.b1 { transform: translate(-7px, 4px) rotate(-7deg); opacity: .8; animation: deskBreathe 3.4s ease-in-out infinite; }
.desk-card.back.b2 { transform: translate(7px, 8px) rotate(6deg); opacity: .55; animation: deskBreathe 3.4s ease-in-out infinite reverse; }
.desk.idle .desk-card.back.b1 { animation-duration: 2.2s; }
.desk-card.top {
  display: flex; flex-direction: column; gap: 3px; padding: 6px 5px;
  transition: transform .45s cubic-bezier(.4,0,.2,1), opacity .45s;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
.desk-card.top.in { transform: translate(32px, -24px) rotate(10deg); opacity: 0; }
.desk-card.top.out { transform: translate(-38px, 14px) rotate(-12deg); opacity: 0; }
.desk.idle .desk-card.top { animation: deskTilt 2.6s ease-in-out infinite; }
.desk-act { font-size: 9px; font-weight: 700; color: var(--accent); line-height: 1.1; max-height: 21px; overflow: hidden; }
.desk-art { font-size: 8.5px; color: var(--text); line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.desk-line { display: block; height: 2px; border-radius: 2px; background: var(--border); width: 80%; }
.desk-line.s { width: 55%; }
@keyframes deskBreathe { 50% { top: 3px; } }
@keyframes deskTilt { 50% { transform: rotate(1.5deg) translateY(-1px); } }
.thinker-body { flex: 1 1 auto; min-width: 0; max-width: 380px; }
.thinker-body .pending-text { display: block; font-size: 13px; color: var(--text); margin-bottom: 2px; }
.thinker-sub { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thinker-ledger { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 7px; }
.thinker-ledger:empty { display: none; }
.ledger-chip {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--text);
  white-space: nowrap; max-width: 190px; overflow: hidden; text-overflow: ellipsis; transition: opacity .4s;
}
.ledger-chip.dim { opacity: .45; }
.thinker-meta { display: block; font-size: 11px; color: var(--text-dim); margin-top: 5px; }

/* ---------- уточняющие вопросы ---------- */
.ask-box { margin-top: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.ask-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--accent-soft); }
.ask-title { font-weight: 600; font-size: 14px; color: var(--text); }
.ask-sub { font-size: 12px; color: var(--text-dim); }
.ask-q { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.ask-q-text { font-size: 14px; line-height: 1.45; color: var(--text); }
.ask-q-text b { color: var(--accent); margin-right: 4px; }
.ask-q-why { font-size: 12.5px; color: var(--text-dim); margin-top: 4px; line-height: 1.4; }
.ask-opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.ask-opt {
  border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; font-family: inherit;
  transition: border-color .15s, background .15s;
}
.ask-opt b { font-size: 11px; color: var(--accent); }
.ask-opt:hover { border-color: var(--accent); }
.ask-opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.ask-opt.muted { color: var(--text-dim); }
.ask-custom {
  width: 100%; margin-top: 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text);
  padding: 8px 10px; font-size: 13px; font-family: inherit; resize: vertical; min-height: 36px;
}
.ask-forks { margin-top: 8px; font-size: 12.5px; color: var(--text-dim); }
.ask-forks summary { cursor: pointer; }
.ask-forks ul { margin: 6px 0 0 18px; padding: 0; }
.ask-forks li { margin: 3px 0; }
.ask-forks b { color: var(--text); font-weight: 600; }
.ask-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 14px; }
.ask-send { background: var(--accent); color: #fff; border: 0; border-radius: 9px; padding: 8px 16px; font-size: 13px; cursor: pointer; font-family: inherit; }
.ask-skip { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 7px 12px; font-size: 13px; cursor: pointer; font-family: inherit; }
.ask-hint { font-size: 12px; color: var(--text-dim); }
.ask-box.done { opacity: .72; }
.ask-box.done .ask-opt, .ask-box.done .ask-send, .ask-box.done .ask-skip, .ask-box.done .ask-custom { pointer-events: none; }
.ask-box.done .ask-actions { display: none; }
@media (prefers-reduced-motion: reduce) {
  .desk-card.back, .desk.idle .desk-card.top { animation: none; }
}

/* ---------- читалка: страница с текстом нормы, указатель чтения, перелистывание ---------- */
.pending.thinker { display: flex; align-items: flex-start; gap: 18px; padding: 8px 0; }
.reader { position: relative; width: 250px; height: 172px; flex: 0 0 250px; perspective: 900px; }
.rpage {
  position: absolute; left: 14px; top: 8px; width: 214px; height: 152px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0,0,0,.14); overflow: hidden;
}
.rpage.back.b1 { transform: translate(-8px, 6px) rotate(-3deg); opacity: .7; }
.rpage.back.b2 { transform: translate(8px, 12px) rotate(3deg); opacity: .45; }
.rpage.top {
  padding: 9px 12px 10px; transform-origin: left center; z-index: 2;
  transition: transform .55s cubic-bezier(.4,0,.2,1), opacity .45s;
}
.rpage.top.enter { transform: translateY(10px) scale(.97); opacity: 0; }
.rpage.top.flip { transform: rotateY(-100deg) translateX(-10px); opacity: 0; z-index: 3; }
.rp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.rp-act { font-size: 10px; font-weight: 700; color: var(--accent); letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rp-art { font-size: 10px; font-weight: 600; color: var(--text-dim); white-space: nowrap; }
.rp-title { font-size: 11px; font-weight: 600; color: var(--text); line-height: 1.25; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rp-text { font-size: 10.5px; line-height: 1.45; color: var(--text-dim); max-height: 92px; overflow: hidden; }
.rp-text .w { border-radius: 2px; transition: color .2s, background-color .25s; }
.rp-text .w.now { color: var(--text); background: rgba(47,111,237,.22); box-shadow: 0 0 0 1px rgba(47,111,237,.28); }
.rp-text .w.hl { color: var(--text); background: linear-gradient(transparent 38%, rgba(255,200,60,.6) 38%); }
html[data-theme="dark"] .rp-text .w.hl { background: linear-gradient(transparent 38%, rgba(255,190,50,.42) 38%); }
.rp-text .w.bar { display: inline-block; height: 7px; background: var(--border); border-radius: 3px; vertical-align: middle; margin: 3px 0; }
.rp-beam {
  position: absolute; left: 0; right: 0; top: 0; height: 30px; pointer-events: none; transform: translateY(-50%);
  background: linear-gradient(180deg, rgba(47,111,237,0), rgba(47,111,237,.17), rgba(47,111,237,0));
}
.thinker-steps { display: flex; gap: 5px; margin: 6px 0 8px; flex-wrap: wrap; }
.tstep { font-size: 10.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); transition: color .3s, background-color .3s, border-color .3s; }
.tstep.done { color: var(--ok); border-color: transparent; background: rgba(47,158,95,.13); }
.tstep.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); animation: tstepPulse 1.4s ease-in-out infinite; }
@keyframes tstepPulse { 50% { box-shadow: 0 0 0 4px rgba(47,111,237,.13); } }
.thinker-body { flex: 1 1 auto; min-width: 0; max-width: 440px; }
.thinker-body .pending-text { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.thinker-sub { font-size: 12.5px; margin-bottom: 4px; }
@media (max-width: 640px) {
  .pending.thinker { flex-direction: column; gap: 10px; }
  .reader { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .rpage.top { transition: none; }
  .tstep.on { animation: none; }
}

/* меню уточнений по ходу разбора */
.ask-box.live { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,111,237,.12), var(--shadow); margin: 6px 0 12px; }
.ask-box.live .ask-head { background: var(--accent-soft); }
.ask-box.live.done { border-color: var(--border); box-shadow: var(--shadow); }

/* ---------- действия над своим сообщением ---------- */
.bubble.user { position: relative; }
.msg-tools { position: absolute; right: 8px; bottom: -30px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; z-index: 5; }
.msg-tools::before { content: ""; position: absolute; left: -12px; right: -12px; top: -12px; height: 14px; }
.bubble.user:hover .msg-tools, .bubble.user:focus-within .msg-tools, .msg-tools:hover { opacity: 1; }
.msg-tool {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; box-shadow: var(--shadow);
  transition: color .15s, border-color .15s;
}
.msg-tool svg { width: 14px; height: 14px; }
.msg-tool:hover { color: var(--text); border-color: var(--accent); }
.msg-tool.ok { color: var(--ok); border-color: var(--ok); }
.msg-edit { display: flex; flex-direction: column; gap: 8px; white-space: normal; }
.msg-edit textarea {
  width: 100%; min-height: 84px; border: 1px solid var(--accent); border-radius: 10px; background: var(--surface); color: var(--text);
  padding: 10px 12px; font: inherit; font-size: 15px; line-height: 1.5; resize: vertical; box-sizing: border-box;
}
.msg-edit-row { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.msg-edit-hint { font-size: 12px; color: var(--text-dim); margin-right: auto; }
.move-menu {
  position: absolute; right: 0; bottom: 34px; min-width: 240px; max-width: 320px; max-height: 280px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 30;
}
.move-menu .mm-title { font-size: 11px; color: var(--text-dim); padding: 6px 8px; white-space: nowrap; }
.move-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; color: var(--text); padding: 7px 8px;
  border-radius: 8px; font-size: 13px; font-family: inherit; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.move-menu button:hover { background: var(--accent-soft); }
.move-menu .mm-new { color: var(--accent); font-weight: 600; }
@media (hover: none) { .msg-tools { opacity: 1; } }


/* Простой ответ без базы: читалка и этапы не показываются. */
.pending.thinker.plain .reader,
.pending.thinker.plain .thinker-ledger,
.pending.thinker.plain .thinker-steps,
.pending.thinker.plain .thinker-bar { display: none; }


/* Спокойный старт индикатора: пока не пошла работа с базой, читалку и этапы
   не показываем — на простом вопросе («привет») их не будет вовсе. */
.pending.thinker.calm .reader,
.pending.thinker.calm .thinker-steps,
.pending.thinker.calm .thinker-ledger,
.pending.thinker.calm .thinker-bar { display: none; }

/* --- Документы: подсказка черновика + красивый выбор проекта (добавлено) --- */
.art-draftnote { font-size: 12.5px; opacity: .72; margin: 6px 0 8px; }
.art-pick { display: flex; flex-direction: column; gap: 8px; padding: 2px 0; }
.art-pick-l { font-size: 13px; opacity: .82; }
.art-pick-sel { background: var(--bg, #0e1420); color: inherit; border: 1px solid var(--border, #2a3446); border-radius: 8px; padding: 8px 10px; font: inherit; width: 100%; box-sizing: border-box; }
.art-pick-btns { display: flex; gap: 8px; }


/* Низкий вьюпорт (открыта клавиатура на телефоне): подсказки не должны
   налезать на поле ввода. */
@media (max-height: 640px) {
  #chatHero .hero-chips { display: none; }
  #chatHero { justify-content: flex-start; padding-top: 34px; }
}


/* ── Мастерская документа: подсказка, аннотации, версии ── */
.art-hint { margin: 2px 0 8px; font-size: 12px; color: var(--text-dim); }
.art-btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.art-annot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 4px 0 10px; padding: 8px 10px;
  background: var(--accent-soft); border: 1px solid var(--border); border-radius: 10px;
}
.art-annot-l { font-size: 12px; color: var(--text-dim); margin-right: 2px; }
.art-versions {
  margin: 4px 0 10px; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
.art-vers-h { font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 4px; }
.art-vrow {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; border-top: 1px solid var(--border); font-size: 12.5px;
}
.art-vrow:first-of-type { border-top: 0; }
.art-vnote { color: var(--text); }
.art-vtime { margin-left: auto; color: var(--text-dim); font-size: 11.5px; white-space: nowrap; }
.art-vcur { color: var(--accent); font-size: 11.5px; font-weight: 600; }
mark.cite-hit { background: color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 3px; padding: 0 1px; }


/* ── Инструкции проекта (изоляция дела) ── */
.proj-instr { margin: 2px 0 10px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; }
.proj-instr-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.proj-instr-title { font-size: 12.5px; font-weight: 600; color: var(--text); }
.proj-instr-iso { margin-left: auto; font-size: 11.5px; color: var(--accent); white-space: nowrap; }
.proj-instr-in { width: 100%; box-sizing: border-box; resize: vertical; min-height: 40px; padding: 8px 10px; font-family: inherit; font-size: 13px; line-height: 1.5; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.proj-instr-in:focus { outline: none; border-color: var(--accent); }
.proj-instr-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.proj-instr-note { font-size: 12px; color: var(--text-dim); }
