/* Public compose pages: new_chat + new_message */
html:has(.pub-hero) {
  color-scheme: light;
  --pub-bg: #F3F7F4;
  --pub-text: #0F1A14;
  --pub-sub: #5B6A62;
  --pub-line: #E1E9E3;
  --pub-green: #0A9B47;
  --pub-green-deep: #067A38;
}
html:has(.pub-hero), body:has(.pub-hero) { background: var(--pub-bg); color: var(--pub-text); }

/* ---- Header (45px, as before) ---- */
.pub-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100; height: 45px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; font-weight: 600; color: var(--pub-text);
  background: rgba(255, 255, 255, 0.92); border-bottom: 1px solid var(--pub-line);
}
@supports (backdrop-filter: blur(1px)) {
  .pub-header { background: rgba(255, 255, 255, 0.72); -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px); }
}
.pub-header svg { width: 16px; height: 16px; color: var(--app-color); }

/* ---------- Hero (one compact row) ---------- */
.pub-hero {
  position: relative; display: grid; grid-template-columns: 56px 1fr; align-items: center; column-gap: 14px;
  margin: 0 0 10px; padding: 14px 16px; color: #fff; text-align: left; overflow: hidden; border-radius: 22px;
  background:
    radial-gradient(rgba(255, 255, 255, 0.14) 1px, transparent 1.4px) 0 0 / 16px 16px,
    linear-gradient(135deg, var(--pub-green), var(--pub-green-deep));
  box-shadow: 0 14px 30px -16px rgba(6, 122, 56, 0.6);
}
.pub-avatar {
  grid-row: 1 / span 2; display: grid; place-items: center; width: 56px; height: 56px; overflow: hidden;
  border-radius: 50%; background: rgba(255, 255, 255, 0.2); color: #fff; font-size: 22px; font-weight: 600;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 0 0 5px rgba(255, 255, 255, 0.28);
}
.pub-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pub-handle { align-self: end; font-size: 13px; font-weight: 500; opacity: 0.85; }
.pub-topic {
  align-self: start; margin: 2px 0 0; font-size: 17px; font-weight: 600; line-height: 1.3; letter-spacing: -0.01em; color: #fff;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---- Mode switch ---- */
.pub-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 0 0 12px; padding: 4px; border-radius: 16px; background: #E6EEE8; }
.pub-mode {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 9px 8px;
  border-radius: 12px; font-size: 14px; font-weight: 600; color: var(--pub-sub); text-decoration: none; text-align: center;
}
.pub-mode small { font-size: 11px; font-weight: 500; opacity: 0.85; }
.pub-mode.is-active { background: #fff; color: var(--pub-text); box-shadow: 0 1px 3px rgba(15, 26, 20, 0.12); }

/* ---------- Composer card (Send lives inside it) ---------- */
.pub-card {
  padding: 14px 14px 10px; background: #fff; border: 1px solid var(--pub-line); border-radius: 22px;
  box-shadow: 0 1px 2px rgba(15, 26, 20, 0.04), 0 12px 30px -16px rgba(15, 26, 20, 0.2);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.pub-card:focus-within { border-color: var(--pub-green); box-shadow: 0 0 0 4px rgba(10, 155, 71, 0.14); }
.pub-input {
  display: block; width: 100%; min-height: 96px; max-height: 220px; padding: 2px; border: 0; outline: 0; resize: none;
  background: transparent; color: var(--pub-text); font-size: 16px; line-height: 1.5; overflow-y: auto;
}
.pub-input::placeholder, .preview-caption::placeholder { color: #8A9890; }
.pub-card-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--pub-line); }
.pub-attach {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 13px; border: 1px solid var(--pub-line);
  border-radius: 999px; background: #fff; color: var(--pub-text); font-size: 13px; font-weight: 500; cursor: pointer;
}
.pub-attach svg { width: 18px; height: 18px; color: var(--pub-green); }
.pub-attach:active { background: var(--pub-bg); }
.pub-count { margin-left: auto; font-size: 12px; color: var(--pub-sub); }
.pub-send {
  display: inline-flex; align-items: center; gap: 6px; padding: 11px 20px; border: 0; border-radius: 999px;
  background: var(--pub-green); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 8px 18px -10px rgba(10, 155, 71, 0.85); transition: transform 0.1s ease, opacity 0.15s ease;
}
.pub-send svg { width: 16px; height: 16px; }
.pub-send:active { transform: scale(0.97); }
.pub-send:disabled { opacity: 0.65; cursor: default; }
.pub-send.is-loading svg { display: none; }
.pub-send.is-loading::after {
  content: ""; width: 14px; height: 14px; border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff;
  border-radius: 50%; animation: pub-spin 0.7s linear infinite;
}
@keyframes pub-spin { to { transform: rotate(360deg); } }

.pub-note { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 10px 0 0; font-size: 12px; color: var(--pub-sub); }
.pub-note svg { width: 14px; height: 14px; color: var(--pub-green); }

.pub-join {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0 0; padding: 14px 16px;
  border: 1px solid var(--pub-line); border-radius: 18px; background: #fff; color: var(--pub-text); text-decoration: none;
}
.pub-join strong { display: block; font-size: 14px; font-weight: 600; }
.pub-join span { display: block; margin-top: 1px; font-size: 12px; color: var(--pub-sub); }
.pub-join svg { flex: none; width: 18px; height: 18px; color: var(--pub-green); }
.pub-join:active { background: var(--pub-bg); }

.pub-legal { margin: 14px 4px 0; text-align: center; font-size: 12px; line-height: 1.6; color: var(--pub-sub); }
.pub-legal a { color: var(--pub-green-deep); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Preview modal ---------- */
#mediaPreviewModal .modal-dialog.preview-dialog { width: 100%; max-width: none; height: 100%; margin: 0; }
#mediaPreviewModal.fade .modal-dialog { transform: translateY(24px); transition: transform 0.25s ease; }
#mediaPreviewModal.show .modal-dialog { transform: none; }
.preview-sheet { display: flex; flex-direction: column; height: 100%; border: 0; border-radius: 0; background: var(--pub-bg); color: var(--pub-text); }
.preview-bar {
  flex: none; display: flex; align-items: center; gap: 8px; box-sizing: border-box;
  height: calc(56px + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 12px 0;
  background: #fff; border-bottom: 1px solid var(--pub-line);
}
.preview-close { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--pub-text); cursor: pointer; }
.preview-close:active { background: var(--pub-bg); }
.preview-close svg { width: 24px; height: 24px; }
.preview-title { margin: 0; font-size: 17px; font-weight: 600; }

.media-preview-modal-body { position: relative; flex: 1; min-height: 0; background: #0B120E; overflow: hidden; }
.preview-media {
  position: absolute; inset: 0; margin: auto; width: auto; height: auto;
  max-width: calc(100% - 32px); max-height: calc(100% - 48px); border-radius: 16px; object-fit: contain;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.preview-fallback {
  position: absolute; inset: 0; margin: auto; width: min(80%, 280px); height: fit-content; padding: 28px 20px;
  text-align: center; border-radius: 20px; color: #fff; font-size: 14px; line-height: 1.5; background: rgba(255, 255, 255, 0.08);
}

.preview-panel {
  position: relative; flex: none; margin-top: -20px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  background: #fff; border-radius: 24px 24px 0 0; box-shadow: 0 -10px 30px -14px rgba(0, 0, 0, 0.3);
}
.preview-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; }
.preview-kind { padding: 3px 10px; border-radius: 999px; background: var(--pub-bg); font-weight: 600; }
.preview-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--pub-sub); }
.preview-size { flex: none; color: var(--pub-sub); }
.preview-change { flex: none; padding: 6px 12px; border: 1px solid var(--pub-line); border-radius: 999px; background: #fff; color: var(--pub-green); font-size: 13px; font-weight: 600; cursor: pointer; }
.preview-caption {
  display: block; width: 100%; min-height: 72px; max-height: 140px; padding: 12px 14px; resize: none; outline: 0;
  border: 1px solid transparent; border-radius: 16px; background: var(--pub-bg); color: var(--pub-text); font-size: 16px; line-height: 1.45;
  transition: border-color 0.15s ease;
}
.preview-caption:focus { border-color: var(--pub-green); }
.preview-count { min-height: 16px; margin: 4px 4px 0; text-align: right; font-size: 12px; color: var(--pub-sub); }
.preview-send { display: flex; width: 100%; justify-content: center; margin-top: 6px; padding: 15px 20px; font-size: 16px; }

@media (prefers-reduced-motion: reduce) {
  #mediaPreviewModal.fade .modal-dialog, .pub-send, .pub-card { transition: none; }
}