:root {
  --accent: #008069;
  --accent-light: #25d366;
  --accent-dark: #075e54;
  --accent-glow: rgba(37, 211, 102, 0.35);
  --header-height: 68px;
  --composer-height: 72px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bubble-own: #d9fdd3;
  --bubble-own-text: #111b21;
  --bubble-other: #ffffff;
  --bubble-other-text: #111b21;
  --chat-bg: #e5ddd5;
  --chat-bg-tint: #efeae2;
  --font-stack: "DM Sans", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --ease-out-expo: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --shadow-soft: 0 2px 8px rgba(11, 20, 26, 0.06), 0 8px 24px rgba(11, 20, 26, 0.04);
  --shadow-bubble: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --shadow-header: 0 4px 20px rgba(7, 94, 84, 0.22);
  --chat-gutter: 0.85rem;
  --bubble-max: min(82%, 420px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-stack);
  background: #f8f9fa;
  overflow: hidden;
}

.min-w-0 { min-width: 0; }

/* Connection bar */
.connection-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  height: 3px;
  transition: height 0.2s, background 0.2s;
  text-align: center;
  font-size: 11px;
  color: #fff;
  overflow: hidden;
}

.connection-bar.online { background: #198754; }
.connection-bar.syncing { background: #ffc107; height: 22px; line-height: 22px; }
.connection-bar.offline { background: #6c757d; height: 22px; line-height: 22px; }

/* Views */
.view {
  height: 100vh;
  height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Login */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #e7f1ff 0%, #f8f9fa 50%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  border: none;
  border-radius: 16px;
}

.auth-tabs {
  display: flex;
  background: #f1f3f5;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  font-weight: 500;
  font-size: 0.9rem;
  color: #6c757d;
  transition: background 0.15s, color 0.15s;
}

.auth-tab.active {
  background: #fff;
  color: #0d6efd;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.auth-panel .form-text {
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

.app-logo {
  width: 64px;
  height: 64px;
  font-size: 32px;
  line-height: 64px;
  background: #e7f1ff;
  border-radius: 16px;
}

/* ========== Premium Chat ========== */
.chat-view {
  background: var(--chat-bg-tint);
  animation: viewFadeIn 0.45s var(--ease-out-expo);
}

.chat-view.view-active .chat-shell {
  animation: chatShellIn 0.5s var(--ease-out-expo);
}

@keyframes chatShellIn {
  from { opacity: 0; transform: scale(0.98) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 960px;
  margin: 0 auto;
  background: var(--chat-bg-tint);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

.chat-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0.55rem 0.85rem 0.55rem;
  padding-top: calc(0.55rem + var(--safe-top));
  min-height: var(--header-height);
  background: linear-gradient(135deg, var(--accent-dark) 0%, var(--accent) 50%, #0a9b7a 100%);
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-header);
  position: relative;
  z-index: 4;
}

.chat-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, transparent 50%);
  pointer-events: none;
}

.chat-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  position: relative;
  z-index: 1;
}

.chat-header-main {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
  flex: 1;
  position: relative;
  z-index: 1;
}

.chat-header-info { min-width: 0; }

.chat-header-name {
  font-weight: 600;
  font-size: 1.0625rem;
  letter-spacing: -0.01em;
}

.chat-header-status {
  font-size: 0.8125rem;
  opacity: 0.88;
  transition: opacity 0.3s ease, color 0.3s ease;
}

.chat-header-status.is-online {
  opacity: 1;
  color: #b8ffe0;
}

.chat-header-status.is-online::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #53ffb1;
  border-radius: 50%;
  margin-right: 6px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2), 0 0 8px rgba(83, 255, 177, 0.6);
  animation: onlinePulse 2s ease-in-out infinite;
}

@keyframes onlinePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.8; }
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

.chat-icon-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s var(--ease-spring);
}

.chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.26);
  transform: scale(1.08);
}

.chat-icon-btn:active { transform: scale(0.92); }

.chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-body-visible {
  animation: chatBodyIn 0.4s var(--ease-out-expo);
}

@keyframes chatBodyIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.messages-panel {
  flex: 1;
  min-height: 0;
  position: relative;
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(ellipse at 10% 0%, rgba(0, 128, 105, 0.07) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 100%, rgba(37, 211, 102, 0.06) 0%, transparent 45%),
    url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23c8c0b8' fill-opacity='0.22'%3E%3Cpath d='M0 0h40v40H0V0zm40 40h40v40H40V40z'/%3E%3C/g%3E%3C/svg%3E");
}

.chat-body .messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.1rem var(--chat-gutter) 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.scroll-bottom-btn {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.2s ease, opacity 0.2s ease;
  animation: scrollBtnIn 0.3s var(--ease-out-expo);
}

.scroll-bottom-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 128, 105, 0.25);
}

.scroll-bottom-btn:active { transform: scale(0.94); }

@keyframes scrollBtnIn {
  from { opacity: 0; transform: translateY(12px) scale(0.8); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.waiting-partner {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    radial-gradient(circle at 50% 30%, rgba(37, 211, 102, 0.08) 0%, transparent 55%),
    var(--chat-bg);
  animation: viewFadeIn 0.5s var(--ease-out-expo);
}

.waiting-card {
  text-align: center;
  max-width: 300px;
  padding: 2.25rem 1.75rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.waiting-avatar-ring {
  width: 80px;
  height: 80px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  padding: 3px;
  animation: ringPulse 2.5s ease-in-out infinite;
}

.waiting-avatar-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 12px transparent; }
}

.waiting-pulse {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 1rem;
}

.waiting-pulse span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: waitingBounce 1.4s ease-in-out infinite;
}

