* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: #111b21;
  color: #e9edef;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Keep clear of the notch in landscape (viewport-fit=cover) */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Login */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  background: #111b21;
}

.login-box {
  background: #1f2c33;
  padding: 40px;
  border-radius: 8px;
  width: 400px;
  max-width: 90vw;
}

.login-box h1 {
  font-size: 20px;
  margin-bottom: 8px;
  color: #e9edef;
}

.login-box p {
  font-size: 13px;
  color: #8696a0;
  margin-bottom: 24px;
}

.login-box input {
  width: 100%;
  padding: 12px;
  border: 1px solid #2a3942;
  border-radius: 6px;
  background: #2a3942;
  color: #e9edef;
  font-size: 14px;
  outline: none;
  margin-bottom: 16px;
}

.login-box input:focus {
  border-color: #00a884;
}

.login-box .error {
  color: #ef4444;
  font-size: 13px;
  margin-bottom: 12px;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn:hover {
  opacity: 0.85;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: #00a884;
  color: #111b21;
  font-weight: 600;
}

.btn-disable {
  background: #5c1f24;
  color: #f3c5c8;
  font-size: 12px;
  padding: 6px 12px;
}

.btn-block {
  width: 100%;
}

.btn-danger {
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  padding: 6px 12px;
}

.btn-secondary {
  background: #2a3942;
  color: #e9edef;
  font-size: 12px;
  padding: 6px 12px;
}

/* Instances */
.instances-screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #202c33;
  border-bottom: 1px solid #2a3942;
}

.topbar h1 {
  font-size: 16px;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.instances-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.instance-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #1f2c33;
  border-radius: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 10px;
}

.instance-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.instance-info h3 {
  font-size: 14px;
  font-weight: 500;
}

.instance-info .phone {
  font-size: 12px;
  color: #8696a0;
}

.allowlist-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 168, 132, 0.15);
  color: #00a884;
  font-size: 11px;
  font-weight: 600;
}

.disabled-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(134, 150, 160, 0.18);
  color: #aebac1;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.instance-card-disabled h3 { color: #aebac1; }

.status-badge {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-badge.connected { background: #00a884; }
.status-badge.connecting, .status-badge.qr_ready { background: #f59e0b; }
.status-badge.disconnected { background: #ef4444; }
.status-badge.disabled { background: #8696a0; }
.status-badge.error { background: #be123c; animation: status-badge-pulse 1.5s ease-in-out infinite; }

@keyframes status-badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.connection-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: #202c33;
  color: #f59e0b;
  border: 1px solid #f59e0b;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  animation: connection-banner-in 0.2s ease-out;
}

.connection-banner::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
  animation: status-badge-pulse 1.2s ease-in-out infinite;
}

@keyframes connection-banner-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.instance-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* New instance modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: #1f2c33;
  padding: 24px;
  border-radius: 8px;
  width: 360px;
  max-width: 90vw;
  /* The share modal grows with its content (link list, expanded visit panels); on a
     short laptop screen that pushed the action buttons off the bottom. */
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 16px;
  margin-bottom: 16px;
}

.modal input {
  width: 100%;
  padding: 10px;
  border: 1px solid #2a3942;
  border-radius: 6px;
  background: #2a3942;
  color: #e9edef;
  font-size: 14px;
  outline: none;
  margin-bottom: 16px;
}

.modal input:focus {
  border-color: #00a884;
}

.modal-textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #2a3942;
  border-radius: 6px;
  background: #2a3942;
  color: #e9edef;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: vertical;
  margin-bottom: 8px;
}

.modal-textarea:focus {
  border-color: #00a884;
}

.modal-hint {
  font-size: 12px;
  color: #8696a0;
  margin-bottom: 16px;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* QR inline */
.qr-container {
  margin-top: 10px;
  text-align: center;
}

.qr-container img {
  max-width: 200px;
  border-radius: 8px;
}

.qr-container p {
  font-size: 12px;
  color: #8696a0;
  margin-top: 6px;
}

/* Chat screen */
.chat-screen {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* Chat list (left panel) */
.chat-list-panel {
  width: 340px;
  min-width: 280px;
  background: #111b21;
  border-right: 1px solid #2a3942;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease;
}

.chat-list-header {
  padding: 12px 16px;
  background: #202c33;
  border-bottom: 1px solid #2a3942;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}

.chat-list-header h2 {
  font-size: 15px;
  font-weight: 600;
}

/* Sync names button */
.btn-sync {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-sync svg {
  fill: #8696a0;
  transition: fill 0.2s;
}

.btn-sync:hover svg {
  fill: #00a884;
}

.btn-sync:disabled {
  cursor: not-allowed;
}

.btn-sync-spinning svg {
  animation: spin 0.8s linear infinite;
}

/* Chat tabs */
.chat-tabs {
  display: flex;
  background: #111b21;
  border-bottom: 1px solid #2a3942;
  padding: 0 8px;
}

.chat-tab {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #8696a0;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-tab:hover {
  color: #e9edef;
}

.chat-tab.active {
  color: #00a884;
  border-bottom-color: #00a884;
}

.chat-tab-count {
  font-size: 11px;
  opacity: 0.8;
}

/* WhatsApp chat lists: filter chips under the tabs, tags on chats, the picker modal */
.chat-lists-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px;
  background: #111b21;
  border-bottom: 1px solid #2a3942;
  scrollbar-width: none;
}

.chat-lists-bar::-webkit-scrollbar {
  display: none;
}

.chat-lists-bar[hidden] {
  display: none;
}

.list-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid #2a3942;
  background: #202c33;
  color: #d1d7db;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.list-chip:hover {
  border-color: var(--list-color);
}

.list-chip.active {
  border-color: var(--list-color);
  background: color-mix(in srgb, var(--list-color) 22%, #202c33);
  color: #e9edef;
}

.list-chip-count {
  color: #8696a0;
  font-size: 11px;
}

.list-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--list-color);
  flex-shrink: 0;
}

.chat-list-tags,
.header-list-tags {
  display: flex;
  gap: 4px;
  overflow: hidden;
  margin-top: 3px;
}

.header-list-tags {
  cursor: pointer;
}

.list-tag {
  flex-shrink: 0;
  font-size: 11px;
  line-height: 16px;
  padding: 0 6px;
  border-radius: 4px;
  color: var(--list-color);
  background: color-mix(in srgb, var(--list-color) 16%, transparent);
  white-space: nowrap;
}

.lists-picker {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
  max-height: 50vh;
  overflow-y: auto;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 6px;
}

.list-row:hover {
  background: #2a3942;
}

.list-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  cursor: pointer;
  font-size: 14px;
}

.list-row-action {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.list-row-action svg {
  fill: #8696a0;
}

.list-row-action:hover svg {
  fill: #e9edef;
}

.list-row-action.danger:hover svg {
  fill: #f15c6d;
}

.list-row-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.lists-new {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.modal .lists-new input {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.modal .list-row input {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: #00a884;
  cursor: pointer;
}

.list-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row-count {
  color: #8696a0;
  font-size: 12px;
}

.lists-empty {
  color: #8696a0;
  font-size: 13px;
  line-height: 1.4;
  padding: 8px 0;
}

/* Search box in chat list */
.chat-search {
  padding: 8px 12px;
  background: #111b21;
  border-bottom: 1px solid #2a3942;
}

.chat-search input {
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: #202c33;
  color: #e9edef;
  font-size: 13px;
  outline: none;
}

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

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #2a3942;
  transition: background 0.15s;
}

.chat-item:hover {
  background: #202c33;
}

.chat-item.active {
  background: #2a3942;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #00a884;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: #111b21;
  flex-shrink: 0;
  margin-right: 12px;
  overflow: hidden;
}

.chat-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-preview {
  flex: 1;
  min-width: 0;
}

.chat-preview-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.chat-preview h3 {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview .time {
  font-size: 11px;
  color: #8696a0;
  flex-shrink: 0;
  margin-left: 8px;
}

.chat-preview .last-msg {
  font-size: 13px;
  color: #8696a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.unread-badge {
  background: #00a884;
  color: #111b21;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  margin-left: 8px;
}

/* Mobile back button in messages header (hidden on desktop) */
.msg-back-btn {
  display: none;
  background: none;
  border: none;
  color: #00a884;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px 4px 0;
  margin-right: 8px;
  flex-shrink: 0;
}

/* Messages panel (right) */
.messages-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #0b141a;
  overflow: hidden;
}

.messages-panel-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8696a0;
  font-size: 14px;
  flex-direction: column;
  gap: 8px;
}

.messages-panel-empty svg {
  width: 48px;
  height: 48px;
  fill: #2a3942;
}

.messages-header {
  padding: 12px 16px;
  background: #202c33;
  border-bottom: 1px solid #2a3942;
  display: flex;
  align-items: center;
  min-height: 56px;
}

.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 10px;
  overflow: hidden;
}

.header-avatar:has(img) {
  cursor: pointer;
}

/* The chat's name opens its profile too */
.header-name-link {
  cursor: pointer;
}

.header-name-link:hover {
  text-decoration: underline;
  text-decoration-color: #8696a0;
}

.header-avatar:empty {
  display: none;
}

.header-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.messages-header-info {
  min-width: 0;
  overflow: hidden;
}

.messages-header h2 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages-header .jid {
  font-size: 12px;
  color: #8696a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.btn-mark-read {
  margin-left: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid #2a3942;
  border-radius: 6px;
  color: #8696a0;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-lists {
  margin-left: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid #2a3942;
  border-radius: 6px;
  color: #8696a0;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-lists svg {
  fill: #8696a0;
  transition: fill 0.2s;
}

.btn-lists:hover {
  border-color: #00a884;
  color: #00a884;
}

.btn-lists:hover svg {
  fill: #00a884;
}

.chat-toggle {
  margin-left: auto;
  margin-right: 14px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #8696a0;
  cursor: pointer;
}

/* Only the first toggle pushes right; otherwise both split the free space */
.chat-toggle + .chat-toggle {
  margin-left: 0;
}

.chat-toggle:last-of-type {
  margin-right: 0;
}

.toggle-switch {
  position: relative;
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: #4a5a63;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #e9edef;
  transition: transform 0.2s;
}

.toggle-switch.on {
  background: #00a884;
}

.toggle-switch.on::after {
  transform: translateX(15px);
}

.toggle-switch:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Timezone picker (chat header, owner + shared views) */
.tz-picker {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #8696a0;
  margin: 0 10px;
}

.tz-picker-label {
  white-space: nowrap;
}

.tz-picker select {
  background: #2a3942;
  color: #e9edef;
  border: 1px solid #2a3942;
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  max-width: 120px;
}

.tz-picker select:focus {
  border-color: #00a884;
}

.btn-mark-read svg {
  fill: #8696a0;
  transition: fill 0.2s;
}

.btn-mark-read:hover {
  border-color: #00a884;
  color: #00a884;
}

.btn-mark-read:hover svg {
  fill: #00a884;
}

.btn-mark-read:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-mark-read-done {
  border-color: #00a884;
  color: #00a884;
}

.btn-mark-read-done svg {
  fill: #00a884;
}

.messages-body-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.messages-body {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sticky-date-header {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(32, 44, 51, 0.92);
  color: #e9edef;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 14px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sticky-date-header.visible {
  opacity: 1;
}

.date-divider {
  display: flex;
  justify-content: center;
  margin: 8px 0;
}

.date-divider span {
  background: #1f2c33;
  color: #8696a0;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
}

.message-bubble {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
  position: relative;
}

.message-bubble.sent {
  background: #005c4b;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.message-bubble.received {
  background: #1f2c33;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.message-bubble .msg-time {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  text-align: right;
  margin-top: 4px;
}

/* Delivery / read ticks after the time: grey until read, then blue */
.msg-ticks {
  display: inline-block;
  margin-left: 3px;
  vertical-align: -2px;
  line-height: 0;
  color: rgba(255, 255, 255, 0.6);
}

.msg-ticks svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.msg-ticks.read { color: #53bdeb; }
.msg-ticks.error { color: #f15c6d; }

/* On received messages they describe this number's own reading, so they stay quieter */
.msg-ticks.incoming { opacity: 0.75; }

/* The bubble's own date, ahead of the clock time. Dimmed a shade below the time so the
   hour stays the thing the eye lands on. */
.message-bubble .msg-date {
  margin-right: 6px;
  opacity: 0.75;
}

/* 'both' timezone mode: two zone readings side by side in a bubble's time slot */
.msg-time-zone-label {
  opacity: 0.65;
  margin-right: 2px;
}

.msg-time-sep {
  margin: 0 4px;
  opacity: 0.5;
}

.message-bubble .msg-sender {
  font-size: 11px;
  color: #00a884;
  margin-bottom: 2px;
  font-weight: 600;
}

.msg-quote {
  display: block;
  width: 100%;
  min-width: 0;
  border: none;
  border-left: 3px solid #00a884;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  padding: 5px 8px;
  margin-bottom: 5px;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.65);
  text-align: left;
}

button.msg-quote.jumpable {
  cursor: pointer;
}

button.msg-quote.jumpable:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* A quote of our own message, like WhatsApp: a different colour than theirs */
.msg-quote:has(.msg-quote-author.me) {
  border-left-color: #53bdeb;
}

.msg-quote-author {
  display: block;
  font-weight: 600;
  font-size: 12px;
  color: #00a884;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-quote-author.me {
  color: #53bdeb;
}

.msg-quote-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}

.view-once-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 4px;
}

.view-once-badge svg {
  fill: currentColor;
}

/* Broadcast list / forwarded: how a message reached the chat */
.msg-origin {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin-bottom: 3px;
}

.msg-origin-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-style: italic;
  color: rgba(255, 255, 255, 0.6);
}

.msg-origin-badge svg {
  fill: currentColor;
  flex-shrink: 0;
}

/* Edited / deleted messages */
/* Keep / Kept: saves one message's media on the server (owner view only) */
.msg-keep-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 1px 8px;
  margin-right: 6px;
  font: inherit;
  color: #e9edef;
  cursor: pointer;
}

