:root {
  --bg: #000000;
  --gold: #e8d5a3;
  --gold-dim: #b89b5e;
  --line: rgba(232, 213, 163, 0.18);
  --muted: #9a958a;
  --text: #f3f0ea;
  --surface: #141414;
  --font-display: "Cinzel", serif;
  --font-chat: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-body: "Cormorant Garamond", Georgia, serif;
  --tap: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--gold);
  font-family: var(--font-body);
}

body {
  min-height: 100dvh;
}

button,
input,
textarea {
  font-family: inherit;
  font-size: 16px;
  color: inherit;
}

button {
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}

button.gold {
  background: var(--gold);
  color: #111;
  border-color: var(--gold);
}

button.ghost {
  border-color: transparent;
  min-width: var(--tap);
}

button:disabled {
  opacity: 0.4;
}

.eyebrow {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.42em;
}

.login-body {
  display: flex;
}

.login-screen {
  width: 100%;
  min-height: 100dvh;
  padding: calc(48px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 420px;
  margin: 0 auto;
}

.login-screen h1 {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2.4rem;
}

.login-lead {
  margin: 8px 0 28px;
  color: var(--muted);
  font-size: 1.15rem;
}

.login-card {
  display: grid;
  gap: 16px;
  padding: 22px 18px;
  border: 1px solid var(--line);
  background: radial-gradient(circle at top, rgba(232, 213, 163, 0.08), transparent 55%);
}

.login-card label {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-card input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  outline: none;
}

.login-card button[type="submit"] {
  width: 100%;
  background: var(--gold);
  color: #111;
  border-color: var(--gold);
  margin-top: 8px;
}

.error {
  margin: 0;
  color: #d4a574;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand strong {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.05rem;
}

#who {
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.workspace {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.inbox,
.thread {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.thread {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 2;
}

.thread.is-open {
  display: flex;
}

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border-bottom: 1px solid var(--line);
}

.mode {
  border: 0;
  border-bottom: 1px solid transparent;
  letter-spacing: 0.06em;
  font-size: 0.78rem;
  padding: 0 6px;
}

.mode.is-active {
  border-bottom-color: var(--gold);
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.conv-list li {
  min-height: 76px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.conv-list li.is-selected {
  background: var(--surface);
}

.conv-name {
  font-family: var(--font-chat);
  font-size: 0.95rem;
  color: var(--text);
}

.conv-preview {
  color: var(--muted);
  font-family: var(--font-chat);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
}

.empty-list {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  cursor: default;
  min-height: auto;
  border-bottom: 0;
}

.thread-empty {
  margin: auto;
  color: var(--muted);
  padding: 24px;
  display: none;
}

.thread-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

.thread-main[hidden] {
  display: none !important;
}

.thread-head {
  display: grid;
  grid-template-columns: var(--tap) 1fr auto;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  border-bottom: 1px solid var(--line);
}

.back {
  font-size: 1.8rem;
  line-height: 1;
  padding: 0;
}

.thread-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.thread-title strong {
  font-family: var(--font-chat);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-title span {
  color: var(--muted);
  font-family: var(--font-chat);
  font-size: 0.75rem;
}

.thread-actions {
  display: flex;
  gap: 6px;
}

.thread-actions button {
  padding: 0 12px;
  font-size: 0.68rem;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 88%;
  padding: 0;
  background: none;
  border: 0;
  font-family: var(--font-chat);
  font-size: 16px;
  line-height: 1.35;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.customer {
  align-self: flex-start;
  align-items: flex-start;
  color: #eceae4;
}

.msg.advisor {
  align-self: flex-end;
  align-items: flex-end;
  color: var(--gold);
  text-align: right;
}

.msg.bot {
  align-self: flex-end;
  align-items: flex-end;
  color: #8f8c85;
  font-size: 14px;
  text-align: right;
}

.msg.system {
  align-self: center;
  align-items: center;
  max-width: 92%;
  color: #6f6c66;
  font-size: 12px;
  font-style: italic;
  text-align: center;
}

.msg.system time {
  display: none;
}

.msg time {
  font-size: 10px;
  line-height: 1;
  color: #6f6c66;
  font-family: var(--font-chat);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  flex-shrink: 0;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid #222;
  background: #0a0a0a;
}

.composer[hidden] {
  display: none !important;
}

.composer textarea {
  resize: none;
  min-height: var(--tap);
  max-height: 120px;
  padding: 12px 14px;
  border: 0;
  border-radius: 22px;
  background: #1c1c1c;
  color: var(--text);
  font-family: var(--font-chat);
  outline: none;
}

.composer textarea::placeholder {
  color: #7a7771;
}

.composer button {
  padding: 0 16px;
  border-radius: 22px;
  background: var(--gold);
  color: #111;
  border-color: var(--gold);
  font-family: var(--font-chat);
  letter-spacing: 0.04em;
}

@media (min-width: 900px) {
  .workspace {
    display: grid;
    grid-template-columns: minmax(280px, 34%) 1fr;
    grid-template-rows: 1fr;
  }

  .thread {
    position: relative;
    display: flex;
    min-height: 0;
    overflow: hidden;
    border-left: 1px solid #1f1f1f;
  }

  .thread-empty {
    display: block;
  }

  .thread.is-open .thread-empty {
    display: none;
  }

  .back {
    display: none;
  }

  .thread-head {
    grid-template-columns: 1fr auto;
    padding: 8px 10px;
  }

  .msg {
    max-width: 72%;
  }
}

@media (max-width: 899px) {
  body.chat-open .topbar {
    display: none;
  }
}
