/* «База Знаний ВЗЛЁТ» — локальная версия. Тёмная тема, акцент из оригинального приложения. */

:root {
  --accent: #3b47c6;
  --accent-soft: rgba(59, 71, 198, 0.16);
  --bg: #0a0c11;
  --bg-elev: #12151d;
  --surface: #161a24;
  --surface-2: #1c2130;
  --border: #242a3a;
  --text: #e9ecf5;
  --muted: #98a1b8;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

a { color: #9fb0ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px 96px;
  min-height: 100vh;
}

/* ---------- Шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0 10px;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(10, 12, 17, 0.86));
  backdrop-filter: blur(8px);
}

.topbar .icon-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
}
.topbar .icon-btn:hover { background: var(--surface-2); }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.brand img { width: 34px; height: 34px; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.brand .t { min-width: 0; }
.brand .t b { display: block; font-size: 15px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .t span { font-size: 12px; color: var(--muted); }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 320px;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
}
.search input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 14px;
  min-width: 0;
}
.search input::placeholder { color: var(--muted); }

/* ---------- Заголовки ---------- */
.hero {
  margin: 8px 0 20px;
  padding: 22px;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 160% at 0% 0%, rgba(59, 71, 198, 0.35), transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
}
.hero h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -0.02em; }
.hero p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; max-width: 720px; }
.hero .sub { margin-top: 14px; color: var(--muted); font-size: 13px; }

.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 12.5px; margin: 4px 0 12px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: 0.5; }

/* ---------- Плитки разделов ---------- */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.tile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.tile:hover { transform: translateY(-2px); border-color: #33406b; background: var(--surface-2); text-decoration: none; }
.tile .emoji {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 19px;
}
.tile .txt { min-width: 0; }
.tile .txt b { display: block; font-size: 14.5px; line-height: 1.3; }
.tile .txt span { font-size: 12.5px; color: var(--muted); }

/* ---------- Карточки инструкций ---------- */
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.card:hover { transform: translateY(-2px); border-color: #33406b; text-decoration: none; }
.card .thumb { aspect-ratio: 16 / 9; background: var(--surface-2); overflow: hidden; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .body b { font-size: 14.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .body span { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .foot { display: flex; gap: 10px; font-size: 11.5px; color: var(--muted); margin-top: auto; }

.section-title { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 12px; }
.section-title h2 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.section-title span { font-size: 12.5px; color: var(--muted); }

/* ---------- Детальная страница ---------- */
.detail { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.block h2 { margin: 0 0 10px; font-size: 18px; letter-spacing: -0.01em; }
.block h3 { margin: 16px 0 6px; font-size: 15px; }
.lead { color: var(--muted); font-size: 14px; margin: 0 0 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.chip b { color: var(--text); font-weight: 600; }

.gallery { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.gallery figure { margin: 0; border-radius: 12px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); cursor: zoom-in; }
.gallery img { width: 100%; height: 130px; object-fit: cover; display: block; }

.docs { display: grid; gap: 8px; }
.doc {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
}
.doc:hover { border-color: #33406b; text-decoration: none; }
.doc .ext { font-size: 11px; font-weight: 700; padding: 3px 6px; border-radius: 6px; background: var(--accent-soft); color: #b9c2ff; }

details.raw { margin-top: 6px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 8px 0; }
table.props { width: 100%; border-collapse: collapse; font-size: 13px; }
table.props td { padding: 7px 8px; border-top: 1px solid var(--border); vertical-align: top; }
table.props td:first-child { color: var(--muted); width: 42%; }

/* ---------- Markdown ---------- */
.md { font-size: 15px; line-height: 1.62; color: #dfe4f2; overflow-wrap: anywhere; }
.md p { margin: 0 0 10px; }
.md h2, .md h3, .md h4 { margin: 18px 0 8px; color: var(--text); }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 4px 0; }
.md img { max-width: 100%; border-radius: 12px; margin: 10px 0; display: block; }
.md code { background: #0d1017; padding: 2px 6px; border-radius: 6px; font-size: 13px; }
.md table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13.5px; }
.md table td, .md table th { border: 1px solid var(--border); padding: 6px 8px; }

/* ---------- Пустое состояние ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 10px; }

/* ---------- Нижняя навигация ---------- */
.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  gap: 2px;
  justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(14, 17, 24, 0.94);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.bottomnav a {
  flex: 1;
  min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 10.5px;
  text-align: center;
}
.bottomnav a.active { color: #c7cdff; background: var(--accent-soft); }
.bottomnav a .i { font-size: 17px; line-height: 1; }
.bottomnav a .l { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---------- Лайтбокс ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.92);
  display: grid; place-items: center;
  padding: 20px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

/* ---------- Служебное ---------- */
.loading { display: grid; place-items: center; min-height: 60vh; color: var(--muted); gap: 12px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error { margin: 30vh auto; max-width: 460px; text-align: center; }
.error h2 { margin: 0 0 8px; font-size: 18px; }
.error p { color: var(--muted); font-size: 14px; }
.error button {
  margin-top: 14px; padding: 10px 18px; border-radius: 10px;
  background: var(--accent); color: #fff; border: 0; font-size: 14px; cursor: pointer;
}

.result { display: block; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); color: var(--text); margin-bottom: 8px; }
.result:hover { border-color: #33406b; text-decoration: none; }
.result b { display: block; font-size: 14px; margin-bottom: 3px; }
.result .path { font-size: 11.5px; color: var(--muted); }
.result .snip { font-size: 12.5px; color: var(--muted); margin-top: 5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result mark { background: var(--accent-soft); color: #cfd6ff; border-radius: 3px; padding: 0 2px; }

@media (max-width: 720px) {
  .app { padding: 0 12px 92px; }
  .hero { padding: 18px; }
  .hero h1 { font-size: 20px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
  .brand .t span { display: none; }
  .search { max-width: none; }
}

/* ---------- редактирование ---------- */
.btn-add {
  margin-left: auto;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  cursor: pointer;
}
.btn-add:hover { filter: brightness(1.1); }

.actions { display: flex; gap: 8px; margin-top: 14px; }
.btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: #33406b; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { border-color: #5a2430; color: #ff9aa8; background: #22141a; }
.btn-danger:hover { background: #2e1a22; }

.chip-user { border-color: var(--accent); color: #c7cdff; background: var(--accent-soft); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(4, 6, 12, 0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  width: min(680px, 100%);
  max-height: 92vh;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.modal-body { padding: 14px 16px; overflow-y: auto; display: grid; gap: 12px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.field { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); }
.field input[type="text"], .field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.field textarea { min-height: 140px; line-height: 1.5; }
.field input[type="file"] { color: var(--muted); font-size: 12px; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; width: 84px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-x {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,0.7); color: #fff;
  font-size: 13px; line-height: 1; cursor: pointer;
}

@media (max-width: 720px) {
  .modal { max-height: 96vh; }
  .section-title { flex-wrap: wrap; }
}