@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/manrope-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/manrope-latin-700.woff2") format("woff2");
}
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/fraunces-latin.woff2") format("woff2");
}

:root {
  --bg0: #dce8df;
  --bg1: #eef4ef;
  --ink: #14201a;
  --muted: #5b6b62;
  --line: rgba(20, 32, 26, 0.12);
  --brand: #0f6b5c;
  --brand-ink: #e8f0ea;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-solid: #f7fbf8;
  --mine: #0f6b5c;
  --mine-ink: #f3faf7;
  --theirs: #ffffff;
  --danger: #9f2d2d;
  --shadow: 0 18px 50px rgba(20, 32, 26, 0.12);
  --radius: 22px;
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 10% -10%, rgba(15, 107, 92, 0.18), transparent 55%),
    radial-gradient(900px 600px at 100% 0%, rgba(47, 93, 80, 0.16), transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 45%, #f4f7f2);
  background-attachment: fixed;
}
body { overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--brand); }

#app { height: 100%; }

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + var(--safe-b));
}
.auth-card {
  width: min(420px, 100%);
  padding: 28px 24px 24px;
  border-radius: calc(var(--radius) + 4px);
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.55);
}
.brand {
  font-family: var(--display);
  font-size: clamp(2.2rem, 7vw, 2.8rem);
  letter-spacing: -0.03em;
  margin: 0 0 6px;
  color: var(--brand);
}
.brand-sub {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.45;
}
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 18px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(20, 32, 26, 0.06);
}
.tabs button {
  padding: 10px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 700;
}
.tabs button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(20,32,26,0.08);
}
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 0.85rem; color: var(--muted); font-weight: 700; }
.field input, .composer textarea, .modal input, .modal select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.9);
  outline: none;
}
.field input:focus, .composer textarea:focus, .modal input:focus {
  border-color: rgba(15,107,92,0.45);
  box-shadow: 0 0 0 3px rgba(15,107,92,0.12);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 14px;
  font-weight: 700;
}
.btn-primary {
  width: 100%;
  margin-top: 8px;
  background: var(--brand);
  color: var(--brand-ink);
}
.btn-ghost {
  background: rgba(20,32,26,0.06);
}
.btn-danger { color: var(--danger); }
.error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(159,45,45,0.1);
  color: var(--danger);
  font-size: 0.92rem;
}

.shell {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 0;
}
.sidebar, .chat {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(14px);
}
.sidebar {
  border-right: 1px solid var(--line);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
}
.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.55rem;
  color: var(--brand);
  letter-spacing: -0.02em;
}
.me {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.me .meta { min-width: 0; }
.me .name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.me .sub { color: var(--muted); font-size: 0.8rem; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  flex: 0 0 auto;
  position: relative;
}
.avatar.sm { width: 34px; height: 34px; border-radius: 12px; font-size: 0.85rem; }
.avatar .dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #2f9e44;
  border: 2px solid #fff;
  display: none;
}
.avatar.online .dot { display: block; }

.toolbar {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
}
.toolbar .btn { flex: 1; min-height: 40px; border-radius: 12px; }

.conv-list {
  overflow: auto;
  padding: 0 8px 16px;
  flex: 1;
}
.conv {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px;
  border-radius: 16px;
  margin-bottom: 4px;
}
.conv:hover { background: rgba(15,107,92,0.06); }
.conv.active { background: rgba(15,107,92,0.12); }
.conv .title { font-weight: 700; }
.conv .preview {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv .time { color: var(--muted); font-size: 0.75rem; }
.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.chat-head .title { font-weight: 700; font-size: 1.05rem; }
.chat-head .sub { color: var(--muted); font-size: 0.82rem; }
.back {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(20,32,26,0.06);
  font-size: 1.2rem;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.day {
  align-self: center;
  margin: 8px 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(20,32,26,0.06);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}
.bubble-row {
  display: flex;
  gap: 8px;
  max-width: min(720px, 92%);
}
.bubble-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  padding: 10px 12px;
  border-radius: 18px;
  background: var(--theirs);
  border: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(20,32,26,0.04);
  min-width: 0;
}
.bubble-row.mine .bubble {
  background: var(--mine);
  color: var(--mine-ink);
  border-color: transparent;
}
.bubble .author {
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 4px;
  opacity: 0.85;
}
.bubble .reply {
  border-left: 3px solid rgba(15,107,92,0.45);
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 8px;
  background: rgba(20,32,26,0.05);
  font-size: 0.82rem;
}
.bubble-row.mine .reply {
  border-left-color: rgba(255,255,255,0.55);
  background: rgba(0,0,0,0.12);
}
.bubble .text { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.bubble .meta {
  margin-top: 6px;
  font-size: 0.72rem;
  opacity: 0.7;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.bubble a.file {
  display: inline-block;
  margin-top: 4px;
  color: inherit;
  text-decoration: underline;
}
.bubble img.preview {
  display: block;
  max-width: min(280px, 70vw);
  max-height: 240px;
  border-radius: 12px;
  margin-top: 6px;
}
.bubble-actions {
  display: none;
  gap: 4px;
  align-self: center;
}
.bubble-row:hover .bubble-actions { display: flex; }
.bubble-actions button {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: rgba(20,32,26,0.06);
  font-size: 0.85rem;
}

.typing-line {
  min-height: 22px;
  padding: 0 18px;
  color: var(--muted);
  font-size: 0.82rem;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px 12px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: rgba(247,251,248,0.88);
}
.composer textarea {
  resize: none;
  max-height: 140px;
  min-height: 44px;
  line-height: 1.35;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(20,32,26,0.06);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}
.icon-btn.send {
  background: var(--brand);
  color: var(--brand-ink);
}
.reply-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(15,107,92,0.08);
  font-size: 0.86rem;
}
.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  max-width: 280px;
}
.empty strong {
  display: block;
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.4rem;
  margin-bottom: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20,32,26,0.35);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
}
.modal {
  width: min(440px, 100%);
  background: var(--panel-solid);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal h2 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-size: 1.4rem;
}
.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.user-pick {
  max-height: 240px;
  overflow: auto;
  display: grid;
  gap: 4px;
  margin-top: 8px;
}
.user-pick label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
}
.user-pick label:hover { background: rgba(15,107,92,0.06); }
.hidden { display: none !important; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .shell.show-chat .sidebar { display: none; }
  .shell:not(.show-chat) .chat { display: none; }
  .back { display: grid; place-items: center; }
  .sidebar, .chat {
    background: transparent;
    backdrop-filter: none;
  }
  .sidebar { border-right: 0; }
}
