:root {
  color-scheme: light;
  --brand: #15803d;
  --brand-hover: #166534;
  --brand-soft: #dcfce7;
  --brand-text: #14532d;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #f1f5f3;
  --border: #e2e8e4;
  --text: #0f172a;
  --text-muted: #526071;
  --bubble-in: #ffffff;
  --bubble-out: #15803d;
  --bubble-out-text: #ffffff;
  --chat-bg: #eef3f0;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --rail-w: 68px;
  --sidebar-w: 330px;
  --panel-w: 320px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --brand: #16a34a;
  --brand-hover: #22c55e;
  --brand-soft: rgba(22, 163, 74, 0.18);
  --brand-text: #86efac;
  --bg: #0c110f;
  --surface: #141b18;
  --surface-2: #1c2622;
  --border: #26332d;
  --text: #e8edea;
  --text-muted: #95a39c;
  --bubble-in: #1c2622;
  --bubble-out: #15803d;
  --bubble-out-text: #f0fdf4;
  --chat-bg: #0f1512;
  --danger: #ef4444;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Thai Looped", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: "Prompt", "Noto Sans Thai Looped", sans-serif;
  margin: 0;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) var(--sidebar-w) 1fr auto;
  height: 100dvh;
  width: 100%;
  background: var(--bg);
  overflow: hidden;
}

.app-shell > * {
  min-height: 0;
}

/* Popout mode (?popout=1) */
.app-shell.popout-mode {
  grid-template-columns: 1fr auto;
}
.app-shell.popout-mode .nav-rail,
.app-shell.popout-mode .sidebar {
  display: none;
}

/* Navigation Rail */
.nav-rail {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 14px 8px;
  z-index: 5;
}

.nav-top, .nav-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.brand-btn {
  width: 44px;
  height: 44px;
  border: 0;
  padding: 0;
  border-radius: 14px;
  background: transparent;
  overflow: hidden;
  margin-bottom: 8px;
}
.brand-btn img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.nav-item {
  position: relative;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg {
  width: 22px;
  height: 22px;
}
.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand);
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.my-avatar-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
  margin-top: 4px;
  padding: 0;
  overflow: hidden;
}
.my-avatar-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Google Sign-In Screen */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: radial-gradient(circle at top, var(--brand-soft), var(--bg) 55%);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px 26px 26px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
}
.auth-card h1 {
  font-size: 1.35rem;
  margin-top: 4px;
}
.auth-sub {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.google-btn-container {
  min-height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-top: 6px;
}
.auth-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.auth-hint.success { color: var(--brand); font-weight: 600; }
.auth-hint.error { color: var(--danger); }

.google-custom-btn {
  width: 100%;
  max-width: 310px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.google-custom-btn:hover {
  background: var(--surface-2);
  border-color: var(--brand);
}
.google-custom-btn:active { transform: scale(0.98); }

.auth-config {
  width: 100%;
  margin-top: 8px;
  text-align: left;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 0.82rem;
}
.auth-config summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
}
.auth-config-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.auth-config-body code {
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.76rem;
}

/* Account Card in Settings */
.account-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-2);
}
.account-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}
.account-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.account-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.account-meta strong {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.app-title {
  font-size: 1.25rem;
  color: var(--brand);
  letter-spacing: -0.02em;
}

.sidebar-actions {
  display: flex;
  gap: 4px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 10px;
}
.search-box svg {
  width: 17px;
  height: 17px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.search-box input {
  border: 0;
  background: transparent;
  width: 100%;
  outline: none;
  font-size: 0.92rem;
}

.filter-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-pills::-webkit-scrollbar { display: none; }

.pill {
  border: 0;
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s;
}
.pill.active {
  background: var(--brand);
  color: #fff;
}

.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.14s;
  position: relative;
}
.room-item:hover {
  background: var(--surface-2);
}
.room-item.active {
  background: var(--brand-soft);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  position: relative;
  user-select: none;
}
.avatar.online::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--surface);
}

.room-meta {
  flex: 1;
  min-width: 0;
}
.room-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}
.room-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-time {
  font-size: 0.74rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.room-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}
.room-preview {
  font-size: 0.84rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.unread-pill {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}
.status-dot.offline {
  background: #f59e0b;
}

/* Main Chat Area */
.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  background: var(--chat-bg);
  position: relative;
}

