:root {
  --site-bg: #f7f1e7;
  --site-card: rgba(255, 252, 246, 0.86);
  --site-text: #2b241a;
  --gold: #d6aa45;
  --gold-dark: #9f7625;

  --chat-bg: #f3eee4;
  --chat-bg-2: #ebe1d2;
  --chat-card: #fffaf0;
  --chat-card-2: #f8f0df;
  --chat-border: rgba(159, 118, 37, 0.20);
  --text: #2b241a;
  --text-2: #756b5a;
  --own: #ecd89e;
  --other: #fffdf8;
  --danger: #b3261e;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--chat-bg);
  color: var(--text);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-screen {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  color: var(--site-text);
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(214,170,69,0.22), transparent 30%),
    linear-gradient(135deg, #fff8ed 0%, #efe1cf 52%, #d8c6ab 100%);
}
.auth-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255,248,236,0.62), rgba(255,248,236,0.78)),
    url('https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?auto=format&fit=crop&w=1600&q=70') center/cover;
  filter: saturate(0.9);
  transform: scale(1.02);
}
.auth-card {
  position: relative;
  width: min(440px, 100%);
  padding: 34px;
  border: 1px solid rgba(159,118,37,0.18);
  border-radius: 30px;
  background: var(--site-card);
  box-shadow: 0 24px 90px rgba(43,36,26,0.22);
  backdrop-filter: blur(18px);
}
.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--gold), #f0d58a);
  color: #211706;
  font-size: 30px;
  font-weight: 800;
  box-shadow: 0 14px 40px rgba(159,118,37,0.35);
}
.auth-kicker {
  margin-top: 20px;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--gold-dark);
  font-weight: 800;
}
.auth-card h1 {
  margin: 8px 0 6px;
  font-size: 42px;
  line-height: 1;
  letter-spacing: -0.04em;
}
.auth-subtitle {
  margin: 0 0 26px;
  color: rgba(43,36,26,0.7);
  line-height: 1.45;
}
.auth-form { display: grid; gap: 14px; }
.auth-form label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: rgba(43,36,26,0.72);
}
.auth-form input {
  width: 100%;
  border: 1px solid rgba(43,36,26,0.12);
  border-radius: 16px;
  padding: 14px 15px;
  color: var(--site-text);
  background: rgba(255,255,255,0.72);
  outline: none;
}
.auth-form input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(214,170,69,0.18);
}
.primary-btn, .secondary-btn {
  border: 0;
  border-radius: 17px;
  padding: 14px 18px;
  font-weight: 800;
  transition: transform .15s ease, box-shadow .15s ease;
}
.primary-btn {
  margin-top: 6px;
  background: linear-gradient(145deg, var(--gold), #f1d47b);
  color: #1e1605;
  box-shadow: 0 16px 40px rgba(159,118,37,0.28);
}
.secondary-btn {
  background: #2b241a;
  color: #fff8ed;
}
.primary-btn:hover, .secondary-btn:hover { transform: translateY(-1px); }
.form-divider {
  margin: 8px 0 0;
  padding-top: 18px;
  border-top: 1px solid rgba(43,36,26,0.12);
  color: var(--gold-dark);
  font-weight: 800;
}
.auth-message {
  min-height: 22px;
  margin-top: 14px;
  font-size: 14px;
  color: rgba(43,36,26,0.76);
}
.auth-message.error { color: #9b211f; font-weight: 700; }

.chat-screen {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  overflow: hidden;
  grid-template-columns: 360px 1fr;
  background: var(--chat-bg);
  color: var(--text);
}
.chat-sidebar {
  min-width: 0;
  border-right: 1px solid var(--chat-border);
  background: linear-gradient(180deg, #fffaf0 0%, #f3ead8 100%);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--chat-border);
}
.app-title { font-size: 23px; font-weight: 850; letter-spacing: -0.03em; }
.user-line { margin-top: 4px; color: var(--text-2); font-size: 13px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 1px solid var(--chat-border);
  background: rgba(214,170,69,0.08);
  color: var(--gold);
}
.status-line {
  padding: 10px 18px;
  color: var(--text-2);
  font-size: 13px;
  border-bottom: 1px solid rgba(214,170,69,0.08);
}
.chat-list { overflow: auto; padding: 8px; }
.chat-list-empty { padding: 24px 12px; color: var(--text-2); }
.chat-row {
  width: 100%;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.chat-row:hover, .chat-row.active {
  background: rgba(214,170,69,0.08);
  border-color: var(--chat-border);
}
.chat-row-avatar, .chat-avatar {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #ead39a, #fff7dc);
  color: #4c3510;
  font-weight: 850;
  border: 1px solid var(--chat-border);
}
.chat-row-main { min-width: 0; flex: 1; }
.chat-row-top, .chat-row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.chat-row-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 780;
}
.chat-row-time { color: var(--text-2); font-size: 12px; }
.chat-row-subtitle {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-size: 13px;
}
.chat-row-flags { display: inline-flex; align-items: center; gap: 5px; }
.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-grid;
  place-items: center;
  border-radius: 99px;
  background: var(--gold);
  color: #1e1605;
  font-size: 12px;
  font-weight: 850;
}
.pin, .muted { color: var(--gold); font-size: 12px; }

.conversation {
  min-width: 0;
  display: grid;
  grid-template-rows: 76px 1fr auto;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 80% 0%, rgba(214,170,69,0.16), transparent 30%),
    linear-gradient(180deg, #f8f1e4 0%, var(--chat-bg) 100%);
}
.conversation-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--chat-border);
  background: rgba(255,250,240,0.88);
  backdrop-filter: blur(14px);
  flex: 0 0 auto;
}
.back-btn {
  display: none;
  border: 0;
  background: transparent;
  color: var(--gold);
  font-size: 24px;
}
.active-chat-title { font-size: 18px; font-weight: 820; }
.active-chat-meta { margin-top: 3px; font-size: 13px; color: var(--text-2); }
.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  padding: 40px;
  text-align: center;
  color: var(--text-2);
}
.empty-state h2 { color: var(--text); margin: 10px 0 6px; }
.empty-state p { max-width: 440px; margin: 0; line-height: 1.55; }
.empty-icon { font-size: 42px; color: var(--gold); }
.message-list {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.message-list::before {
  content: '';
  margin-top: auto;
}
.message-row { display: flex; }
.message-row.own { justify-content: flex-end; }
.message-row.other { justify-content: flex-start; }
.message-bubble {
  max-width: min(660px, 74%);
  padding: 10px 12px 7px;
  border-radius: 18px;
  border: 1px solid rgba(214,170,69,0.10);
  box-shadow: 0 10px 28px rgba(43,36,26,0.10);
}
.message-row.own .message-bubble {
  background: var(--own);
  border-bottom-right-radius: 7px;
}
.message-row.other .message-bubble {
  background: var(--other);
  border-bottom-left-radius: 7px;
}
.message-author {
  margin-bottom: 4px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 780;
}
.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
.message-meta {
  margin-top: 5px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  color: var(--text-2);
  font-size: 11px;
}
.message-read { color: var(--gold); }
.message-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--chat-border);
  background: rgba(255,250,240,0.94);
}
.message-form textarea {
  flex: 1;
  min-height: 46px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  padding: 12px 14px;
  background: #fffdf8;
  color: var(--text);
  outline: none;
}
.message-form textarea:focus {
  border-color: rgba(214,170,69,0.45);
  box-shadow: 0 0 0 4px rgba(214,170,69,0.08);
}
.send-btn {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 16px;
  background: var(--gold);
  color: #1e1605;
  flex: 0 0 auto;
  font-size: 18px;
  font-weight: 900;
}

@media (max-width: 760px) {
  .auth-screen { padding: 16px; }
  .auth-card { padding: 25px; border-radius: 24px; }
  .auth-card h1 { font-size: 36px; }

  .chat-screen { grid-template-columns: 1fr; }
  .chat-sidebar { display: flex; }
  .conversation { display: none; }
  body.mobile-chat-open .chat-sidebar { display: none; }
  body.mobile-chat-open .conversation { display: grid; height: 100vh; height: 100dvh; }
  .back-btn { display: block; }
  .message-bubble { max-width: 88%; }
  .message-list { padding: 14px; }
}