.waiting-pulse span:nth-child(2) { animation-delay: 0.16s; }
.waiting-pulse span:nth-child(3) { animation-delay: 0.32s; }

@keyframes waitingBounce {
  0%, 80%, 100% { transform: translateY(0) scale(0.7); opacity: 0.35; }
  40% { transform: translateY(-6px) scale(1); opacity: 1; }
}

.avatar-lg {
  width: 50px;
  height: 50px;
  font-size: 1.15rem;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.25);
}

.load-older-btn {
  display: block;
  width: calc(100% - 16px);
  margin: 8px auto 4px;
  padding: 0.45rem 0.75rem;
  border: 1px dashed rgba(7, 94, 84, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #075e54;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.load-older-btn:hover:not(:disabled) {
  background: #f0faf8;
  border-color: rgba(7, 94, 84, 0.55);
}

.load-older-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.msg-image-stripped {
  font-size: 0.8rem;
  color: #667781;
  padding: 0.35rem 0;
  font-style: italic;
}

.date-separator {
  text-align: center;
  margin: 0.85rem 0 0.65rem;
  animation: msgSlideIn 0.35s var(--ease-out-expo);
}

.msg-row.system {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.35rem 1rem;
  margin: 0.15rem 0;
}

.msg-system-notice {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
  max-width: min(92%, 420px);
  padding: 0.4rem 0.85rem;
  border-radius: 10px;
  background: rgba(17, 27, 33, 0.08);
  color: #3b4a54;
  font-size: 0.8rem;
  line-height: 1.35;
  text-align: center;
}

.msg-system-notice.is-warning {
  background: rgba(180, 83, 9, 0.14);
  color: #7a3e05;
  border: 1px solid rgba(180, 83, 9, 0.28);
  font-weight: 600;
}

.msg-system-text {
  font-weight: 550;
}

.msg-system-time {
  font-size: 0.7rem;
  opacity: 0.72;
  white-space: nowrap;
}

.date-separator span {
  display: inline-block;
  background: rgba(255, 255, 255, 0.94);
  color: #54656f;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 10px;
  box-shadow: var(--shadow-bubble);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.new-messages-separator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0.9rem 0 0.75rem;
  padding: 0 8px;
  animation: msgSlideIn 0.35s var(--ease-out-expo);
}

.new-messages-separator::before,
.new-messages-separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(7, 94, 84, 0.35), transparent);
}