.empty-chat {
  margin: auto;
  text-align: center;
  max-width: 380px;
  padding: 24px;
}
.empty-chat h2 {
  margin-top: 14px;
  font-size: 1.25rem;
}
.empty-chat p {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 3;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.chat-header-meta {
  min-width: 0;
}
.chat-header-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-header-title-row h2 {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.group-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-text);
}
.chat-header-sub {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  transition: background 0.14s, color 0.14s;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn.active {
  background: var(--brand-soft);
  color: var(--brand);
}
.mini-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
}

/* In-chat search */
.inchat-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.inchat-search input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 6px 12px;
  outline: none;
}
.search-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Pinned note banner */
.pinned-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
}
.pinned-text {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pinned-text span {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Message List */
.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.date-divider {
  align-self: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  background: var(--surface);
  padding: 3px 12px;
  border-radius: 999px;
  margin: 8px 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 78%;
  position: relative;
}
.msg-row.outgoing {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg-row.incoming {
  align-self: flex-start;
}
.msg-row.highlight .msg-bubble {
  outline: 2px solid #f59e0b;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.msg-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.msg-row.outgoing .msg-col {
  align-items: flex-end;
}

.msg-sender {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin: 0 0 2px 6px;
}

.msg-bubble {
  background: var(--bubble-in);
  color: var(--text);
  padding: 9px 13px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.msg-row.outgoing .msg-bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}
.msg-bubble.sticker-bubble,
.msg-bubble.card-bubble {
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  white-space: normal !important;
}

.sticker-card {
  font-size: 3.4rem;
  line-height: 1.1;
  text-align: center;
  user-select: none;
}
.sticker-caption {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  padding: 2px 10px;
  border-radius: 999px;
  margin-top: 2px;
}

.msg-reply-quote {
  border-left: 3px solid var(--brand);
  background: rgba(0, 0, 0, 0.05);
  padding: 4px 8px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}
.msg-row.outgoing .msg-reply-quote {
  border-left-color: #bbf7d0;
  background: rgba(255, 255, 255, 0.14);
}
.msg-reply-quote strong {
  display: block;
  font-size: 0.74rem;
}

.msg-img {
  max-width: 280px;
  max-height: 280px;
  border-radius: 10px;
  display: block;
  cursor: zoom-in;
  margin-top: 4px;
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.06);
  text-decoration: none;
  color: inherit;
  margin-top: 4px;
}
.msg-row.outgoing .msg-file {
  background: rgba(255, 255, 255, 0.16);
}
.msg-file-name {
  font-weight: 600;
  font-size: 0.86rem;
}
.msg-file-size {
  font-size: 0.74rem;
  opacity: 0.8;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.reaction-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.78rem;
  cursor: pointer;
}

.msg-actions {
  opacity: 0;
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
  box-shadow: var(--shadow);
  transition: opacity 0.14s;
  align-self: center;
}
.msg-row:hover .msg-actions {
  opacity: 1;
}
.msg-act-btn {
  border: 0;
  background: transparent;
  padding: 3px 6px;
  border-radius: 7px;
  font-size: 0.82rem;
}
.msg-act-btn:hover {
  background: var(--surface-2);
}

/* Typing indicator */
.typing-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 20px 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.typing-dots {
  display: inline-flex;
  gap: 3px;
}
.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
  animation: bounce 1.1s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Composer */
.composer-wrap {
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: relative;
}

.reply-preview, .attach-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
}
.reply-preview-body {
  border-left: 3px solid var(--brand);
  padding-left: 8px;
  min-width: 0;
}
.reply-preview-body strong { display: block; color: var(--brand); }
.reply-preview-body span { color: var(--text-muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px;
}

#msg-input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 9px 14px;
  resize: none;
  max-height: 130px;
  outline: none;
  line-height: 1.45;
}
#msg-input:focus {
  border-color: var(--brand);
}

.send-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover { background: var(--brand-hover); }
.send-btn:active { transform: scale(0.96); }
.send-btn svg { width: 18px; height: 18px; }

