:root {
  --bg: #f3f5fb;
  --card: #ffffff;
  --text: #141a2e;
  --muted: #6b7390;
  --line: #e5e8f2;
  --soft: #f6f7fc;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-soft: #eef0ff;
  --danger: #e11d48;
  --danger-soft: #fff1f3;
  --ok: #10b981;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 26, 46, .06);
  --shadow: 0 1px 3px rgba(20, 26, 46, .05), 0 10px 30px -12px rgba(20, 26, 46, .14);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
}
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font: 15px/1.55 var(--font);
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.err { color: var(--danger); min-height: 20px; font-size: 14px; text-align: center; }
::selection { background: #c7d2fe; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text);
  font: 500 14px/1 var(--font);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { border-color: #cdd2e3; background: var(--soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 6px 16px -6px rgba(79, 70, 229, .6); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: transparent; box-shadow: none; background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--soft); color: var(--text); }
.btn.disabled { pointer-events: none; opacity: .45; }
.btn.full { width: 100%; }
.btn svg { width: 17px; height: 17px; flex: none; }

input, textarea { font: inherit; color: inherit; }
input:focus, textarea:focus { outline: none; }

.card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 32px; border: 1px solid var(--line); }

/* ---------- Логотип ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--grad); display: grid; place-items: center; color: #fff; box-shadow: 0 6px 14px -6px rgba(79, 70, 229, .7); }
.logo svg { width: 20px; height: 20px; }

/* ---------- Переключатель языка ---------- */
.lang { display: inline-flex; padding: 3px; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; gap: 2px; }
.lang button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer;
  font: 600 13px/1.2 var(--font); color: var(--muted); transition: .15s;
}
.lang button:hover { color: var(--text); }
.lang button.active { background: var(--card); color: var(--accent); box-shadow: var(--shadow-sm); }