.msg-keep-btn:hover { background: rgba(255, 255, 255, 0.16); }
.msg-keep-btn:disabled { opacity: 0.6; cursor: wait; }

.msg-keep-btn.kept {
  background: rgba(0, 168, 132, 0.18);
  border-color: rgba(0, 168, 132, 0.45);
  color: #7ee2c5;
}

/* Kept reads as a status until hovered, then says what a click does */
.msg-keep-btn .keep-hover { display: none; }
.msg-keep-btn.kept:hover { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
.msg-keep-btn.kept:hover .keep-idle { display: none; }
.msg-keep-btn.kept:hover .keep-hover { display: inline; }

.msg-edited-btn {
  background: none;
  border: none;
  padding: 0;
  margin-right: 6px;
  font: inherit;
  font-style: italic;
  color: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}

.msg-edited-btn:hover {
  color: #e9edef;
}

.msg-deleted-badge {
  display: inline-block;
  font-size: 11px;
  color: #f15c6d;
  margin-bottom: 4px;
}

.message-bubble.deleted {
  box-shadow: inset 0 0 0 1px rgba(241, 92, 109, 0.45);
}

.msg-deleted-empty {
  font-style: italic;
  color: rgba(255, 255, 255, 0.55);
}

.edit-history-modal {
  width: 440px;
}

.edit-history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.edit-history-row {
  background: #2a3942;
  border-radius: 6px;
  padding: 8px 10px;
}

.edit-history-row.original {
  border-left: 3px solid #00a884;
}

.edit-history-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  color: #8696a0;
  margin-bottom: 4px;
}

.edit-history-text {
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.edit-history-empty {
  font-style: italic;
  color: #8696a0;
}

/* Media in messages */
/* Photos and videos show as same-width thumbnails; click a photo (or a video's
   fullscreen button) to see it large. The wrap's width also keeps a long caption
   wrapping under the thumbnail instead of widening the bubble. */
.msg-image-wrap {
  margin: -4px -4px 4px -4px;
  width: 260px;
  max-width: calc(100% + 8px);
}

.msg-image {
  display: block;
  width: 100%;
  height: auto;
  min-height: 120px;
  max-height: 260px;
  object-fit: cover; /* tall or very wide photos are cropped to fit the box */
  border-radius: 6px;
  cursor: zoom-in;
  transition: opacity 0.2s;
}

.msg-image:hover {
  opacity: 0.9;
}

.msg-video {
  display: block;
  width: 100%;
  max-height: 260px;
  background: #000;
  border-radius: 6px;
  outline: none;
}

.msg-image-wrap .msg-media-placeholder {
  min-width: 0;
}

.msg-sticker {
  display: block;
  max-width: 160px;
  max-height: 160px;
}

.msg-caption {
  padding-top: 6px;
  font-size: 14px;
  line-height: 1.4;
}

.msg-media-placeholder {
  background: #1a2a32;
  border-radius: 6px;
  padding: 40px 20px;
  text-align: center;
  color: #8696a0;
  font-size: 12px;
  min-width: 200px;
}

.msg-sticker-placeholder {
  padding: 30px;
  min-width: 100px;
}

.msg-media-error {
  color: #ef4444;
}

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.85);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.lightbox.active {
  display: flex;
}

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  max-height: 90dvh;
  border-radius: 4px;
  object-fit: contain;
}

/* Compose bar */
.compose-bar {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  /* Clear the iPhone home indicator */
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: #202c33;
  gap: 10px;
}

.compose-bar-readonly {
  justify-content: center;
  color: #8696a0;
  font-size: 13px;
}

.compose-bar input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: #2a3942;
  color: #e9edef;
  font-size: 14px;
  outline: none;
}

.compose-bar button {
  background: #00a884;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.compose-bar button svg {
  fill: #111b21;
  width: 20px;
  height: 20px;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #374045;
  border-radius: 3px;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: #8696a0;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: #8696a0;
  font-size: 14px;
}

/* Load-older indicator */
.load-older {
  text-align: center;
  padding: 12px;
  color: #8696a0;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
}

.load-older .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #2a3942;
  border-top-color: #00a884;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.load-older-done {
  text-align: center;
  padding: 12px;
  color: #374045;
  font-size: 11px;
  flex-shrink: 0;
}

/* "Load more from phone" — shown once stored history runs out */
.load-from-phone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  flex-shrink: 0;
}