/* Picker Popover */
.picker-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 14px;
  width: 310px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 10px;
  z-index: 20;
}
.picker-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.picker-tab {
  flex: 1;
  border: 0;
  background: var(--surface-2);
  padding: 6px;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 600;
}
.picker-tab.active {
  background: var(--brand);
  color: #fff;
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}
.picker-item {
  border: 0;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.12s, background 0.12s;
}
.picker-item:hover {
  background: var(--brand-soft);
  transform: translateY(-1px);
}
.picker-item .big-em { font-size: 1.8rem; line-height: 1.1; }
.picker-item .em-label { font-size: 0.68rem; color: var(--text-muted); }

/* Right Panel (Notes & Room Info) */
.right-panel {
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.right-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.right-tabs {
  display: flex;
  gap: 4px;
}
.right-tab {
  border: 0;
  background: transparent;
  padding: 5px 8px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.right-tab.active {
  background: var(--brand-soft);
  color: var(--brand);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.note-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-2);
  padding: 12px;
  border-radius: 14px;
  margin-bottom: 14px;
}
.note-form input[type="text"],
.note-form textarea {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
  font-size: 0.88rem;
}
.note-form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}
.file-chip {
  font-size: 0.78rem;
  color: var(--brand);
  cursor: pointer;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.checkbox-inline {
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.note-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 12px;
}
.note-card.pinned {
  border-color: var(--brand);
  background: var(--brand-soft);
}
.note-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
}
.note-card h4 { font-size: 0.94rem; }
.note-card p {
  margin: 6px 0 0;
  font-size: 0.86rem;
  white-space: pre-wrap;
}
.note-card-meta {
  margin-top: 8px;
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Info panel */
.info-hero {
  text-align: center;
  padding: 10px 0 14px;
}
.info-hero .avatar {
  width: 64px;
  height: 64px;
  font-size: 1.5rem;
  margin: 0 auto 8px;
}
.info-actions {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.info-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.info-section h3 {
  font-size: 0.92rem;
  margin-bottom: 6px;
}
.member-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--surface-2);
}
.member-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.media-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
}

/* Buttons & Form Controls */
.btn-primary, .btn-outline, .btn-danger, .text-btn {
  border-radius: 10px;
  font-weight: 600;
  padding: 9px 16px;
  border: 0;
  transition: all 0.14s;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--surface-2); }
.btn-danger {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.text-btn {
  background: transparent;
  color: var(--brand);
  padding: 4px 8px;
}
.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
}
.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 90dvh;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-card.modal-lg {
  max-width: 560px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
}
.field span { font-weight: 600; }
.field input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
}
.field input:focus { border-color: var(--brand); }
.flex-1 { flex: 1; }

.seg-control {
  display: flex;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 12px;
  gap: 4px;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 7px 10px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--text-muted);
}
.seg-btn.active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.color-swatches {
  display: flex;
  gap: 10px;
}
.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid transparent;
}
.swatch.active {
  border-color: var(--text);
  transform: scale(1.1);
}

/* Settings */
.settings-section {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: 0; padding-bottom: 0; }
.settings-section h4 { font-size: 0.96rem; margin-bottom: 8px; }
.settings-row { display: flex; gap: 10px; flex-wrap: wrap; }
.hint-text { margin: 2px 0 0; font-size: 0.78rem; color: var(--text-muted); }
.version-label { font-size: 0.8rem; color: var(--text-muted); }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}
.icon-choice {
  border: 2px solid var(--border);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}
.icon-choice.active {
  border-color: var(--brand);
  background: var(--brand-soft);
}
.icon-choice img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

/* Call Stage */
.call-stage {
  width: 100%;
  max-width: 820px;
  background: #0f1713;
  color: #f8fafc;
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.call-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.04);
}
.call-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  background: #16a34a;
  color: #fff;
  padding: 2px 9px;
  border-radius: 999px;
  margin-bottom: 4px;
}
.call-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.05rem;
  background: rgba(255, 255, 255, 0.1);
  padding: 5px 12px;
  border-radius: 999px;
}
.call-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  min-height: 320px;
}
.call-tile {
  position: relative;
  background: #1a2621;
  border-radius: 16px;
  overflow: hidden;
  min-height: 220px;
  display: grid;
  place-items: center;
}
.call-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.call-tile.has-video video { display: block; }
.call-tile.has-video .tile-fallback { display: none; }

