
:root {
  --bg-main: #111b21;
  --bg-sidebar: #202c33;
  --bg-chat: #0b141a;
  --bg-bubble-in: #202c33;
  --bg-bubble-out: #005c4b;
  --accent: #00a884;
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  --header-height: 56px;
  --sidebar-width: 320px;
  --radius-bubble: 16px;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --topbar-offset: 52px;
  --topbar-height: 52px;
}

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

html, body {
  block-size: 100%;
  inline-size: 100%;
  background: #0b141a;
  color: var(--text-primary);
  font-family: var(--font-ui);
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

header.topbar {
  position: fixed;
  inset-block-start: 0;
  inset-inline-start: 0;
  inset-inline-end: 0;
  padding: 10px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: #111b21;
  border-block-end: 1px solid #202c33;
  z-index: 10;
  font-size: 12px;
  min-block-size: 52px;
}

.topbar__hint {
  font-size: 11px;
  color: var(--text-secondary);
  max-inline-size: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text-primary);
  margin: 0;
}

.topbar__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.topbar__donate {
  order: -1;
}

.app-wrapper {
  inline-size: 100%;
  max-inline-size: 100vw;
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding-block-start: var(--topbar-offset); /* space for topbar */
  overflow: hidden;
  max-width: 1600px;
}

.app {
  display: flex;
  inline-size: min(100%, 1200px);
  max-inline-size: 100vw;
  min-inline-size: 0;
  flex: 1;
  background: var(--bg-main);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5),
              0 8px 24px rgba(0, 0, 0, .6);
}

/* Sidebar */

.sidebar {
  inline-size: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-inline-end: 1px solid #111b21;
}

.sidebar__search {
  padding: 12px 12px 4px;
  border-block-end: 1px solid #111b21;
}

.sidebar__search input {
  inline-size: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  background: #111b21;
  color: var(--text-primary);
}

.sidebar__search input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar__chats {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar .app-footer {
  padding: 10px 12px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  border-block-start: 1px solid #111b21;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

.chat-item {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  border-block-end: 1px solid #111b21;
  background: transparent;
  transition: background 0.15s ease;
  inline-size: 100%;
  text-align: start;
  border: none;
  color: inherit;
  font: inherit;
}

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

.chat-item--active {
  background: linear-gradient(90deg, rgba(0,168,132,0.18), rgba(0,168,132,0.08));
  box-shadow: inset 0 0 0 2px rgba(0, 168, 132, 0.8);
}

.chat-item--match {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.chat-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.chat-item__avatar {
  flex-shrink: 0;
  inline-size: 40px;
  block-size: 40px;
  border-radius: 50%;
  background: #202c33;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-secondary);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
}

.chat-item__body {
  flex: 1;
  min-inline-size: 0;
}

.chat-item__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-block-end: 2px;
}

.chat-item__name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-inline-end: 8px;
}

.chat-item__time {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.chat-item__preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat view */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  min-inline-size: 0;
}

.chat__header {
  flex-shrink: 0;
  block-size: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #202c33;
  border-block-end: 1px solid #111b21;
}

.chat__avatar {
  inline-size: 40px;
  block-size: 40px;
  border-radius: 50%;
  background: #202c33;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-secondary);
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
}

.chat__titles {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-inline-size: 0;
}

.chat__title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat__subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat__messages {
  flex: 1;
  padding: 16px 24px 16px;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid #202c33;
  background-image:
    linear-gradient(to bottom, #0b141a 0, #0b141a 40%, #111b21 100%);
}

.chat__messages-inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.msg-date {
  align-self: center;
  margin: 6px 0;
  padding: 4px 8px;
  border-radius: 999px;
  background: #202c33;
  font-size: 11px;
  color: var(--text-secondary);
}

.msg-row {
  display: flex;
  margin-block-end: 2px;
}

.msg-row--out { justify-content: flex-end; }
.msg-row--in  { justify-content: flex-start; }

.msg {
  max-inline-size: min(75%, 580px);
  padding: 6px 8px 4px;
  border-radius: var(--radius-bubble);
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg--in {
  background: var(--bg-bubble-in);
  border-end-start-radius: 2px;
}

.msg--out {
  background: var(--bg-bubble-out);
  border-end-end-radius: 2px;
}

.msg__sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-block-end: 2px;
}

.msg__meta {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  margin-inline-start: 8px;
}

.msg__time {
  white-space: nowrap;
}

.msg__text {
  vertical-align: middle;
}

.chat__empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-secondary);
  padding: 24px;
  font-size: 14px;
  min-block-size: 200px;
}

.chat__empty--loading {
  flex-direction: column;
  gap: 10px;
  color: var(--text-primary);
}

.sidebar__chats::-webkit-scrollbar,
.chat__messages::-webkit-scrollbar {
  inline-size: 8px;
}

.sidebar__chats::-webkit-scrollbar-thumb,
.chat__messages::-webkit-scrollbar-thumb {
  background: #374045;
  border-radius: 4px;
}

@media (max-width: 800px) {
  .app {
    max-inline-size: none;
  }

  .sidebar {
    inline-size: 100%;
    max-inline-size: none;
  }

  .app--single-chat .sidebar {
    display: none;
  }

  .chat__header-back {
    display: inline-flex;
  }
}

.chat__header-back {
  display: none;
  margin-inline-end: 8px;
  inline-size: 28px;
  block-size: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.chat__header-back:hover {
  background: rgba(255, 255, 255, 0.08);
}

.msg__text a {
  color: #53bdeb;
  text-decoration: none;
}

.msg__text a:hover {
  text-decoration: underline;
}

.msg--highlight {
  box-shadow: 0 0 0 2px var(--accent);
  outline: 2px solid var(--accent);
}

.msg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Onboarding modal */
dialog.onboarding {
  border: 1px solid #1f2a33;
  border-radius: 12px;
  padding: 18px;
  inline-size: min(520px, 100%);
  margin: auto;
  background: #0f1620;
  color: var(--text-primary);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

dialog.onboarding::backdrop,
dialog.donate::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

dialog.donate {
  border: 1px solid #1f2a33;
  border-radius: 12px;
  padding: 18px;
  inline-size: min(420px, 100%);
  margin: auto;
  background: #0f1620;
  color: var(--text-primary);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.modal__title {
  font-size: 18px;
  font-weight: 700;
  margin-block-end: 8px;
}

.modal__text {
  font-size: 13px;
  color: var(--text-secondary);
  margin-block-end: 12px;
  line-height: 1.5;
}

.modal__list {
  margin: 0 0 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.modal__actions {
  display: flex;
  gap: 10px;
  margin-block-start: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid #202c33;
  background: #0b141a;
  color: var(--text-primary);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn:hover,
.btn:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--top {
  padding: 8px 12px;
  font-weight: 600;
}

.btn--primary {
  background: var(--accent);
  color: #0b141a;
  border-color: var(--accent);
  font-weight: 700;
}

.btn--primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}

.loader {
  inline-size: 18px;
  block-size: 18px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-block-start-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  flex-shrink: 0;
}

.loader--large {
  inline-size: 36px;
  block-size: 36px;
  border-width: 3px;
}

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}

.loading-overlay[hidden] {
  display: none;
}

.loading-box {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid rgba(134,150,160,0.35);
  background: rgba(17,27,33,0.92);
  color: #c8d0d6;
  font-size: 15px;
  line-height: 1.6;
  min-inline-size: 240px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}

.app-footer {
  padding: 10px 14px 16px;
  font-size: 12px;
  color: var(--text-secondary);
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

.kofi-link img {
  border: none;
  display: inline-block;
}

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
