:root {
  --bg: #fff; --side: #f5f5f6; --card: #fff; --hover: #0000000a; --line: #e6e6e8; --text: #1f1f21;
  --muted: #8a8a90; --accent: #1e96eb; --accent-text: #fff; --danger: #eb4335; --warn: #b7791f;
  --shadow: 0 2px 12px #0000000f;
}
:root[data-theme="dark"] { --bg: #141414; --side: #1c1c1d; --card: #212123; --hover: #ffffff10; --line: #2f2f32; --text: #e6e6e8; --muted: #7e7e84; --warn: #f6c453; --shadow: 0 2px 14px #0006; color-scheme: dark; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100dvh; display: grid; grid-template-columns: 252px 1fr; background: var(--bg); color: var(--text); font: 15px/1.55 Inter, system-ui, "Noto Sans", sans-serif; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

#sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 10px 8px; gap: 6px; }
.workspace { display: flex; align-items: center; gap: 8px; padding: 2px 4px 2px 8px; }
.workspace strong { flex: 1; font-weight: 600; }
.logo { color: var(--accent); }
.search-trigger { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: var(--muted); }
.search-trigger span { flex: 1; text-align: left; }
kbd { font: 11px system-ui; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
#rail { display: flex; flex-direction: column; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; background: none; border: 0; border-radius: 6px; padding: 6px 10px; text-align: left; }
.nav-item:hover, .nav-item.active { background: var(--hover); }
.nav-item.active .icon { color: var(--accent); }
.side-panel { display: flex; flex-direction: column; gap: 2px; min-height: 0; flex: 1; overflow-y: auto; border-top: 1px solid var(--line); padding-top: 6px; }
.panel-head { display: flex; align-items: center; color: var(--muted); font-size: 12px; padding-left: 8px; }
.panel-head span { flex: 1; }
.panel-head .icon-button { width: 28px; height: 28px; }
.panel-head .icon { width: 17px; height: 17px; }
.list { list-style: none; margin: 0; padding: 0; }
.item { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 5px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.item:hover, .item.active { background: var(--hover); }
.item small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.tree-folder > summary { cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 14px; }
.tree-folder > summary:hover, .tree-folder > summary.selected { background: var(--hover); }
.tree-children { margin-left: 11px; border-left: 1px solid var(--line); padding-left: 4px; }
#index-pill { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; color: var(--muted); text-align: left; margin-top: auto; }
progress { width: 100%; height: 5px; appearance: none; border: 0; border-radius: 3px; overflow: hidden; background: var(--line); }
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.icon-button { display: inline-grid; place-content: center; width: 34px; height: 34px; flex: none; background: none; border: 0; border-radius: 8px; padding: 0; color: var(--muted); }
.icon-button:hover { background: var(--hover); color: var(--text); }
.icon-button.active, .toggle.active { color: var(--accent); background: #1e96eb1c; }
.icon-button.primary { background: var(--accent); color: var(--accent-text); border-radius: 50%; }
.icon-button.danger:hover { color: var(--danger); }
.input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.input:focus { outline: 2px solid #1e96eb55; border-color: var(--accent); }
.btn, .btn-primary { display: inline-flex; align-items: center; gap: 6px; border-radius: 8px; padding: 6px 12px; font-size: 14px; border: 1px solid var(--line); background: var(--card); text-decoration: none; color: inherit; }
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn .icon, .btn-primary .icon { width: 17px; height: 17px; }
.toolbar { display: flex; gap: 2px; }
.hint { color: var(--muted); font-size: 13px; }
.warn { color: var(--warn); }
.badge { font-size: 11px; color: var(--warn); border: 1px solid currentColor; border-radius: 10px; padding: 0 7px; }
.spacer { flex: 1; }

#main { position: relative; min-width: 0; min-height: 0; }
.view { display: none; height: 100%; flex-direction: column; min-height: 0; }
.view.active { display: flex; }
.view-header { display: flex; align-items: center; gap: 4px; padding: 7px 14px; border-bottom: 1px solid var(--line); min-height: 49px; }
.view-title { font-size: 15px; font-weight: 600; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 6px; }
.menu-button { display: none; }
.empty { margin: auto; color: var(--muted); padding: 20px; text-align: center; }
.page { overflow-y: auto; flex: 1; padding: 20px max(16px, calc(50% - 400px)) 60px; }

#format-bar { display: flex; gap: 2px; padding: 4px max(18px, calc(50% - 390px)); overflow-x: auto; }
#editor { flex: 1; width: 100%; background: none; border: 0; outline: none; resize: none; padding: 16px max(22px, calc(50% - 390px)) 60px; font-size: 16px; line-height: 1.75; }
#preview { flex: 1; overflow-y: auto; padding: 8px max(22px, calc(50% - 390px)) 60px; font-size: 16px; line-height: 1.75; }
#slash-menu { position: fixed; z-index: 15; margin: 0; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; }
#slash-menu button { display: flex; gap: 8px; align-items: center; width: 220px; background: none; border: 0; border-radius: 6px; padding: 6px 8px; text-align: left; }
#slash-menu button.active, #slash-menu button:hover { background: var(--hover); }
#graph { flex: 1; width: 100%; min-height: 0; touch-action: none; cursor: grab; }
.markdown { overflow-wrap: anywhere; }
.markdown img { max-width: 100%; border-radius: 8px; }
.markdown audio { width: 100%; }
.markdown pre { background: var(--side); border-radius: 8px; padding: 12px; overflow-x: auto; }
.markdown code { background: var(--side); border-radius: 4px; padding: 0 4px; font-size: .9em; }
.markdown pre code { padding: 0; }
.markdown a { color: var(--accent); }
.markdown blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; }
.markdown td, .markdown th { border: 1px solid var(--line); padding: 4px 10px; }
.frontmatter { color: var(--muted); font-size: 12px; }

dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 16px; }
dialog::backdrop { background: #0007; }
#search-dialog { width: min(640px, 94vw); margin-top: 10vh; }
#search-input { width: 100%; }
#search-results { max-height: 55vh; overflow-y: auto; margin-top: 8px; }
#login-form { display: flex; flex-direction: column; gap: 10px; }
/* Уведомление — по центру над чатом: внизу оно заслоняло кнопки ввода и микрофон. */
#toast { position: fixed; left: calc(50% + 126px); top: 58px; transform: translateX(-50%); width: max-content; max-width: min(420px, 92vw); text-align: center; background: var(--card); border: 1px solid var(--accent); border-radius: 22px; padding: 8px 18px; box-shadow: var(--shadow); z-index: 30; font-size: 14px; pointer-events: none; animation: toast-in .2s ease-out; }
@keyframes toast-in { from { opacity: 0; translate: 0 -8px; } }
#toast.error { border-color: var(--danger); }
#drawer-shade { display: none; }

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #main { grid-row: 1; }
  /* Нижняя панель значков; список чатов или файлов выезжает сбоку. */
  #sidebar { grid-row: 2; padding: 2px 4px env(safe-area-inset-bottom); border: 0; border-top: 1px solid var(--line); }
  .workspace, .search-trigger, #index-pill { display: none; }
  #rail { flex-direction: row; justify-content: space-around; }
  .nav-item { flex-direction: column; gap: 1px; padding: 5px 4px; font-size: 10px; color: var(--muted); }
  .nav-item.active { color: var(--text); background: none; }
  .side-panel { position: fixed; z-index: 12; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); background: var(--side); border: 0; padding: 12px 8px; transform: translateX(-102%); transition: transform .18s; }
  body.drawer .side-panel { transform: none; }
  body.drawer #drawer-shade { display: block; position: fixed; inset: 0; z-index: 11; background: #0007; }
  .menu-button { display: inline-grid; }
  #toast { left: 50%; }
  kbd { display: none; }
}
@media print { #view-vault { display: none !important; } }