.tile-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: #cbd5e1;
  font-size: 0.88rem;
}
.tile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #15803d;
  color: #fff;
  font-size: 1.7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.tile-avatar.speaking {
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.35);
}
.tile-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.55);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
}
.call-controls {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 16px 20px 22px;
  background: rgba(255, 255, 255, 0.03);
}
.call-btn {
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  min-width: 72px;
  padding: 10px 14px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  transition: background 0.15s;
}
.call-btn:hover { background: rgba(255, 255, 255, 0.2); }
.call-btn.active { background: #16a34a; }
.call-btn.off { background: #475569; opacity: 0.8; }
.call-btn.danger { background: #dc2626; }
.call-btn.danger:hover { background: #b91c1c; }
.call-btn-icon { font-size: 1.25rem; }

/* Lightbox */
.lightbox-wrap {
  max-width: 92vw;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lightbox-wrap img {
  max-width: 90vw;
  max-height: 78dvh;
  border-radius: 14px;
  object-fit: contain;
}
.lightbox-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  padding: 10px 14px;
  border-radius: 12px;
  gap: 12px;
}

/* Toast */
.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  animation: fadeInUp 0.2s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Multi-Image Preview & Note/Album Grids */
.multi-preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.multi-preview-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--surface);
}
.multi-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.multi-preview-del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
}

.note-img-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.note-img-grid.single {
  grid-template-columns: 1fr;
}
.note-img-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
}

/* Albums */
.albums-list, .events-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.album-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 12px;
}
.album-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 8px;
}
.album-head h4 { font-size: 0.94rem; }
.album-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.album-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
}

/* Calendar Events & Real Monthly Calendar Picker */
.mini-cal {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 12px;
}
.mini-cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.mini-cal-head strong {
  font-size: 0.9rem;
}
.mini-cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.mini-cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-day {
  position: relative;
  border: 0;
  background: transparent;
  height: 32px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  display: grid;
  place-items: center;
  transition: background 0.12s, color 0.12s;
}
.cal-day:hover { background: var(--surface); }
.cal-day.other-month { color: var(--text-muted); opacity: 0.4; }
.cal-day.today {
  border: 1px solid var(--brand);
  color: var(--brand);
  font-weight: 700;
}
.cal-day.selected {
  background: var(--brand);
  color: #fff !important;
  font-weight: 700;
}
.cal-day.has-event::after {
  content: "";
  position: absolute;
  bottom: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
}
.cal-day.selected.has-event::after { background: #fff; }

.selected-date-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--brand-soft);
  color: var(--brand-text);
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 0.82rem;
}
.event-time-row {
  display: flex;
  gap: 8px;
}
.event-time-row input[type="time"],
.event-time-row select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  padding: 6px 8px;
  font-size: 0.82rem;
  outline: none;
  width: 100%;
}

/* Rich Note & Album Chat Notification Cards (Compact) */
.chat-rich-card {
  white-space: normal;
  width: 248px;
  max-width: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.chat-rich-head {
  padding: 8px 10px 6px;
  cursor: pointer;
}
.chat-rich-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--brand-text);
  background: var(--brand-soft);
  padding: 1px 7px;
  border-radius: 999px;
  margin-bottom: 3px;
}
.chat-rich-title {
  font-weight: 700;
  font-size: 0.86rem;
  line-height: 1.3;
}
.chat-rich-body {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-rich-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 0 8px 6px;
}
.chat-rich-grid.single {
  grid-template-columns: 1fr;
}
.chat-rich-thumb {
  position: relative;
  border-radius: 7px;
  overflow: hidden;
  height: 86px;
  cursor: zoom-in;
}
.chat-rich-grid.single .chat-rich-thumb {
  height: 132px;
}
.chat-rich-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.chat-rich-more {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  display: grid;
  place-items: center;
}
.chat-rich-foot {
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--brand);
  cursor: pointer;
}
.chat-rich-foot:hover {
  background: var(--surface-2);
}

/* Quick 30-min Thai Time Chips */
.quick-time-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.time-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  transition: all 0.12s;
}
.time-chip:hover,
.time-chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* Lightbox Gallery Arrows */
.lightbox-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  display: grid;
  place-items: center;
  z-index: 2;
  transition: background 0.15s;
}
.lb-nav:hover { background: rgba(0, 0, 0, 0.85); }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }
.lb-counter {
  margin-left: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.detail-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.detail-photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  cursor: zoom-in;
}

