/* ---------- Theme tokens (Telegram vars with graceful fallbacks) ---------- */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-accent-text-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #efeff3);
  --section-bg: var(--tg-theme-section-bg-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, #e53935);

  /* Chat preview palette */
  --chat-bg-1: #cfd9e3;
  --chat-bg-2: #e6e2dd;
  --bubble-bg: #ffffff;
  --bubble-text: #000000;
  --bubble-meta: rgba(0, 0, 0, 0.35);
  --bubble-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
  --kbd-bg: rgba(255, 255, 255, 0.5);
  --kbd-text: #2481cc;

  --radius: 14px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #7d8b99);
    --link: var(--tg-theme-link-color, #6ab3f3);
    --accent: var(--tg-theme-accent-text-color, #6ab3f3);
    --button: var(--tg-theme-button-color, #5288c1);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #232e3c);
    --section-bg: var(--tg-theme-section-bg-color, #17212b);

    --chat-bg-1: #0e1621;
    --chat-bg-2: #1c2733;
    --bubble-bg: #182533;
    --bubble-text: #ffffff;
    --bubble-meta: rgba(255, 255, 255, 0.45);
    --bubble-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --kbd-bg: rgba(20, 30, 43, 0.46);
    --kbd-text: #6ab3f3;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* App shell: the body is exactly the Telegram viewport height (set in pixels
   from JS, see applyViewport in app.js), so the page itself never scrolls.
   The topbar + preview are fixed flex items; only the editor scrolls. */
html, body { overflow: hidden; }
body {
  height: var(--app-h, 100dvh);
  max-height: var(--app-h, 100dvh);
  padding-top: var(--safe-top);
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

/* ---------- Topbar / channel picker ---------- */
.topbar {
  flex: 0 0 auto;
  z-index: 30;
  background: var(--bg);
  padding: 8px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 18%, transparent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.channel-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 4px 4px;
  color: var(--text);
  cursor: pointer;
}

.user-avatar {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 16px; overflow: hidden;
  background-color: #6f42c1;
  background-image: linear-gradient(135deg, #9b6dff, #6f42c1);
  background-size: cover; background-position: center;
  transition: transform 0.08s ease;
}
.user-avatar:active { transform: scale(0.92); }

.ch-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 17px;
  color: #fff;
  overflow: hidden;
  background-color: #2d7fd6;
  background-image: linear-gradient(135deg, #5ca8f0, #2d7fd6);
  background-size: cover;
  background-position: center;
}

.ch-meta { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; flex: 1; }
.ch-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw; }
.ch-sub { font-size: 13px; color: var(--hint); }
.chevron { color: var(--hint); flex: 0 0 auto; }

/* ---------- Preview ---------- */
/* Tabs */
.tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 5px;
  padding: 6px 12px 8px;
  background: var(--bg);
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 14%, transparent);
}
.tab {
  flex: 1;
  padding: 9px;
  border: 0;
  border-radius: 9px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab.active { background: var(--accent); color: #fff; }

/* The active tab's panel is the scroll region. */
.preview-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  z-index: 20;
  display: flex;
  flex-direction: column;
}
.preview-wrap .chat-bg { flex: 1 1 auto; }

.chat-bg {
  position: relative;
  padding: 18px 12px 20px;
  background:
    radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--chat-bg-1) 70%, transparent), transparent),
    linear-gradient(160deg, var(--chat-bg-1), var(--chat-bg-2));
  border-bottom: 1px solid color-mix(in srgb, #000 8%, transparent);
}

.msg-line {
  display: flex;
  align-items: flex-end;
  gap: 7px;
}
.msg-avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #2d7fd6;
  background-image: linear-gradient(135deg, #5ca8f0, #2d7fd6);
  background-size: cover;
  background-position: center;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
}

.bubble {
  max-width: calc(100% - 43px);
  width: fit-content;
  background: var(--bubble-bg);
  color: var(--bubble-text);
  border-radius: 16px;
  border-top-left-radius: 6px;
  box-shadow: var(--bubble-shadow);
  overflow: hidden;
  padding: 7px 9px 6px;
  /* Force a clipping layer so border-radius actually clips media in WebKit
     (iOS Telegram WebView), where overflow:hidden alone can leak square corners. */
  transform: translateZ(0);
  isolation: isolate;
}
/* A bubble with a photo/video gets a definite width: avoids the
   fit-content + image-width:100% sizing cycle that broke the borders. */
.bubble.has-media {
  width: min(72vw, 300px);
}

.bubble-author {
  font-weight: 600;
  font-size: 14px;
  color: var(--bubble-accent, #3aa0e0);
  margin-bottom: 2px;
  padding: 0 1px;
}

.bubble-media {
  position: relative;
  /* Bleed to the side edges (cancel the 9px side padding) but NOT upward:
     a negative top margin used to pull the square corners over the bubble's
     rounded top in WebKit, which is what looked broken. */
  margin: 0 -9px 6px;
  background: #000;
  line-height: 0;
  overflow: hidden;
}
.bubble-media img,
.bubble-media video {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
}
.play-badge {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  backdrop-filter: blur(2px);
}

.bubble-text {
  font-size: 15.5px;
  line-height: 1.34;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  padding: 0 1px;
  min-height: 2px;
}
.bubble-text:empty::before {
  content: attr(data-placeholder);
  color: var(--bubble-meta);
}
.bubble-text a { color: var(--bubble-accent, #3aa0e0); text-decoration: none; pointer-events: none; }
.bubble-text code { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 0.92em; background: color-mix(in srgb, var(--bubble-text) 8%, transparent); padding: 1px 4px; border-radius: 5px; }
.bubble-text .tg-spoiler {
  background: color-mix(in srgb, var(--bubble-text) 22%, transparent);
  border-radius: 4px;
  color: transparent;
  filter: blur(0.2px);
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 12px;
  color: var(--bubble-meta);
  margin-top: 2px;
  padding: 0 1px;
  user-select: none;
}
.views { display: inline-flex; align-items: center; gap: 3px; }
.views svg { opacity: 0.8; }

/* Inline keyboard under the bubble (indented past the avatar) */
.kbd {
  margin-top: 4px;
  margin-left: 43px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kbd-row { display: flex; gap: 4px; }
.kbd-btn {
  flex: 1;
  position: relative;
  background: var(--kbd-bg);
  /* Frosted glass so a default (no-colour) button reads as transparent over the
     chat wallpaper, like a real Telegram inline button. */
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  color: var(--kbd-text);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  padding: 9px 10px;
  border-radius: 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--bubble-shadow);
}
.kbd-btn .ext {
  position: absolute;
  top: 4px;
  right: 5px;
  opacity: 0.5;
}
.kbd-btn.kbd-primary { background: #3390ec; color: #fff; }
.kbd-btn.kbd-success { background: #4dcd5e; color: #fff; }
.kbd-btn.kbd-danger { background: #e53935; color: #fff; }

/* ---------- Empty / loading ---------- */
.empty {
  flex: 1 1 auto;
  overflow-y: auto;
  text-align: center;
  padding: 60px 28px;
}
.empty-icon { color: var(--hint); opacity: 0.85; }
.empty-icon svg { display: inline-block; }
.error-gif { width: 150px; max-width: 62%; height: auto; border-radius: 14px; margin: 0 auto 8px; display: block; }
.btn-link {
  border: 0; background: transparent; color: var(--accent);
  font-size: 14px; cursor: pointer; padding: 10px; margin-top: 6px; width: 100%;
}
.empty h2 { font-size: 19px; margin: 14px 0 8px; }
.empty p { color: var(--hint); margin: 0 0 22px; font-size: 14.5px; }

.loading { flex: 1 1 auto; display: grid; place-items: center; padding: 80px 0; }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid color-mix(in srgb, var(--hint) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Editor (the only scrollable region) ---------- */
.editor {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 12px 0;
}

.card {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--hint) 12%, transparent);
}

.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.card-title { font-weight: 600; font-size: 15px; }
.card-hint { font-size: 12.5px; color: var(--hint); }

/* Media */
.media-row { display: flex; gap: 10px; align-items: center; }
.media-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  flex: 1 1 0; min-width: 0; height: 84px;
  border: 1.5px dashed color-mix(in srgb, var(--hint) 45%, transparent);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  text-align: center;
  cursor: pointer;
}
.media-thumb { position: relative; flex: 0 0 84px; width: 84px; height: 84px; border-radius: var(--radius-sm); overflow: hidden; background: #1c2733; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-thumb.is-video::after {
  content: "";
  position: absolute; inset: 0; margin: auto;
  width: 0; height: 0;
  border-style: solid;
  border-width: 11px 0 11px 18px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.92);
}
.media-remove {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); border: 0; cursor: pointer;
  display: grid; place-items: center;
  z-index: 2;
}
.media-thumb-icon {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--accent);
  background: var(--secondary-bg);
}
.media-badge {
  position: absolute; left: 4px; bottom: 4px;
  font-size: 10px; font-weight: 600; line-height: 1;
  padding: 3px 5px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  text-transform: uppercase; letter-spacing: 0.2px;
}
.media-progress {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff; font-size: 12px; font-weight: 700;
}
.mp-spinner {
  width: 22px; height: 22px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Media picker grid */
.media-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 2px;
}
.media-cell {
  position: relative;
  aspect-ratio: 1;
  border: 0; padding: 0; cursor: pointer;
  border-radius: 10px; overflow: hidden;
  background: var(--secondary-bg);
}
.media-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-cell .mc-icon { position: absolute; inset: 0; display: grid; place-items: center; color: var(--accent); }
.media-cell .mc-badge {
  position: absolute; left: 3px; bottom: 3px;
  font-size: 9px; font-weight: 600; line-height: 1;
  padding: 2px 4px; border-radius: 5px;
  background: rgba(0, 0, 0, 0.6); color: #fff; text-transform: uppercase;
}
.media-picker-empty { color: var(--hint); font-size: 14px; text-align: center; padding: 24px 10px 12px; }
.media-picker-empty p { margin: 0 0 10px; line-height: 1.4; }
.media-picker-empty .btn { margin-top: 6px; }

/* Attachment row in the bubble (voice / audio / file) */
.bubble-attach {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 1px 2px;
}
.bubble-attach .ba-icon {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #5ca8f0, #2d7fd6);
}
.bubble-attach .ba-text { display: flex; flex-direction: column; min-width: 0; }
.bubble-attach .ba-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubble-attach .ba-sub { font-size: 12px; color: var(--bubble-meta); }

/* Sticker: no bubble fill, contained, smaller */
.bubble.is-sticker { background: transparent; box-shadow: none; }
.bubble.is-sticker .bubble-author,
.bubble.is-sticker .bubble-meta { padding-left: 1px; }
.bubble.is-sticker .bubble-media { margin: 2px 0 4px; background: transparent; }
.bubble.is-sticker .bubble-media img { width: auto; max-width: 160px; max-height: 160px; object-fit: contain; }

/* Round video note */
.bubble-media.is-round { background: transparent; }
.bubble-media.is-round img,
.bubble-media.is-round video { width: 180px; height: 180px; border-radius: 50%; margin: 0 auto; }

/* Toolbar */
.toolbar { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar button {
  min-width: 38px; height: 36px; padding: 0 9px;
  border: 0; border-radius: 8px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
}
.toolbar button svg { display: block; }
.toolbar .tb-text { font-size: 15px; line-height: 1; }
.toolbar button:active { background: color-mix(in srgb, var(--accent) 22%, var(--secondary-bg)); }

/* Composer */
.composer {
  min-height: 80px;
  font-size: 15.5px;
  line-height: 1.4;
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.composer:empty::before { content: attr(data-placeholder); color: var(--hint); }
.composer .tg-spoiler { background: color-mix(in srgb, var(--text) 22%, transparent); border-radius: 4px; padding: 0 2px; }
.composer code { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--secondary-bg); padding: 1px 4px; border-radius: 5px; }
.composer a { color: var(--link); }
.composer.disabled { opacity: 0.4; pointer-events: none; }
.text-locked-hint { font-size: 12.5px; color: var(--hint); margin-top: 8px; line-height: 1.35; }

/* Buttons builder */
.btn-builder { display: flex; flex-direction: column; gap: 10px; }
.bb-row { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: var(--radius-sm); background: var(--secondary-bg); }
.bb-row-head { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--hint); }
.bb-btns { display: flex; flex-direction: column; gap: 10px; }
.bb-btn { display: flex; flex-direction: column; gap: 6px; }
.bb-btn-top { display: flex; gap: 6px; align-items: center; }
.bb-btn-top .field { flex: 1; }
.bb-del {
  flex: 0 0 auto; width: 38px; height: 38px; border: 0; border-radius: 9px;
  background: color-mix(in srgb, var(--destructive) 14%, transparent);
  color: var(--destructive); cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.08s ease;
}
.bb-del:active { transform: scale(0.92); }
.bb-row-del {
  border: 0; background: transparent; color: var(--destructive);
  cursor: pointer; padding: 4px 6px; font-size: 13px;
}
.bb-add-btn {
  align-self: flex-start; border: 0; background: transparent; color: var(--accent);
  font-size: 13.5px; cursor: pointer; padding: 2px 0;
}

.char-count {
  text-align: right;
  font-size: 12px;
  color: var(--hint);
  margin-top: 6px;
  user-select: none;
}
.char-count.over { color: var(--destructive); font-weight: 600; }

/* Inline-button colour picker */
.bb-colors { display: flex; gap: 9px; padding: 2px 1px 0; }
.bb-color {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid transparent; padding: 0; cursor: pointer;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hint) 35%, transparent);
}
.bb-color.active { border-color: var(--text); }
/* "Обычная" = transparent/normal button: a faint glassy swatch, clearly set
   apart from the solid colour dots. */
.bb-color-auto { background: color-mix(in srgb, var(--text) 8%, transparent); }
.bb-color-primary { background: #3390ec; }
.bb-color-success { background: #4dcd5e; }
.bb-color-danger { background: #e53935; }

.field {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--hint) 26%, transparent);
  background: color-mix(in srgb, var(--text) 9%, var(--secondary-bg));
  color: var(--text);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 14.5px;
  outline: none;
}
.field:focus { border-color: var(--accent); }

.add-row {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 10px; border: 0; background: transparent;
  color: var(--accent); font-size: 14px; cursor: pointer; padding: 4px 0;
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 11px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-secondary { background: var(--secondary-bg); color: var(--accent); }

/* Subtle press feedback across tappable controls */
.media-add, .media-cell, .channel-item, .add-row { transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease; }
.media-add:active, .media-cell:active { transform: scale(0.97); }
.media-add:active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.card { transition: box-shadow 0.2s ease; }
.bottom-pad { height: 12px; }

/* Bottom action bar: save-draft + publish on one row */
.action-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid color-mix(in srgb, var(--hint) 14%, transparent);
  z-index: 30;
}
.action-bar .btn { margin: 0; }
.action-bar #saveDraftBtn { flex: 1 1 0; }
.action-bar #publishBtn { flex: 1.35 1 0; }
.btn:disabled { cursor: default; }
.btn-primary:disabled,
.btn-primary.is-disabled { background: var(--secondary-bg); color: var(--hint); }

/* Profile */
.profile-head {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  column-gap: 12px; align-items: center; margin-bottom: 14px; padding: 0 2px;
}
.profile-avatar {
  grid-row: 1 / 3; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 20px; overflow: hidden;
  background-color: #6f42c1; background-image: linear-gradient(135deg, #9b6dff, #6f42c1);
  background-size: cover; background-position: center;
}
.profile-name { font-weight: 600; font-size: 17px; align-self: end; }
.profile-sub { font-size: 13px; color: var(--hint); align-self: start; }
.profile-row {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; border: 0; background: var(--secondary-bg); color: var(--text);
  padding: 14px 14px; border-radius: 11px; margin-top: 8px; cursor: pointer; font-size: 15px;
  transition: transform 0.08s ease;
}
.profile-row:active { transform: scale(0.99); }
.profile-row-val { color: var(--hint); font-size: 14px; }
.profile-row-val.danger { color: var(--destructive); }

/* Drafts list */
.draft-item { display: flex; align-items: center; gap: 8px; }
.draft-open {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  border: 0; background: transparent; color: var(--text); text-align: left;
  padding: 11px 8px; border-radius: 10px; cursor: pointer;
}
.draft-open:active { background: var(--secondary-bg); }
.draft-snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 72vw; font-size: 15px; }
.draft-date { font-size: 12px; color: var(--hint); }
.draft-del {
  flex: 0 0 auto; width: 36px; height: 36px; border: 0; border-radius: 9px;
  background: color-mix(in srgb, var(--destructive) 14%, transparent); color: var(--destructive);
  display: grid; place-items: center; cursor: pointer;
}

/* ---------- Profile page ---------- */
.profile-page {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: fadein 0.22s ease;
}
.profile-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 18%, transparent);
}
.back-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--text);
  display: grid; place-items: center; cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.back-btn:active { transform: scale(0.92); background: var(--secondary-bg); }