.new-messages-separator span {
  display: inline-block;
  background: linear-gradient(135deg, #075e54, #128c7e);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(7, 94, 84, 0.25);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.msg-row.msg-row-incoming-new .msg-bubble {
  box-shadow: 0 0 0 1.5px rgba(7, 94, 84, 0.22), var(--shadow-bubble);
}

.msg-row.msg-row-incoming-new.other .msg-bubble {
  background: linear-gradient(180deg, #fff 0%, #f0faf8 100%);
}

.msg-row {
  display: flex;
  width: 100%;
  margin-bottom: 1px;
  padding: 0 2px;
  align-items: flex-end;
  gap: 6px;
}

.msg-row.msg-row-new {
  animation: msgSlideIn 0.3s var(--ease-out-expo) both;
}

.msg-row.msg-row-stable {
  animation: none;
}

.msg-row.own {
  justify-content: flex-end;
}

.msg-row.other {
  justify-content: flex-start;
}

.msg-row.msg-grouped {
  margin-top: 1px;
}

.msg-avatar {
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 2px;
}

.msg-avatar-spacer {
  width: 36px;
  flex-shrink: 0;
}

@keyframes msgSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg-bubble {
  position: relative;
  max-width: var(--bubble-max);
  padding: 0.5rem 0.75rem 0.4rem;
  border-radius: 14px;
  font-size: 0.9375rem;
  line-height: 1.48;
  word-wrap: break-word;
  box-shadow: var(--shadow-bubble);
  transition: transform 0.15s ease;
}

.msg-row.own .msg-bubble {
  background: var(--bubble-own);
  color: var(--bubble-own-text);
  border-bottom-right-radius: 4px;
}

.msg-row.own.msg-first .msg-bubble,
.msg-row.own.msg-middle .msg-bubble {
  border-bottom-right-radius: 14px;
}

.msg-row.own.msg-last .msg-bubble,
.msg-row.own.msg-first.msg-last .msg-bubble {
  border-bottom-right-radius: 4px;
}

.msg-row.other .msg-bubble {
  background: var(--bubble-other);
  color: var(--bubble-other-text);
  border-bottom-left-radius: 4px;
}

.msg-row.other.msg-first .msg-bubble,
.msg-row.other.msg-middle .msg-bubble {
  border-bottom-left-radius: 14px;
}

.msg-row.other.msg-last .msg-bubble,
.msg-row.other.msg-first.msg-last .msg-bubble {
  border-bottom-left-radius: 4px;
}

.msg-bubble.pending {
  opacity: 0.8;
}

.msg-bubble.failed {
  box-shadow: 0 0 0 2px #ea4335, var(--shadow-bubble);
}

.msg-body {
  display: block;
  width: 100%;
}

.msg-text {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 0.15rem;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 0.68rem;
  line-height: 1;
  color: #667781;
  margin-left: auto;
  float: right;
  margin-top: 2px;
  padding-left: 12px;
}

.msg-row.own .msg-meta { color: #667781; }

.msg-status {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.msg-status.sent { color: #8696a0; }
.msg-status.delivered { color: #8696a0; }
.msg-status.seen { color: #53bdeb; }
.msg-status.pending { color: #8696a0; animation: tickBlink 1.2s ease infinite; }
.msg-status.failed { color: #ea4335; }

@keyframes tickBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.retry-btn {
  background: none;
  border: none;
  color: #ea4335;
  font-size: 0.68rem;
  cursor: pointer;
  padding: 0;
  margin-left: 4px;
  text-decoration: underline;
  font-weight: 600;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  min-height: 280px;
  animation: viewFadeIn 0.5s var(--ease-out-expo);
}

.chat-empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff 0%, #f0faf5 100%);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-soft);
  animation: emptyIconFloat 3s ease-in-out infinite;
}

@keyframes emptyIconFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.chat-empty-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #111b21;
  margin: 0 0 0.5rem;
}

.chat-empty p {
  color: #667781;
  font-size: 0.875rem;
  margin: 0;
  max-width: 260px;
  line-height: 1.55;
}

/* Composer */
.composer {
  flex-shrink: 0;
  padding: 0.6rem var(--chat-gutter);
  padding-bottom: calc(0.6rem + var(--safe-bottom));
  background: linear-gradient(180deg, transparent 0%, #f0f2f5 20%);
  position: relative;
  z-index: 2;
}

/* m1 quota meters — chat header topbar (not composer) */
.m1-limit-topbar {
  position: relative;
  z-index: 1;
  margin-top: 0.4rem;
  padding: 0.4rem 0.45rem 0.35rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.m1-limit-topbar.d-none,
.m1-limit-topbar[hidden] {
  display: none !important;
}

.m1-limit-topbar-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.m1-limit-chip {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}

.m1-limit-chip-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.72);
}

.m1-limit-chip-value {
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m1-limit-chip-track {
  display: block;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.m1-limit-chip-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: #7dffa8;
  transition: width 0.15s ease, background-color 0.2s ease;
}

.m1-limit-topbar.is-warn .m1-limit-chip-fill {
  background: #ffd166;
}

.m1-limit-topbar.is-full .m1-limit-chip-fill {
  background: #ff8a80;
}

.m1-limit-topbar.is-warn {
  background: rgba(196, 122, 0, 0.35);
  border-color: rgba(255, 209, 102, 0.45);
}

.m1-limit-topbar.is-full {
  background: rgba(192, 57, 43, 0.4);
  border-color: rgba(255, 138, 128, 0.5);
}

.m1-limit-topbar-hint {
  margin: 0.35rem 0 0;
  padding: 0 0.15rem;
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.95);
}

.m1-limit-topbar-hint.d-none,
.m1-limit-topbar-hint[hidden] {
  display: none !important;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: #fff;
  border-radius: 28px;
  padding: 0.4rem 0.4rem 0.4rem 1.1rem;
  box-shadow: 0 2px 12px rgba(11, 20, 26, 0.08);
  border: 1px solid rgba(11, 20, 26, 0.06);
  transition: box-shadow 0.25s ease, border-color 0.25s ease, transform 0.2s ease;
}

.composer-inner:focus-within {
  box-shadow: 0 4px 20px rgba(0, 128, 105, 0.18);
  border-color: rgba(0, 128, 105, 0.2);
}

.composer-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.96rem;
  line-height: 1.45;
  max-height: 120px;
  padding: 0.55rem 0;
  color: #111b21;
}

.composer-input::placeholder { color: #8696a0; }

.composer-send {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(145deg, var(--accent-light) 0%, var(--accent) 100%);
  box-shadow: 0 3px 12px rgba(0, 128, 105, 0.4);
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s ease, opacity 0.2s ease;
}

.composer-send-icon {
  display: flex;
  transition: transform 0.2s var(--ease-spring);
}

.composer-send:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: 0 5px 18px rgba(0, 128, 105, 0.5);
}

.composer-send:not(:disabled):hover .composer-send-icon {
  transform: translateX(1px) translateY(-1px);
}

.composer-send:not(:disabled):active {
  transform: scale(0.92);
}

.composer-send:disabled {
  opacity: 0.4;
  background: #bcc3c9;
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  .chat-view,
  .chat-shell,
  .chat-body-visible,
  .msg-row,
  .date-separator,
  .chat-empty,
  .chat-empty-icon,
  .scroll-bottom-btn,
  .waiting-avatar-ring,
  .waiting-pulse span {
    animation: none !important;
  }

  .chat-body .messages {
    scroll-behavior: auto;
  }
}

/* Legacy aliases */
.chat-single { display: flex; flex-direction: column; height: 100%; }
.chat-topbar { display: none; }
.chat-input-area { display: none; }
.chat-input { display: none; }
.send-btn { display: none; }
.waiting-icon { display: none; }

/* Avatar */
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
  position: relative;
  transition: transform 0.25s var(--ease-out-expo);
}

.avatar-sm {
  width: 36px;
  height: 36px;
  font-size: 0.85rem;
}

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  background: #25d366;
  border: 2.5px solid var(--accent-dark);
  border-radius: 50%;
  animation: onlinePulse 2s ease-in-out infinite;
}

/* Skeleton */
.skeleton-item,
.skeleton-bubble {
  background: linear-gradient(90deg, #e9ecef 25%, #f8f9fa 50%, #e9ecef 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 8px;
}

.skeleton-item { height: 64px; margin: 0.5rem 1rem; }
.skeleton-bubble { height: 40px; margin-bottom: 0.5rem; }
.skeleton-bubble.left { width: 60%; align-self: flex-start; }
.skeleton-bubble.right { width: 50%; align-self: flex-end; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Install banner */
.install-banner {
  position: fixed;
  bottom: calc(1rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(100% - 2rem, 480px);
  background: linear-gradient(135deg, #075e54 0%, #008069 55%, #25d366 100%);
  color: #fff;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  z-index: 1050;
  box-shadow: 0 12px 40px rgba(7, 94, 84, 0.35), 0 2px 8px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  animation: install-slide-up 0.45s var(--ease-out-expo);
}

@keyframes install-slide-up {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.install-banner-icon img {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: block;
}

.install-banner-body {
  flex: 1;
  min-width: 0;
}

.install-banner-title {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
  margin-bottom: 0.15rem;
}

.install-banner-text {
  font-size: 0.8rem;
  line-height: 1.35;
  opacity: 0.92;
}

.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn-install {
  background: #fff;
  color: var(--accent-dark);
  border: none;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  white-space: nowrap;
}

.btn-install:hover,
.btn-install:focus {
  background: #f0fff8;
  color: var(--accent-dark);
}

.btn-install-dismiss {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}

.btn-install-dismiss:hover {
  background: rgba(255, 255, 255, 0.24);
  color: #fff;
}

.install-banner.ios-mode .btn-install {
  display: none;
}

/* Avatar colors — ২ জনের জন্য */
.avatar-color-0 { background: #0d6efd; }
.avatar-color-1 { background: #6610f2; }
.avatar-color-2 { background: #d63384; }
.avatar-color-3 { background: #dc3545; }
.avatar-color-4 { background: #fd7e14; }
.avatar-color-5 { background: #198754; }
.avatar-color-6 { background: #20c997; }
.avatar-color-7 { background: #0dcaf0; }
.avatar-color-8 { background: #6f42c1; }
.avatar-color-9 { background: #495057; }

/* Admin panel */
.admin-view {
  overflow-y: auto;
  background: #f0f2f5;
}

.admin-login-wrap {
  min-height: 100dvh;
}

.admin-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
  padding-top: calc(1rem + var(--safe-top));
  padding-bottom: calc(2rem + var(--safe-bottom));
}

.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.admin-section {
  background: #fff;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.admin-room-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.admin-room-item {
  width: 100%;
  text-align: left;
  border: 1px solid #e9ecef;
  border-radius: 10px;
  padding: 0.75rem;
  background: #fff;
}

.admin-room-item:hover {
  border-color: #0d6efd;
  background: #f8fbff;
}

.admin-push-settings {
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
  border-radius: 0.5rem;
  background: rgba(7, 94, 84, 0.04);
}

.admin-member-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.admin-member-row {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid #f1f3f5;
}

.admin-member-info {
  min-width: 0;
}

.admin-member-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.admin-member-password-form .input-group {
  width: 100%;
}

@media (min-width: 480px) {
  .admin-member-row {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .admin-member-actions {
    flex: 1;
    max-width: 280px;
  }
}

.admin-member-row:last-child {
  border-bottom: none;
}

.quick-login-hint {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: #e8f8f1;
  color: #0f5132;
  font-size: 0.85rem;
  line-height: 1.4;
}

.quick-login-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #25d366;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(37, 211, 102, 0.15);
}

.home-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0 1.25rem;
  color: #6c757d;
  font-size: 0.8rem;
}

.home-divider::before,
.home-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #dee2e6;
}

.share-link-panel {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 12px;
  padding: 0.75rem;
}

.room-code {
  font-size: 0.85em;
  background: #e9ecef;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.text-break {
  word-break: break-all;
}

/* View transitions */
.view-enter {
  animation: viewEnter 0.38s var(--ease-out-expo);
}

.view-exit {
  animation: viewExit 0.28s ease forwards;
}

@keyframes viewEnter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes viewExit {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

/* Partner status typing */
.chat-header-status.is-typing::after {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 4px;
  border-radius: 50%;
  background: #25d366;
  animation: typingDot 1.2s ease infinite;
}

@keyframes typingDot {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

/* Room menu */
.chat-header-actions {
  position: relative;
}

.room-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(0, 0, 0, 0.06);
  z-index: 20;
  overflow: hidden;
  animation: menuPop 0.2s var(--ease-out-expo);
}

@keyframes menuPop {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.room-menu-item {
  display: block;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: #111b21;
}

.room-menu-item:hover {
  background: #f0f2f5;
}

.room-menu-item.danger {
  color: #ea4335;
}

.room-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
}

.room-menu-toggle input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent, #25d366);
  flex-shrink: 0;
}

/* Notification settings sheet */
.notify-sheet {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.notify-sheet.d-none,
.notify-sheet[hidden] {
  display: none !important;
}

.notify-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 20, 26, 0.45);
}

.notify-sheet-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: min(88vh, 640px);
  overflow: auto;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 0.5rem 1rem 1.25rem;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  animation: notifySheetUp 0.22s var(--ease-out-expo, ease-out);
}

@keyframes notifySheetUp {
  from { transform: translateY(24px); opacity: 0.85; }
  to { transform: translateY(0); opacity: 1; }
}

.notify-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #d1d7db;
  margin: 0.35rem auto 0.75rem;
}

.notify-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.notify-sheet-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: #111b21;
}

.notify-sheet-close {
  border: none;
  background: #f0f2f5;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  color: #54656f;
  font-size: 0.95rem;
  line-height: 1;
}

.notify-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.notify-status-label {
  font-size: 0.9rem;
  color: #54656f;
}

.notify-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.notify-chip.chip-ready {
  background: #d9fdd3;
  color: #0b6b2f;
}

.notify-chip.chip-off {
  background: #f0f2f5;
  color: #54656f;
}

.notify-chip.chip-blocked {
  background: #ffe8e6;
  color: #b3261e;
}

.notify-chip.chip-admin {
  background: #fff3cd;
  color: #856404;
}

.notify-chip.chip-unsupported {
  background: #e8e8e8;
  color: #667781;
}

.notify-admin-line {
  font-size: 0.82rem;
  color: #856404;
  background: #fff8e6;
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  margin: 0 0 0.75rem;
}

.notify-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-top: 1px solid #f0f2f5;
  border-bottom: 1px solid #f0f2f5;
  cursor: pointer;
}

.notify-toggle-title {
  display: block;
  font-size: 0.95rem;
  color: #111b21;
  font-weight: 500;
}

.notify-toggle-hint {
  display: block;
  font-size: 0.78rem;
  color: #667781;
  margin-top: 0.15rem;
}

.notify-toggle-row input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--accent, #25d366);
  flex-shrink: 0;
}

.notify-quiet-range {
  display: flex;
  gap: 0.75rem;
  margin: 0.5rem 0 0.25rem;
}

.notify-quiet-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: #54656f;
}

.notify-quiet-field input[type="time"] {
  border: 1px solid #e9edef;
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  font-size: 0.9rem;
  color: #111b21;
  background: #f0f2f5;
}

.notify-quiet-hint {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: #856404;
  background: #fff8e6;
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}

.notify-preview-block {
  margin-top: 0.85rem;
}

.notify-text-preview {
  margin: 0.35rem 0 0;
  padding: 0.65rem 0.75rem;
  background: #f0f2f5;
  border-radius: 10px;
  font-size: 0.9rem;
  color: #111b21;
  word-break: break-word;
}

.notify-last-push {
  margin: 0.65rem 0 0;
  font-size: 0.8rem;
  color: #667781;
}

.chat-icon-btn#notifySettingsBtn {
  position: relative;
}

.chat-icon-btn#notifySettingsBtn[data-notify-state="off"] .notify-bell-icon,
.chat-icon-btn#notifySettingsBtn[data-notify-state="blocked"] .notify-bell-icon,
.chat-icon-btn#notifySettingsBtn[data-notify-state="admin_off"] .notify-bell-icon,
.chat-icon-btn#notifySettingsBtn[data-notify-state="unsupported"] .notify-bell-icon {
  opacity: 0.45;
}

.chat-icon-btn#notifySettingsBtn[data-notify-state="ready"] .notify-bell-icon {
  opacity: 1;
}

.notify-bell-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ea4335;
  border: 1.5px solid #fff;
}

.chat-icon-btn#notifySettingsBtn[data-notify-state="blocked"] .notify-bell-dot {
  display: block !important;
}

.notify-denied-guide {
  margin-top: 0.85rem;
  padding: 0.75rem;
  background: #fff5f5;
  border-radius: 10px;
  border: 1px solid #ffc9c4;
  font-size: 0.82rem;
  color: #5c2b29;
  white-space: pre-line;
  line-height: 1.45;
}

.notify-denied-guide::after {
  content: "ঠিক হলে «স্ট্যাটাস রিফ্রেশ» চাপুন।";
  display: block;
  margin-top: 0.5rem;
  font-weight: 600;
  color: #008069;
}

.notify-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.notify-action-btn {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  background: #008069;
  color: #fff;
}

.notify-action-btn.secondary {
  background: #f0f2f5;
  color: #111b21;
}

.notify-action-btn:disabled {
  opacity: 0.55;
}

.notify-devices {
  margin-top: 1.25rem;
}

.notify-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #54656f;
  margin: 0 0 0.5rem;
}

.notify-device-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.notify-device-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid #f0f2f5;
  font-size: 0.85rem;
  color: #111b21;
}

.notify-device-list .device-meta {
  color: #667781;
  font-size: 0.75rem;
}

/* Pinned bar */
.pinned-bar {
  flex-shrink: 0;
  background: #fff8e6;
  border-bottom: 1px solid #f0e4c8;
  padding: 0.5rem var(--chat-gutter);
}

.pinned-bar-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pinned-bar-text {
  flex: 1;
  font-size: 0.85rem;
  color: #54656f;
}

.pinned-bar-close,
.pinned-bar-icon {
  flex-shrink: 0;
  border: none;
  background: none;
  color: #8696a0;
}

/* Reply preview */
.reply-preview {
  flex-shrink: 0;
  padding: 0.5rem var(--chat-gutter) 0;
}

.reply-preview-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #fff;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.reply-preview-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
}

.reply-preview-text {
  display: block;
  font-size: 0.85rem;
  color: #54656f;
}

.reply-preview-close {
  border: none;
  background: none;
  color: #8696a0;
}

.msg-reply-quote {
  border-left: 3px solid rgba(0, 128, 105, 0.45);
  padding-left: 0.5rem;
  margin-bottom: 0.35rem;
  opacity: 0.85;
}

.msg-reply-name {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
}

.msg-reply-text {
  display: block;
  font-size: 0.8rem;
  color: #667781;
}

/* Links */
.msg-link {
  color: #027eb5;
  text-decoration: underline;
  word-break: break-all;
}

.msg-row.own .msg-link {
  color: #006d5b;
}

.msg-link-card {
  display: block;
  margin-top: 0.35rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  color: inherit;
}

.msg-link-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.5rem 0.65rem 0.15rem;
}

