:root {
  --ink: #122033;
  --muted: #5b6b7c;
  --paper: #edf1f6;
  --surface: #ffffff;
  --line: #d5dee8;
  --line-strong: #b7c4d3;
  --sidebar: #101820;
  --sidebar-text: #b8c5d3;
  --accent: #12b5c9;
  --accent-ink: #06353c;
  --accent-soft: #d7f5f9;
  --ok: #1f8a5b;
  --ok-soft: #ddf5ea;
  --warn: #b86a12;
  --warn-soft: #fff1d9;
  --error: #c0392b;
  --error-soft: #fde8e6;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(18, 32, 51, .04), 0 8px 24px rgba(18, 32, 51, .05);
  font-family: "Trebuchet MS", "Segoe UI", Candara, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, white);
  outline-offset: 2px;
}
input, textarea, select {
  width: 100%;
  min-height: 44px;
  background: #fbfcfe;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  padding: 11px 13px;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
input:hover, textarea:hover, select:hover { border-color: #8ea0b4; }
label { display: block; font-size: 12px; font-weight: 700; margin: 16px 0 7px; letter-spacing: .2px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
svg {
  width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}
[hidden] { display: none !important; }
.eyebrow {
  font-size: 10px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); margin: 0;
}
.muted { color: var(--muted); }
.tiny { font-size: 10px; margin-top: 4px; }
.primary, .secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 11px 16px; min-height: 44px; border-radius: 8px; font-size: 13px; font-weight: 700;
}
.primary { background: var(--ink); color: #fff; border: 1px solid var(--ink); }
.primary:hover:not(:disabled) { background: #1c3148; }
.secondary { background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink); }
.secondary:hover:not(:disabled) { background: var(--accent-soft); border-color: #8ed4de; }
.text-button {
  border: 0; background: transparent; padding: 8px 4px; color: #0f7f8d;
  font-size: 12px; font-weight: 700; min-height: 36px;
}
.text-button:hover:not(:disabled) { text-decoration: underline; }
.feedback { font-size: 13px; line-height: 1.5; color: var(--error); margin: 12px 0 0; }
.feedback:empty { display: none; }
.feedback.success { color: var(--ok); }
.help { font-size: 12px; color: var(--muted); line-height: 1.55; margin: 8px 0 0; }

.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 22px; font-weight: 800; letter-spacing: -.4px; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 900; letter-spacing: -.5px;
}
.brand-sub { display: block; font-size: 9px; letter-spacing: 1.6px; color: #8092a5; margin-top: 3px; font-weight: 600; }

.login-simple {
  min-height: 100svh; display: grid; place-items: center; padding: 28px 18px;
  background:
    radial-gradient(900px 420px at 12% -10%, rgba(18, 181, 201, .22), transparent 60%),
    linear-gradient(160deg, #0e1620 0%, #172433 48%, #101820 100%);
}
.simple-login { width: 100%; max-width: 400px; }
.simple-login > .brand { justify-content: center; margin-bottom: 22px; }
.simple-login-card {
  background: var(--surface); border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px; padding: 28px 26px; box-shadow: 0 18px 50px rgba(0,0,0,.28);
}
.simple-login-card h1 { font-size: 22px; letter-spacing: -.4px; font-weight: 800; margin: 0 0 18px; }
.password-field { position: relative; }
.password-field input { padding-right: 78px; }
.password-toggle {
  position: absolute; right: 4px; top: 4px; bottom: 4px; min-width: 66px; border: 0;
  background: transparent; font-size: 12px; font-weight: 700; color: #0f7f8d;
}
.full { width: 100%; justify-content: space-between; margin-top: 20px; }

.app-body { font-size: 14px; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 228px; padding: 22px 14px 16px;
  background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; z-index: 10;
}
.sidebar .brand { padding: 2px 8px; margin-bottom: 28px; }
.nav-caption { font-size: 9px; letter-spacing: 1.5px; color: #6f8194; padding: 0 10px; margin: 0 0 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600;
  padding: 11px 12px; min-height: 42px; margin-bottom: 4px; border-radius: 8px; transition: background .12s;
}
.nav-item > span { font-size: 9px; margin-left: auto; opacity: .55; font-variant-numeric: tabular-nums; }
.nav-item:hover { background: #1a2532; color: #e8eef5; }
.nav-item.active { background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.sidebar-note {
  margin-top: auto; padding: 14px 12px; border: 1px solid #243141; border-radius: 10px;
  background: #15202b; font-size: 11px; line-height: 1.55; color: #93a5b8;
}
.sidebar-note p { margin: 0; }
.account {
  border-top: 1px solid #243141; display: flex; gap: 10px; align-items: center; padding: 14px 6px 0; margin-top: 14px;
}
.account-avatar {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%;
  background: #243141; font-size: 11px; color: var(--accent); font-weight: 800;
}
.account b { display: block; font-size: 12px; color: #f3f6fa; }
.account div > span { display: block; font-size: 10px; margin-top: 3px; color: #8092a5; }
.icon-button { border: 0; background: none; color: #a9b8c8; margin-left: auto; padding: 8px; border-radius: 6px; }
.icon-button:hover { background: #243141; }

.workspace { margin-left: 228px; min-width: 0; }
.topbar {
  min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--line); padding: 12px 28px; font-size: 12px; background: rgba(255,255,255,.78); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.topbar > div { color: var(--muted); }
.topbar > div span { margin: 0 8px; color: #9aabbc; }
.topbar strong { color: var(--ink); font-weight: 700; }
.status-pill {
  font-size: 11px; display: inline-flex; align-items: center; gap: 7px;
  background: #e8eef5; color: #42566b; border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; white-space: nowrap;
}
.status-pill:before { content: ""; width: 6px; height: 6px; background: #8092a5; border-radius: 50%; }
.status-pill.connected:before { background: var(--ok); }
.status-pill.warning { color: var(--warn); background: var(--warn-soft); border-color: #efd2a0; }

.main-content { max-width: 1280px; margin: 0 auto; padding: 24px 28px 40px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-heading h1 { font-size: 26px; line-height: 1.15; letter-spacing: -.6px; font-weight: 800; margin: 6px 0 8px; }
.page-heading p:not(.eyebrow) { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0; max-width: 52ch; }

.view { display: none; }
.view.active-view { display: block; }

.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 12px; box-shadow: var(--shadow);
}
.stat-card span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 8px; font-weight: 700; }
.stat-card b { font-size: 24px; letter-spacing: -.7px; font-weight: 800; font-variant-numeric: tabular-nums; }

.surface {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.editor-section { padding: 18px 18px 16px; scroll-margin-top: 72px; }
.section-heading { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.section-number {
  font-size: 10px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px;
  color: var(--muted); line-height: 1; font-weight: 800;
}
.section-heading h2, .bot-summary h2 { font-size: 15px; font-weight: 800; letter-spacing: -.2px; margin: 0 0 4px; }
.section-heading p { font-size: 12px; line-height: 1.45; color: var(--muted); margin: 0; }

.editor-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .9fr); gap: 14px; align-items: start; }
.editor-grid.single { grid-template-columns: 1fr; }
.editor-column { min-width: 0; }
.field-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; margin-bottom: 7px; }
.field-heading label { margin: 0; }
.optional { font-weight: 500; font-size: 11px; color: var(--muted); margin-left: 6px; }
.count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.upload-area {
  position: relative; border: 1px dashed #9eb0c2; background: #f7fafc; border-radius: 8px; min-height: 84px;
}
.upload-area:focus-within, .upload-area.dragging { outline: 2px solid var(--accent); outline-offset: 1px; background: var(--accent-soft); }
.upload-area input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.upload-content { display: flex; align-items: center; gap: 12px; padding: 16px; pointer-events: none; }
.upload-content svg { color: #0f7f8d; }
.upload-content b { font-size: 12px; font-weight: 700; display: block; }
.upload-content div > span { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); }
.upload-content img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }

.two-fields { display: grid; grid-template-columns: 1.2fr 1fr; gap: 12px; }
.two-fields label { margin-top: 0; }
.prefixed-input { position: relative; }
.prefixed-input > span { position: absolute; top: 12px; left: 12px; color: #6f8194; font-size: 12px; }
.prefixed-input input { padding-left: 38px; }

.save-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0 4px; border-top: 1px solid var(--line); margin-top: 14px;
}
.save-bar > div:first-child { font-size: 11px; line-height: 1.45; }
.save-dot { display: inline-block; width: 6px; height: 6px; background: var(--ok); border-radius: 50%; margin-right: 5px; }
.save-dot.dirty { background: var(--warn); }
.save-actions { display: flex; align-items: center; gap: 10px; }
#page-error:not(:empty) {
  padding: 11px 12px; background: var(--error-soft); border: 1px solid #f0b8b2; border-radius: 8px; margin-bottom: 14px;
}
.test-row { display: flex; gap: 10px; }
.test-row input { min-width: 0; }

.preview-sticky { position: sticky; top: 74px; }
.preview-heading { display: flex; justify-content: space-between; align-items: center; margin: 0 0 8px; }
.preview-label { font-size: 10px; color: var(--muted); font-weight: 700; }
.telegram-preview {
  border: 1px solid var(--line-strong); border-radius: 14px; overflow: hidden;
  background: linear-gradient(180deg, #dbe7f0, #c9d9e6);
}
.telegram-header {
  display: flex; align-items: center; gap: 10px; background: #fff; padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.telegram-avatar {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: #0f7f8d; font-size: 10px; font-weight: 900;
}
.telegram-header b { font-size: 13px; font-weight: 800; }
.telegram-header small { display: block; font-size: 10px; color: var(--muted); margin-top: 2px; }
.telegram-chat {
  min-height: 240px; padding: 14px 14px 22px;
  background-image: radial-gradient(rgba(18,32,51,.08) .7px, transparent .7px); background-size: 12px 12px;
}
.chat-date {
  text-align: center; font-size: 10px; color: #355064; background: rgba(255,255,255,.72);
  padding: 4px 9px; border-radius: 999px; width: max-content; margin: 0 auto 14px; font-weight: 700;
}
.message-bubble { background: #fff; border-radius: 10px 10px 10px 3px; overflow: hidden; padding-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.message-bubble img { width: 100%; max-height: 240px; object-fit: contain; display: block; background: #eef3f7; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px 12px 4px; font-size: 13px; line-height: 1.55; min-height: 36px; }
.message-time { display: block; text-align: right; font-size: 9px; color: #8a9aab; margin-right: 10px; }
.telegram-button {
  display: flex; justify-content: center; position: relative; margin-top: 4px;
  background: #9ec8d6; color: #123041; border-radius: 4px 4px 10px 10px; padding: 11px 24px;
  font-size: 12px; font-weight: 700; text-align: center; overflow-wrap: anywhere;
}
.telegram-button span { position: absolute; right: 10px; }
.telegram-button[data-style=primary] { background: #2a8fd6; color: #fff; }
.telegram-button[data-style=success] { background: #1f8a5b; color: #fff; }
.telegram-button[data-style=danger] { background: #c0392b; color: #fff; }
.telegram-button:not([href]) { opacity: .65; cursor: default; }
.preview-note { font-size: 11px; color: var(--muted); line-height: 1.5; margin: 10px 2px 0; }

.data-table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th, .data-table td {
  padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top;
}
.data-table th { color: var(--muted); font-weight: 800; font-size: 10px; letter-spacing: .5px; text-transform: uppercase; }
.badge {
  display: inline-flex; padding: 3px 8px; border-radius: 999px; font-size: 10px; font-weight: 800;
  background: #e8eef5; color: #42566b;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.choice-row { display: flex; gap: 16px; margin: 8px 0 12px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; margin: 0; }
.check input { width: auto; min-height: 0; }
.bot-check-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px;
  margin-bottom: 14px; max-height: 200px; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc;
}

.workspace-footer {
  display: flex; justify-content: space-between; border-top: 1px solid var(--line);
  padding: 16px 0 0; margin-top: 18px; color: #7b8c9e; font-size: 11px;
}
.skip-link { position: fixed; top: -80px; left: 240px; padding: 10px 12px; background: var(--accent); z-index: 50; color: var(--accent-ink); font-weight: 800; border-radius: 8px; }
.skip-link:focus { top: 10px; }

.rich-editor-shell { border: 1px solid var(--line-strong); border-radius: 8px; background: #fbfcfe; overflow: hidden; }
.rich-editor-shell:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.format-toolbar {
  display: flex; flex-wrap: wrap; gap: 3px; padding: 6px; border-bottom: 1px solid var(--line); background: #f0f4f8;
}
.format-toolbar button {
  display: grid; place-items: center; min-width: 32px; height: 32px; padding: 4px 6px;
  border: 1px solid transparent; border-radius: 6px; background: transparent; color: #314556; font-size: 13px;
}
.format-toolbar button:hover:not(:disabled) { background: var(--accent-soft); border-color: #9adbe4; }
.rich-editor {
  min-height: 150px; max-height: 380px; overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  line-height: 1.6; padding: 12px; font-size: 14px; outline: none;
}
.rich-editor[aria-disabled=true] { opacity: .65; }
.rich-editor .format-text_link { color: #0f7f8d; text-decoration: underline; }
.format-spoiler { background: #e4ebf2; border-radius: 3px; color: #42566b; }
.format-code, .format-pre { font-family: Consolas, monospace; font-size: .94em; background: #e8eef5; padding: 1px 3px; border-radius: 3px; }
.format-blockquote, .format-expandable_blockquote { border-left: 3px solid var(--accent); background: #eef8fa; padding-left: 7px; }
.custom-emoji-token {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  width: 1.45em; height: 1.45em; line-height: 1; white-space: nowrap;
}
.custom-emoji-token img, .message-text .custom-emoji-token img {
  width: 1.4em; height: 1.4em; max-height: none; object-fit: contain; background: none; display: inline-block;
}
.rich-editor .custom-emoji-token { border-radius: 3px; outline: 1px solid #9adbe4; cursor: default; }
.emoji-library { border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; background: #f8fafc; }
.emoji-library summary { cursor: pointer; padding: 11px 12px; font-size: 12px; font-weight: 700; min-height: 40px; }
.emoji-library summary > span { float: right; font-size: 10px; font-weight: 600; color: var(--muted); }
.emoji-library-content { padding: 0 12px 12px; border-top: 1px solid var(--line); }
.emoji-library label { font-size: 11px; margin-top: 12px; }
.pack-import-row { display: flex; gap: 7px; }
.pack-import-row input { min-width: 0; font-size: 12px; padding: 9px 11px; }
.pack-import-row button { font-size: 12px; padding: 8px 12px; white-space: nowrap; }
.pack-select-row { display: flex; align-items: center; gap: 10px; margin: 12px 0 8px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 5px; max-height: 210px; overflow: auto; padding: 2px; }
.emoji-pick {
  position: relative; display: grid; place-items: center; width: 100%; height: 40px; padding: 4px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 20px;
}
.emoji-pick:hover { background: var(--accent-soft); border-color: #8ed4de; }
.emoji-pick img { height: 28px; width: 28px; object-fit: contain; }
.emoji-motion { position: absolute; bottom: 0; right: 3px; font-size: 12px; color: #0f7f8d; }
.emoji-policy { font-size: 10px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 10px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .editor-grid { grid-template-columns: 1fr; }
  .preview-sticky { position: static; }
}
@media (max-width: 860px) {
  .sidebar {
    position: static; width: 100%; padding: 14px 14px 0; display: grid;
    grid-template-columns: 1fr auto;
  }
  .sidebar .brand { margin: 0; }
  .nav-caption, .sidebar-note { display: none; }
  .sidebar nav {
    grid-column: 1 / -1; display: flex; gap: 4px; overflow: auto; margin-top: 12px; padding-bottom: 0;
  }
  .nav-item { white-space: nowrap; border-radius: 8px 8px 0 0; margin: 0; }
  .account { border: 0; padding: 0; }
  .account div, .account-avatar { display: none; }
  .workspace { margin-left: 0; }
  .topbar { position: static; padding: 12px 16px; }
  .main-content { padding: 16px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-fields, .test-row { grid-template-columns: 1fr; flex-direction: column; }
  .page-heading h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