/* ---------- Вход ---------- */
.center {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(900px 500px at 10% -10%, #e0e7ff 0%, transparent 60%),
    radial-gradient(800px 500px at 110% 110%, #ede9fe 0%, transparent 60%),
    var(--bg);
}
.login { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }
.login .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.login h1 { margin: 6px 0 0; font-size: 24px; letter-spacing: -.02em; }
.login .sub { margin: -6px 0 6px; color: var(--muted); font-size: 14px; }
.login input {
  height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.login input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.login .btn { height: 46px; font-size: 15px; }

/* ---------- Кабинет ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 24px;
  background: rgba(255, 255, 255, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.layout { display: grid; grid-template-columns: 300px 1fr; min-height: calc(100vh - 64px); }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 20px 16px; }
.side h3 { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 24px 8px 8px; }
#docList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
#docList > .muted { padding: 10px 8px; font-size: 14px; }
.doc {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 10px; cursor: pointer; transition: background .12s;
  position: relative;
}
.doc::before {
  content: ""; width: 34px; height: 34px; flex: none; border-radius: 9px; background: var(--soft) center/18px no-repeat;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7390' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M8 13h8M8 17h5'/%3E%3C/svg%3E");
}
.doc > div { min-width: 0; }
.doc:hover { background: var(--soft); }
.doc.active { background: var(--accent-soft); }
.doc.active::before {
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M8 13h8M8 17h5'/%3E%3C/svg%3E");
}
.doc.active .dt { color: var(--accent); }
.doc .dt { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc .small { font-size: 12px; }

.main { padding: 32px; min-width: 0; }
.empty {
  max-width: 420px; margin: 14vh auto 0; text-align: center; color: var(--muted); font-size: 16px;
  padding: 48px 32px; border: 2px dashed var(--line); border-radius: 20px; background: rgba(255, 255, 255, .5);
}
.empty::before {
  content: ""; display: block; width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px; background: var(--accent-soft) center/30px no-repeat;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='7' rx='1'/%3E%3Crect x='14' y='3' width='7' height='7' rx='1'/%3E%3Crect x='3' y='14' width='7' height='7' rx='1'/%3E%3Cpath d='M14 14h3v3h-3zM20 14v.01M14 20h.01M17 20h4v-3'/%3E%3C/svg%3E");
}

#editorWrap {
  max-width: 920px; margin: 0 auto; display: flex; flex-direction: column; gap: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden;
}
.title {
  font-size: 28px; font-weight: 700; letter-spacing: -.02em;
  padding: 26px 32px 10px; border: 0; background: transparent;
}
.title::placeholder { color: #b8bdd0; }

.tabs { display: flex; gap: 4px; padding: 0 28px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: none; padding: 12px 8px; margin: 0 6px -1px; cursor: pointer;
  font: 500 14px/1 var(--font); color: var(--muted);
  border-bottom: 2px solid transparent; transition: .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  padding: 8px 24px; background: var(--soft); border-bottom: 1px solid var(--line);
}
.toolbar.disabled { opacity: .35; pointer-events: none; }
.toolbar button {
  min-width: 34px; height: 34px; padding: 0 8px; border: 0; background: none; border-radius: 8px; cursor: pointer;
  font: 600 14px/1 var(--font); color: #3b4260; transition: background .12s, color .12s;
}
.toolbar button:hover { background: #fff; color: var(--accent); box-shadow: var(--shadow-sm); }
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.toolbar input[type=color] {
  width: 34px; height: 34px; border: 0; padding: 7px; background: none; cursor: pointer; border-radius: 8px;
}
.toolbar input[type=color]:hover { background: #fff; }
.toolbar input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.toolbar input[type=color]::-webkit-color-swatch { border: 0; border-radius: 5px; }

.editor {
  min-height: 420px; padding: 24px 32px; background: var(--card); border: 0; outline: none; overflow: auto;
  font-size: 16px; line-height: 1.7;
}
.editor:empty::before { content: attr(data-placeholder); color: #b8bdd0; }
.editor img { max-width: 100%; border-radius: 10px; }
.editor h1, .editor h2 { letter-spacing: -.02em; line-height: 1.25; }
.editor a { color: var(--accent); }
.source {
  font-family: "JetBrains Mono", Consolas, "Courier New", monospace; font-size: 13.5px; line-height: 1.6;
  resize: vertical; width: 100%; display: block; background: #0f1426; color: #d6dcf5; padding: 24px 32px;
}

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#editorWrap > .actions { padding: 14px 24px; border-top: 1px solid var(--line); background: var(--soft); }
#status { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
#status:not(:empty)::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
#status.dirty::before { background: #f59e0b; }

/* ---------- QR окно ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 20, 38, .45); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px; z-index: 10; animation: fade .15s;
}
.qrcard { text-align: center; max-width: 420px; width: 100%; animation: pop .2s cubic-bezier(.2, .9, .3, 1.2); }
.qrcard h3 { margin: 0 0 20px; font-size: 20px; letter-spacing: -.01em; }
#qrBox {
  display: inline-block; padding: 18px; background: #fff; border-radius: 18px;
  border: 1px solid var(--line); box-shadow: 0 0 0 6px var(--accent-soft);
}
#qrBox img, #qrBox canvas { display: block; }
.qrcard > .muted { margin: 18px 0 10px; font-size: 14px; }
.linkrow { display: flex; gap: 6px; margin: 0 0 20px; padding: 4px; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; }
.linkrow input { flex: 1; min-width: 0; padding: 0 10px; border: 0; background: transparent; font-size: 13px; color: var(--muted); }
.linkrow .btn { height: 34px; padding: 0 14px; }
.qrcard .actions { justify-content: center; }
.qrcard .actions .btn { flex: 1; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(8px); } }

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #141a2e; color: #fff; padding: 11px 20px 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 12px 30px -10px rgba(20, 26, 46, .5);
  opacity: 0; transition: .25s cubic-bezier(.2, .9, .3, 1.2); pointer-events: none; z-index: 20;
}
.toast::before { content: "✓"; width: 20px; height: 20px; border-radius: 50%; background: var(--ok); display: grid; place-items: center; font-size: 12px; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- Публичная страница ---------- */
.viewpage {
  background:
    radial-gradient(900px 420px at 50% -120px, #e0e7ff 0%, transparent 70%),
    var(--bg);
  min-height: 100vh;
}
.viewbar { display: flex; align-items: center; max-width: 820px; margin: 0 auto; padding: 16px; }
.article {
  max-width: 788px; margin: 8px auto 48px; padding: 48px 56px 56px;
  background: var(--card); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow);
}
.article h1 { font-size: 34px; line-height: 1.2; margin: 0 0 10px; letter-spacing: -.025em; }
.article #vMeta { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.article #vMeta:empty { display: none; }
.content { margin-top: 28px; padding-top: 28px; border-top: 1px solid var(--line); font-size: 17.5px; line-height: 1.75; overflow-wrap: break-word; color: #262d45; }
.content > :first-child { margin-top: 0; }
.content h1, .content h2, .content h3 { color: var(--text); line-height: 1.3; letter-spacing: -.02em; margin: 1.6em 0 .5em; }
.content p { margin: 0 0 1em; }
.content img { max-width: 100%; height: auto; border-radius: 14px; }
.content blockquote { margin: 1.2em 0; padding: 4px 20px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 12px 12px 0; }
.content table { border-collapse: collapse; max-width: 100%; display: block; overflow-x: auto; }
.content td, .content th { border: 1px solid var(--line); padding: 8px 12px; }
.content th { background: var(--soft); }
.content a { color: var(--accent); text-underline-offset: 3px; }
.content code { background: var(--soft); padding: 2px 6px; border-radius: 6px; font-size: .9em; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 0 16px 32px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding: 16px; }
  .top { padding: 0 16px; }
  .title { padding: 20px 20px 8px; font-size: 22px; }
  .tabs { padding: 0 14px; }
  .toolbar { padding: 8px 12px; }
  .editor, .source { padding: 18px 20px; }
  #editorWrap > .actions { padding: 12px 16px; }
  .card { padding: 24px; }
  .article { margin: 0 12px 32px; padding: 28px 22px 32px; border-radius: 20px; }
  .article h1 { font-size: 26px; }
  .content { font-size: 16.5px; }
}