.msg-link-card-domain {
  font-size: 0.72rem;
  color: #667781;
  padding: 0 0.65rem 0.5rem;
}

/* Images */
.msg-image-btn {
  display: block;
  border: none;
  padding: 0;
  background: none;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 0.25rem;
  cursor: zoom-in;
}

.msg-image {
  display: block;
  max-width: min(280px, 100%);
  max-height: 320px;
  border-radius: 10px;
}

/* Reactions */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 0.25rem;
}

.msg-reaction-pill {
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.msg-reaction-pill.active {
  border-color: var(--accent);
  background: #e7f8f1;
}

.msg-react-add {
  border: 1px dashed rgba(0, 0, 0, 0.15);
  background: rgba(255, 255, 255, 0.65);
  border-radius: 999px;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1;
  color: #667781;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.msg-react-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.msg-reaction-picker {
  position: fixed;
  z-index: 1200;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0.45rem;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.msg-reaction-picker.d-none {
  display: none;
}

.msg-reaction-pick {
  border: none;
  background: transparent;
  border-radius: 10px;
  width: 2.1rem;
  height: 2.1rem;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}

.msg-reaction-pick:hover {
  background: #f0f2f5;
}

.msg-deleted {
  font-size: 0.85rem;
  color: #8696a0;
  font-style: italic;
}

.msg-delete-warning {
  font-size: 0.78rem;
  line-height: 1.35;
  color: #8a6d3b;
  background: #fff8e6;
  border: 1px solid #f0e0b2;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  margin-bottom: 0.4rem;
}

.msg-row.own .msg-delete-warning {
  background: rgba(255, 248, 230, 0.92);
  border-color: rgba(240, 224, 178, 0.9);
}

.msg-highlight .msg-bubble {
  animation: msgHighlight 1.2s ease;
}

@keyframes msgHighlight {
  0%, 100% { box-shadow: var(--shadow-bubble); }
  40% { box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.45), var(--shadow-bubble); }
}

/* Composer attach + upload */
.composer-attach {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8696a0;
  background: transparent;
  transition: color 0.2s ease, transform 0.2s ease;
}

.composer-attach:hover {
  color: var(--accent);
  transform: scale(1.05);
}

.upload-progress {
  height: 3px;
  background: #e9edef;
  flex-shrink: 0;
}

.upload-progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  transition: width 0.2s ease;
}

