:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --sidebar: #111827;
  --sidebar2: #182235;
  --text: #192231;
  --muted: #7b8798;
  --line: #e6eaf0;
  --blue: #2aabee;
  --blue2: #168bd1;
  --soft-blue: #eaf7fe;
  --green: #1ea672;
  --red: #d94d5c;
  --shadow: 0 12px 35px rgba(22, 37, 63, .08);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", Arial, sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 238px; background: linear-gradient(180deg, var(--sidebar), var(--sidebar2)); color: #fff; padding: 28px 18px 22px; display: flex; flex-direction: column; z-index: 10; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 28px; }
.brand-icon { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(145deg, #37b9f4, #1d8ddd); font-size: 21px; transform: rotate(-12deg); box-shadow: 0 9px 24px rgba(42,171,238,.28); }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 17px; letter-spacing: .2px; }
.brand span { margin-top: 2px; font-size: 12px; color: #9eacc1; }
.nav { display: grid; gap: 7px; }
.nav-item { width: 100%; border: 0; background: transparent; color: #acb8c9; border-radius: 12px; padding: 12px 13px; display: flex; align-items: center; gap: 11px; text-align: left; font-weight: 650; }
.nav-item span { width: 21px; text-align: center; font-size: 17px; }
.nav-item em { margin-left: auto; min-width: 22px; padding: 2px 6px; border-radius: 99px; background: rgba(255,255,255,.08); color: #d9e1ed; font-size: 11px; font-style: normal; text-align: center; }
.nav-item:hover, .nav-item.active { background: rgba(42,171,238,.14); color: #fff; }
.nav-item.active { box-shadow: inset 3px 0 0 var(--blue); }
.side-footer { margin-top: auto; padding: 15px 10px 0; border-top: 1px solid rgba(255,255,255,.08); }
.local-badge { display: flex; align-items: center; gap: 7px; color: #cfe5dc; font-size: 11px; font-weight: 800; letter-spacing: .7px; }
.local-badge i { width: 8px; height: 8px; border-radius: 50%; background: #31c48d; box-shadow: 0 0 0 4px rgba(49,196,141,.12); }
.side-footer p { font-size: 11px; line-height: 1.55; color: #78869a; margin: 10px 0 0; }
.main { grid-column: 2; min-width: 0; }
.topbar { height: 96px; background: rgba(255,255,255,.86); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 34px; position: sticky; top: 0; z-index: 7; backdrop-filter: blur(14px); }
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: -.4px; }
.topbar p { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.connection-pill { border: 1px solid #dbe3ec; border-radius: 999px; padding: 8px 12px; font-size: 11px; font-weight: 750; color: #778293; background: #fff; }
.connection-pill.connected { color: #197d58; border-color: #caeadc; background: #effaf5; }
.view { display: none; padding: 28px 34px 42px; }
.view.active { display: block; }
.composer-grid { display: grid; grid-template-columns: minmax(540px, 760px) minmax(330px, 430px); gap: 26px; align-items: start; }
.editor-column { min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 17px; padding: 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.card-head > div { display: flex; align-items: center; gap: 10px; }
.card-head h2 { margin: 0; font-size: 15px; }
.step { height: 26px; min-width: 26px; padding: 0 6px; border-radius: 8px; display: inline-grid; place-items: center; background: var(--soft-blue); color: var(--blue2); font-size: 11px; font-weight: 850; }
.muted { color: var(--muted); font-size: 11px; }
.field-label { display: block; margin: 16px 0 7px; font-size: 12px; font-weight: 760; color: #465365; }
.field-label small { font-weight: 500; color: #96a0af; margin-left: 6px; }
.input, .textarea, .mini-select { width: 100%; border: 1px solid #dfe4ec; background: #fbfcfe; color: var(--text); border-radius: 10px; outline: none; transition: .18s; }
.input { height: 42px; padding: 0 12px; }
.textarea { resize: vertical; min-height: 168px; padding: 12px 13px; line-height: 1.6; }
.input:focus, .textarea:focus, .mini-select:focus { border-color: #8ccff2; background: #fff; box-shadow: 0 0 0 3px rgba(42,171,238,.1); }
.upload-box { border: 1.5px dashed #d7dee8; border-radius: 13px; min-height: 112px; background: #fafbfd; display: grid; place-items: center; transition: .2s; overflow: hidden; }
.upload-box:hover, .upload-box.dragover { border-color: #65bfee; background: #f3fbff; }
.upload-empty { padding: 18px; display: flex; flex-direction: column; align-items: center; color: #8793a4; gap: 5px; }
.upload-empty strong { color: #536174; font-size: 12px; }
.upload-empty span, .upload-selected span { font-size: 10px; color: #98a3b3; }
.upload-icon { width: 31px; height: 31px; border-radius: 9px; display: grid; place-items: center; background: #edf6fc; color: #209edb; font-size: 19px; margin-bottom: 2px; }
.upload-selected { width: 100%; display: grid; grid-template-columns: 74px 1fr 35px; gap: 12px; align-items: center; padding: 10px; }
.upload-selected img { width: 74px; height: 74px; object-fit: cover; border-radius: 10px; background: #e9edf2; }
.upload-selected strong, .upload-selected span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-selected strong { max-width: 420px; font-size: 12px; margin-bottom: 5px; }
.hidden { display: none !important; }
.icon-button { width: 30px; height: 30px; border: 0; border-radius: 8px; background: #f3f5f8; color: #677386; font-size: 19px; }
.icon-button.danger:hover { background: #fff0f2; color: var(--red); }
.label-row { display: flex; align-items: flex-end; justify-content: space-between; }
.label-row .field-label { flex: 1; }
.mini-select { width: auto; min-width: 118px; height: 31px; padding: 0 8px; font-size: 10.5px; }
.format-help, .field-hint, .button-tip { color: #929dac; font-size: 10.5px; line-height: 1.55; margin-top: 7px; }
.small-button { border: 1px solid #dce3eb; background: #fff; color: #536174; border-radius: 9px; padding: 7px 10px; font-size: 10.5px; font-weight: 750; }
.small-button:hover { border-color: #acd9ef; color: #168bd1; }
.button-list { display: grid; gap: 9px; }
.button-row-editor { display: grid; grid-template-columns: 1fr 1.45fr 82px 34px 34px; gap: 8px; align-items: center; padding: 10px; border-radius: 11px; background: #f8fafc; border: 1px solid #edf0f4; }
.button-row-editor input, .button-row-editor select { height: 36px; border: 1px solid #dfe4eb; border-radius: 8px; background: #fff; padding: 0 9px; min-width: 0; outline: none; font-size: 11px; }

.editor-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 10px 0 10px; flex-wrap: wrap; }
.toolbar-group { display: flex; gap: 7px; flex-wrap: wrap; }
.toolbar-group.right { margin-left: auto; }
.toolbar-btn { min-width: 36px; height: 34px; border: 1px solid #dce3eb; background: #fff; color: #536174; border-radius: 9px; padding: 0 10px; font-size: 11px; font-weight: 780; }
.toolbar-btn:hover { border-color: #acd9ef; color: #168bd1; background: #f7fbfe; }
.emoji-panel { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid #e6ebf1; border-radius: 12px; background: #fbfcfe; margin-bottom: 10px; }
.emoji-chip { width: 36px; height: 36px; border: 1px solid #e1e7ef; border-radius: 10px; background: #fff; font-size: 18px; line-height: 1; }
.emoji-chip:hover { border-color: #acd9ef; background: #f5fbff; }
.save-preset { font-size: 15px; }
.preset-library-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin: 14px 0 9px; }
.preset-library-head strong { font-size: 12px; color: #435164; }
.preset-library-head span { font-size: 10px; color: #8f9aaa; }
.preset-list { display: flex; flex-wrap: wrap; gap: 9px; }
.preset-empty { width: 100%; padding: 12px; border: 1px dashed #d9e1ea; border-radius: 12px; background: #fafbfd; color: #97a1af; font-size: 11px; }
.preset-chip { display: flex; align-items: stretch; max-width: 100%; border: 1px solid #dbe5ef; border-radius: 12px; overflow: hidden; background: #fff; }
.preset-chip-main { border: 0; background: #fff; text-align: left; padding: 9px 11px; min-width: 0; }
.preset-chip-main strong, .preset-chip-main span { display: block; }
.preset-chip-main strong { font-size: 11px; color: #39485c; }
.preset-chip-main span { margin-top: 3px; font-size: 9.5px; color: #8a95a4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.preset-chip-main:hover { background: #f8fbff; }
.preset-chip-delete { width: 34px; border: 0; border-left: 1px solid #ebeff4; background: #fff; color: #8d98a8; font-size: 16px; }
.preset-chip-delete:hover { background: #fff3f4; color: #d94d5c; }

.action-bar { display: flex; gap: 10px; justify-content: flex-end; padding: 4px 0; }
.primary-button, .secondary-button { min-height: 42px; border-radius: 10px; padding: 0 16px; font-weight: 780; font-size: 12px; }
.primary-button { border: 0; color: #fff; background: linear-gradient(135deg, #2aabee, #168bd1); box-shadow: 0 8px 18px rgba(42,171,238,.22); }
.primary-button:hover { filter: brightness(.97); transform: translateY(-1px); }
.primary-button:disabled { opacity: .55; transform: none; cursor: not-allowed; }
.secondary-button { border: 1px solid #dce3eb; background: #fff; color: #4f5e72; }
.secondary-button:hover { background: #f8fafc; }
.compact { min-height: 36px; padding: 0 12px; font-size: 11px; }
.preview-sticky { position: sticky; top: 122px; }
.preview-title { display: flex; justify-content: space-between; align-items: center; color: #7d899a; font-size: 10px; font-weight: 850; letter-spacing: .7px; margin: 0 4px 9px; }
.preview-title span:last-child { color: #3f8db6; letter-spacing: 0; font-weight: 700; }
.phone { max-width: 390px; margin: 0 auto; background: #fff; border: 1px solid #dfe4eb; border-radius: 27px; padding: 8px; box-shadow: 0 22px 52px rgba(31,50,80,.13); }
.phone-top { height: 42px; display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: center; padding: 0 12px; font-size: 10px; }
.phone-top strong { text-align: center; font-size: 12px; }
.phone-top span:last-child { text-align: right; }
.telegram-bg { min-height: 575px; border-radius: 20px; padding: 15px 10px; background-color: #dfe9e2; background-image: radial-gradient(rgba(255,255,255,.35) 1px, transparent 1px), radial-gradient(rgba(123,151,139,.08) 1px, transparent 1px); background-size: 18px 18px, 28px 28px; }
.tg-message { width: 100%; background: #fff; border-radius: 11px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.12); position: relative; padding-bottom: 22px; }
.tg-channel-row { padding: 10px 11px 8px; display: flex; align-items: center; gap: 8px; }
.tg-avatar { width: 31px; height: 31px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(145deg, #34b7f1, #168bd1); color: #fff; font-weight: 850; font-size: 12px; }
.tg-channel-row strong, .tg-channel-row small { display: block; }
.tg-channel-row strong { color: #2689bd; font-size: 11px; }
.tg-channel-row small { font-size: 9px; color: #9ba4af; margin-top: 1px; }
.preview-image { width: 100%; height: auto; max-height: none; object-fit: contain; display: block; background: #eef2f6; }
.preview-caption { padding: 9px 11px 4px; font-size: 11.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.preview-caption.placeholder { color: #a2abb7; }
.preview-caption a { color: #168bd1; text-decoration: none; }
.preview-buttons { padding: 7px 8px 0; display: grid; gap: 5px; }
.preview-button-row { display: flex; gap: 5px; }
.preview-button { flex: 1 1 0; min-width: 0; border-radius: 6px; padding: 8px 6px; background: #e9f5fb; color: #1689c4; text-align: center; font-size: 10px; font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-time { position: absolute; right: 8px; bottom: 5px; color: #9ba4af; font-size: 8.5px; }
.preview-note { max-width: 390px; margin: 10px auto 0; text-align: center; color: #98a3b2; font-size: 9.5px; line-height: 1.5; }
.list-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.list-toolbar p { margin: 0; color: var(--muted); font-size: 12px; }
.record-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.record-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: 0 8px 24px rgba(28,43,67,.055); }
.record-image { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #edf1f5; }
.record-no-image { width: 100%; aspect-ratio: 16/9; display: grid; place-items: center; background: linear-gradient(135deg, #eff8fd, #f5f7fa); color: #95a5b6; font-size: 25px; }
.record-body { padding: 13px; }
.record-body h3 { margin: 0 0 7px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-body p { color: #697588; margin: 0; font-size: 10.5px; line-height: 1.5; min-height: 31px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.record-meta { display: flex; justify-content: space-between; color: #a0a9b5; font-size: 9px; margin-top: 11px; }
.record-actions { display: flex; gap: 6px; margin-top: 10px; }
.record-actions button { flex: 1; min-height: 32px; border-radius: 8px; border: 1px solid #e1e6ed; background: #fff; color: #596779; font-size: 10px; font-weight: 700; }
.record-actions button:hover { border-color: #acd9ef; color: #168bd1; }
.record-actions button.delete:hover { border-color: #f0c8ce; color: var(--red); }
.empty-state { grid-column: 1/-1; padding: 70px 20px; text-align: center; border: 1px dashed #d8dfe8; border-radius: 14px; color: #9ba5b2; font-size: 12px; background: rgba(255,255,255,.55); }
.history-list { display: grid; gap: 8px; }
.history-item { display: grid; grid-template-columns: 42px minmax(0,1fr) 130px 90px 150px; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; }
.history-status { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; font-weight: 850; }
.history-status.ok { background: #eaf8f2; color: #19835d; }
.history-status.fail { background: #fff0f2; color: #c44152; }
.history-main { min-width: 0; }
.history-main strong { display: block; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-main span { display: block; margin-top: 4px; color: #8994a2; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-date, .history-message { font-size: 9.5px; color: #8994a2; text-align: right; }

.history-actions { display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; justify-content: flex-end; justify-self: end; gap: 8px; width: 150px; min-width: 150px; }
.history-actions .small-button { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 68px; min-width: 68px; height: 34px; padding: 0 10px; white-space: nowrap; word-break: keep-all; writing-mode: horizontal-tb; line-height: 1; }
.history-preview-modal-card { width: min(560px, calc(100vw - 28px)); max-height: calc(100vh - 34px); overflow: auto; }
.history-preview-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.history-preview-head h3 { margin: 0; font-size: 16px; }
.history-preview-head p { margin: 5px 0 0; color: #8b96a5; font-size: 10.5px; }
.history-preview-message { overflow: hidden; border: 1px solid #dfe5ec; border-radius: 14px; background: #fff; box-shadow: 0 8px 24px rgba(31,50,80,.08); }
.history-preview-image { width: 100%; height: auto; max-height: none; object-fit: contain; display: block; background: #eef2f6; }
.history-preview-caption { padding: 14px 15px 8px; font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.history-preview-caption.placeholder { color: #a2abb7; }
.history-preview-caption a { color: #168bd1; text-decoration: none; }
.history-preview-buttons { padding: 8px 10px 12px; }

.settings-wrap { display: grid; grid-template-columns: minmax(520px, 720px) minmax(270px, 360px); gap: 22px; align-items: start; }
.settings-card, .guide-card { margin: 0; }
.notice { background: #eff8fd; border: 1px solid #d4edf9; border-radius: 11px; padding: 11px 13px; margin-bottom: 18px; }
.notice strong, .notice span { display: block; }
.notice strong { color: #257da8; font-size: 11px; }
.notice span { margin-top: 4px; color: #65879a; font-size: 10px; }
.password-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.select-input { appearance: auto; }
.settings-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.guide-card h3 { margin: 0 0 15px; font-size: 14px; }
.guide-card ol { padding-left: 19px; margin: 0; color: #5c697a; font-size: 11px; line-height: 1.7; }
.guide-card li { margin-bottom: 7px; }
.security-box { background: #fff8e8; border: 1px solid #f1e1b4; color: #816d35; border-radius: 10px; padding: 11px; font-size: 10px; line-height: 1.55; margin-top: 16px; }
.security-box code { background: rgba(255,255,255,.65); padding: 1px 4px; border-radius: 4px; }
.toast { position: fixed; right: 25px; bottom: 25px; z-index: 50; background: #172132; color: #fff; border-radius: 11px; padding: 11px 14px; font-size: 11px; box-shadow: 0 13px 35px rgba(13,24,42,.25); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .25s; max-width: 340px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #9f3340; }
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(18,28,44,.4); backdrop-filter: blur(4px); }
.modal-card { width: min(420px, calc(100vw - 30px)); background: #fff; border-radius: 16px; padding: 22px; box-shadow: 0 25px 70px rgba(11,21,38,.24); }
.modal-card h3 { margin: 0 0 8px; font-size: 16px; }
.modal-card p { margin: 0; color: #7c8795; font-size: 11px; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
@media (max-width: 1050px) {
  .composer-grid { grid-template-columns: 1fr; }
  .preview-column { order: -1; }
  .preview-sticky { position: static; }
  .phone { max-width: 430px; }
  .telegram-bg { min-height: 400px; }
  .record-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .settings-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; min-height: 0; padding: 14px; }
  .brand { padding: 0 4px 13px; }
  .nav { grid-template-columns: repeat(4, 1fr); gap: 5px; }
  .nav-item { justify-content: center; padding: 10px 5px; font-size: 10px; }
  .nav-item span, .nav-item em, .side-footer { display: none; }
  .main { width: 100%; }
  .topbar { height: auto; padding: 17px 16px; position: static; }
  .connection-pill { display: none; }
  .view { padding: 16px; }
  .button-row-editor { grid-template-columns: 1fr; }
  .record-grid { grid-template-columns: 1fr; }
  .history-item { grid-template-columns: 38px minmax(0,1fr) auto; }
  .history-main { grid-column: 2; }
  .history-actions { grid-column: 3; grid-row: 1; justify-self: end; justify-content: flex-end; width: 150px; min-width: 150px; }
  .history-date, .history-message { display: none; }
  .action-bar { flex-wrap: wrap; }
  .action-bar button { flex: 1; }
}

/* v3: Rich Text / Multi Channel / Scheduler */
.no-margin { margin: 0 !important; }
.rich-editor {
  width: 100%; min-height: 210px; max-height: 520px; overflow-y: auto;
  border: 1px solid #dfe4ec; background: #fbfcfe; color: var(--text);
  border-radius: 12px; outline: none; padding: 14px 15px; line-height: 1.62;
  font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; transition: .18s;
}
.rich-editor:focus { border-color: #8ccff2; background: #fff; box-shadow: 0 0 0 3px rgba(42,171,238,.1); }
.rich-editor:empty:before { content: attr(data-placeholder); white-space: pre-wrap; color: #a2abb7; pointer-events: none; }
.rich-editor a { color: #168bd1; text-decoration: underline; }
.toolbar-btn.wide { min-width: 68px; }
.toolbar-btn.active { background: #eaf7fe; color: #168bd1; border-color: #86ccef; box-shadow: inset 0 0 0 1px rgba(42,171,238,.08); }
.toolbar-btn.disabled { opacity: .42; cursor: not-allowed; }
.channel-select-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.text-button { border: 0; background: transparent; color: #168bd1; font-size: 10.5px; font-weight: 800; padding: 4px 2px; }
.text-button:hover { text-decoration: underline; }
.channel-picker { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.channel-choice { position: relative; display: flex; align-items: center; gap: 9px; min-height: 54px; padding: 10px 11px; border: 1px solid #e0e6ed; background: #fbfcfe; border-radius: 12px; cursor: pointer; transition: .16s; }
.channel-choice:hover { border-color: #b9dcef; background: #f8fcff; }
.channel-choice.selected { border-color: #81c8ec; background: #eff9fe; box-shadow: inset 0 0 0 1px rgba(42,171,238,.08); }
.channel-choice input { position: absolute; opacity: 0; pointer-events: none; }
.channel-choice-dot { width: 25px; height: 25px; border-radius: 8px; display: grid; place-items: center; flex: 0 0 auto; background: #edf1f5; color: transparent; font-size: 11px; font-weight: 900; }
.channel-choice.selected .channel-choice-dot { background: #2aabee; color: #fff; }
.channel-choice strong, .channel-choice small { display: block; min-width: 0; }
.channel-choice strong { font-size: 11.5px; color: #3f4d5f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-choice small { margin-top: 3px; font-size: 9.5px; color: #8e99a8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-empty { width: 100%; padding: 13px; border: 1px dashed #d9e1e9; border-radius: 11px; color: #95a0ae; background: #fafbfd; font-size: 10.5px; }
.schedule-box { display: grid; grid-template-columns: 1fr minmax(220px, 270px); gap: 18px; align-items: center; margin-top: 20px; padding-top: 18px; border-top: 1px solid #eef1f5; }
.schedule-input { background: #fff; }
.schedule-button { color: #6e5d93; border-color: #ddd5ed; background: #faf8ff; }
.schedule-button:hover { color: #5a448d; background: #f6f2ff; border-color: #cfc3e9; }
.action-bar-wrap { flex-wrap: wrap; }
.schedule-warning { margin: -5px 0 16px; padding: 11px 13px; border: 1px solid #f0dfb0; background: #fff9ea; color: #7d6b36; border-radius: 11px; font-size: 10.5px; line-height: 1.55; }
.scheduled-list { display: grid; gap: 10px; }
.scheduled-card { display: grid; grid-template-columns: 100px minmax(0,1fr) auto; gap: 15px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 15px; box-shadow: 0 7px 22px rgba(28,43,67,.045); }
.scheduled-time { text-align: center; border-right: 1px solid #edf0f4; padding-right: 14px; }
.scheduled-time strong, .scheduled-time span { display: block; }
.scheduled-time strong { font-size: 11px; color: #5e6b7d; }
.scheduled-time span { margin-top: 4px; font-size: 17px; font-weight: 850; color: #29364a; }
.scheduled-main { min-width: 0; }
.scheduled-title-row { display: flex; align-items: center; gap: 9px; min-width: 0; }
.scheduled-title-row h3 { margin: 0; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scheduled-main p { margin: 6px 0 0; color: #697588; font-size: 10.5px; line-height: 1.45; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scheduled-meta { margin-top: 7px; color: #8793a2; font-size: 9.5px; }
.scheduled-error { margin-top: 7px; color: #b23f4d; font-size: 9.5px; line-height: 1.4; }
.status-badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 7px; font-size: 8.5px; font-weight: 850; letter-spacing: .2px; background: #eef2f6; color: #677386; }
.status-badge.scheduled, .status-badge.retry { background: #eef8fd; color: #277fa9; }
.status-badge.processing { background: #fff8e8; color: #8d742e; }
.status-badge.published { background: #eaf8f2; color: #19835d; }
.status-badge.partial { background: #fff6e6; color: #a26c16; }
.status-badge.failed { background: #fff0f2; color: #bf3f50; }
.scheduled-actions { display: flex; gap: 7px; align-items: center; }
.channel-add-grid { display: grid; grid-template-columns: .8fr 1.2fr auto; gap: 9px; align-items: center; }
.settings-channel-list { display: grid; gap: 8px; margin-top: 15px; }
.settings-channel-row { display: grid; grid-template-columns: 34px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid #e8ecf1; border-radius: 11px; background: #fbfcfe; }
.settings-channel-icon { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: #eaf7fe; color: #168bd1; font-weight: 900; }
.settings-channel-row strong, .settings-channel-row span { display: block; }
.settings-channel-row strong { font-size: 11px; color: #3f4d5f; }
.settings-channel-row span { margin-top: 3px; font-size: 9.5px; color: #8d98a7; }
.danger-text { color: #ba4654 !important; }
.settings-wrap > div .settings-card + .settings-card { margin-top: 18px; }

@media (max-width: 900px) {
  .channel-picker { grid-template-columns: 1fr; }
  .schedule-box { grid-template-columns: 1fr; }
  .channel-add-grid { grid-template-columns: 1fr; }
  .scheduled-card { grid-template-columns: 82px minmax(0,1fr); }
  .scheduled-actions { grid-column: 1 / -1; justify-content: flex-end; border-top: 1px solid #eef1f5; padding-top: 9px; }
}

@media (max-width: 720px) {
  .nav { grid-template-columns: repeat(5, 1fr); }
  .nav-item { font-size: 9px; }
  .rich-editor { min-height: 180px; }
  .preset-library-head { display: block; }
  .preset-library-head span { display: block; margin-top: 4px; }
  .scheduled-card { grid-template-columns: 1fr; }
  .scheduled-time { text-align: left; border-right: 0; border-bottom: 1px solid #edf0f4; padding: 0 0 9px; display: flex; align-items: center; gap: 8px; }
  .scheduled-time span { margin: 0; font-size: 13px; }
  .scheduled-actions { grid-column: auto; justify-content: stretch; }
  .scheduled-actions button { flex: 1; }
}

.logout-link { display:inline-block; margin-top:12px; color:#9fb0c6; font-size:11px; text-decoration:none; }
.logout-link:hover { color:#fff; }
.login-page { min-height:100vh; display:grid; place-items:center; padding:24px; background:linear-gradient(135deg,#eef5fb,#f7f8fb); }
.login-card { width:min(430px,100%); background:#fff; border:1px solid #e4e9ef; border-radius:20px; padding:30px; box-shadow:0 24px 65px rgba(22,37,63,.12); }
.login-brand { display:flex; align-items:center; gap:12px; margin-bottom:26px; }
.login-brand strong,.login-brand span { display:block; }
.login-brand strong { font-size:17px; }
.login-brand span { color:#8a96a6; font-size:12px; margin-top:2px; }
.login-card h1 { margin:0; font-size:22px; }
.login-card > p { margin:7px 0 22px; color:#8792a1; font-size:12px; line-height:1.6; }
.login-warning,.login-error { padding:11px 12px; border-radius:10px; font-size:11px; line-height:1.55; margin:0 0 14px; }
.login-warning { background:#fff8e8; border:1px solid #f0dfad; color:#7e6a34; }
.login-error { background:#fff0f2; border:1px solid #f3ccd1; color:#a63b48; }
.login-submit { width:100%; margin-top:16px; }

/* ================================================================
   HOSTING EDITION v2 — MOBILE UX PASS
   ================================================================ */
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.mobile-preview-toggle { display: none; border: 1px solid #d7e0ea; background: #fff; color: #466076; border-radius: 10px; min-height: 38px; padding: 0 12px; font-size: 11px; font-weight: 800; }
.mobile-preview-toggle.active { color: #147fb8; border-color: #9ed5f1; background: #eef9ff; }

/* Better touch/keyboard behavior without changing desktop density. */
.rich-editor { overflow-wrap: anywhere; word-break: break-word; }
.editor-toolbar { scrollbar-width: thin; }
.toolbar-btn, .small-button, .primary-button, .secondary-button, .text-button, .icon-button { touch-action: manipulation; }

@media (max-width: 820px) {
  :root { --mobile-nav-h: 70px; --mobile-action-h: 64px; }
  html { scroll-behavior: smooth; }
  body { padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)); overflow-x: hidden; }
  button, input, select, textarea, .rich-editor { -webkit-tap-highlight-color: transparent; }

  .app-shell { display: block; min-height: 100dvh; }
  .main { width: 100%; min-width: 0; }

  /* Bottom app navigation: thumb-friendly, never cramped in a top row. */
  .sidebar {
    position: fixed;
    z-index: 80;
    inset: auto 0 0 0;
    width: 100%;
    min-height: 0;
    height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
    padding: 6px 8px env(safe-area-inset-bottom);
    display: block;
    background: rgba(17,24,39,.97);
    border-top: 1px solid rgba(255,255,255,.08);
    backdrop-filter: blur(16px);
  }
  .brand, .side-footer { display: none !important; }
  .nav { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 2px; height: 100%; }
  .nav-item {
    min-width: 0;
    height: 58px;
    border-radius: 12px;
    padding: 5px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 9.5px;
    line-height: 1.05;
    text-align: center;
    white-space: nowrap;
  }
  .nav-item span { width: auto; font-size: 18px; line-height: 1; }
  .nav-item em { position: absolute; transform: translate(13px,-17px); min-width: 17px; padding: 1px 4px; font-size: 8px; }
  .nav-item { position: relative; }
  .nav-item.active { box-shadow: none; background: rgba(42,171,238,.18); }

  /* Compact sticky header. */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    min-height: 64px;
    height: auto;
    padding: 10px 14px;
    gap: 10px;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(18px);
  }
  .topbar h1 { font-size: 17px; letter-spacing: -.2px; }
  .topbar p { display: none; }
  .topbar-actions { margin-left: auto; gap: 6px; }
  .connection-pill { max-width: 118px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 7px 9px; font-size: 9.5px; }
  .mobile-preview-toggle { display: inline-flex; align-items: center; justify-content: center; }

  .view { padding: 14px 12px 24px; }
  #view-create { padding-bottom: calc(var(--mobile-action-h) + 28px); }
  .composer-grid { display: block; }
  .editor-column, .preview-column { width: 100%; min-width: 0; }

  /* Preview is intentionally collapsible on phones. */
  .preview-column { display: none; margin-bottom: 14px; }
  .preview-column.mobile-open { display: block; }
  .preview-sticky { position: static; }
  .preview-title { margin: 0 2px 7px; }
  .phone { max-width: 100%; width: 100%; border-radius: 18px; padding: 5px; box-shadow: 0 10px 28px rgba(31,50,80,.11); }
  .phone-top { height: 32px; padding: 0 9px; }
  .telegram-bg { min-height: 0; padding: 8px 6px 10px; border-radius: 14px; }
  .tg-message { border-radius: 10px; }
  .preview-image { width: 100%; height: auto; max-height: none; object-fit: contain; }
  .preview-note { margin-top: 7px; font-size: 9px; }

  /* Cards and form controls. */
  .card { padding: 16px 14px; border-radius: 15px; margin-bottom: 12px; box-shadow: 0 7px 22px rgba(22,37,63,.055); }
  .card-head { margin-bottom: 14px; gap: 8px; }
  .card-head h2 { font-size: 14px; }
  .step { height: 25px; min-width: 25px; }
  .field-label { margin: 14px 0 7px; font-size: 12px; }
  .field-label small { display: inline; }
  .input, .mini-select { min-height: 46px; font-size: 16px; }
  .input { height: 46px; padding: 0 11px; }
  .mini-select { height: 40px; min-width: 108px; font-size: 13px; }
  .field-hint, .format-help, .button-tip { font-size: 10.5px; }

  /* Upload area uses a lower height and bigger tap target. */
  .upload-box { min-height: 96px; }
  .upload-selected { grid-template-columns: 64px minmax(0,1fr) 44px; gap: 9px; }
  .upload-selected img { width: 64px; height: 64px; }
  .upload-selected strong { max-width: 100%; }
  .icon-button { min-width: 42px; width: 42px; height: 42px; }

  /* Rich text controls stay on one horizontally scrollable row. */
  .label-row { align-items: center; }
  .editor-toolbar {
    position: sticky;
    top: 64px;
    z-index: 25;
    margin: 8px -4px 9px;
    padding: 6px 4px;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    background: rgba(255,255,255,.97);
    border-bottom: 1px solid #edf0f4;
  }
  .toolbar-group, .toolbar-group.right { flex: 0 0 auto; flex-wrap: nowrap; margin-left: 0; }
  .toolbar-btn { flex: 0 0 auto; min-width: 44px; height: 42px; padding: 0 11px; font-size: 13px; }
  .toolbar-btn.wide { min-width: auto; }
  .emoji-panel {
    display: grid;
    grid-template-columns: repeat(6, minmax(0,1fr));
    gap: 7px;
    padding: 9px;
    max-height: 184px;
    overflow-y: auto;
  }
  .emoji-chip { width: 100%; height: 42px; font-size: 19px; }
  .rich-editor {
    min-height: 190px;
    max-height: 48dvh;
    overflow-y: auto;
    padding: 13px;
    font-size: 16px;
    line-height: 1.55;
    border-radius: 12px;
    -webkit-overflow-scrolling: touch;
  }

  /* Inline button editor: text/url full-width; row + actions compact underneath. */
  .button-row-editor {
    grid-template-columns: minmax(0,1fr) 44px 44px !important;
    gap: 8px;
    padding: 10px;
    border-radius: 12px;
  }
  .button-row-editor .btn-text,
  .button-row-editor .btn-url { grid-column: 1 / -1; width: 100%; min-height: 44px; height: 44px; font-size: 15px; }
  .button-row-editor .btn-row { grid-column: 1; width: 100%; min-height: 42px; height: 42px; font-size: 13px; }
  .button-row-editor .save-preset { grid-column: 2; }
  .button-row-editor .remove-btn { grid-column: 3; }
  .small-button { min-height: 42px; font-size: 11.5px; padding: 0 12px; }
  .preset-library-head { display: block; margin-top: 14px; }
  .preset-library-head span { display: block; margin-top: 4px; }
  .preset-list { display: grid; grid-template-columns: 1fr; gap: 7px; }
  .preset-chip { width: 100%; }
  .preset-chip-main { flex: 1; min-width: 0; }
  .preset-chip-main span { max-width: none; }
  .preset-chip-delete { min-width: 44px; width: 44px; }

  /* Channels become large tap cards. */
  .channel-select-head { align-items: center; }
  .text-button { min-height: 40px; padding: 0 8px; }
  .channel-picker { display: grid; grid-template-columns: 1fr !important; gap: 8px; }
  .channel-option { min-height: 54px; padding: 10px 11px; border-radius: 12px; }
  .channel-option input { width: 20px; height: 20px; }
  .schedule-box { display: block !important; padding: 12px; }
  .schedule-input { margin-top: 10px; width: 100% !important; }

  /* Bottom sticky publishing controls above the app nav. */
  .action-bar.action-bar-wrap {
    position: fixed;
    z-index: 70;
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
    height: var(--mobile-action-h);
    padding: 7px 8px;
    margin: 0;
    display: grid;
    grid-template-columns: .8fr .9fr 1.15fr 1.15fr;
    gap: 6px;
    background: rgba(255,255,255,.96);
    border-top: 1px solid #e4e9f0;
    box-shadow: 0 -8px 24px rgba(25,39,62,.08);
    backdrop-filter: blur(14px);
  }
  .action-bar.action-bar-wrap button { min-width: 0; min-height: 48px; height: 48px; padding: 0 5px; font-size: 9.8px; border-radius: 10px; line-height: 1.1; }
  .action-bar.action-bar-wrap .primary-button { box-shadow: none; }

  /* Lists: cards, not desktop tables. */
  .list-toolbar { gap: 8px; margin-bottom: 12px; }
  .list-toolbar p { font-size: 11px; }
  .record-grid { grid-template-columns: 1fr; gap: 10px; }
  .record-card { border-radius: 13px; }
  .record-image, .record-no-image { aspect-ratio: 16/8.5; }
  .record-actions button { min-height: 42px; }

  .scheduled-card {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 9px !important;
    padding: 13px !important;
    border-radius: 14px;
  }
  .scheduled-time { display: flex !important; align-items: baseline; gap: 7px; }
  .scheduled-time strong, .scheduled-time span { display: inline !important; }
  .scheduled-title-row { align-items: flex-start; gap: 8px; }
  .scheduled-title-row h3 { white-space: normal; }
  .scheduled-actions { display: grid !important; grid-template-columns: 1fr 1fr; gap: 7px; width: 100%; }
  .scheduled-actions button { width: 100%; min-height: 42px; }

  .history-list { gap: 9px; }
  .history-item {
    display: grid !important;
    grid-template-columns: 42px minmax(0,1fr) !important;
    gap: 8px 10px !important;
    padding: 12px !important;
    border-radius: 14px;
  }
  .history-main strong { white-space: normal; line-height: 1.25; }
  .history-main span { white-space: normal; line-height: 1.25; }
  .history-date, .history-message { display: inline !important; grid-column: 2; text-align: left !important; font-size: 9.5px; }
  .history-message { margin-top: -5px; }
  .history-actions {
    grid-column: 1 / -1 !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
    width: 100% !important;
    justify-self: stretch !important;
  }
  .history-actions button { width: 100%; min-height: 42px; }

  /* Settings: clean single column with larger channel controls. */
  .settings-wrap { display: block; }
  .settings-card, .guide-card { margin-bottom: 12px; }
  .password-row { grid-template-columns: minmax(0,1fr) 70px; }
  .settings-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
  .settings-actions button { width: 100%; min-height: 46px; }
  .channel-add-grid { grid-template-columns: 1fr !important; gap: 8px !important; }
  .channel-add-grid button { min-height: 46px; width: 100%; }
  .settings-channel-item { grid-template-columns: minmax(0,1fr) 44px !important; gap: 8px !important; }
  .settings-channel-item .small-button { min-width: 44px; padding: 0; }

  /* Modals become mobile bottom sheets with safe scrolling. */
  .modal { align-items: end; padding: 0; }
  .modal-card {
    width: 100%;
    max-width: none;
    max-height: 90dvh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    padding: 18px 15px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -18px 48px rgba(11,21,38,.2);
  }
  .modal-actions { position: sticky; bottom: 0; padding-top: 10px; background: linear-gradient(transparent, #fff 25%); display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; }
  #confirmModal .modal-actions { grid-template-columns: 1fr 1fr; }
  .modal-actions button { min-height: 46px; padding: 0 8px; }

  /* Toast avoids both fixed bars. */
  .toast { left: 12px; right: 12px; bottom: calc(var(--mobile-nav-h) + var(--mobile-action-h) + env(safe-area-inset-bottom) + 10px); max-width: none; text-align: center; font-size: 11px; }
}

@media (max-width: 390px) {
  .connection-pill { display: none; }
  .topbar h1 { font-size: 16px; }
  .mobile-preview-toggle { padding: 0 9px; }
  .nav-item { font-size: 8.8px; }
  .action-bar.action-bar-wrap { gap: 4px; padding-left: 5px; padding-right: 5px; }
  .action-bar.action-bar-wrap button { font-size: 9px; }
  .emoji-panel { grid-template-columns: repeat(5, minmax(0,1fr)); }
}

/* Login page mobile polish */
@media (max-width: 620px) {
  .login-page { min-height: 100dvh; padding: 18px 12px; align-items: center; }
  .login-card { width: 100%; max-width: 430px; padding: 24px 18px; border-radius: 18px; }
  .login-card .input { height: 48px; font-size: 16px; }
  .login-submit { width: 100%; min-height: 48px; }
}
