:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #000);
  --hint: var(--tg-theme-hint-color, #999);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #fff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f1);
  --border: color-mix(in srgb, var(--hint) 30%, transparent);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; min-height: 100vh; }

header { padding: 8px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 5; }
main { flex: 1; padding: 10px 12px 24px; }
footer { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 10px 12px;
  background: var(--bg); border-top: 1px solid var(--border); z-index: 5; }

.channel-select { width: 100%; padding: 9px 12px; font-size: 15px; color: var(--text);
  background: var(--secondary-bg); border: 1px solid transparent; border-radius: 10px; outline: none; }

.btn { flex: 1; padding: 12px; font-size: 16px; border: none; border-radius: 10px; cursor: pointer; }
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-secondary { background: var(--secondary-bg); color: var(--text); }
.btn:disabled { opacity: .5; }

.add-block { width: 100%; margin-top: 8px; padding: 11px; font-size: 15px; color: var(--link);
  background: transparent; border: 1px dashed var(--border); border-radius: 10px; cursor: pointer; }

.status { min-height: 20px; margin-top: 8px; font-size: 14px; color: var(--hint); }
.status.ok { color: #2e7d32; }
.status.err { color: #c62828; }

/* ---------- блоки ---------- */
.block { border: 1px solid var(--border); border-radius: 10px; margin: 8px 0; background: var(--bg); }
.block.dragging { opacity: .5; }
.block-bar { display: flex; align-items: center; gap: 2px; padding: 4px 6px;
  border-bottom: 1px solid var(--border); color: var(--hint); }
.drag-handle { cursor: grab; padding: 2px 6px; font-size: 15px; user-select: none; }
.block-kind { min-width: 24px; text-align: center; font-size: 13px; }
button.block-kind { background: var(--secondary-bg); border: none; color: var(--text);
  border-radius: 6px; padding: 2px 6px; cursor: pointer; }
.spacer { flex: 1; }
.ba { background: transparent; border: none; color: var(--hint); font-size: 15px;
  padding: 4px 7px; border-radius: 6px; cursor: pointer; }
.ba:active { background: var(--secondary-bg); }
.block-body { padding: 8px 10px; }

/* ---------- editable ---------- */
.editable { outline: none; min-height: 1.45em; white-space: pre-wrap; word-break: break-word; }
.editable.is-empty::before { content: attr(data-ph); color: var(--hint); pointer-events: none; }
.editable.heading { font-weight: 700; }
.editable.h1 { font-size: 24px; }
.editable.h2 { font-size: 20px; }
.editable.h3 { font-size: 18px; }
.block[data-type="quote"] .block-body { border-left: 3px solid var(--link); }

/* инлайн-стили в editable */
.editable code { background: var(--secondary-bg); padding: 0 4px; border-radius: 4px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; }
.editable a { color: var(--link); }
.editable .spoiler { background: var(--hint); color: var(--hint); border-radius: 3px; }

/* ---------- списки ---------- */
.list { display: flex; flex-direction: column; gap: 2px; }
.list-item { display: flex; align-items: baseline; gap: 6px; }
.list-item .editable { flex: 1; }
.block[data-type="bulleted_list"] .list-item::before { content: "•"; color: var(--hint); }
.block[data-type="numbered_list"] .list { counter-reset: li; }
.block[data-type="numbered_list"] .list-item { counter-increment: li; }
.block[data-type="numbered_list"] .list-item::before { content: counter(li) "."; color: var(--hint); min-width: 18px; }
.li-check { margin: 0; align-self: center; width: 18px; height: 18px; }
.add-item { margin-top: 6px; background: transparent; border: none; color: var(--link);
  font-size: 14px; padding: 4px 2px; cursor: pointer; }

/* ---------- код ---------- */
.code-lang { width: 100%; margin-bottom: 6px; padding: 6px 8px; font-size: 13px; color: var(--text);
  background: var(--secondary-bg); border: 1px solid transparent; border-radius: 8px; outline: none; }
.code-text { width: 100%; padding: 8px; font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace;
  color: var(--text); background: var(--secondary-bg); border: 1px solid transparent; border-radius: 8px;
  outline: none; resize: vertical; }

.divider-line { height: 0; border-top: 2px solid var(--border); margin: 6px 0; }

/* ---------- инлайн-тулбар ---------- */
.inline-toolbar { position: fixed; z-index: 50; display: flex; gap: 1px; padding: 4px;
  background: var(--secondary-bg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.inline-toolbar button { min-width: 30px; height: 30px; border: none; background: transparent;
  color: var(--text); font-size: 14px; border-radius: 7px; cursor: pointer; }
.inline-toolbar button:active { background: var(--bg); }

/* ---------- нижний лист ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; background: var(--bg);
  border-radius: 16px 16px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); }
.sheet-title { font-size: 14px; color: var(--hint); margin-bottom: 10px; text-align: center; }
.sheet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet-grid button { padding: 14px 10px; font-size: 15px; text-align: left; color: var(--text);
  background: var(--secondary-bg); border: none; border-radius: 10px; cursor: pointer; }
.sheet-cancel { width: 100%; margin-top: 10px; padding: 12px; font-size: 15px; color: var(--text);
  background: transparent; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }

/* ---------- модалка ссылки ---------- */
.modal { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-panel { position: relative; width: 100%; max-width: 360px; background: var(--bg);
  border-radius: 14px; padding: 16px; }
.modal-title { font-size: 15px; margin-bottom: 10px; }
.modal-input { width: 100%; padding: 10px 12px; font-size: 16px; color: var(--text);
  background: var(--secondary-bg); border: 1px solid var(--border); border-radius: 10px; outline: none; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
