:root {
  --bg: #18171d;
  --bg-subtle: #1f1e24;
  --bg-strong: #28272d;
  --bg-overlay: #333238;
  --border: #424248;
  --border-strong: #6e6b76;
  --text: #ececef;
  --text-subtle: #bfbfc3;
  --text-muted: #89888d;
  --link: #9dc7f1;
  --blue: #428fdc;
  --blue-hover: #63a6e9;
  --blue-active: #1f75cb;
  --orange: #e24329;
  --green: #108548;
  --danger: #dd2b0e;
  --danger-bg: #3c1510;
  --out: #1f4b8a;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  --topbar: 48px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--orange);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 360px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-card h1 {
  margin: 12px 0 0;
  font-size: 22px;
  font-weight: 600;
}

.auth-lead {
  margin: 0 0 8px;
  color: var(--text-subtle);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-subtle);
  font-weight: 600;
  font-size: 13px;
}

.field input {
  height: 36px;
  padding: 0 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text);
  font-weight: 400;
}

.field input:focus {
  outline: 1px solid var(--blue);
  outline-offset: 1px;
  border-color: var(--blue);
}

.password-wrap {
  position: relative;
  display: block;
}

.password-wrap input { width: 100%; padding-right: 84px; }

.ghost {
  position: absolute;
  right: 6px;
  top: 4px;
  height: 28px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--link);
  border-radius: 4px;
}

.ghost:hover { background: var(--bg-overlay); }

.form-error {
  min-height: 1.2em;
  margin: 0;
  color: #f57f6c;
  font-size: 13px;
}

.btn-primary, .btn-default {
  height: 32px;
  padding: 0 14px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-weight: 600;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue-active);
}

.btn-primary:hover { background: var(--blue-hover); }

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-default {
  background: var(--bg-strong);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-default:hover { background: var(--bg-overlay); }

.text-link {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
}

.text-link:hover { text-decoration: underline; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.who { color: var(--text-subtle); }

.shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.inbox {
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inbox-head {
  height: 49px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.contact {
  display: flex;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: inherit;
}

.contact.is-active {
  background: var(--bg-overlay);
  border-left-color: var(--orange);
}

.avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: #4e2a22;
  color: #fcb;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid #6b3a2e;
}

.contact-body { min-width: 0; flex: 1; }

.contact-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.contact-name { font-weight: 600; }

.contact time, .preview {
  color: var(--text-muted);
  font-size: 12px;
}

.preview {
  display: block;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.chat-head {
  height: 58px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

.presence {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.clear-chat {
  margin-left: auto;
}

.clear-chat.is-confirm {
  background: #3c1510;
  border-color: var(--danger);
  color: #f57f6c;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.tags {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

.tags-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tags-split {
  width: 1px;
  height: 20px;
  background: var(--border-strong);
}

.tag {
  height: 28px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-subtle);
  font-weight: 600;
  font-size: 13px;
}

.tag.is-on {
  background: #3a241f;
  border-color: var(--orange);
  color: var(--text);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 8% 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.messages::before {
  content: "";
  margin-top: auto;
}

.empty {
  margin: auto;
  color: var(--text-muted);
  text-align: center;
}

.day {
  align-self: center;
  margin: 8px 0;
  padding: 2px 10px;
  border-radius: 4px;
  background: var(--bg-strong);
  color: var(--text-subtle);
  font-size: 12px;
  border: 1px solid var(--border);
}

.bubble {
  max-width: min(72%, 520px);
  padding: 8px 10px 6px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.voz {
  align-self: flex-start;
  background: var(--bg-strong);
  border: 1px solid var(--border);
  border-top-left-radius: 2px;
}

.bubble.user {
  align-self: flex-end;
  background: var(--out);
  border-top-right-radius: 2px;
}

.bubble time {
  display: block;
  margin-top: 2px;
  text-align: right;
  color: var(--text-muted);
  font-size: 11px;
}

.bubble.user time { color: #c5d7ef; }

.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg-strong);
  border: 1px solid var(--border);
  border-radius: 8px;
  border-top-left-radius: 2px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}

.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.composer {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 16px 14px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
}

.composer input {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

.composer input:focus {
  outline: 1px solid var(--blue);
  border-color: var(--blue);
}

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .inbox { display: none; }
  .messages { padding: 14px 12px; }
  .bubble { max-width: 86%; }
  .who { display: none; }
}