.profile-topbar-title { font-weight: 600; font-size: 17px; }
.profile-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px 14px calc(20px + var(--safe-bottom));
}
/* On the full page the header is centred (vs. the old compact sheet row). */
.profile-page .profile-head {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 6px; margin: 6px 0 4px;
}
.profile-page .profile-avatar { width: 76px; height: 76px; font-size: 28px; }
/* Reset the sheet grid's align-self so name/sub stay centred in the flex column. */
.profile-page .profile-name { font-size: 19px; align-self: center; }
.profile-page .profile-sub { align-self: center; }
.profile-section-title {
  font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--hint); margin: 24px 4px 8px;
}
.drafts-list { display: flex; flex-direction: column; gap: 2px; }

/* View transitions */
.empty, .loading { animation: fadein 0.22s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }
.ch-avatar, .ch-title, .ch-sub { transition: opacity 0.15s ease; }
.channel-pick.switching .ch-avatar,
.channel-pick.switching .ch-title,
.channel-pick.switching .ch-sub { opacity: 0.35; }

/* ---------- Sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: flex-end;
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(18px + var(--safe-bottom));
  animation: slideup 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--hint) 50%, transparent); margin: 6px auto 12px; }
.sheet-title { font-weight: 600; font-size: 16px; margin-bottom: 12px; text-align: center; }
.sheet-list { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; }

.channel-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px; border-radius: 10px; cursor: pointer;
  background: transparent; border: 0; width: 100%; text-align: left; color: var(--text);
}
.channel-item:active { background: var(--secondary-bg); }
.channel-item .ci-avatar {
  width: 42px; height: 42px; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 17px;
  background-color: #2d7fd6;
  background-image: linear-gradient(135deg, #5ca8f0, #2d7fd6);
  background-size: cover; background-position: center;
}
.channel-item .ci-meta { min-width: 0; flex: 1; }
.channel-item .ci-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-item .ci-sub { font-size: 13px; color: var(--hint); }
.channel-item .ci-check { color: var(--accent); }
.channel-item .ci-warn { font-size: 12px; color: var(--destructive); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.84); color: #fff;
  padding: 11px 18px; border-radius: 12px; font-size: 14px;
  z-index: 80; max-width: 88vw; text-align: center;
  animation: fade 0.2s ease;
}
.toast.error { background: var(--destructive); }
