:root {
  --bg0: #1a1512;
  --bg1: #241e19;
  --bg2: #2e2620;
  --ink: #f3ebe3;
  --ink-dim: #b8a99a;
  --ink-mute: #8a7a6c;
  --accent: #c45c4a;
  --accent-soft: #e8a090;
  --line: rgba(243, 235, 227, 0.12);
  --mine: #3a2f28;
  --theirs: #2a231e;
  --danger: #d4635a;
  --ok: #7a9e7e;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Manrope", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

/* —— Login —— */
.page-login {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b));
  position: relative;
  overflow: hidden;
}

.login-atmosphere {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(196, 92, 74, 0.35), transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 100%, rgba(90, 60, 50, 0.45), transparent 50%),
    linear-gradient(165deg, #1a1512 0%, #2a2018 45%, #15110f 100%);
  animation: atmosphere-shift 14s ease-in-out infinite alternate;
}

@keyframes atmosphere-shift {
  from { filter: hue-rotate(0deg) brightness(1); }
  to { filter: hue-rotate(-8deg) brightness(1.05); }
}

.login-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 400px);
  display: flex;
  flex-direction: column;
  gap: 36px;
  animation: rise-in 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

.login-kicker {
  margin: 0 0 10px;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent-soft);
  font-weight: 600;
}

.login-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.6rem, 10vw, 3.4rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
}

.login-title span {
  font-style: italic;
  font-weight: 500;
  color: var(--accent-soft);
}

.login-sub {
  margin: 14px 0 0;
  color: var(--ink-dim);
  font-size: 0.95rem;
  line-height: 1.45;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.field input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.field input:focus,
.composer textarea:focus {
  border-color: rgba(232, 160, 144, 0.55);
  background: rgba(255, 255, 255, 0.07);
}

.field input::placeholder,
.composer textarea::placeholder {
  color: var(--ink-mute);
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(212, 99, 90, 0.15);
  color: #f0b4ae;
  font-size: 0.9rem;
}

.form-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-mute);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 600;
  font-size: 0.92rem;
  transition: transform 0.15s, background 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff8f5;
}

.btn-primary:hover {
  background: #d16855;
}

.btn-block {
  width: 100%;
  padding: 15px 18px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  padding: 8px 12px;
  font-size: 0.82rem;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
}

.btn-send {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  padding: 0;
}

.btn-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-icon {
  border: none;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

/* —— Chat layout —— */
.page-chat {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(ellipse 80% 40% at 0% 0%, rgba(196, 92, 74, 0.18), transparent 50%),
    var(--bg0);
  overflow: hidden;
}

.chat-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-t)) 14px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(26, 21, 18, 0.88);
  backdrop-filter: blur(12px);
  z-index: 5;
}

.chat-brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 5vw, 1.7rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.chat-brand span {
  font-style: italic;
  color: var(--accent-soft);
  font-weight: 500;
}

.chat-who {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--ink-mute);
  word-break: break-all;
}

.chat-top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.chat-main {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px 8px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
  min-height: 100%;
}

.messages-empty {
  margin: auto;
  text-align: center;
  color: var(--ink-mute);
  padding: 40px 16px;
  font-size: 0.95rem;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: min(92%, 520px);
  animation: msg-in 0.28s ease-out both;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.msg.mine {
  align-self: flex-end;
}

.msg.theirs {
  align-self: flex-start;
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 4px 4px;
  font-size: 0.72rem;
}

.msg.mine .msg-meta {
  justify-content: flex-end;
}

.msg-author {
  font-weight: 700;
  color: var(--accent-soft);
}

.msg.mine .msg-author {
  color: #dfc3b4;
}

.msg-time {
  color: var(--ink-mute);
}

.msg-bubble {
  position: relative;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--theirs);
  border: 1px solid var(--line);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg.mine .msg-bubble {
  background: var(--mine);
  border-bottom-right-radius: 6px;
}

.msg.theirs .msg-bubble {
  border-bottom-left-radius: 6px;
}

.msg-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 0.95rem;
}

.msg-photo {
  display: block;
  max-width: 100%;
  width: auto;
  max-height: min(55vh, 360px);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: zoom-in;
  background: #000;
}

.msg-photo:only-child,
.msg-bubble > .msg-photo:last-child {
  margin-bottom: 0;
}

.msg-actions {
  margin-top: 6px;
}

.btn-delete {
  border: none;
  background: transparent;
  color: var(--ink-mute);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-delete:hover {
  color: var(--danger);
}

/* —— Composer —— */
.composer {
  border-top: 1px solid var(--line);
  background: rgba(26, 21, 18, 0.95);
  backdrop-filter: blur(12px);
  padding: 10px 12px calc(10px + var(--safe-b));
  z-index: 5;
}

.composer-preview {
  position: relative;
  width: fit-content;
  margin: 0 0 8px 44px;
}

.composer-preview img {
  display: block;
  max-height: 88px;
  max-width: min(180px, 50vw);
  border-radius: 10px;
  border: 1px solid var(--line);
}

.composer-preview .btn-icon {
  position: absolute;
  top: -8px;
  right: -8px;
}

.composer-form {
  display: grid;
  grid-template-columns: 40px 1fr 46px;
  gap: 8px;
  align-items: end;
  max-width: 720px;
  margin: 0 auto;
}

.attach {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink-dim);
  cursor: pointer;
  margin-bottom: 3px;
}

.attach:hover,
.attach:focus-within {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

.composer textarea {
  resize: none;
  min-height: 46px;
  max-height: 140px;
  line-height: 1.4;
  padding: 12px 14px;
  border-radius: 14px;
}

/* —— Modal —— */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 24px);
  width: 420px;
  margin: auto;
}

.modal::backdrop {
  background: rgba(10, 8, 7, 0.72);
  backdrop-filter: blur(4px);
}

.modal-inner {
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  max-height: min(80dvh, 640px);
  overflow: auto;
  animation: rise-in 0.3s ease-out;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
}

.user-list {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

.user-list .ulabel {
  font-weight: 700;
  font-size: 0.9rem;
}

.user-list .uemail {
  font-size: 0.8rem;
  color: var(--ink-mute);
  word-break: break-all;
}

.add-user-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

/* —— Toast / lightbox —— */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 40;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.9);
  display: grid;
  place-items: center;
  padding: 20px;
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

/* —— Desktop —— */
@media (min-width: 768px) {
  .chat-top {
    padding-left: 24px;
    padding-right: 24px;
  }

  .chat-main {
    padding: 24px 20px 12px;
  }

  .composer {
    padding-left: 20px;
    padding-right: 20px;
  }

  .msg {
    max-width: min(70%, 520px);
  }
}

@media (max-width: 380px) {
  .chat-top-actions .btn-ghost {
    padding: 7px 10px;
    font-size: 0.75rem;
  }

  .chat-brand {
    font-size: 1.25rem;
  }
}