.event-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  background: var(--surface);
  border-radius: 12px;
  padding: 11px 12px;
}
.event-card.triggered {
  border-left-color: #f59e0b;
  background: rgba(245, 158, 11, 0.08);
}
.event-time-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 4px;
}
.event-card.triggered .event-time-badge {
  color: #b45309;
  background: rgba(245, 158, 11, 0.18);
}

/* QR Code Modal */
.qr-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.qr-canvas-box {
  background: #ffffff;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}
.qr-canvas-box canvas {
  display: block;
  border-radius: 6px;
}
.qr-scanner-box {
  width: 100%;
  height: 190px;
  border-radius: 14px;
  background: #0f1713;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.qr-scanner-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.qr-scanner-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  color: #e2e8f0;
  font-size: 0.84rem;
  background: rgba(15, 23, 19, 0.55);
  pointer-events: none;
}
.qr-scanner-box.scanning .qr-scanner-overlay {
  background: transparent;
  align-items: end;
  padding-bottom: 10px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}
.qr-manual-form {
  width: 100%;
  text-align: left;
  margin-top: 4px;
}
.qr-input-row {
  display: flex;
  gap: 6px;
}
.qr-input-row input { flex: 1; }

.my-id-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--brand-soft);
  color: var(--brand-text);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.84rem;
}
.id-search-result {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}
.id-result-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.id-sample-box {
  width: 100%;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

/* Responsive Tablet & Mobile + PWA Safe Areas */
.mobile-only { display: none; }

@media (max-width: 1200px) {
  .right-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow);
  }
}

@media (max-width: 1024px) {
  :root {
    --rail-w: 58px;
    --sidebar-w: 278px;
  }
  .pill {
    padding: 4px 9px;
    font-size: 0.78rem;
  }
  .chat-header {
    padding: 10px 12px;
  }
  .chat-header-actions {
    gap: 2px;
  }
}

@media (max-width: 768px) {
  .mobile-only { display: grid; }
  .app-shell {
    grid-template-columns: 1fr;
  }
  .nav-rail { display: none; }
  .sidebar {
    width: 100%;
    height: 100dvh;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .chat-main {
    position: fixed;
    inset: 0;
    z-index: 20;
    transform: translateX(100%);
    transition: transform 0.22s ease;
  }
  .app-shell.mobile-chat-open .chat-main {
    transform: translateX(0);
  }
  .app-shell.popout-mode .chat-main {
    position: static;
    transform: none;
  }
  .chat-header {
    padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px;
    gap: 6px;
  }
  .chat-header-left {
    gap: 8px;
  }
  .chat-header .avatar {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
  }
  .chat-header-title-row h2 {
    font-size: 0.92rem;
  }
  .chat-header-sub {
    font-size: 0.74rem;
  }
  .chat-header .icon-btn {
    width: 32px;
    height: 32px;
  }
  .chat-header .icon-btn svg {
    width: 18px;
    height: 18px;
  }
  /* Popout is desktop-only; Albums & Calendar are accessible inside the drawer tabs */
  #btn-popout-chat { display: none; }
  .composer-wrap {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .composer {
    padding: 8px 8px;
    gap: 4px;
  }
  .message-list {
    padding: 12px 12px;
  }
  .msg-row { max-width: 90%; }
  .msg-img { max-width: min(240px, 68vw); }
  .picker-popover { left: 8px; right: 8px; width: auto; }
  .right-panel {
    width: min(360px, 100vw);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

@media (max-width: 520px) {
  /* Keep top bar clean on narrow phones (360-430px): Search, Voice, Video, Notes/Drawer, Info */
  #btn-toggle-albums,
  #btn-toggle-calendar {
    display: none;
  }
  .chat-rich-card {
    width: min(240px, 72vw);
  }
  .icon-picker-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .event-time-row {
    flex-direction: column;
  }
  .call-controls {
    gap: 8px;
    flex-wrap: wrap;
  }
  .call-btn {
    min-width: 64px;
    padding: 8px 10px;
  }
  .modal-card {
    max-height: 92dvh;
    border-radius: 16px;
  }
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}