.composer-send-pulse {
  animation: sendPulse 0.4s var(--ease-spring);
}

@keyframes sendPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Context menu */
.msg-context-menu {
  position: fixed;
  z-index: 2000;
  min-width: 180px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(0, 0, 0, 0.06);
  overflow: hidden;
  animation: menuPop 0.18s var(--ease-out-expo);
}

.msg-context-item {
  display: block;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
}

.msg-context-item:hover {
  background: #f0f2f5;
}

.msg-context-item.danger {
  color: #ea4335;
}

/* Search overlay */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 2100;
  background: rgba(11, 20, 26, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  animation: viewFadeIn 0.2s ease;
}

.search-panel {
  width: min(100%, 520px);
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}

.search-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid #e9edef;
}

.search-input {
  flex: 1;
  border: 1px solid #e9edef;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
}

.search-close {
  border: none;
  background: #f0f2f5;
  border-radius: 10px;
  width: 40px;
}

.search-results {
  max-height: 60vh;
  overflow-y: auto;
}

.search-result-item {
  display: block;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0f2f5;
}

.search-result-item:hover {
  background: #f8f9fa;
}

.search-result-name {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
}

.search-result-text {
  display: block;
  font-size: 0.88rem;
  color: #111b21;
}

.search-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: #8696a0;
}

