/* ═══════════════════════════════════════════
   Chat Surface — Styles (v0.2.0)
   Uses variables.css theme tokens:
     --bg, --bg-surface, --bg-raised, --bg-hover, --bg-secondary
     --text, --text-2, --text-3
     --accent, --accent-dim, --border, --border-light
     --input-bg, --danger, --danger-bg, --success
   ═══════════════════════════════════════════ */

/* ── Layout ─────────────────────────────── */

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

.chat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

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

.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

/* ── Topbar extras ──────────────────────── */

.chat-topbar__thread-title {
  font-weight: 600;
  font-size: 14px;
  margin-right: 8px;
  color: var(--text-2);
}

/* ── Sidebar ────────────────────────────── */

.chat-sidebar {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
}

.chat-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-sidebar__title {
  font-weight: 600;
  font-size: 14px;
}

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

.chat-sidebar__empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

.chat-sidebar__item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}

.chat-sidebar__item:hover {
  background: var(--bg-hover);
}

.chat-sidebar__item--active {
  background: var(--accent-dim);
}

.chat-sidebar__item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}

.chat-sidebar__item-title {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin-right: 8px;
}

.chat-sidebar__item-time {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}

.chat-sidebar__item-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-sidebar__item-preview {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-sidebar__badge {
  background: var(--accent);
  color: var(--text-on-color);
  font-size: 11px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* ── Sidebar Search ────────────────────── */

.chat-sidebar__search {
  position: relative;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-light);
}

.chat-sidebar__search-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  box-sizing: border-box;
}

.chat-sidebar__search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-sidebar__search-clear {
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}

.chat-sidebar__search-clear:hover {
  color: var(--text);
}

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

.chat-sidebar__search-section {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
}

.chat-sidebar__search-loading {
  display: flex;
  justify-content: center;
  padding: 16px;
}

.chat-sidebar__item--search-msg .chat-sidebar__item-preview {
  font-size: 13px;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Message Thread ─────────────────────── */

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

.chat-thread--empty {
  align-items: center;
  justify-content: center;
  color: var(--text-3);
}

.chat-thread__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-thread__loading {
  display: flex;
  justify-content: center;
  padding: 24px;
}

.chat-thread__loading-more {
  display: flex;
  justify-content: center;
  padding: 8px;
}

.chat-thread__load-more {
  align-self: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  margin-bottom: 8px;
}

.chat-thread__load-more:hover {
  background: var(--bg-hover);
}

.chat-thread__typing {
  padding: 4px 16px 8px;
  font-size: 12px;
  color: var(--text-3);
  font-style: italic;
}

/* ── Message Bubble ─────────────────────── */

.chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  position: relative;
}

.chat-msg--own {
  flex-direction: row-reverse;
}

.chat-msg--system {
  justify-content: center;
  padding: 2px 0;
}

.chat-msg--system span {
  font-size: 12px;
  color: var(--text-3);
  font-style: italic;
}

.chat-msg--deleted {
  justify-content: center;
  padding: 2px 0;
}

.chat-msg--deleted em {
  font-size: 12px;
  color: var(--text-3);
}

.chat-msg__body {
  max-width: 65%;
  background: var(--bg-raised);
  border-radius: 12px;
  padding: 8px 12px;
}

.chat-msg--own .chat-msg__body {
  background: var(--accent);
  color: var(--text-on-color);
}

.chat-msg__name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  display: block;
  margin-bottom: 2px;
}

.chat-msg__content {
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg__meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}

.chat-msg__time {
  font-size: 10px;
  color: var(--text-3);
}

.chat-msg--own .chat-msg__time {
  color: rgba(255, 255, 255, 0.7);
}

.chat-msg__edited {
  font-size: 10px;
  color: var(--text-3);
  font-style: italic;
}

.chat-msg--own .chat-msg__edited {
  color: rgba(255, 255, 255, 0.7);
}

/* ── Message Actions ────────────────────── */

.chat-msg__actions {
  display: flex;
  gap: 2px;
  position: absolute;
  top: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  padding: 2px;
}

.chat-msg--own .chat-msg__actions {
  right: auto;
  left: 0;
}

.chat-msg__action {
  background: none;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  color: var(--text-2);
}

.chat-msg__action:hover {
  background: var(--bg-hover);
}

.chat-msg__action--danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ── Message Edit ───────────────────────── */

.chat-msg__edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-msg__edit-input {
  width: 100%;
  min-width: 200px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  background: var(--input-bg);
  color: var(--text);
}

.chat-msg__edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ── Compose Bar ────────────────────────── */

.chat-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.chat-compose__input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  line-height: 1.4;
  max-height: 160px;
  background: var(--input-bg);
  color: var(--text);
}

.chat-compose__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

/* ── Participant Sidebar ────────────────── */

.chat-participants {
  width: 240px;
  min-width: 240px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
}

.chat-participants__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}

.chat-participants__list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.chat-participants__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
}

.chat-participants__name {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-participants__badge {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  margin-left: 4px;
}

.chat-participants__status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}

.chat-participants__status--online {
  background: var(--success);
}

.chat-participants__remove {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}

.chat-participants__remove:hover {
  color: var(--danger);
}

/* ── New Conversation Dialog ────────────── */

.chat-new {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 320px;
}

.chat-new__type {
  display: flex;
  gap: 16px;
}

.chat-new__type label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.chat-new__title {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}

.chat-new__selected {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-new__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 12px;
}

.chat-new__chip button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}

/* ── Dialog UserPicker overflow fix ─────── */
/* Allow the autocomplete dropdown to overflow the dialog body.
   Applies to both New Conversation and Add Participant dialogs. */

.sw-dialog__body:has(.sw-user-picker) {
  overflow: visible;
}

.sw-dialog:has(.sw-user-picker) {
  overflow: visible;
}
