/* ═══════════════ Клуб Volvo 940 — mobile-first, без наложений ═══════════════ */
:root {
  --bg: #101418;
  --panel: #171d23;
  --panel2: #1e262e;
  --border: #2a3540;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #f5a623;
  --accent2: #ff7a00;
  --green: #3fb950;
  --danger: #ff8a8a;
  --topbar-h: 56px;
  --nav-h: 60px;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ─── Кнопки ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 14.5px;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #141414; font-weight: 600; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-danger { color: var(--danger); border-color: #5a2f33; }
.btn-danger:hover { border-color: #ff6b6b; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 17px; cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

/* ─── Шапка ─── */
.topbar {
  flex: 0 0 var(--topbar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: linear-gradient(90deg, #1a2129, #141a20);
  border-bottom: 1px solid var(--border); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 26px; }
.brand h1 { font-size: 17px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-right { display: flex; align-items: center; gap: 8px; }

/* ─── Вход ─── */
.auth-gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #1b2430, #0d1117 70%);
  padding: 20px;
}
.auth-gate.hidden, .screen.hidden, .hidden, .doc-head.hidden, .chat-config.hidden { display: none !important; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 32px 26px;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.auth-logo { font-size: 44px; margin-bottom: 6px; }
.auth-card h2 { font-size: 19px; margin-bottom: 6px; }
.auth-card p { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.auth-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 16px; letter-spacing: 2px; text-align: center; outline: none;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card .btn-primary { width: 100%; padding: 13px; font-size: 15px; }
.auth-error { color: #ff9d9d; font-size: 13px; margin-top: 10px; background: rgba(255,90,90,.08); border: 1px solid rgba(255,90,90,.25); padding: 8px; border-radius: 8px; }
.auth-hint { margin-top: 14px; color: var(--muted); font-size: 12px; }

/* ─── Каркас ─── */
.layout { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.screen { flex: 1 1 auto; min-height: 0; }
.screen-catalog { display: flex; flex-direction: column; }
.screen-chat { display: flex; flex-direction: column; }

/* ─── Каталог (мобильный: дерево или документ, по одному) ─── */
.sidebar {
  flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel);
}
.search-box { flex: 0 0 auto; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 15px; outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.tree { flex: 1 1 auto; overflow-y: auto; padding: 6px 0 16px; -webkit-overflow-scrolling: touch; }
.node .row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; font-size: 14.5px; cursor: pointer; user-select: none;
  border-left: 3px solid transparent;
}
.node .row:active { background: var(--panel2); }
.node .row.active { background: var(--panel2); border-left-color: var(--accent); color: var(--accent); }
.node .chev { font-size: 10px; transition: transform .15s; color: var(--muted); }
.node .row.open .chev { transform: rotate(90deg); }
.node .row .icon { font-size: 14px; }
.children { margin-left: 14px; }
.children.hidden { display: none; }

.content { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 48px 24px; min-height: 100%;
  color: var(--muted);
}
.empty-icon { font-size: 52px; margin-bottom: 14px; }
.empty-state h2 { color: var(--text); font-size: 19px; margin-bottom: 8px; }
.empty-state p { font-size: 14px; max-width: 420px; }

.doc { padding: 18px 16px 40px; max-width: 860px; margin: 0 auto; }
.doc h2 { font-size: 20px; margin-bottom: 14px; line-height: 1.3; }
.doc-body { font-size: 15px; }
.doc-body h1 { font-size: 21px; margin: 18px 0 10px; }
.doc-body h2 { font-size: 18px; margin: 16px 0 8px; }
.doc-body h3 { font-size: 16px; margin: 14px 0 6px; }
.doc-body p { margin: 8px 0; }
.doc-body ul, .doc-body ol { margin: 8px 0 8px 22px; }
.doc-body li { margin: 4px 0; }
.doc-body table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13.5px; }
.doc-body th, .doc-body td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.doc-body th { background: var(--panel2); }
.doc-body code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.doc-body pre { background: var(--panel2); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 10px 0; }
.doc-body pre code { background: none; padding: 0; }
.doc-body img { max-width: 100%; border-radius: 8px; }
.doc-body a { color: var(--accent); }
.doc-path { color: var(--muted); font-size: 12px; margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--border); }

/* шапка документа на мобильном (кнопка назад) */
.doc-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.crumb { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Чат (весь экран) ─── */
.chat-wrap { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.chat-title { font-weight: 600; font-size: 15px; }
.cfg-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 16px; cursor: pointer;
}
.cfg-btn:active { transform: scale(.94); }
.cfg-btn.active { border-color: var(--accent); color: var(--accent); }

.chat-config { flex: 0 0 auto; background: var(--panel); border-bottom: 1px solid var(--border); padding: 10px 12px; }
.cfg-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cfg-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--muted); }
.cfg-fields select {
  width: 100%; padding: 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 13.5px; outline: none;
}
.cfg-fields select:focus { border-color: var(--accent); }
.cfg-summary-row { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.cfg-summary-row span { color: var(--accent); font-weight: 600; }

.chat-body {
  flex: 1 1 auto; overflow-y: auto; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.bot { justify-content: flex-start; }
.bubble {
  max-width: 88%; padding: 10px 13px; border-radius: 14px;
  font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: linear-gradient(135deg, #2b3a4a, #22303d); border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: var(--panel2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble .user-cfg { font-size: 11px; color: #b7d9ae; opacity: .9; margin-bottom: 3px; border-bottom: 1px dashed rgba(255,255,255,.15); padding-bottom: 3px; }
.srcs { margin-top: 8px; }
.srcs-title { font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.src-chip {
  display: inline-block; margin: 2px 4px 2px 0; padding: 4px 9px;
  border-radius: 12px; border: 1px solid rgba(245,166,35,.4); background: rgba(245,166,35,.1);
  color: var(--accent); font-size: 11.5px; cursor: pointer; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
.typing .bubble::after { content: '…'; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.chat-input {
  flex: 0 0 auto; display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
}
.chat-input input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 22px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 15px; outline: none;
}
.chat-input input:focus { border-color: var(--accent); }
.chat-input button {
  flex: 0 0 46px; height: 46px; border-radius: 50%; border: none;
  background: var(--accent); color: #141414; font-size: 17px; cursor: pointer;
}
.chat-input button:disabled { opacity: .5; cursor: default; }
.chat-input button:active:not(:disabled) { transform: scale(.93); }

/* ─── Нижняя навигация (мобильные) ─── */
.bottom-nav {
  flex: 0 0 var(--nav-h); display: flex;
  border-top: 1px solid var(--border); background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer;
}
.nav-btn span { font-size: 11px; font-weight: 600; }
.nav-btn.active { color: var(--accent); }

/* ─── Мобильный режим: показываем по одному экрану ─── */
.screen-catalog:not(.hidden) { display: flex; }
.screen-chat:not(.hidden) { display: flex; }
/* документ открыт → скрыть дерево */
.layout.doc-open .sidebar { display: none; }
.layout.doc-open .doc-head { display: flex; }
.doc-head:not(.hidden) { display: flex; }

/* ═══════════════ Десктоп: всё рядом, без оверлеев ═══════════════ */
@media (min-width: 1024px) {
  :root { --topbar-h: 60px; }
  body { height: 100vh; }
  .bottom-nav { display: none; }
  .layout { flex-direction: row; }
  .screen-catalog { flex: 1 1 auto; display: grid !important; grid-template-columns: 300px 1fr; }
  .screen-chat { flex: 0 0 420px; border-left: 1px solid var(--border); }
  .screen-chat.hidden { display: none !important; }
  .layout.doc-open .sidebar { display: flex; }
  .doc-head { display: none !important; }
  .sidebar { border-right: 1px solid var(--border); }
  .content { flex: 1 1 auto; }
  .chat-body { padding: 16px; }
  .bubble { max-width: 78%; }
}

/* ═══════════════ Админка ═══════════════ */
.admin-body { overflow: auto; height: auto; min-height: 100dvh; }
.admin-panel { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.admin-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.tab {
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); color: var(--muted); cursor: pointer; font-size: 13.5px;
}
.tab:hover { color: var(--text); border-color: var(--accent); }
.tab.active { background: var(--accent); color: #141414; border-color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 9px;
  background: #e5534b; color: #fff; font-size: 11px; font-weight: 700;
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 22px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.card-num { font-size: 26px; font-weight: 700; color: var(--accent); }
.card-label { color: var(--muted); font-size: 12px; margin-top: 2px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select, .note-input {
  padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 13.5px; outline: none;
}
.toolbar input:focus, .toolbar select:focus, .note-input:focus { border-color: var(--accent); }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 12px; overflow: hidden; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; vertical-align: top; }
.table th { background: var(--panel2); color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; }
.table tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.li-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.li-q { font-weight: 600; font-size: 14px; }
.li-answer { color: var(--muted); font-size: 13px; margin-top: 4px; white-space: pre-wrap; }
.li-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.li-note { color: #b7d9ae; font-size: 12.5px; margin-top: 4px; }
.li-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 11px; font-weight: 600; }
.tag-ok { background: rgba(63,185,80,.15); color: var(--green); border: 1px solid rgba(63,185,80,.4); }
.tag-fail { background: rgba(229,83,75,.15); color: #ff9d9d; border: 1px solid rgba(229,83,75,.4); }
.tag-warn { background: rgba(245,166,35,.15); color: var(--accent); border: 1px solid rgba(245,166,35,.4); }
.hint { color: var(--muted); font-size: 13px; }
.form-card { max-width: 640px; margin-bottom: 14px; }
.form-card h3 { margin-bottom: 12px; }
.form-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.form-card input, .form-card select {
  padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 14px; outline: none;
}
.form-card input:focus { border-color: var(--accent); }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.form-actions { display: flex; gap: 8px; }
.result-card { text-align: center; border-color: var(--accent); padding: 18px; }
.token-code {
  font-size: 24px; font-weight: 700; letter-spacing: 5px; color: var(--accent);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  padding: 12px; background: var(--panel2); border-radius: 10px; margin: 10px 0;
}
.result-card .btn { margin: 0 4px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; color: var(--muted); font-size: 13px; }

.layout.blurred { filter: blur(3px); pointer-events: none; }
