* {
  box-sizing: border-box;
}

:root {
  --bg: #0f1120;
  --bg-soft: #161830;
  --surface: #1c1e3a;
  --surface-2: #242650;
  --accent: #7c5cff;
  --accent-2: #5b8cff;
  --accent-soft: rgba(124, 92, 255, 0.15);
  --text: #eef0ff;
  --text-muted: #9a9dc2;
  --bubble-mine-start: #7c5cff;
  --bubble-mine-end: #5b8cff;
  --bubble-theirs: #242650;
  --danger: #ff6b81;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

/* ---------- Tela de login ---------- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #241f55 0%, var(--bg) 60%);
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 30px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.06);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 800;
}

.brand-text {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.brand-emoji {
  -webkit-text-fill-color: initial;
}

.login-card p {
  margin: 0 0 26px;
  color: var(--text-muted);
  font-size: 14px;
}

.login-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-btn {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  padding: 14px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}

.login-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* ---------- Tela de bloqueio ---------- */
.lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #241f55 0%, var(--bg) 60%);
  padding: 20px;
}

.lock-overlay .modal-input {
  margin-bottom: 12px;
}

.lock-overlay .history-auth-error {
  margin-bottom: 12px;
}

/* ---------- Tela do chat ---------- */
.chat-screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-soft);
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-title {
  font-weight: 700;
  font-size: 16px;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 50%;
  line-height: 1;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.08);
}

.clear-btn {
  background: rgba(255,107,129,0.12);
  border: 1px solid rgba(255,107,129,0.3);
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 20px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background .15s ease;
}

.clear-btn:hover {
  background: rgba(255,107,129,0.22);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-image: radial-gradient(circle at 80% 0%, rgba(124,92,255,0.06), transparent 40%);
}

.msg-row {
  display: flex;
  max-width: 100%;
}

.msg-row.mine {
  justify-content: flex-end;
}

.bubble {
  max-width: 78%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}

.msg-row.mine .bubble {
  background: linear-gradient(135deg, var(--bubble-mine-start), var(--bubble-mine-end));
  color: #fff;
  border-bottom-right-radius: 3px;
}

.msg-row.theirs .bubble {
  background: var(--bubble-theirs);
  border-bottom-left-radius: 3px;
}

.bubble .sender {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
  font-weight: 600;
}

.bubble .time {
  display: block;
  text-align: right;
  font-size: 10.5px;
  color: rgba(255,255,255,0.65);
  margin-top: 3px;
}

.msg-row.theirs .bubble .time {
  color: var(--text-muted);
}

.bubble.emoji-only {
  background: transparent !important;
  font-size: 40px;
  padding: 0;
}

.bubble img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  display: block;
  margin-top: 2px;
}

.bubble audio {
  margin-top: 2px;
  max-width: 220px;
}

.audio-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-soft);
  border-top: 1px solid rgba(255,255,255,0.06);
}

#audio-preview-label {
  flex: 1;
  color: var(--text);
  font-size: 14px;
}

.text-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 6px 10px;
}

.text-btn.primary {
  color: var(--accent-2);
  font-weight: 600;
}

.emoji-picker {
  background: var(--bg-soft);
  border-top: 1px solid rgba(255,255,255,0.06);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  padding: 10px;
  max-height: 160px;
  overflow-y: auto;
  flex-shrink: 0;
}

.emoji-picker button {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.emoji-picker button:hover {
  background: rgba(255,255,255,0.08);
}

/* ---------- Menu de imagem (câmera / galeria) ---------- */
.image-menu {
  background: var(--bg-soft);
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  padding: 8px;
  flex-shrink: 0;
}

.image-menu-option {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  padding: 12px 10px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}

.image-menu-option:hover {
  background: rgba(255,255,255,0.06);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 10px;
  background: var(--bg-soft);
  flex-shrink: 0;
}

#text-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 15px;
  max-height: 100px;
  font-family: inherit;
}

.send-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:hover {
  filter: brightness(1.1);
}

/* ---------- Modal da câmera ---------- */
.camera-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.camera-modal-inner {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#camera-video {
  width: 100%;
  max-height: 60vh;
  border-radius: 16px;
  background: #000;
  object-fit: cover;
}

.camera-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  width: 100%;
}

.capture-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.capture-btn:hover {
  background: #eee;
}

/* ---------- Modal do histórico completo ---------- */
.history-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}

.history-modal-inner {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.history-header h2 {
  margin: 0;
  font-size: 17px;
}

.history-auth {
  padding: 24px 22px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-auth p {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.4;
}

#history-password,
.modal-input {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  width: 100%;
}

#history-password:focus,
.modal-input:focus {
  border-color: var(--accent);
}

.history-auth-error {
  color: var(--danger);
  font-size: 13px;
}

.history-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.history-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.history-list {
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13.5px;
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.history-item-sender {
  font-weight: 600;
  color: var(--accent-2);
}

.history-item-time {
  color: var(--text-muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.history-item-body {
  color: var(--text);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.history-item-body img {
  max-width: 100%;
  max-height: 160px;
  border-radius: 8px;
  display: block;
  margin-top: 4px;
}

.history-item-body audio {
  width: 100%;
  margin-top: 4px;
}

.history-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.history-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255,107,129,0.15);
  color: var(--danger);
}

.history-restore-btn {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 14px;
  cursor: pointer;
}

.history-restore-btn:hover {
  background: rgba(124,92,255,0.25);
}

/* ---------- Responsivo / celular ---------- */
@media (max-width: 640px) {
  .chat-screen {
    max-width: 100%;
  }

  .bubble {
    max-width: 85%;
  }

  .emoji-picker {
    grid-template-columns: repeat(6, 1fr);
  }

  .clear-btn {
    font-size: 11.5px;
    padding: 7px 10px;
  }
}

@media (max-width: 380px) {
  .icon-btn {
    font-size: 18px;
    padding: 5px 6px;
  }

  .bubble {
    font-size: 14px;
  }

  .header-title {
    font-size: 15px;
  }

  .clear-btn {
    font-size: 11px;
    padding: 6px 8px;
  }
}
