:root {
  color-scheme: dark;
  --ink: #eef3ef;
  --muted: #91a8a0;
  --deep: #031217;
  --navy: #071f2a;
  --green: #0c352d;
  --green-soft: #84b397;
  --cream: #dce8db;
  --gold: #d9b76f;
  --line: rgba(224, 236, 231, 0.13);
  --surface: rgba(9, 39, 38, 0.76);
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 80% 8%, rgba(33, 97, 76, 0.24), transparent 30rem),
    radial-gradient(circle at 10% 90%, rgba(14, 60, 82, 0.42), transparent 34rem),
    linear-gradient(145deg, var(--deep), #061d24 48%, #07191f);
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.24;
  background-image: radial-gradient(circle, rgba(255,255,255,0.16) 0 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

a { color: inherit; text-decoration: none; }
button, textarea { font: inherit; }

.topbar {
  position: relative;
  z-index: 2;
  width: min(1180px, calc(100% - 40px));
  min-height: 72px;
  margin: 22px auto 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(4, 25, 29, 0.72);
  backdrop-filter: blur(18px);
}

.brand, .topbar-actions { display: flex; align-items: center; gap: 10px; }
.brand { font-size: 1.08rem; font-weight: 760; }
.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  color: #08211b;
  background: linear-gradient(145deg, #cbdcc9, #79b18f);
}
.account {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quiet-link {
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #c8d5d0;
}

.page-shell { position: relative; z-index: 1; width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.page-heading { padding: 56px 4px 28px; }
.eyebrow { margin: 0 0 12px; color: var(--gold); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.15em; text-transform: uppercase; }
.page-heading h1 { margin: 0; font: 500 clamp(2.5rem, 7vw, 4.8rem)/0.98 Georgia, serif; letter-spacing: -0.045em; }
.page-heading > p:last-child { max-width: 620px; margin: 16px 0 0; color: var(--muted); font-size: 1rem; }

.messenger {
  min-height: min(680px, calc(100vh - 250px));
  display: grid;
  grid-template-columns: minmax(230px, 310px) minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(11, 49, 40, 0.78), rgba(6, 27, 38, 0.9));
  box-shadow: var(--shadow);
}
.messenger[hidden] { display: none; }

.contacts-panel { min-width: 0; padding: 22px 14px; border-right: 1px solid var(--line); background: rgba(3, 20, 24, 0.24); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 16px; color: #c7d6d0; font-size: 0.8rem; font-weight: 780; letter-spacing: 0.05em; text-transform: uppercase; }
.contact-count { min-width: 28px; padding: 3px 8px; border-radius: 999px; color: var(--cream); background: rgba(217, 183, 111, 0.12); text-align: center; }
.contact-list { display: grid; gap: 7px; }
.contact-button {
  width: 100%;
  min-width: 0;
  padding: 11px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  border: 1px solid transparent;
  border-radius: 15px;
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.contact-button:hover { background: rgba(255,255,255,0.045); }
.contact-button.is-active { border-color: rgba(217, 183, 111, 0.28); background: rgba(217, 183, 111, 0.08); }
.contact-avatar, .avatar {
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #0a211b;
  background: linear-gradient(145deg, #c7dac7, #7cad8e);
  font-weight: 820;
}
.contact-avatar { width: 42px; height: 42px; }
.contact-copy { min-width: 0; display: grid; gap: 3px; }
.contact-copy strong, .contact-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-copy strong { font-size: 0.9rem; }
.contact-copy small { color: var(--muted); font-size: 0.75rem; }
.list-note { padding: 18px 10px; color: var(--muted); font-size: 0.86rem; line-height: 1.55; }

.conversation { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; }
.conversation-header { min-height: 82px; padding: 17px 22px; display: flex; align-items: center; gap: 13px; border-bottom: 1px solid var(--line); }
.avatar { width: 48px; height: 48px; font-size: 1.05rem; }
.conversation-header h2 { margin: 0; font: 500 1.35rem/1.2 Georgia, serif; }
.conversation-header p { margin: 5px 0 0; color: var(--muted); font-size: 0.78rem; }
.messages { min-height: 0; padding: 24px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; scrollbar-gutter: stable; }
.message { width: fit-content; max-width: min(76%, 620px); padding: 11px 14px; border: 1px solid var(--line); border-radius: 16px 16px 16px 5px; color: #dde8e3; background: rgba(255,255,255,0.055); line-height: 1.5; overflow-wrap: anywhere; }
.message.is-mine { align-self: flex-end; border-color: rgba(137, 188, 157, 0.2); border-radius: 16px 16px 5px 16px; color: #082019; background: linear-gradient(145deg, #c8dbc8, #85b596); }
.message-meta { display: block; margin-top: 5px; color: rgba(8,32,25,0.62); font-size: 0.68rem; text-align: right; }
.message:not(.is-mine) .message-meta { color: #78928a; text-align: left; }
.empty-state { margin: auto; max-width: 390px; display: grid; justify-items: center; gap: 9px; color: var(--muted); text-align: center; }
.empty-state > span { display: grid; width: 52px; height: 52px; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--gold); background: rgba(255,255,255,0.035); font-size: 1.25rem; }
.empty-state strong { color: #dbe5e1; font-family: Georgia, serif; font-size: 1.18rem; font-weight: 500; }
.empty-state p { margin: 0; font-size: 0.84rem; }

.composer { padding: 13px 18px; display: grid; grid-template-columns: minmax(0, 1fr) 48px; align-items: end; gap: 10px; border-top: 1px solid var(--line); background: rgba(2, 16, 20, 0.34); }
.composer textarea { width: 100%; min-height: 48px; max-height: 150px; padding: 13px 15px; resize: none; overflow-y: auto; outline: none; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); background: rgba(255,255,255,0.055); font-size: 16px; line-height: 1.4; }
.composer textarea:focus { border-color: rgba(142, 187, 159, 0.58); box-shadow: 0 0 0 3px rgba(132,179,151,0.08); }
.composer textarea:disabled { opacity: 0.52; cursor: not-allowed; }
.composer button { width: 48px; height: 48px; border: 0; border-radius: 15px; color: #082019; background: linear-gradient(145deg, #c8dbc8, #7fb290); cursor: pointer; font-weight: 900; }
.composer button:disabled { opacity: 0.38; cursor: not-allowed; }
.composer-note { min-height: 28px; margin: 0; padding: 4px 20px 9px; color: #789189; background: rgba(2, 16, 20, 0.34); font-size: 0.74rem; }

.auth-gate { max-width: 540px; margin: 40px auto 80px; padding: 34px; border: 1px solid var(--line); border-radius: 28px; background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.auth-gate[hidden] { display: none; }
.gate-mark { width: 54px; height: 54px; margin: 0 auto 19px; display: grid; place-items: center; border-radius: 17px; color: #0a211b; background: linear-gradient(145deg, #c7dac7, #7cad8e); }
.auth-gate h2 { margin: 0; font: 500 clamp(2rem, 7vw, 3rem)/1 Georgia, serif; }
.auth-gate p { margin: 16px auto 23px; color: var(--muted); line-height: 1.65; }
.gate-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.primary-action, .secondary-action { min-height: 46px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; font-weight: 730; }
.primary-action { color: #082019; background: linear-gradient(145deg, #c8dbc8, #7fb290); }
.secondary-action { border: 1px solid var(--line); color: #d4dfda; background: rgba(255,255,255,0.035); }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 20px; max-width: min(430px, calc(100% - 30px)); padding: 11px 16px; border: 1px solid var(--line); border-radius: 999px; color: #e8efeb; background: rgba(4, 24, 29, 0.96); box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: 180ms ease; text-align: center; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .topbar, .page-shell { width: min(100% - 24px, 1180px); }
  .topbar { margin-top: 12px; border-radius: 22px; }
  .account { display: none; }
  .page-heading { padding: 38px 2px 22px; }
  .messenger { min-height: calc(100dvh - 215px); grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); border-radius: 22px; }
  .contacts-panel { padding: 11px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .panel-heading { padding: 0 4px 9px; }
  .contact-list { display: flex; }
  .contact-button { flex: 0 0 190px; }
  .conversation { min-height: 480px; }
  .messages { padding: 18px 13px; }
  .message { max-width: 88%; }
}

@media (max-width: 430px) {
  .brand > span:last-child { display: none; }
  .quiet-link { padding: 0 13px; }
  .conversation-header { padding: 14px; }
  .composer { padding: 10px; }
  .composer-note { padding-left: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