/* Image lightbox */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2200;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  gap: 1rem;
}

.image-lightbox-actions {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 2;
}

.image-lightbox img {
  max-width: 100%;
  max-height: calc(100% - 4rem);
  object-fit: contain;
  border-radius: 8px;
}

.image-lightbox-download,
.image-lightbox-close {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 999px;
  font-size: 0.9rem;
  backdrop-filter: blur(8px);
}

.image-lightbox-download {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  font-weight: 600;
}

.image-lightbox-download:hover,
.image-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

.image-lightbox-close {
  width: 44px;
  height: 44px;
  font-size: 1.25rem;
}

/* Secret gallery panel */
.secret-gallery-panel {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: linear-gradient(165deg, #0f1c24 0%, #1a2f3a 48%, #122028 100%);
  color: #f2f5f7;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
}

.secret-gallery-panel.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.secret-gallery-panel.d-none {
  display: none !important;
}

.secret-gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  padding-top: calc(0.85rem + var(--safe-top));
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.secret-gallery-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.secret-gallery-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 10px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.secret-gallery-add-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
}

.secret-gallery-add-btn:disabled {
  opacity: 0.55;
}

.secret-gallery-upload-hint {
  margin: 0;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
}

.secret-gallery-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem 0.85rem 1rem;
  -webkit-overflow-scrolling: touch;
}

