:root {
  --bg: #f4f6f8; --card: #ffffff; --accent: #2481cc; --accent-dark: #1c6aa8;
  --text: #1c2733; --muted: #6b7785; --border: #dce3ea;
  --ok-bg: #e7f6ec; --ok-border: #36a35b; --err-bg: #fdecec; --err-border: #d33;
  --warn: #b46b00; --sel: #2481cc; --tg-bg: #eeffde;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* ensure hidden beats display:flex etc. */
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
.muted { color: var(--muted); } .small { font-size: .8rem; } .hint { color: var(--muted); font-size: .85rem; }

/* ---------- generic form / button ---------- */
.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .35rem; }
.field a { color: var(--accent); font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=file], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  font-size: .92rem; background: #fbfcfd; color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.row2 { display: flex; gap: .75rem; } .row2 .field { flex: 1; }
.stack > * { margin-bottom: .75rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--muted); }
.checkbox.inline { margin: 0; } .checkbox input { width: auto; }
.color-row { display: flex; align-items: center; gap: .75rem; }
.color-row input[type=color] { width: 48px; height: 34px; padding: 2px; }
details summary { cursor: pointer; font-size: .88rem; color: var(--accent); margin-bottom: .6rem; }

button { padding: .65rem .9rem; border: none; border-radius: 8px; font-size: .92rem; font-weight: 600; cursor: pointer; background: #eef2f6; color: var(--text); }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
button.ghost:hover { background: #eef4fb; }
button.ghost.danger { color: #c0392b; border-color: #f0c4bd; }
button.small { font-size: .75rem; padding: .25rem .5rem; }
button:disabled { opacity: .5; cursor: not-allowed; }

.status, .result { margin-top: .75rem; padding: .7rem .9rem; border-radius: 8px; font-size: .88rem; }
.status { background: #eef4fb; border: 1px solid var(--border); color: var(--muted); }
.status.ok2 { background: var(--ok-bg); border-color: var(--ok-border); color: #226b3c; }
.status.err, .result.err { background: var(--err-bg); border: 1px solid var(--err-border); color: #a11; }
.result.ok { background: var(--ok-bg); border: 1px solid var(--ok-border); }
.result a { color: var(--accent-dark); font-weight: 600; word-break: break-all; }
.result .meta { color: var(--muted); font-size: .82rem; margin-top: .5rem; }
.token { font-family: monospace; font-size: .78rem; background: #fff; padding: .2rem .35rem; border-radius: 5px; border: 1px solid var(--border); word-break: break-all; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: .5rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 1.5rem; box-shadow: 0 4px 16px rgba(0,0,0,.05); }
.card h1, .card h2 { margin: 0 0 .25rem; } .card h2 { font-size: 1.2rem; }
.sub { margin: 0 0 1.25rem; color: var(--muted); font-size: .9rem; }

/* ---------- login ---------- */
.center-screen { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.login-card { max-width: 380px; width: 100%; }

/* ---------- navbar ---------- */
.navbar { display: flex; align-items: center; gap: 1.5rem; padding: 0 1.25rem; height: 56px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.nav-brand { font-weight: 700; }
.nav-tabs { display: flex; gap: .25rem; flex: 1; }
.nav-tab { background: transparent; color: var(--muted); border-radius: 8px; }
.nav-tab.active { background: #eaf2fb; color: var(--accent-dark); }
.nav-user { display: flex; align-items: center; gap: .75rem; }

.tab-panel { display: none; padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
.tab-panel.active { display: block; }

/* ---------- Telegram composer ---------- */
.composer { display: flex; gap: 1.25rem; align-items: flex-start; }
.composer-main { flex: 1 1 55%; min-width: 0; }
.composer-preview { flex: 1 1 45%; min-width: 0; position: sticky; top: 72px; }
.toolbar2 { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .5rem; }
.tb { width: 38px; height: 36px; padding: 0; background: var(--card); border: 1px solid var(--border); font-size: .95rem; }
.tb:hover { background: #eef4fb; }
#tg-input { width: 100%; min-height: 320px; resize: vertical; font-family: "Segoe UI", system-ui, sans-serif; line-height: 1.5; overflow-wrap: anywhere; word-break: break-word; }
.composer-actions { display: flex; justify-content: space-between; gap: 1rem; margin-top: .6rem; flex-wrap: wrap; }
.ai-group, .footer-group { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.ai-btn { background: #f0e9ff; color: #5b3fb0; }
.ai-btn:hover { background: #e6dcff; }
.mini-select { width: auto; padding: .4rem .5rem; font-size: .82rem; }

.phone { background: #cfe3f7; border-radius: 16px; padding: 1.25rem; min-height: 200px; }
.tg-bubble { background: var(--tg-bg); border-radius: 12px; padding: .6rem .75rem; max-width: 100%; font-size: 15px; line-height: 1.45; color: #0b0b0b; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; overflow-wrap: anywhere; }
.tg-bubble p { margin: 0 0 .5rem; } .tg-bubble p:last-child { margin-bottom: 0; }
.tg-bubble .tg-empty { color: #8a9; }
.tg-bubble a { color: #168acd; text-decoration: none; }
.tg-bubble blockquote { border-left: 3px solid #3aa3df; margin: .4rem 0; padding: .1rem 0 .1rem .6rem; color: #33414d; }
.tg-bubble code { background: rgba(0,0,0,.06); padding: 0 .25rem; border-radius: 4px; font-family: Menlo, Consolas, monospace; font-size: 13px; }
.tg-bubble pre { background: rgba(0,0,0,.06); padding: .5rem .6rem; border-radius: 8px; overflow-x: auto; margin: .4rem 0; }
.tg-bubble pre code { background: none; padding: 0; }
.tg-spoiler { background: #6b7785; color: transparent; border-radius: 3px; cursor: pointer; user-select: none; }
.tg-spoiler.revealed { background: rgba(0,0,0,.06); color: inherit; }
.copy-row { display: flex; align-items: center; gap: .6rem; margin-top: .75rem; }
.corrections { margin-top: .6rem; padding: .6rem .8rem; background: #f5f8fb; border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; max-height: 220px; overflow: auto; }
.corrections ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.corrections li { margin: .15rem 0; }

/* ---------- docx tab ---------- */
.subbar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.subbar .hint { flex: 1; }
.editor { display: flex; align-items: flex-start; gap: 1.25rem; }
.preview-pane { flex: 1 1 auto; min-width: 0; }
.preview-frame { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 2rem 1.5rem; }
.side-pane { flex: 0 0 320px; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 72px; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem 1.2rem; }
.panel h3 { margin: 0 0 .75rem; font-size: 1rem; display: flex; justify-content: space-between; align-items: center; }

/* Telegra.ph-faithful preview */
.tl_preview { font-family: Georgia, "Times New Roman", serif; color: #000; font-size: 20px; line-height: 30px; max-width: 640px; margin: 0 auto; }
.tl_preview .tl-title { font-size: 38px; line-height: 1.2; font-weight: 700; margin: 0 0 8px; font-family: inherit; color: #000; }
.tl_preview h3 { font-size: 24px; line-height: 32px; font-weight: 600; margin: 30px 0 0; }
.tl_preview h4 { font-size: 20px; line-height: 28px; font-weight: 600; margin: 24px 0 0; }
.tl_preview p { margin: 20px 0 0; }
.tl_preview ul, .tl_preview ol { margin: 20px 0 0; padding-left: 24px; }
.tl_preview a { color: #3979d1; text-decoration: none; }
.tl_preview blockquote { border-left: 3px solid #000; margin: 20px 0 0; padding-left: 20px; }
.tl_preview figure { margin: 24px 0 0; text-align: center; }
.tl_preview figure img { max-width: 100%; height: auto; }
.tl_preview figcaption { color: #8d96a0; font-size: 15px; margin-top: 6px; }
.tl_preview figure img.tl-selectable { cursor: pointer; border: 3px solid transparent; border-radius: 4px; }
.tl_preview figure img.tl-selectable:hover { border-color: #b9d6f2; }
.tl_preview figure img.selected { border-color: var(--sel); box-shadow: 0 0 0 3px rgba(36,129,204,.25); }
.tl_preview figure.tl-group { position: relative; }
.tl_preview figure.tl-group img { border: 3px solid #36a35b; border-radius: 4px; cursor: pointer; }
.tl_preview figure.tl-group.active img { border-color: var(--sel); box-shadow: 0 0 0 3px rgba(36,129,204,.25); }
.tl-badge { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); background: #36a35b; color: #fff; font-family: -apple-system, sans-serif; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.tl_preview figure.tl-group.active .tl-badge { background: var(--sel); }
.tl_preview figure img.tl-selectable.editing { border-color: var(--sel); box-shadow: 0 0 0 3px rgba(36,129,204,.25); }

/* layers list (images inside a merged group) */
.layers { margin-top: .9rem; }
.layers-head { font-size: .78rem; color: var(--muted); margin-bottom: .4rem; }
.layer { display: flex; align-items: center; gap: .5rem; padding: .3rem; border: 1px solid var(--border); border-radius: 8px; margin-bottom: .35rem; cursor: pointer; background: #fbfcfd; }
.layer.active { border-color: var(--sel); box-shadow: 0 0 0 2px rgba(36,129,204,.18); }
.layer-thumb { width: 40px; height: 30px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }
.layer-label { flex: 1; font-size: .82rem; }
.layer-ctrls { display: flex; gap: .25rem; }
.layer-ctrls button { width: 26px; padding: .2rem 0; }
#i-actions { margin-top: .6rem; }
.crop-row { display: flex; align-items: center; gap: .5rem; }

/* crop modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal { background: var(--card); border-radius: 12px; padding: 1.25rem; max-width: 92vw; max-height: 92vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 .25rem; }
.crop-stage { position: relative; display: inline-block; margin: .75rem 0; line-height: 0; user-select: none; touch-action: none; }
.crop-stage img { display: block; max-width: min(70vw, 700px); max-height: 62vh; }
#crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--accent), 0 0 0 9999px rgba(0,0,0,.45); cursor: move; box-sizing: border-box; touch-action: none; }
#crop-box .ch { position: absolute; width: 16px; height: 16px; background: #fff; border: 2px solid var(--accent); border-radius: 50%; box-sizing: border-box; }
#crop-box .ch[data-h=nw] { left: -8px; top: -8px; cursor: nwse-resize; }
#crop-box .ch[data-h=ne] { right: -8px; top: -8px; cursor: nesw-resize; }
#crop-box .ch[data-h=sw] { left: -8px; bottom: -8px; cursor: nesw-resize; }
#crop-box .ch[data-h=se] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.modal-actions { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; }

/* ---------- settings / admin ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
.kv-row { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: none; }
.row-actions { display: flex; gap: .4rem; }
.tag { background: #eaf2fb; color: var(--accent-dark); font-size: .72rem; padding: 1px 7px; border-radius: 10px; }
.admin-card { max-width: 640px; }

/* help / tutorials */
.help-wrap { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; }
.help-wrap h2 { font-size: 1.2rem; }
.help-wrap h3 { margin: 1.1rem 0 .35rem; font-size: .96rem; color: var(--accent-dark); }
.help-steps { margin: .4rem 0 0; padding-left: 1.4rem; line-height: 1.55; font-size: .92rem; }
.help-steps li { margin: .35rem 0; }
.help-wrap a { color: var(--accent); }
.user-edit { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; padding: .5rem .6rem; margin: 0 0 .5rem; background: #f5f8fb; border: 1px solid var(--border); border-radius: 8px; }
.user-edit input { width: auto; flex: 1; min-width: 130px; }
.user-edit .ue-status { flex-basis: 100%; }

@media (max-width: 900px) {
  .composer, .editor { flex-direction: column; }
  .composer-preview, .side-pane { position: static; width: 100%; flex-basis: auto; }
  .nav-tabs { overflow-x: auto; }
}
