:root {
  --bg: #eef2f1;
  --surface: #ffffff;
  --text: #11201d;
  --muted: #5b6b67;
  --brand: #0f766e;
  --brand-text: #ffffff;
  --mine: #d1f2ea;
  --theirs: #ffffff;
  --border: #d5dedb;
  --danger: #b42318;
  --chat-bg: #e7ece9;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1513;
    --surface: #16211e;
    --text: #e6efec;
    --muted: #93a5a0;
    --brand: #2bb3a3;
    --brand-text: #04211d;
    --mine: #135a50;
    --theirs: #1e2b28;
    --border: #2a3935;
    --danger: #f97066;
    --chat-bg: #0b1210;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

button, .button, input, select, textarea { font: inherit; color: inherit; }

button, .button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

button.primary {
  background: var(--brand);
  color: var(--brand-text);
  border-color: var(--brand);
  font-weight: 600;
}

button.link {
  border: 0;
  background: none;
  color: var(--brand);
  padding: 0;
  min-height: 0;
}

button.danger { color: var(--danger); }

button.icon {
  border: 0;
  background: none;
  font-size: 1.3rem;
  width: 44px;
  padding: 0;
  color: var(--brand-text);
}

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* --- home & setup --- */

.view:not(.chat) {
  max-width: 34rem;
  margin: 0 auto;
  padding: 1.5rem 16px 3rem;
}

.hero h1 { margin: 0 0 0.25rem; color: var(--brand); font-size: 2rem; }
.hero p { margin: 0 0 1.25rem; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.card > .primary { width: 100%; }
.card h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }

.chat-list { list-style: none; margin: 0; padding: 0; }
.chat-list li + li { border-top: 1px solid var(--border); }
.chat-list a {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}
.chat-list small { color: var(--muted); font-weight: 400; }

.muted { color: var(--muted); margin: 0; }

.notice { color: var(--muted); font-size: 0.85rem; }

.form { display: grid; gap: 1rem; }
.form label { display: grid; gap: 0.35rem; font-weight: 600; }
.form input[type="text"], .form input:not([type]) {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  background: var(--bg);
}
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; margin-bottom: 0.35rem; }
.lang-options { display: grid; gap: 0.5rem; }
.lang-option {
  display: flex !important;
  align-items: center;
  gap: 0.6rem;
  font-weight: 400 !important;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  cursor: pointer;
}
.lang-option:has(input:checked) { border-color: var(--brand); background: var(--mine); }

/* --- chat --- */

.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 48rem;
  margin: 0 auto;
  background: var(--chat-bg);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.5rem;
  padding-top: max(0.4rem, env(safe-area-inset-top));
  background: var(--brand);
  color: var(--brand-text);
}

.chat-title { flex: 1; min-width: 0; display: grid; }
.chat-title strong, .chat-title small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title small { opacity: 0.85; }

#chat-lang {
  background: transparent;
  color: var(--brand-text);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.3rem 0.5rem;
  max-width: 9rem;
}
#chat-lang option { color: #11201d; }

.panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 16px;
  display: grid;
  gap: 0.6rem;
}
.panel p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.share-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
#share-whatsapp { background: #25d366; color: #062814; border-color: #25d366; font-weight: 600; }

.messages {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 1rem 12px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.msg {
  max-width: min(80%, 32rem);
  padding: 0.45rem 0.7rem 0.3rem;
  border-radius: 14px;
  box-shadow: 0 1px 1px rgb(0 0 0 / 0.08);
  overflow-wrap: anywhere;
}
.msg.mine { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 4px; }
.msg .who { display: block; font-size: 0.8rem; font-weight: 700; color: var(--brand); }
.msg .text { margin: 0; white-space: pre-wrap; }
.msg .meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: var(--muted);
}
.msg .toggle {
  border: 0;
  background: none;
  padding: 0;
  min-height: 24px;
  color: var(--brand);
  font-size: 0.72rem;
}
.msg .pending { font-style: italic; }

.empty { text-align: center; color: var(--muted); padding: 0 16px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 12px;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 0.6rem 0.9rem;
  background: var(--bg);
  max-height: 160px;
}
.composer .send { width: 44px; padding: 0; flex: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%);
  background: #11201d;
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  max-width: calc(100% - 32px);
  text-align: center;
  font-size: 0.9rem;
  z-index: 10;
}
