:root {
  --bg: #f4f6f9; --card: #fff; --text: #1d2330; --muted: #6b7486; --line: #e3e7ee;
  --accent: #2481cc; --accent-dark: #1b6aa8; --green: #2e9e5b; --red: #d64545; --amber: #c98a00;
  --blue-bg: #e7f1fb; --green-bg: #e5f5ec; --red-bg: #fbeaea; --amber-bg: #fff4d6; --grey-bg: #eef0f4;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
h4 { font-size: 13px; margin: 8px 0 4px; color: var(--muted); }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.red { color: var(--red); } .ok-text { color: var(--green); } .warn-text { color: var(--amber); }
.hidden { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 16px; background: #17212b; color: #fff; padding: 0 20px; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.top .brand a { color: #fff; font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; padding: 12px 0; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 15px; }
.logo.big { width: 56px; height: 56px; font-size: 28px; margin: 0 auto 8px; }
.top nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.top nav a { color: #c9d4df; padding: 16px 12px; border-bottom: 3px solid transparent; display: flex; align-items: center; gap: 6px; }
.top nav a:hover { color: #fff; text-decoration: none; }
.top nav a.on { color: #fff; border-bottom-color: var(--accent); }
.top .logout .link { color: #c9d4df; }
.badge { background: var(--accent); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; line-height: 18px; }
.badge.red { background: var(--red); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: #4cd07d; } .dot.bad { background: #ff6b6b; }

.banner { padding: 10px 20px; font-size: 14px; }
.banner.test { background: #6c3fc5; color: #fff; } .banner.test a { color: #fff; text-decoration: underline; }
.banner.warn { background: var(--amber-bg); color: #6b4a00; border-bottom: 1px solid #f0dca0; }

main { max-width: 1240px; margin: 0 auto; padding: 16px 20px 40px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 12px; }

/* cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card.narrow { max-width: 460px; }
.card.note { background: var(--blue-bg); border-color: #cfe2f5; font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-gap { display: flex; gap: 8px; align-items: center; }
.row-gap.wrap { flex-wrap: wrap; margin-bottom: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
form.inline { display: inline; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c4ccd8; text-decoration: none; background: #fafbfc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger-outline { color: var(--red); border-color: #efc4c4; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 4px 0; }

/* forms */
label { display: block; margin: 10px 0; font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
label.check.sub { margin-left: 26px; color: var(--muted); }
label.check input { margin-top: 4px; }
.inline-label { display: inline-flex; gap: 8px; align-items: center; margin: 0; font-weight: 400; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfd6e0; border-radius: 8px; background: #fff; color: var(--text); }
label > input:not([type=checkbox]), label > select, label > textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus, .editor:focus { outline: 2px solid #a8cdee; border-color: var(--accent); }
.w80 { width: 80px; }
.form-grid h2 { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }
.form-grid h2:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
.hint { display: block; color: var(--muted); font-size: 13px; font-weight: 400; margin-top: 4px; }
.inline-fields { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.or { color: var(--muted); font-size: 13px; text-align: center; }
details summary { cursor: pointer; color: var(--accent); margin: 10px 0; }

/* flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.flash.ok { background: var(--green-bg); border-color: #bfe3cd; color: #1e6b3e; }
.flash.error { background: var(--red-bg); border-color: #f0c4c4; color: #8c2424; }
.flash.warn { background: var(--amber-bg); border-color: #f0dca0; color: #6b4a00; }

/* chips */
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--grey-bg); color: #4b5466; white-space: nowrap; }
.chip.big { font-size: 14px; padding: 4px 12px; }
.chip.green, .st-published { background: var(--green-bg); color: #1e6b3e; }
.chip.red, .st-error { background: var(--red-bg); color: #a12c2c; }
.chip.blue, .st-pending { background: var(--blue-bg); color: #1b5f96; }
.st-scheduled { background: #efe7fb; color: #5b33a3; }
.st-received { background: var(--amber-bg); color: #7a5600; }
.st-sending { background: #e0f4f7; color: #0f6a7a; }
.st-cancelled, .chip.grey { background: var(--grey-bg); color: #6b7486; }

/* tables */
.table { width: 100%; border-collapse: collapse; background: var(--card); }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 13px; color: var(--muted); font-weight: 500; }
tr.off td { opacity: .6; }
.events td { font-size: 14px; }
.lvl-error td { background: #fff6f6; } .lvl-warning td { background: #fffbef; }
.check-results td.icon { width: 32px; font-size: 18px; }

/* dashboard */
.pair-card.off { opacity: .7; }
.pair-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.route { margin: 6px 0 10px; font-size: 14px; }
.arrow { color: var(--accent); font-weight: 700; padding: 0 4px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stats > div { background: var(--bg); border-radius: 8px; padding: 8px; text-align: center; }
.stats .num { display: block; font-size: 22px; font-weight: 600; }
.stats .num.red { color: var(--red); }
.stats span:not(.num) { font-size: 12px; color: var(--muted); }
.err-line { color: #a12c2c; margin-top: 6px; }
.steps ol { margin: 0; padding-left: 20px; } .steps li { margin: 6px 0; } .steps li.done { text-decoration: line-through; color: var(--muted); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
.tabs .cnt { background: var(--grey-bg); border-radius: 9px; padding: 0 7px; font-size: 12px; }
.tabs .cnt.red { background: var(--red); color: #fff; }

/* post list */
.post-list { display: flex; flex-direction: column; gap: 8px; }
.post-row { display: grid; grid-template-columns: 170px 1fr 150px; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; color: var(--text); }
.post-row:hover { border-color: #b9c6d6; text-decoration: none; box-shadow: 0 2px 6px rgba(0,0,0,.04); }
.post-row.status-error { border-left: 3px solid var(--red); }
.post-row.status-scheduled { border-left: 3px solid #7b4fc8; }
.post-row .thumbs { display: flex; gap: 4px; }
.post-row .thumbs img, .post-row .ph { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; background: var(--grey-bg); display: grid; place-items: center; font-size: 20px; }
.post-row .ph.more { font-size: 13px; color: var(--muted); }
.post-row .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; font-size: 13px; }
.post-row .text { font-size: 14px; }
.post-row .when { text-align: right; color: var(--muted); }
@media (max-width: 760px) { .post-row { grid-template-columns: 1fr; } .post-row .when { text-align: left; } }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }

/* post page */
.facts > div { display: grid; grid-template-columns: 200px 1fr; gap: 12px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.facts > div:last-child { border-bottom: 0; }
.facts span { color: var(--muted); }
.facts .err { color: #a12c2c; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.media-item img, .media-item .ph.big { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--grey-bg); display: grid; place-items: center; font-size: 40px; }

/* telegram-like preview */
.tg-preview { background: #eef5fb; border-radius: 10px; padding: 12px 14px; white-space: normal; word-wrap: break-word; min-height: 40px; font-size: 15px; }
.tg-preview blockquote { border-left: 3px solid var(--accent); margin: 6px 0; padding: 2px 10px; background: rgba(36,129,204,.08); border-radius: 4px; }
.tg-preview pre { background: rgba(0,0,0,.05); padding: 8px; border-radius: 6px; white-space: pre-wrap; }
.tg-preview code { background: rgba(0,0,0,.06); padding: 0 4px; border-radius: 4px; }
.tg-spoiler { background: #9aa4b2; color: transparent; border-radius: 3px; transition: .2s; }
.tg-spoiler:hover, .editor .tg-spoiler { color: inherit; background: #d5dbe3; }
.removed { margin: 4px 0; padding-left: 20px; color: #8c2424; }
.preview-item { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }

/* editor */
.editor-toolbar { display: flex; gap: 4px; margin-bottom: 6px; flex-wrap: wrap; }
.editor-toolbar button { border: 1px solid var(--line); background: #fff; border-radius: 6px; min-width: 34px; height: 32px; cursor: pointer; font-size: 14px; }
.editor-toolbar button:hover { background: var(--blue-bg); }
.editor { min-height: 180px; border: 1px solid #cfd6e0; margin-bottom: 8px; }

.danger-zone { border-color: #f0c4c4; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; background: #17212b; }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 360px; max-width: 92vw; text-align: center; }
.login-card h1 { margin: 4px 0; }
.login-card label { text-align: left; }