.secret-gallery-load-more {
  display: block;
  width: 100%;
  margin: 0.75rem 0 0.25rem;
  padding: 0.55rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #f5f7fa;
  font-size: 0.85rem;
  font-weight: 600;
}

.secret-gallery-load-more:disabled {
  opacity: 0.6;
}

.secret-gallery-load-more.d-none {
  display: none !important;
}

.secret-gallery-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  text-align: center;
  color: rgba(255, 255, 255, 0.65);
}

.secret-gallery-empty.d-none {
  display: none !important;
}

.secret-gallery-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

@media (min-width: 480px) {
  .secret-gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.9rem;
  }
}

@media (min-width: 800px) {
  .secret-gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    max-width: 720px;
    margin: 0 auto;
  }
}

.secret-gallery-item {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  animation: secretGalleryItemIn 0.32s ease both;
}

@keyframes secretGalleryItemIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.secret-gallery-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: min(52vw, 280px);
  flex: 1;
  padding: 0.5rem;
  border: none;
  background: transparent;
  cursor: zoom-in;
  position: relative;
}

@media (min-width: 480px) {
  .secret-gallery-thumb {
    min-height: 240px;
  }
}

@media (min-width: 800px) {
  .secret-gallery-thumb {
    min-height: 280px;
  }
}

.secret-gallery-thumb img {
  width: 100%;
  height: auto;
  max-height: min(58vh, 420px);
  object-fit: contain;
  object-position: center;
  display: block;
  border-radius: 8px;
  transition: transform 0.25s ease;
}

@media (min-width: 480px) {
  .secret-gallery-thumb img {
    max-height: min(46vh, 360px);
  }
}

.secret-gallery-thumb:hover img,
.secret-gallery-thumb:focus-visible img {
  transform: scale(1.015);
}

.secret-gallery-expand-hint {
  position: absolute;
  left: 0.65rem;
  bottom: 0.65rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  pointer-events: none;
  opacity: 0.85;
  backdrop-filter: blur(6px);
}

.secret-gallery-item-actions {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.secret-gallery-share {
  border: none;
  border-radius: 999px;
  background: rgba(46, 160, 120, 0.88);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 650;
  padding: 0.35rem 0.65rem;
  line-height: 1.1;
}

.secret-gallery-share:hover {
  background: rgba(46, 160, 120, 1);
}

.secret-gallery-delete {
  position: static;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.95rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

.secret-gallery-delete:hover {
  background: rgba(180, 40, 40, 0.85);
}

.secret-gallery-views {
  padding: 0.55rem 0.75rem 0.7rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.28);
}

.secret-gallery-views-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.88);
  margin-bottom: 0.35rem;
}

.secret-gallery-views-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.secret-gallery-views-list li {
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.82);
}

.secret-gallery-views-more {
  opacity: 0.75;
}

.secret-gallery-footer {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + var(--safe-bottom, 0px));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 14, 18, 0.55);
  backdrop-filter: blur(10px);
}

.secret-gallery-back-btn {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font-size: 1rem;
  font-weight: 650;
  background: #fff;
  color: #0f1c24;
}

.secret-gallery-back-btn:hover {
  background: #e8eef1;
}

/* m1 gallery open banner */
.gallery-open-banner {
  position: absolute;
  top: calc(var(--header-height) + var(--safe-top, 0px) + 0.35rem);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 25;
  max-width: calc(100% - 2rem);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  background: rgba(15, 28, 36, 0.92);
  color: #f5f7f8;
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.gallery-open-banner.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.gallery-open-banner.d-none {
  display: none !important;
}

/* m1: realtime m2 gallery session */
.gallery-live-bar {
  position: absolute;
  top: calc(var(--header-height) + var(--safe-top, 0px) + 0.35rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 26;
  width: min(420px, calc(100% - 1.5rem));
  pointer-events: none;
}

.gallery-live-bar.d-none,
.gallery-live-bar[hidden] {
  display: none !important;
}

.gallery-live-bar-inner {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.85rem;
  border-radius: 16px;
  background: rgba(15, 28, 36, 0.94);
  color: #f5f7f8;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.gallery-live-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #2ea078;
  box-shadow: 0 0 0 4px rgba(46, 160, 120, 0.22);
  flex-shrink: 0;
  animation: galleryLivePulse 1.4s ease infinite;
}

.gallery-live-bar.is-closed .gallery-live-dot {
  background: #8a949c;
  box-shadow: none;
  animation: none;
}

@keyframes galleryLivePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}

.gallery-live-thumb {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.08);
}