.load-from-phone-note {
  color: #8696a0;
  font-size: 11px;
  text-align: center;
  max-width: 320px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Reactions ─── */
/* Pill on the reacted-to bubble's bottom edge, like WhatsApp */
.message-bubble.has-reactions {
  margin-bottom: 14px;
}

.msg-reactions {
  position: absolute;
  bottom: -15px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  height: 22px;
  padding: 0 6px;
  background: #202c33;
  border: 2px solid #0b141a;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
  cursor: default;
}

.message-bubble.sent .msg-reactions {
  right: 8px;
}

.message-bubble.received .msg-reactions {
  left: 8px;
}

.msg-reactions-count {
  margin-left: 3px;
  font-size: 11px;
  color: #aebac1;
}

.msg-reactions.clickable {
  cursor: pointer;
}

.msg-reactions.clickable:hover {
  border-color: #2a3942;
}

/* React button: beside the bubble on its outer side, revealed on hover */
.msg-react-btn {
  position: absolute;
  top: 50%;
  width: 28px;
  height: 28px;
  margin-top: -14px;
  border: none;
  border-radius: 50%;
  background: #202c33;
  color: #8696a0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

/* Bridges the gap to the bubble, so moving the pointer across keeps it shown */
.msg-react-btn::before {
  content: '';
  position: absolute;
  inset: -4px -10px;
}

.message-bubble.received .msg-react-btn {
  left: calc(100% + 8px);
}

.message-bubble.sent .msg-react-btn {
  right: calc(100% + 8px);
}

.msg-react-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.message-bubble:hover .msg-react-btn,
.msg-react-btn:focus-visible {
  opacity: 1;
}

.msg-react-btn:hover {
  color: #e9edef;
}

/* Reply button: next to the react button, further out */
.msg-reply-btn {
  position: absolute;
  top: 50%;
  width: 28px;
  height: 28px;
  margin-top: -14px;
  border: none;
  border-radius: 50%;
  background: #202c33;
  color: #8696a0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.msg-reply-btn::before {
  content: '';
  position: absolute;
  inset: -4px -4px;
}

.message-bubble.received .msg-reply-btn {
  left: calc(100% + 40px);
}

.message-bubble.sent .msg-reply-btn {
  right: calc(100% + 40px);
}

.msg-reply-btn svg {
  fill: currentColor;
}

.message-bubble:hover .msg-reply-btn,
.msg-reply-btn:focus-visible {
  opacity: 1;
}

.msg-reply-btn:hover {
  color: #e9edef;
}

/* Narrow screens have room for one button beside the bubble: stack them */
@media (max-width: 768px) {
  .message-bubble .msg-react-btn {
    margin-top: -30px;
  }

  .message-bubble .msg-reply-btn {
    margin-top: 2px;
  }

  .message-bubble.received .msg-reply-btn {
    left: calc(100% + 8px);
  }

  .message-bubble.sent .msg-reply-btn {
    right: calc(100% + 8px);
  }
}

/* Emoji picker, fixed on the page above the bubble */
.reaction-picker {
  position: fixed;
  z-index: 50;
  background: #233138;
  border: 1px solid #2a3942;
  border-radius: 24px;
  padding: 4px 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  max-width: calc(100vw - 16px);
}

.reaction-picker-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.reaction-pick {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, background 0.12s;
}

.reaction-pick:hover {
  background: #2a3942;
  transform: scale(1.15);
}

.reaction-pick.on {
  background: #3b4a54;
}

.reaction-pick-more {
  font-size: 20px;
  color: #aebac1;
  background: #2a3942;
}

.reaction-picker-other {
  display: flex;
  gap: 6px;
  padding: 6px 2px 4px;
}

.reaction-picker-other[hidden] {
  display: none;
}

.reaction-picker-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid #2a3942;
  border-radius: 16px;
  background: #2a3942;
  color: #e9edef;
  font-size: 15px;
  outline: none;
}

.reaction-picker-input:focus {
  border-color: #00a884;
}

.reaction-picker-error {
  color: #ef4444;
  font-size: 11px;
  padding: 0 8px 4px;
}

.reaction-picker-error[hidden] {
  display: none;
}

/* A reaction in the timeline: one small, quiet line on the reactor's side */
.reaction-line {
  display: flex;
  max-width: 70%;
  min-width: 0;
}

.reaction-line.sent {
  align-self: flex-end;
}

.reaction-line.received {
  align-self: flex-start;
}

.reaction-line-card {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  padding: 2px 8px;
  border: none;
  border-radius: 10px;
  background: rgba(32, 44, 51, 0.55);
  color: #8696a0;
  font: inherit;
  font-size: 11px;
  line-height: 1.4;
  cursor: pointer;
}

.reaction-line-card:hover {
  background: rgba(32, 44, 51, 0.95);
  color: #aebac1;
}

.reaction-line-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reaction-line-emoji {
  font-size: 12px;
}

.reaction-line-target {
  color: #aebac1;
  font-style: italic;
}

.reaction-line-time {
  flex-shrink: 0;
  font-size: 10px;
  opacity: 0.7;
}

/* ─── Messages on their way out ─── */
.message-bubble.pending {
  opacity: 0.7;
}

/* Nothing in a pending bubble is clickable yet, apart from Retry / Discard */
.message-bubble.pending > :not(.msg-time) {
  pointer-events: none;
}

.message-bubble.pending.failed {
  opacity: 1;
  box-shadow: inset 0 0 0 1px rgba(241, 92, 109, 0.7);
}

.msg-pending-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.msg-pending-clock {
  width: 8px;
  height: 8px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.msg-pending-error {
  color: #f15c6d;
  font-weight: 500;
}

.msg-pending-retry,
.msg-pending-discard {
  padding: 0 0 0 6px;
  border: none;
  background: none;
  color: #e9edef;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ─── Responsive ─── */

/* Tablets / medium screens */
@media (max-width: 768px) {
  .chat-list-panel {
    width: 280px;
    min-width: 240px;
  }

  .message-bubble {
    max-width: 80%;
  }

  .topbar {
    padding: 10px 14px;
  }

  .topbar h1 {
    font-size: 15px;
  }

  .instances-list {
    padding: 12px 14px;
  }

  .instance-card {
    padding: 12px;
  }

  .instance-actions {
    flex-wrap: wrap;
  }
}

/* Mobile */
@media (max-width: 600px) {
  /* Chat screen: toggle between panels */
  .chat-screen {
    position: relative;
  }

  .chat-list-panel {
    width: 100%;
    min-width: unset;
    position: absolute;
    inset: 0;
    z-index: 2;
    border-right: none;
  }

  .messages-panel {
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  /* When a chat is selected, hide chat list and show messages */
  .chat-screen.chat-open .chat-list-panel {
    display: none;
  }

  .chat-screen.chat-open .messages-panel {
    z-index: 3;
  }

  /* When no chat is selected, messages panel shows empty state behind */
  .chat-screen:not(.chat-open) .messages-panel {
    display: none;
  }

  /* Show mobile back button */
  .msg-back-btn {
    display: block;
  }

  /* Timezone picker: drop the "TZ" label and shrink the select on mobile */
  .tz-picker {
    margin: 0 6px;
  }

  .tz-picker-label {
    display: none;
  }

  .tz-picker select {
    max-width: 84px;
  }

  .message-bubble {
    max-width: 85%;
  }

  /* Instance cards: actions below as an even grid, main action across the top */
  .instance-card {
    flex-direction: column;
    align-items: stretch;
  }

  .instance-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .instance-actions .btn {
    min-width: 0;
    padding: 10px 6px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .instance-actions .btn-primary {
    grid-column: 1 / -1;
  }

  /* Topbar */
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .topbar-actions {
    width: 100%;
    display: flex;
  }

  .topbar-actions .btn {
    flex: 1;
  }

  /* Login box full width on small screens */
  .login-box {
    padding: 24px;
    border-radius: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  /* Compose bar */
  .compose-bar {
    padding: 8px 10px;
    gap: 8px;
  }

  /* Chat items — larger touch targets */
  .chat-item {
    padding: 14px 16px;
  }

  .chat-avatar {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  /* Modal */
  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    /* Exactly the visible screen (not the area behind the browser's toolbars),
       scrolling inside, so the action buttons are never hidden */
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    /* Centre short popups; start tall ones at the top instead of cutting it off */
    justify-content: flex-start;
    justify-content: safe center;
  }

  /* A flex column would otherwise squeeze the content instead of scrolling it */
  .modal > * {
    flex-shrink: 0;
  }

  .instances-list,
  .chat-list {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Share button (chat header) — mirrors .btn-mark-read */
.btn-share {
  margin-left: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid #2a3942;
  border-radius: 6px;
  color: #8696a0;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-share svg {
  fill: #8696a0;
  transition: fill 0.2s;
}

.btn-share:hover {
  border-color: #00a884;
  color: #00a884;
}

.btn-share:hover svg {
  fill: #00a884;
}

/* Share modal */
.share-list {
  /* Roomier than the plain link list needed — an expanded visit panel is tall, and
     scrolling a 260px window through device cards made them unreadable. */
  max-height: min(340px, 50vh);
  overflow-y: auto;
  margin-bottom: 12px;
}

.share-item {
  border: 1px solid #2a3942;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
}

.share-url {
  width: 100%;
  padding: 8px;
  border: 1px solid #2a3942;
  border-radius: 6px;
  background: #111b21;
  color: #e9edef;
  font-size: 12px;
  font-family: monospace;
  outline: none;
}

.share-meta {
  font-size: 11px;
  color: #8696a0;
  margin: 6px 0 8px;
}

.share-item-actions {
  display: flex;
  gap: 6px;
}

.share-label {
  font-size: 13px;
  font-weight: 500;
  color: #e9edef;
  margin-bottom: 6px;
}

/* The create-row label input sits outside .share-item, so it needs the tighter
   bottom margin the stock .modal input doesn't give it. */
.share-label-input {
  margin-bottom: 12px !important;
  font-size: 13px !important;
}

/* ─── Share link usage (per-device visit history) ─── */

.visit-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0;
  margin-bottom: 8px;
  border: none;
  background: none;
  color: #8696a0;
  font-size: 11px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.visit-toggle:disabled {
  cursor: default;
}

.visit-toggle:not(:disabled):hover {
  color: #e9edef;
}

.visit-caret {
  width: 8px;
  flex-shrink: 0;
}

.visit-panel {
  margin-bottom: 8px;
}

.visit-empty {
  font-size: 11px;
  color: #8696a0;
  padding: 8px 0;
}

/* Even padding above and below, so the separator reads as *between* two devices —
   with a tight bottom the stats row visually attached itself to the next device. */
.visit-device {
  border-top: 1px solid #2a3942;
  padding: 12px 0;
}

.visit-device-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #e9edef;
}

.visit-glyph {
  fill: #8696a0;
  flex-shrink: 0;
}

.visit-device-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visit-device-when {
  color: #8696a0;
  font-size: 11px;
  flex-shrink: 0;
}

.visit-device-specs {
  font-size: 11px;
  color: #8696a0;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Activity strip: one bar per time bucket over the link's life, height = time spent
   reading in that bucket. Single series, so a single hue — the accent for buckets with
   activity, the border grey for the empty ones, which stay as a 2px tick so the strip
   reads as a continuous timeline instead of floating bars. */
.visit-strip {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 34px;
  margin-top: 8px;
  border-bottom: 1px solid #2a3942;
}

.visit-bucket {
  flex: 1;
  min-width: 3px;
  height: max(2px, var(--h, 0%));
  background: #2a3942;
  border-radius: 2px 2px 0 0;
}

.visit-bucket.on {
  background: #00a884;
}

.visit-bucket.on:hover {
  background: #06cf9c;
}

/* Shared x-axis for every strip in the panel — stated once, at the top, and stuck
   there while the list scrolls so the strips below never lose their scale. Sticky is
   scoped to .visit-panel, so it releases at the end of its own link's devices. */
.visit-axis {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #8696a0;
  padding-bottom: 6px;
  background: #1f2c33;
  z-index: 1;
}

.visit-device-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
  font-size: 11px;
  color: #8696a0;
  margin-top: 8px;
}

/* Separators between stats, so the row reads as a list instead of a sentence that lost
   its punctuation. Leading rather than trailing: when the row wraps, the dot starts the
   next line instead of dangling at the end of the previous one. */
.visit-device-stats span:not(:first-child)::before {
  content: '·';
  margin-right: 8px;
  color: #3b4a54;
}

.btn-small {
  padding: 5px 10px;
  font-size: 12px;
  background: #2a3942;
  color: #e9edef;
}

/* Shared read-only chat view */
/* No compose bar here, so the message list itself clears the iPhone home indicator */
.shared-screen .messages-body {
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.shared-screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  background: #0b141a;
}

.shared-panel {
  flex: 1;
  min-width: 0;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #0b141a;
  overflow: hidden;
}

.shared-invalid {
  margin: auto;
  text-align: center;
  color: #8696a0;
  padding: 24px;
}

.shared-invalid h2 {
  color: #e9edef;
  margin-bottom: 8px;
  font-size: 18px;
}

@media (max-width: 768px) {
  /* Share and Lists: icon only on narrow screens */
  .btn-share span,
  .btn-lists span {
    display: none;
  }

  .btn-share,
  .btn-lists {
    padding: 6px;
  }
}

/* ─── Marked messages ─── */

/* Marks toggle button (chat header) — mirrors .btn-share / .btn-mark-read */
.btn-marks-toggle {
  margin-left: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid #2a3942;
  border-radius: 6px;
  color: #8696a0;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-marks-toggle .marks-star {
  color: #f59e0b;
}

.btn-marks-toggle:hover,
.btn-marks-toggle.active {
  border-color: #f59e0b;
  color: #f59e0b;
}

/* Mark button on a message bubble — floats just outside the top-right corner so it
   never sits over the text or .msg-time, revealed on hover or once marked. */
.msg-mark-btn {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: #202c33;
  color: #8696a0;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, transform 0.15s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.message-bubble:hover .msg-mark-btn,
.message-bubble.marked .msg-mark-btn {
  opacity: 1;
}

.msg-mark-btn:hover {
  color: #f59e0b;
  transform: scale(1.1);
}

.message-bubble.marked .msg-mark-btn {
  color: #f59e0b;
}

/* Marked bubble — warm accent rail + a subtle tint layered underneath whichever
   sent/received background-color is already set. A background-image (rather than a
   ::before overlay) is used deliberately: backgrounds always paint behind an element's
   own content, so this can't end up covering the message text the way a positioned
   pseudo-element with z-index:auto would (it'd win the paint order over normal-flow
   text, since positioned-but-auto-z-index descendants paint after in-flow content). */
.message-bubble.marked {
  box-shadow: inset 3px 0 0 #f59e0b;
  background-image: linear-gradient(rgba(245, 158, 11, 0.12), rgba(245, 158, 11, 0.12));
}

.msg-mark-note {
  position: relative;
  margin-top: 4px;
  padding: 4px 8px;
  background: rgba(245, 158, 11, 0.14);
  border-left: 2px solid #f59e0b;
  border-radius: 4px;
  font-size: 12px;
  font-style: italic;
  color: rgba(255, 255, 255, 0.75);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Mark popover */
.mark-popover {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  width: 220px;
  max-width: 70vw;
  background: #233138;
  border: 1px solid #2a3942;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 20;
}

.message-bubble.sent .mark-popover {
  left: auto;
  right: 0;
}

.mark-popover-input {
  width: 100%;
  padding: 8px;
  border: 1px solid #2a3942;
  border-radius: 6px;
  background: #2a3942;
  color: #e9edef;
  font-size: 13px;
  outline: none;
  margin-bottom: 8px;
}

.mark-popover-input:focus {
  border-color: #00a884;
}

.mark-popover-error {
  color: #ef4444;
  font-size: 11px;
  margin-bottom: 8px;
}

.mark-popover-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Jump-to-mark flash */
@keyframes mark-jump-flash {
  0%, 100% { box-shadow: none; }
  25% { box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.65); }
}

.mark-jump-flash {
  animation: mark-jump-flash 1.5s ease-out;
}

/* Marks panel — third flex child of .chat-screen (owner) / sibling of .shared-panel
   inside .shared-screen (shared view) */
.marks-panel {
  display: none;
  flex-direction: column;
  width: 300px;
  min-width: 260px;
  background: #111b21;
  border-left: 1px solid #2a3942;
}

.marks-panel.open {
  display: flex;
}

.marks-panel-header {
  padding: 12px 16px;
  background: #202c33;
  border-bottom: 1px solid #2a3942;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}

.marks-panel-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: #e9edef;
}

.marks-panel-close {
  background: none;
  border: none;
  color: #8696a0;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.marks-panel-close:hover {
  color: #e9edef;
}

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

.marks-panel-empty {
  text-align: center;
  padding: 40px 16px;
  color: #8696a0;
  font-size: 13px;
  line-height: 1.5;
}

.mark-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.mark-row:hover {
  background: #1f2c33;
}

.mark-row-main {
  flex: 1;
  min-width: 0;
}

.mark-row-meta {
  display: flex;
  gap: 6px;
  font-size: 11px;
  color: #8696a0;
  margin-bottom: 2px;
}

.mark-row-sender {
  font-size: 11px;
  color: #00a884;
  font-weight: 600;
  margin-bottom: 2px;
}

.mark-row-preview {
  font-size: 13px;
  color: #e9edef;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.mark-row-note {
  margin-top: 4px;
  font-size: 12px;
  font-style: italic;
  color: #f59e0b;
}

.mark-row-remove {
  background: none;
  border: none;
  color: #8696a0;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  flex-shrink: 0;
}

.mark-row-remove:hover {
  color: #ef4444;
}

.mark-row-error {
  font-size: 11px;
  color: #ef4444;
  margin-top: 4px;
}

.mark-row.mark-row-jumping {
  opacity: 0.6;
  pointer-events: none;
}

.mark-row.mark-row-jumping::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  margin-top: -7px;
  width: 14px;
  height: 14px;
  border: 2px solid #2a3942;
  border-top-color: #00a884;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@media (max-width: 768px) {
  /* Marks toggle: icon + count only on mobile, same treatment as Share/Mark read */
  .btn-marks-toggle .marks-label {
    display: none;
  }

  .btn-marks-toggle {
    padding: 6px;
  }
}

@media (max-width: 600px) {
  /* Marks panel takes over the full screen when opened, same pattern as the
     chat-list/messages panel swap already used at this breakpoint. .shared-screen needs
     an explicit positioned ancestor for that (.chat-screen already gets one above). */
  .shared-screen {
    position: relative;
  }

  .marks-panel.open {
    position: absolute;
    inset: 0;
    z-index: 4;
    width: 100%;
    min-width: unset;
  }
}

/* A contact's other names (WhatsApp profile name, business name) beside the shown one */
.chat-alt-names,
.header-alt-names {
  font-size: 12px;
  color: #8696a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-alt-names {
  margin-top: 2px;
}

.header-alt-names {
  margin-bottom: 1px;
}

/* ─── AI access ─── */
.modal-wide {
  width: 620px;
}

.ai-modal input[type="checkbox"],
.ai-modal input[type="radio"] {
  width: auto;
  margin: 0;
  padding: 0;
  accent-color: #00a884;
  flex-shrink: 0;
}

.ai-modal select,
.ai-draft-edit {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #2a3942;
  border-radius: 6px;
  background: #2a3942;
  color: #e9edef;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.ai-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8696a0;
  margin: 16px 0 8px;
}

.modal-actions-spacer {
  flex: 1;
}

.ai-modal .modal-actions {
  flex-wrap: wrap;
  margin-top: 16px;
}

/* Small buttons keep their colour when they are also primary/danger */
.btn-small.btn-primary {
  background: #00a884;
  color: #111b21;
}

.btn-small.btn-danger {
  background: #ef4444;
  color: #fff;
  padding: 5px 10px;
}

/* Instance card / chat list badges */
.ai-pending-count {
  display: inline-block;
  background: #f5b942;
  color: #111b21;
  font-weight: 700;
  font-size: 11px;
  border-radius: 9px;
  padding: 0 6px;
  margin-left: 4px;
}

.ai-badge {
  background: #f5b942;
  color: #111b21;
  font-size: 10px;
  font-weight: 700;
  border-radius: 4px;
  padding: 2px 5px;
  margin-left: 8px;
  flex-shrink: 0;
}

/* Keys */
.ai-keys {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-key {
  background: #111b21;
  border: 1px solid #2a3942;
  border-radius: 8px;
  padding: 12px;
}

.ai-key.inactive {
  opacity: 0.6;
}

.ai-key-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.ai-key-name {
  font-weight: 600;
  font-size: 15px;
}

.ai-key-prefix {
  font-size: 12px;
  color: #8696a0;
}

.ai-key-state {
  font-size: 11px;
  text-transform: uppercase;
  color: #ef4444;
  font-weight: 600;
}

.ai-mode-switch {
  display: flex;
  border: 1px solid #2a3942;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}

.ai-mode-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: #aebac1;
  font-size: 12px;
  padding: 7px 6px;
  cursor: pointer;
}

.ai-mode-btn + .ai-mode-btn {
  border-left: 1px solid #2a3942;
}

.ai-mode-btn.on {
  background: #00a884;
  color: #111b21;
  font-weight: 600;
}

.ai-mode-btn:disabled {
  cursor: not-allowed;
}

.ai-key-scope {
  font-size: 13px;
  color: #d1d7db;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.ai-key-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: #8696a0;
  margin-bottom: 8px;
}

.ai-key-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Activity log */
.ai-activity {
  margin-top: 10px;
  border-top: 1px solid #2a3942;
  padding-top: 10px;
}

.ai-activity-filters {
  margin-bottom: 8px;
  max-width: 200px;
}

.ai-activity-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-event {
  font-size: 12px;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 6px;
  background: #1f2c33;
}

.ai-event.blocked {
  border-left: 3px solid #ef4444;
}

.ai-event-time {
  color: #8696a0;
  margin-right: 8px;
}

.ai-event-outcome {
  color: #ef4444;
  font-weight: 600;
  margin-left: 6px;
}

.ai-event-detail {
  color: #aebac1;
  margin-top: 2px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ai-activity-more {
  margin-top: 8px;
}

/* Form */
.ai-form .ai-label,
.ai-created .ai-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #8696a0;
  margin: 4px 0 6px;
}

.ai-mode-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.ai-mode-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid #2a3942;
  border-radius: 6px;
  cursor: pointer;
}

.ai-mode-option input {
  margin-top: 3px !important;
}

.ai-mode-option span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
}

.ai-mode-option small {
  color: #8696a0;
  font-size: 12px;
}

.ai-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 8px;
  cursor: pointer;
}

.ai-chat-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #2a3942;
  border-radius: 6px;
  margin: -8px 0 6px;
}

.ai-chat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}

.ai-chat-row:hover {
  background: #2a3942;
}

.ai-chat-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-jid {
  color: #8696a0;
  font-size: 11px;
  flex-shrink: 0;
}

.ai-picked-count {
  font-size: 12px;
  color: #8696a0;
  margin-bottom: 8px;
}

.ai-form-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.ai-form-row > div {
  flex: 1;
}

.ai-webhook-pick {
  margin: -2px 0 8px 26px;
}

.ai-webhook-pick[hidden] {
  display: none;
}

.ai-level {
  border-left: 2px solid #2a3942;
  padding-left: 10px;
  margin-bottom: 12px;
}

.ai-level .modal-hint {
  margin: -2px 0 6px;
}

.ai-level-name {
  color: #8696a0;
}

.ai-request-changes {
  margin: 0 0 8px;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.5;
}

.ai-created-warn {
  color: #f5b942;
  font-weight: 600;
  margin-bottom: 10px;
}

.ai-created .share-url {
  margin-bottom: 6px;
}

.ai-created .btn-small {
  margin-bottom: 14px;
}

.ai-setup {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}

/* Draft cards: in the AI access window and above the chat's compose bar */
.ai-drafts {
  background: #182229;
  border-top: 1px solid #2a3942;
  padding: 8px 16px;
  max-height: 45vh;
  max-height: 45dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-drafts[hidden] {
  display: none;
}

.ai-draft {
  border: 1px dashed #f5b942;
  border-radius: 8px;
  padding: 10px 12px;
  background: #1f2c33;
  margin-bottom: 8px;
}

.ai-drafts .ai-draft {
  margin-bottom: 0;
  align-self: flex-end;
  max-width: min(640px, 100%);
  width: 100%;
}

.ai-draft.done {
  opacity: 0.5;
}

.ai-draft-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  font-size: 12px;
  margin-bottom: 6px;
}

.ai-tag {
  background: #f5b942;
  color: #111b21;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  border-radius: 4px;
  padding: 1px 5px;
}

.ai-draft-key {
  font-weight: 600;
}

.ai-draft-chat {
  color: #d1d7db;
}

.ai-draft-when {
  color: #8696a0;
  margin-left: auto;
}

.ai-draft-note {
  font-size: 12px;
  font-style: italic;
  color: #aebac1;
  margin-bottom: 6px;
}

.ai-draft-text {
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-bottom: 8px;
}

.ai-draft-edit {
  margin-bottom: 8px;
  resize: vertical;
}

.ai-draft-error {
  color: #ef4444;
  font-size: 12px;
  margin-bottom: 8px;
}

.ai-draft-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* "Sent by AI" on a message bubble */
.msg-ai-label {
  font-size: 10px;
  font-weight: 600;
  color: #f5b942;
  margin-right: 6px;
}

@media (max-width: 600px) {
  .ai-form-row {
    flex-direction: column;
  }
  .ai-mode-btn {
    font-size: 11px;
    padding: 7px 3px;
  }
  .ai-draft-when {
    margin-left: 0;
  }
}

/* ─── Chat picker (AI keys and webhooks) ─── */
.cp-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.modal .cp-toolbar input {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.ai-modal .cp-toolbar select {
  width: auto;
  flex-shrink: 0;
}

.cp-picker .ai-chat-list {
  margin: 0 0 6px;
}

.cp-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.cp-count {
  font-size: 12px;
  color: #8696a0;
}

.cp-footer .btn-small:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ─── Webhooks ─── */
.wh-count {
  display: inline-block;
  background: #2a3942;
  color: #e9edef;
  font-weight: 700;
  font-size: 11px;
  border-radius: 9px;
  padding: 0 6px;
  margin-left: 4px;
}

.wh-count.failing {
  background: #ef4444;
  color: #fff;
}

.wh-url {
  display: block;
  font-size: 12px;
  color: #aebac1;
  overflow-wrap: anywhere;
  margin-bottom: 8px;
}

.wh-k {
  display: inline-block;
  min-width: 52px;
  color: #8696a0;
  font-size: 12px;
}

.wh-hook .ai-key-scope code {
  font-size: 12px;
  overflow-wrap: anywhere;
}

.wh-delivery.ok {
  color: #00a884;
}

.wh-delivery.failing {
  color: #ef4444;
}

.wh-note {
  font-size: 12px;
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.wh-note.ok {
  background: rgba(0, 168, 132, 0.12);
  color: #7ee2c8;
}

.wh-note.failing {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}

.wh-example {
  margin-top: 14px;
  font-size: 13px;
}

.wh-example summary {
  cursor: pointer;
  color: #aebac1;
  margin-bottom: 8px;
}

.wh-example code,
.wh-auth-hint code {
  font-size: 11px;
  background: #111b21;
  border-radius: 3px;
  padding: 0 3px;
}

.wh-pre {
  background: #111b21;
  border: 1px solid #2a3942;
  border-radius: 6px;
  padding: 10px;
  font-size: 11px;
  line-height: 1.45;
  overflow-x: auto;
  max-height: 260px;
  color: #d1d7db;
}

.wh-optional {
  font-weight: 400;
}

.wh-auth {
  display: flex;
  gap: 8px;
}

.modal .wh-auth input {
  margin-bottom: 6px;
}

.wh-auth-header {
  flex: 0 0 34%;
  min-width: 0;
}

.wh-auth-value {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.wh-auth-value input {
  flex: 1;
  min-width: 0;
}

.wh-auth-value .btn-small {
  margin-top: 6px;
  flex-shrink: 0;
}

.wh-auth-hint {
  margin-bottom: 10px;
}

.wh-auth-remove {
  margin-bottom: 16px;
}

.wh-events {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.wh-event-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wh-event-group-title {
  font-size: 12px;
  color: #aebac1;
}

.wh-chats-hint {
  margin-bottom: 8px;
}

/* Wait for "Messages received, grouped" */
.wh-batch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -6px 0 16px;
  font-size: 13px;
  color: #d1d7db;
}

.wh-batch input[type='number'] {
  width: 64px;
  margin: 0;
}

.wh-batch .modal-hint {
  flex-basis: 100%;
  margin: 0;
}

@media (max-width: 520px) {
  .wh-auth {
    flex-direction: column;
    gap: 0;
  }

  .wh-auth-header {
    flex-basis: auto;
  }
}

/* ── Sending files ── */
.compose-bar .compose-attach-btn {
  background: transparent;
  flex-shrink: 0;
}

.compose-bar .compose-attach-btn svg {
  fill: #8696a0;
  width: 22px;
  height: 22px;
}

.compose-bar .compose-attach-btn:hover svg {
  fill: #d1d7db;
}

.compose-bar button:disabled {
  opacity: 0.5;
  cursor: default;
}

.compose-reply {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #1f2c33;
  border-top: 1px solid #2a3942;
}

.compose-reply[hidden] {
  display: none;
}

.compose-reply-quote {
  flex: 1;
  min-width: 0;
  border: none;
  border-left: 3px solid #00a884;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  color: #aebac1;
  text-align: left;
  cursor: pointer;
}

.compose-reply-quote:has(.msg-quote-author.me) {
  border-left-color: #53bdeb;
}

.compose-reply-cancel {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #8696a0;
  font-size: 16px;
  cursor: pointer;
}

.compose-reply-cancel:hover {
  background: #2a3942;
  color: #e9edef;
}

.compose-attachment {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #1f2c33;
  border-top: 1px solid #2a3942;
}

.compose-attachment[hidden] {
  display: none;
}

.attach-preview {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  background: #111b21;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attach-preview img,
.attach-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attach-info {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}

.attach-name {
  color: #e9edef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-meta,
.attach-status {
  color: #8696a0;
  font-size: 12px;
  margin-top: 2px;
}

.attach-as-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #aebac1;
  font-size: 12px;
  margin-top: 4px;
  cursor: pointer;
}

.attach-error {
  color: #ef4444;
  font-size: 12px;
  margin-top: 4px;
}

.attach-remove {
  background: transparent;
  border: none;
  color: #8696a0;
  font-size: 24px;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
}

.attach-remove:hover:not(:disabled) {
  background: #2a3942;
  color: #e9edef;
}

.messages-body-wrap.drop-target {
  outline: 2px dashed #00a884;
  outline-offset: -8px;
}

/* Audio and documents in messages and drafts */
.msg-audio {
  display: block;
  width: 260px;
  max-width: 100%;
  height: 40px;
}

.msg-audio-placeholder {
  padding: 12px 20px;
}

.msg-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 200px;
  max-width: 320px;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.18);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.msg-doc:hover {
  background: rgba(0, 0, 0, 0.28);
}

.msg-doc-icon {
  flex-shrink: 0;
  width: 38px;
  height: 44px;
  border-radius: 4px;
  background: #53bdeb;
  color: #111b21;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.msg-doc-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.msg-doc-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-doc-meta {
  font-size: 12px;
  color: #8696a0;
}

.ai-draft-media {
  margin-bottom: 8px;
  max-width: 320px;
}

.ai-draft-media .msg-image,
.ai-draft-media .msg-video {
  max-height: 280px;
}

.ai-draft-media-meta {
  font-size: 12px;
  color: #8696a0;
  margin-top: 4px;
}

.ai-draft-text.empty {
  display: none;
}

@media (max-width: 768px) {
  .compose-attachment {
    padding: 8px 10px;
  }
}

/* "Load more chats" at the bottom of the chat list */
.chat-load-more {
  display: block;
  width: calc(100% - 24px);
  margin: 10px 12px 16px;
  padding: 8px 12px;
  font-size: 13px;
}

/* ─── Message search ─── */

/* Search toggle (chat header): icon-only twin of .btn-marks-toggle */
.btn-search-toggle {
  margin-left: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  background: none;
  border: 1px solid #2a3942;
  border-radius: 6px;
  color: #8696a0;
  padding: 5px 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-search-toggle svg {
  fill: currentColor;
}

.btn-search-toggle:hover,
.btn-search-toggle.active {
  border-color: #00a884;
  color: #00a884;
}

.search-panel .marks-panel-header {
  gap: 8px;
}

.search-panel-input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: #2a3942;
  color: #e9edef;
  font-size: 13px;
  outline: none;
}

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

/* One result: same look as a marks-panel row */
.search-row {
  position: relative;
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.search-row:hover {
  background: #1f2c33;
}

.search-row-chat {
  color: #e9edef;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: auto;
}

.search-row-type {
  display: inline-block;
  margin-right: 6px;
  padding: 0 5px;
  border-radius: 3px;
  background: #2a3942;
  color: #8696a0;
  font-size: 10px;
  text-transform: uppercase;
  vertical-align: 1px;
}

.search-hit {
  -webkit-line-clamp: 3;
  white-space: pre-line;
}

.search-hit mark {
  background: rgba(0, 168, 132, 0.35);
  color: #e9edef;
  border-radius: 2px;
  padding: 0 1px;
}

.search-row.search-row-jumping {
  opacity: 0.6;
  pointer-events: none;
}

.search-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  color: #8696a0;
  font-size: 13px;
}

.search-status .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #2a3942;
  border-top-color: #00a884;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.search-error {
  color: #ef4444;
}

.search-more {
  display: block;
  margin: 8px auto;
}

/* The chat list's "Messages" section, under the matching chats */
.chat-search-section {
  padding: 10px 16px 6px;
  font-size: 12px;
  font-weight: 600;
  color: #00a884;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #2a3942;
}

.chat-search-results {
  padding: 4px 8px;
}

.chat-search-results .search-row {
  border-bottom: 1px solid #202c33;
  border-radius: 0;
  margin-bottom: 0;
}

@media (max-width: 600px) {
  .search-panel.open {
    position: absolute;
    inset: 0;
    z-index: 4;
    width: 100%;
    min-width: unset;
  }
}

/* ─── Chat options ⋮ menu ───
   Every chat option lives here on all screen sizes: Lists, Mark read and the toggles
   (.chat-quick-opts) on top, then the time zone, Share and Marked. */
.messages-header-info {
  flex: 1;
}

.chat-settings {
  position: relative;
  margin-left: 10px;
  flex-shrink: 0;
}

.chat-settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid #2a3942;
  border-radius: 6px;
  padding: 5px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.chat-settings-btn svg {
  fill: #8696a0;
}

.chat-settings-btn:hover,
.chat-settings.open .chat-settings-btn {
  border-color: #00a884;
}

.chat-settings-btn:hover svg,
.chat-settings.open .chat-settings-btn svg {
  fill: #00a884;
}

.chat-settings-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  min-width: 230px;
  flex-direction: column;
  padding: 6px 0;
  background: #233138;
  border: 1px solid #2a3942;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.chat-settings.open .chat-settings-menu {
  display: flex;
}

.chat-settings-menu .chat-quick-opts {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid #2a3942;
  margin-bottom: 6px;
  padding-bottom: 6px;
}

/* Every item in the menu is a full-width row with its label */
.chat-settings-menu .btn-lists,
.chat-settings-menu .btn-mark-read,
.chat-settings-menu .btn-share,
.chat-settings-menu .btn-marks-toggle,
.chat-settings-menu .chat-toggle,
.chat-settings-menu .tz-picker {
  width: 100%;
  margin: 0;
  padding: 12px 16px;
  gap: 10px;
  border: none;
  border-radius: 0;
  font-size: 14px;
  color: #e9edef;
}

.chat-settings-menu .chat-toggle,
.chat-settings-menu .tz-picker {
  justify-content: space-between;
}

.chat-settings-menu .btn-lists:hover,
.chat-settings-menu .btn-mark-read:hover,
.chat-settings-menu .btn-share:hover,
.chat-settings-menu .btn-marks-toggle:hover,
.chat-settings-menu .btn-marks-toggle.active {
  background: #2a3942;
  color: #e9edef;
}

.chat-settings-menu .btn-lists span,
.chat-settings-menu .btn-mark-read span,
.chat-settings-menu .btn-share span,
.chat-settings-menu .btn-marks-toggle .marks-label,
.chat-settings-menu .tz-picker-label {
  display: inline;
}

.chat-settings-menu .btn-lists svg,
.chat-settings-menu .btn-mark-read svg,
.chat-settings-menu .btn-share svg,
.chat-settings-menu .btn-lists:hover svg,
.chat-settings-menu .btn-mark-read:hover svg,
.chat-settings-menu .btn-share:hover svg {
  fill: #e9edef;
}

.chat-settings-menu .btn-mark-read-done,
.chat-settings-menu .btn-mark-read-done svg {
  color: #00a884;
  fill: #00a884;
}

.chat-settings-menu .btn-marks-toggle .marks-star {
  width: 18px;
  text-align: center;
}

.chat-settings-menu .tz-picker select {
  max-width: none;
  min-width: 140px;
  padding: 8px 10px;
  font-size: 14px;
}

@media (max-width: 600px) {
  /* A comfortable tap target on a phone; 16px also stops iOS zooming in on focus */
  .chat-settings-menu .tz-picker select {
    flex: 1;
    min-height: 42px;
    font-size: 16px;
  }

  .chat-settings-menu {
    min-width: 260px;
  }
}

/* ── Contact profile panel: a wider marks-panel (full screen on phones, same rule) ── */
.profile-panel {
  width: 360px;
  min-width: 300px;
}

.profile-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 32px;
  font-size: 13px;
  color: #e9edef;
}

.pf-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding-bottom: 16px;
}

.pf-photo {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  overflow: hidden;
  background: #2a3942;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: #aebac1;
  margin-bottom: 8px;
}

.pf-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pf-photo-zoom {
  cursor: zoom-in;
}

.pf-name {
  font-size: 18px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.pf-alt,
.pf-muted,
.pf-hint {
  color: #8696a0;
}

.pf-alt {
  font-size: 12px;
}

.pf-phone {
  font-size: 14px;
  color: #d1d7db;
}

.pf-copy {
  margin-left: 6px;
  background: none;
  border: 1px solid #2a3942;
  border-radius: 4px;
  color: #8696a0;
  font-size: 11px;
  padding: 1px 6px;
  cursor: pointer;
}

.pf-copy:hover {
  color: #e9edef;
}

.pf-top-tags,
.chat-crm-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.chat-crm-tags {
  justify-content: flex-start;
  margin-top: 2px;
  overflow: hidden;
  max-height: 18px;
}

/* App-only tags: outlined, so they don't look like WhatsApp lists (filled) */
.crm-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  line-height: 16px;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid #3b4a54;
  color: #aebac1;
  white-space: nowrap;
}

.crm-tag-remove {
  background: none;
  border: none;
  color: #8696a0;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 0 0 2px;
}

.crm-tag-remove:hover {
  color: #ef4444;
}

.pf-warning {
  background: color-mix(in srgb, #f59e0b 14%, transparent);
  border: 1px solid color-mix(in srgb, #f59e0b 40%, transparent);
  color: #f5b942;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.pf-section {
  border-top: 1px solid #2a3942;
  padding: 14px 0 6px;
}

.pf-section-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8696a0;
  margin-bottom: 8px;
}

.pf-section-head svg {
  fill: currentColor;
  flex-shrink: 0;
}

.pf-local .pf-section-head {
  color: #00a884;
}

.pf-banner {
  background: color-mix(in srgb, #00a884 10%, transparent);
  border-left: 3px solid #00a884;
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 12px;
  color: #d1d7db;
  font-size: 12px;
}

.pf-hint {
  font-size: 12px;
  margin-bottom: 8px;
}

.pf-status {
  margin-left: auto;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: #8696a0;
}

.pf-status-error {
  color: #ef4444;
}

.pf-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.pf-field > span {
  font-size: 12px;
  color: #8696a0;
}

.pf-field input,
.pf-field select,
.pf-field textarea,
.pf-handle-add input,
.pf-handle-add select,
.pf-handle-label {
  width: 100%;
  background: #202c33;
  border: 1px solid #2a3942;
  border-radius: 6px;
  color: #e9edef;
  font: inherit;
  /* 16px stops iOS from zooming in on focus */
  font-size: 16px;
  padding: 7px 9px;
  outline: none;
}

@media (min-width: 601px) {
  .pf-field input,
  .pf-field select,
  .pf-field textarea,
  .pf-handle-add input,
  .pf-handle-add select,
  .pf-handle-label {
    font-size: 13px;
  }
}

.pf-field input:focus,
.pf-field select:focus,
.pf-field textarea:focus,
.pf-handle-add input:focus,
.pf-handle-label:focus {
  border-color: #00a884;
}

.pf-field textarea {
  resize: vertical;
  min-height: 72px;
}

.pf-field input[type='date'] {
  color-scheme: dark;
}

.pf-country {
  text-transform: uppercase;
}

.pf-tags-edit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  background: #202c33;
  border: 1px solid #2a3942;
  border-radius: 6px;
  padding: 5px 6px;
}

.pf-tags-edit:focus-within {
  border-color: #00a884;
}

.pf-tags-edit input {
  flex: 1;
  min-width: 90px;
  width: auto;
  border: none;
  background: none;
  padding: 2px;
}

.pf-subhead {
  font-size: 12px;
  color: #8696a0;
  margin: 14px 0 6px;
}

.pf-handles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.pf-handle {
  display: grid;
  grid-template-columns: 1fr 88px auto;
  grid-template-areas:
    'type label remove'
    'value label remove';
  align-items: center;
  column-gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  background: #1a252c;
}

.pf-handle-type {
  grid-area: type;
  font-size: 11px;
  color: #8696a0;
}

.pf-handle-value {
  grid-area: value;
  overflow-wrap: anywhere;
}

.pf-handle-value a,
.pf-row-value a {
  color: #53bdeb;
  text-decoration: none;
}

.pf-handle-value a:hover,
.pf-row-value a:hover {
  text-decoration: underline;
}

.pf-handle .pf-handle-label {
  grid-area: label;
  padding: 4px 6px;
}

.pf-handle-remove {
  grid-area: remove;
  background: none;
  border: none;
  color: #8696a0;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

.pf-handle-remove:hover {
  color: #ef4444;
}

.pf-handle-add {
  display: grid;
  grid-template-columns: minmax(0, 110px) minmax(0, 1fr) auto;
  gap: 6px;
}

.pf-handle-add .btn {
  padding: 6px 12px;
}

.pf-error {
  color: #ef4444;
  font-size: 12px;
  margin-top: 6px;
}

.pf-empty {
  color: #8696a0;
  font-size: 12px;
  padding: 4px 0;
}

.pf-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 8px;
  padding: 5px 0;
}

.pf-row-label {
  color: #8696a0;
  font-size: 12px;
}

.pf-row-value {
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.pf-lists {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-right: 6px;
}

.pf-sync-note {
  font-size: 11px;
}

.pf-refresh {
  margin-left: auto;
  background: none;
  border: 1px solid #2a3942;
  border-radius: 4px;
  color: #8696a0;
  padding: 3px 5px;
  cursor: pointer;
  display: flex;
}

.pf-refresh:hover {
  color: #e9edef;
}

.pf-refresh svg {
  fill: currentColor;
}

.pf-ids,
.pf-history {
  margin-top: 8px;
}

.pf-ids summary,
.pf-history summary {
  cursor: pointer;
  color: #8696a0;
  font-size: 12px;
  padding: 4px 0;
}

.pf-ids .pf-row-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.pf-change {
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 1px solid #1f2c33;
  overflow-wrap: anywhere;
}

.pf-delete {
  margin-top: 14px;
  background: none;
  border: 1px solid color-mix(in srgb, #ef4444 50%, transparent);
  color: #ef4444;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
}

.pf-delete:hover {
  background: color-mix(in srgb, #ef4444 12%, transparent);
}

.pf-retry {
  margin-top: 12px;
}

/* ─── Assistant ─── */

.btn-assistant-toggle svg {
  fill: currentColor;
}

.btn-assistant-toggle:hover,
.btn-assistant-toggle.active {
  border-color: #a78bfa;
  color: #a78bfa;
}

.assistant-panel {
  width: 380px;
  min-width: 300px;
}

.as-header {
  gap: 8px;
}

.as-header h3 {
  margin-right: auto;
}

/* The mode, as a chip that opens a menu */
.as-mode-wrap {
  position: relative;
}

.as-mode-chip {
  background: none;
  border: 1px solid #a78bfa;
  border-radius: 14px;
  color: #a78bfa;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}

.as-mode-chip-off {
  border-color: #3b4a54;
  color: #8696a0;
  font-weight: 400;
}

.as-mode-chip-auto {
  border-color: #f5b942;
  color: #f5b942;
}

.as-mode-chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.as-mode-caret {
  font-size: 10px;
  margin-left: 2px;
}

.as-mode-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  width: min(290px, calc(100vw - 32px));
  background: #233138;
  border: 1px solid #2a3942;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  padding: 4px;
}

.as-mode-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  color: #e9edef;
  cursor: pointer;
}

.as-mode-option:hover:not(:disabled) {
  background: #2a3942;
}

.as-mode-option.active {
  background: color-mix(in srgb, #a78bfa 18%, transparent);
}

.as-mode-option:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.as-mode-option-label {
  font-size: 13px;
  font-weight: 600;
}

.as-mode-option.active .as-mode-option-label::after {
  content: ' ✓';
  color: #a78bfa;
}

.as-mode-option-auto .as-mode-option-label {
  color: #f5b942;
}

.as-mode-option-hint {
  font-size: 12px;
  line-height: 1.4;
  color: #8696a0;
}

/* Conversation | Notes */
.as-panel-tabs {
  display: flex;
  border-bottom: 1px solid #2a3942;
  background: #111b21;
}

.as-panel-tabs[hidden] {
  display: none;
}

.as-panel-tabs .as-tab {
  flex: 1;
  padding: 10px 8px;
}

.as-tab-badge {
  display: inline-block;
  min-width: 16px;
  padding: 0 4px;
  margin-left: 4px;
  border-radius: 8px;
  background: #f5b942;
  color: #111b21;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
}

.as-tab-badge[hidden] {
  display: none;
}

/* On the Conversation tab the thread fills the panel, so a short one sits at the bottom */
.as-body-chat {
  display: flex;
  flex-direction: column;
}

.as-body-chat .as-thread {
  margin-top: auto;
}

.as-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 20px;
  font-size: 13px;
  color: #e9edef;
}

.as-body .pf-section:first-of-type {
  margin-top: 4px;
}

.as-warning {
  border-left-color: #f5b942;
  background: color-mix(in srgb, #f5b942 10%, transparent);
}

.as-warning code,
.as-modal code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #e9edef;
}

.as-mode-auto {
  color: #f5b942;
}

.as-status {
  margin: 0 0 8px;
  font-size: 12px;
  color: #a78bfa;
}

.as-problem {
  color: #f5b942;
  overflow-wrap: anywhere;
}

.as-intro {
  margin-top: 16px;
  line-height: 1.5;
}

.as-intro p + p {
  margin-top: 8px;
  font-size: 12px;
}

.as-brief {
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.as-count {
  color: #8696a0;
  font-weight: 400;
}

.as-none {
  padding: 4px 0 8px;
}

.as-items,
.as-runs {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.as-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px;
  margin: 0 -8px;
  border-radius: 6px;
}

.as-item:hover {
  background: #202c33;
}

.as-item-main {
  flex: 1;
  min-width: 0;
}

.as-item-text {
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.as-item-meta {
  margin-top: 2px;
  font-size: 11px;
  color: #8696a0;
}

.as-kind {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #aebac1;
  background: #2a3942;
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 4px;
}

.as-kind-commitment,
.as-kind-date {
  color: #f5b942;
}

.as-kind-open_question {
  color: #53bdeb;
}

.as-due {
  font-size: 11px;
  color: #8696a0;
}

.as-overdue {
  color: #f15c6d;
}

.as-item-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0.55;
}

.as-item:hover .as-item-actions,
.as-item:focus-within .as-item-actions {
  opacity: 1;
}

.as-item-actions button {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: #aebac1;
  font-size: 12px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}

.as-item-actions button:hover {
  border-color: #2a3942;
  color: #e9edef;
}

.as-item-actions button.on {
  color: #00a884;
}

.as-add {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.as-add input,
.as-add select,
.as-label input,
.as-label select,
.as-label textarea,
.as-event-form input,
.as-event-form select,
.as-hours-row input,
.as-compose textarea {
  background: #2a3942;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #e9edef;
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  min-width: 0;
  margin: 0;
}

.as-add input {
  flex: 1;
}

.as-add input:focus,
.as-add select:focus,
.as-label input:focus,
.as-label select:focus,
.as-label textarea:focus,
.as-event-form input:focus,
.as-hours-row input:focus,
.as-compose textarea:focus {
  outline: none;
  border-color: #a78bfa;
}

.as-add .btn,
.as-event-form .btn {
  padding: 6px 12px;
  flex-shrink: 0;
}

.as-instructions summary,
.as-hours summary {
  cursor: pointer;
  list-style-position: inside;
}

.as-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 12px;
  color: #8696a0;
}

.as-label input,
.as-label textarea {
  width: 100%;
  resize: vertical;
}

.as-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.as-link {
  background: none;
  border: none;
  color: #8696a0;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  margin-left: auto;
}

.as-form-actions .as-link {
  margin-left: 0;
}

.as-link:hover {
  color: #e9edef;
}

.as-danger:hover {
  color: #f15c6d;
}

/* The conversation with the assistant */
.as-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.as-turn {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 92%;
}

.as-turn-me {
  align-self: flex-end;
  align-items: flex-end;
}

.as-turn-it {
  align-self: flex-start;
}

.as-bubble {
  padding: 7px 10px;
  border-radius: 8px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  background: #202c33;
}

.as-turn-me .as-bubble {
  background: #3b2f6b;
}

.as-pending {
  color: #aebac1;
  font-style: italic;
}

/* The assistant's answers, lightly formatted */
.as-bubble p + p,
.as-bubble p + ul,
.as-bubble p + ol,
.as-bubble ul + p,
.as-bubble ol + p {
  margin-top: 6px;
}

.as-bubble ul,
.as-bubble ol {
  padding-left: 18px;
}

.as-bubble li + li {
  margin-top: 2px;
}

.as-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #111b21;
  padding: 0 4px;
  border-radius: 4px;
}

.as-thread-head {
  display: flex;
  justify-content: flex-end;
}

/* An empty conversation: a few questions to start with */
.as-empty {
  margin: auto 0;
  padding: 24px 0 8px;
  text-align: center;
}

.as-quick {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
}

.as-quick-ask {
  background: #202c33;
  border: 1px solid #2a3942;
  border-radius: 16px;
  color: #e9edef;
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
}

.as-quick-ask:hover {
  border-color: #a78bfa;
}

/* A draft waiting above the message box */
.as-draft-ready {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, #a78bfa 12%, transparent);
  font-size: 12px;
}

.as-draft-ready.fresh {
  background: color-mix(in srgb, #a78bfa 24%, transparent);
}

.as-mode-note {
  font-size: 12px;
  margin-bottom: 8px;
}

.as-turn-on {
  margin-top: 14px;
}

.as-suggestion {
  border: 1px solid #a78bfa;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.as-suggestion-text {
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.as-suggestion .btn {
  padding: 4px 10px;
  font-size: 12px;
}

.as-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px 10px;
}

/* Under the panel: "Write a message for me", then the question box */
.as-footer {
  border-top: 1px solid #2a3942;
  background: #202c33;
}

.as-footer[hidden],
.as-write[hidden],
.as-write-form[hidden],
.as-write-toggle[hidden] {
  display: none;
}

.as-write {
  padding: 8px 12px 0;
}

.as-write-toggle {
  background: none;
  border: 1px dashed #a78bfa;
  border-radius: 16px;
  color: #a78bfa;
  font-size: 12px;
  padding: 5px 12px;
  cursor: pointer;
}

.as-write-toggle:hover:not(:disabled) {
  background: color-mix(in srgb, #a78bfa 12%, transparent);
}

.as-write-toggle:disabled {
  cursor: default;
  border-style: solid;
  opacity: 0.8;
}

.as-write-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.as-write-form input {
  flex: 1;
  min-width: 0;
  background: #2a3942;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #e9edef;
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
}

.as-write-form input:focus {
  outline: none;
  border-color: #a78bfa;
}

.as-write-form .btn {
  padding: 6px 12px;
  flex-shrink: 0;
}

.as-write-form .as-link {
  margin-left: 0;
  flex-shrink: 0;
}

.as-compose textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  line-height: 1.4;
}

.as-compose .btn {
  padding: 7px 14px;
}

/* A chat in the list whose assistant is on */
.as-chat-badge {
  color: #a78bfa;
  font-size: 12px;
  margin-left: 8px;
  flex-shrink: 0;
}

.as-chat-auto {
  color: #f5b942;
}

/* The instance's Assistant window */
.as-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid #2a3942;
  margin-bottom: 14px;
  overflow-x: auto;
}

.as-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #8696a0;
  font-size: 13px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.as-tab:hover {
  color: #e9edef;
}

.as-tab.active {
  color: #e9edef;
  border-bottom-color: #a78bfa;
}

.as-modal-body {
  font-size: 13px;
  min-height: 240px;
}

.as-modal .pf-section-head {
  margin-top: 14px;
}

.as-group:first-of-type .pf-section-head {
  margin-top: 4px;
}

.as-week {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 4px;
}

.as-day {
  display: flex;
  gap: 12px;
}

.as-day span:first-child {
  width: 84px;
  flex-shrink: 0;
  color: #8696a0;
}

.as-day em {
  color: #8696a0;
  font-style: normal;
}

.as-day {
  align-items: center;
}

.as-day-free-text {
  flex: 1;
  min-width: 0;
}

.as-day-free .as-day-free-text {
  color: #00a884;
}

.as-day button {
  background: none;
  border: 1px solid #2a3942;
  border-radius: 4px;
  color: #aebac1;
  font-size: 11px;
  line-height: 1;
  padding: 3px 7px;
  cursor: pointer;
  flex-shrink: 0;
}

.as-day button:hover {
  border-color: #a78bfa;
  color: #e9edef;
}

.as-cycle {
  margin: 4px 0 10px;
  color: #aebac1;
  font-size: 13px;
}

.as-cycle select {
  background: #2a3942;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #e9edef;
  font: inherit;
  padding: 3px 6px;
  margin: 0 2px;
}

.as-cycle-week {
  margin-bottom: 10px;
}

.as-cycle-week[hidden] {
  display: none;
}

.as-cycle-head {
  font-size: 12px;
  color: #e9edef;
  margin-bottom: 6px;
}

.as-cycle-head span {
  color: #8696a0;
}

.as-event-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 4px;
}

.as-event-times {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

.as-event-times label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #8696a0;
}

.as-check {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  font-size: 13px !important;
  color: #e9edef !important;
  padding-bottom: 7px;
}

.as-settings .as-model-hint {
  margin: -6px 0 12px;
}

.as-label input[hidden] {
  display: none;
}

.as-settings .as-check {
  display: flex;
  padding-bottom: 4px;
}

.as-hours-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.as-hours-row span {
  width: 84px;
  flex-shrink: 0;
  color: #8696a0;
}

.as-hours-row input {
  flex: 1;
}

.as-run {
  padding: 8px 0;
  border-bottom: 1px solid #202c33;
}

.as-run-top {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.as-run-chat {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.as-run-when {
  color: #8696a0;
  font-size: 11px;
  flex-shrink: 0;
}

.as-run-outcome {
  margin-top: 3px;
  color: #aebac1;
  overflow-wrap: anywhere;
}

/* Spending tab */
.as-spend-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.as-spend-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: #111b21;
  border: 1px solid #2a3942;
  border-radius: 8px;
}

.as-spend-stat > span:first-child {
  color: #8696a0;
  font-size: 11px;
}

.as-spend-stat strong {
  color: #e9edef;
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.as-spend-stat em {
  color: #8696a0;
  font-size: 11px;
  font-style: normal;
}

.as-spend-periods {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.as-spend-period {
  background: none;
  border: 1px solid #2a3942;
  border-radius: 12px;
  color: #aebac1;
  font-size: 12px;
  padding: 3px 10px;
  cursor: pointer;
}

.as-spend-period.active {
  border-color: #00a884;
  color: #00a884;
}

.as-spend-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 120px;
  padding: 4px 0;
  border-bottom: 1px solid #2a3942;
}

.as-spend-day {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
}

.as-spend-day span {
  display: block;
  width: 100%;
  background: #00a884;
  border-radius: 2px 2px 0 0;
}

.as-spend-day:hover span {
  background: #53bdeb;
}

.as-spend-axis {
  display: flex;
  justify-content: space-between;
  color: #8696a0;
  font-size: 11px;
  margin: 4px 0 8px;
}

.as-spend-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.as-spend-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(40px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.as-spend-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.as-spend-bar {
  display: block;
  height: 6px;
  background: #202c33;
  border-radius: 3px;
  overflow: hidden;
}

.as-spend-bar > span {
  display: block;
  height: 100%;
  background: #00a884;
  border-radius: 3px;
}

.as-spend-budget {
  margin-top: 4px;
}

.as-spend-budget.over > span {
  background: #f15c6d;
}

.as-spend-num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.as-spend-runs {
  color: #8696a0;
  font-size: 11px;
  min-width: 52px;
  text-align: right;
}

@media (max-width: 480px) {
  .as-spend-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .as-spend-row .as-spend-bar {
    display: none;
  }
}

.as-run-failed .as-run-outcome {
  color: #f15c6d;
}

.as-run-cancelled .as-run-outcome {
  color: #f5b942;
}

/* Every field of the pattern ("Repeats every [2] week(s)") sits inline in the
   sentence; .ai-modal select would otherwise stretch each one across the line. */
.as-cycle select {
  width: auto;
}

/* .ai-modal select is full width, which in this row crushed the text field to nothing */
.as-add select {
  width: auto;
}

@media (max-width: 600px) {
  /* The four tabs share the width instead of scrolling sideways on a narrow phone */
  .as-tab {
    flex: 1;
    padding: 8px 4px;
  }

  /* The text gets its own line; the kind and Add share the one below */
  .as-add {
    flex-wrap: wrap;
  }

  .as-add input {
    order: -1;
    flex-basis: 100%;
  }

  .as-add select {
    flex: 1;
  }
}

/* iOS zooms in on any field under 16px when it's focused, and stays zoomed after,
   leaving the page draggable sideways. One rule for every field on phones and
   touch screens; !important because many component rules (.as-add input,
   .ai-modal select, ...) are more specific than anything a media query adds. */
@media (max-width: 768px), (pointer: coarse) {
  input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']),
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* An earlier version of a draft, under the one that replaced it */
.ai-draft-prev {
  margin-bottom: 6px;
  font-size: 12px;
  color: #8696a0;
}

.ai-draft-prev summary {
  cursor: pointer;
}

.ai-draft-prev-text {
  margin-top: 4px;
  padding: 6px 8px;
  border-left: 2px solid #3b4a54;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-decoration: line-through;
  text-decoration-color: #3b4a54;
}

/* The draft cards, pointed at from the assistant panel */
@keyframes as-flash {
  0% { box-shadow: 0 0 0 2px #a78bfa; }
  100% { box-shadow: 0 0 0 2px transparent; }
}

.ai-drafts.as-flash .ai-draft {
  animation: as-flash 1.6s ease-out;
}
