* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #17102e;
  color: #f1eefc;
}
#app { max-width: 560px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* Auth */
#screen-auth { justify-content: center; padding: 24px; }
.auth-card { background: #241a4a; border: 1px solid #3b2d6e; border-radius: 20px; padding: 28px 22px; text-align: center; }
.logo { width: 96px; height: 96px; border-radius: 22px; margin-bottom: 10px; }
.auth-card h1 { font-size: 30px; margin-bottom: 4px; }
.sub { color: #b9aee0; font-size: 14px; margin-bottom: 18px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid #3b2d6e; background: transparent; color: #cfc6f2; font-size: 15px; cursor: pointer; }
.tab.active { background: #6d28d9; border-color: #6d28d9; color: #fff; }
input[type="text"], input[type="password"] {
  width: 100%; padding: 12px 14px; margin-bottom: 10px; border-radius: 12px;
  border: 1px solid #3b2d6e; background: #17102e; color: #fff; font-size: 16px; outline: none;
}
input:focus { border-color: #22d3ee; }
.password-wrap { position: relative; margin-bottom: 10px; }
.password-wrap input { margin-bottom: 0; padding-right: 44px; }
.eye-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: transparent; border: none; color: #cfc6f2; font-size: 18px; cursor: pointer; padding: 6px; line-height: 1; }
.btn-primary {
  width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: linear-gradient(90deg, #7c3aed, #06b6d4); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.error { color: #f87171; font-size: 13px; min-height: 18px; margin-top: 8px; }
.hint { color: #8d83b5; font-size: 12px; margin-top: 10px; }
.hint a { color: #22d3ee; text-decoration: none; }
#forgot-contact[type="email"] { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #3b2d6e; background: #241a45; color: #fff; font-size: 15px; margin-bottom: 10px; box-sizing: border-box; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 10px; position: relative;
  padding: calc(12px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 12px calc(14px + env(safe-area-inset-left));
  background: #241a4a; border-bottom: 1px solid #3b2d6e;
}
.mini-logo { width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0; }
.title { font-size: 18px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { width: 60px; flex-shrink: 0; }
.icon-btn { background: transparent; border: 1px solid #3b2d6e; color: #cfc6f2; border-radius: 9px; padding: 7px 10px; font-size: 14px; cursor: pointer; flex-shrink: 0; }

/* Menú de usuario */
.user-menu {
  position: absolute; top: calc(100% + 8px); right: 12px; z-index: 40;
  background: #241a4a; border: 1px solid #3b2d6e; border-radius: 14px;
  padding: 10px; min-width: 240px; max-width: calc(100vw - 24px);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.user-menu-head { padding: 6px 8px 10px; border-bottom: 1px solid #3b2d6e; margin-bottom: 6px; }
.user-menu-label { display: block; color: #8d83b5; font-size: 12px; margin-bottom: 2px; }
#menu-username { font-size: 18px; color: #fff; overflow-wrap: anywhere; }
.menu-item {
  display: block; width: 100%; text-align: left; background: transparent; border: none;
  color: #f1eefc; font-size: 15px; padding: 10px 8px; border-radius: 9px; cursor: pointer;
}
.menu-item:active { background: #2a2050; }
.menu-item.danger { color: #f87171; }

/* Modal de cuenta */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.modal-card { background: #241a4a; border: 1px solid #3b2d6e; border-radius: 20px; padding: 22px; width: 100%; max-width: 380px; position: relative; }
.modal-card h2 { font-size: 19px; margin-bottom: 14px; }
.modal-close { position: absolute; top: 12px; right: 12px; background: transparent; border: none; color: #cfc6f2; font-size: 17px; cursor: pointer; padding: 4px 8px; }
.modal-card .btn-primary { margin-top: 4px; }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; padding: 10px 13px; border-radius: 16px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg.mine { align-self: flex-end; background: #6d28d9; color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: #2a2050; border: 1px solid #3b2d6e; border-bottom-left-radius: 4px; }
.msg.typing { color: #8d83b5; }
.msg-del { background: transparent; border: none; color: rgba(255,255,255,.55); font-size: 12px; cursor: pointer; padding: 2px 4px; margin-left: 4px; vertical-align: middle; }
.blocked { background: #7f1d1d; color: #fecaca; text-align: center; padding: 10px; font-size: 14px; }

/* Composer */
.composer { display: flex; gap: 8px; padding: 10px calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); background: #241a4a; border-top: 1px solid #3b2d6e; }
.composer input[type="text"] { flex: 1; margin: 0; }
.btn-send {
  width: 46px; height: 46px; border: none; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #7c3aed, #06b6d4); color: #fff; font-size: 18px; cursor: pointer;
}
.btn-attach { font-size: 22px; align-self: center; cursor: pointer; padding: 0 2px; }
.attach-bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #2a2050; border-top: 1px solid #3b2d6e; font-size: 13px; }
.attach-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.once-toggle { display: flex; align-items: center; gap: 5px; color: #b9aee0; cursor: pointer; }
.media-btn { background: #0e7490; color: #fff; border: none; border-radius: 10px; padding: 8px 12px; font-size: 14px; cursor: pointer; }

/* Secret menu */
.search-box { padding: 12px 14px 4px; }
.search-results { margin-top: 6px; }
.search-item { display: flex; justify-content: space-between; align-items: center; background: #2a2050; border: 1px solid #3b2d6e; border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; }
.search-item button { background: #6d28d9; color: #fff; border: none; border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.thread-list { flex: 1; overflow-y: auto; padding: 8px 14px 16px; }
.thread-item { background: #241a4a; border: 1px solid #3b2d6e; border-radius: 14px; padding: 13px; margin-bottom: 8px; cursor: pointer; }
.thread-item b { font-size: 16px; }
.thread-last { display: block; color: #8d83b5; font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-badge { background: #22d3ee; color: #082f49; font-size: 12px; font-weight: 700; border-radius: 10px; padding: 2px 8px; margin-left: 6px; }
.empty { color: #8d83b5; text-align: center; margin-top: 30px; font-size: 14px; }

/* Viewer */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,0.92); display: flex; align-items: center; justify-content: center; z-index: 50; }
.viewer-close { position: absolute; top: calc(16px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right)); background: #333; color: #fff; border: none; border-radius: 50%; width: 42px; height: 42px; font-size: 18px; cursor: pointer; z-index: 51; }
.viewer-content { max-width: 94vw; max-height: 88vh; }
.viewer-content img, .viewer-content video { max-width: 94vw; max-height: 88vh; border-radius: 12px; }

/* Cita de respuesta + gestos en mensajes */
.msg { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: pan-y; }
.msg-quote { font-size: 12px; background: rgba(0,0,0,.28); border-left: 3px solid #22d3ee; border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; }
.msg-quote b { display: block; color: #22d3ee; font-size: 12px; }
.msg-quote span { color: #d8d2f0; }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #2a2050; border-top: 1px solid #3b2d6e; font-size: 13px; }
.reply-bar-text { flex: 1; overflow: hidden; border-left: 3px solid #22d3ee; padding-left: 8px; }
.reply-bar-text b { display: block; color: #22d3ee; font-size: 12px; }
.reply-bar-text span { color: #d8d2f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.msg-menu { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.msg-menu-sheet { width: 100%; max-width: 480px; background: #241a4a; border-radius: 16px 16px 0 0; padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
.msg-menu-btn { display: block; width: 100%; padding: 14px; margin-top: 6px; border: none; border-radius: 10px; background: #3b2d6e; color: #fff; font-size: 16px; cursor: pointer; }
.msg-menu-btn.danger { background: #991b1b; color: #fecaca; }