.gallery-live-thumb.d-none {
  display: none !important;
}

.gallery-live-copy {
  min-width: 0;
  flex: 1;
}

.gallery-live-title {
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.2;
}

.gallery-live-sub {
  margin-top: 0.12rem;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Gallery activity sheet (m1) */
.gallery-activity-sheet {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.gallery-activity-sheet.d-none,
.gallery-activity-sheet[hidden] {
  display: none !important;
}

.gallery-activity-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 20, 26, 0.45);
}

.gallery-activity-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: min(70vh, 480px);
  overflow: auto;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 0.5rem 1rem 1.25rem;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
}

.gallery-activity-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: #d0d7db;
  margin: 0.25rem auto 0.65rem;
}

.gallery-activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.gallery-activity-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.gallery-activity-close {
  border: none;
  background: #f0f2f4;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  font-size: 1.1rem;
}

.gallery-activity-empty.d-none {
  display: none !important;
}

.gallery-activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.gallery-activity-item {
  padding: 0.7rem 0;
  border-bottom: 1px solid #eef1f3;
  font-size: 0.9rem;
  color: #1f2a30;
}

.gallery-activity-item:last-child {
  border-bottom: none;
}

.admin-gallery-secret .form-text {
  font-size: 0.78rem;
}

/* Gallery 2D / 3D viewer */
body.gallery-viewer-open {
  overflow: hidden;
  touch-action: none;
}

.gallery-viewer {
  position: fixed;
  inset: 0;
  z-index: 2300;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at 50% 35%, #15232c 0%, #0a1218 62%, #060b0f 100%);
  color: #f2f5f7;
  opacity: 0;
  transition: opacity 0.28s ease;
  pointer-events: none;
}

.gallery-viewer.is-open {
  opacity: 1;
  pointer-events: auto;
}

.gallery-viewer.d-none {
  display: none !important;
}

.gallery-viewer-actions {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: calc(0.75rem + var(--safe-top)) calc(0.75rem + env(safe-area-inset-right, 0px)) 0.75rem 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 100%;
}

.gallery-viewer-modes {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.gallery-viewer-modes.d-none {
  display: none !important;
}

.gallery-viewer-mode,
.gallery-viewer-download,
.gallery-viewer-close {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 999px;
  font-size: 0.82rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.18s ease;
}

.gallery-viewer-modes .gallery-viewer-mode {
  background: transparent;
  min-width: 0;
  height: 34px;
  padding: 0 0.7rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.gallery-viewer-modes .gallery-viewer-mode.is-active {
  background: rgba(46, 160, 120, 0.55);
}

.gallery-viewer-modes .gallery-viewer-mode.is-active[data-viewer-mode="card"] {
  background: rgba(70, 130, 180, 0.55);
}

.gallery-viewer-modes .gallery-viewer-mode.is-active[data-viewer-mode="2d"] {
  background: rgba(255, 255, 255, 0.22);
}

.gallery-viewer-download {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  font-weight: 600;
  height: 40px;
}

.gallery-viewer-close {
  width: 40px;
  height: 40px;
  font-size: 1.15rem;
  line-height: 1;
}

.gallery-viewer-mode:hover,
.gallery-viewer-download:hover,
.gallery-viewer-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.gallery-viewer-modes .gallery-viewer-mode.is-active:hover {
  background: rgba(46, 160, 120, 0.7);
}

.gallery-viewer-stage {
  flex: 1;
  position: relative;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.gallery-viewer-img {
  max-width: min(100%, 920px);
  max-height: calc(100dvh - 5.5rem - var(--safe-top) - var(--safe-bottom));
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  margin: 3.5rem 1rem 2rem;
}

.gallery-viewer-canvas-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.gallery-viewer-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

.gallery-viewer-loading {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.gallery-viewer-hint {
  position: absolute;
  left: 50%;
  bottom: calc(1.25rem + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 2;
  margin: 0;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.88);
  white-space: nowrap;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.gallery-viewer-hint.is-fading {
  opacity: 0;
}

.gallery-viewer-hint.d-none {
  display: none !important;
}

@media (max-width: 480px) {
  .gallery-viewer-download span,
  .gallery-viewer-download {
    font-size: 0.8rem;
  }

  .gallery-viewer-download svg {
    width: 16px;
    height: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-viewer {
    transition: none;
  }

  .gallery-viewer-hint {
    transition: none;
  }
}

/* Soft curtain before remote open (m2) */
.gallery-soft-curtain {
  position: fixed;
  inset: 0;
  z-index: 2400;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 14, 18, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 0.28s ease;
  pointer-events: none;
}

.gallery-soft-curtain.is-open {
  opacity: 1;
  pointer-events: auto;
}

.gallery-soft-curtain.d-none {
  display: none !important;
}

.gallery-soft-curtain-text {
  margin: 0;
  padding: 0.85rem 1.25rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #f2f5f7;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

