@import url('https://fonts.googleapis.com/css2?family=Mukta:wght@200;400;600&display=swap');

:root {
  --header-h: 11vh;
  --header-min: 60px;
  --header-max: 125px;
  --sidebar-bg: #353535;
  --accent: #876AB7;
  --accent-dark: #5a4080;
  --bubble-me: #cc8177;
  --bubble-them: #e5e5ea;
  --bubble-narrator: #55759E;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html {
  scroll-behavior: smooth;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
}

body {
  font-family: "Mukta", sans-serif;
  background-color: #55759E;
  font-size: 12pt;
  overflow: hidden;
  margin: 5px;
  padding: 2px;
  background: url(../images/fondo2.png) no-repeat center center / cover;
  height: 100%;
  max-width: 100%;
}

/* ── Container ── */
#container {
  width: 99vw;
  height: 98vh;
  max-width: 1920px;
  max-height: 1080px;
  margin: auto;
  padding: 0;
  overflow: hidden;
  box-shadow:
    0px 2.1px 2.6px rgba(0,0,0,.087),
    0 5.9px 7.1px rgba(0,0,0,.105),
    0 14.2px 27.2px rgba(0,0,0,.13),
    0 28px 40px rgba(0,0,0,.2);
  border-radius: 1em;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ── Grid layout ── */
#grid {
  display: grid;
  grid-template-columns: minmax(80px, 384px) minmax(320px, 1536px);
  margin: 0;
  padding: 1vh 1vw;
  background-color: var(--sidebar-bg);
  color: #fff;
  overflow: hidden;
  height: 100%;
  box-sizing: border-box;
}

#menu-left, #menu-right {
  text-align: left;
  padding: 0;
  margin: 0;
}

/* ── Top bars ── */
.menu-right2 {
  display: flex;
  align-items: center;
  text-align: left;
  margin: auto 10px;
  flex-shrink: 0;
}

#menu-top, .menu-right2 {
  height: var(--header-h);
  max-height: var(--header-max);
  min-height: var(--header-min);
}

/* ── Sidebar contact cards ── */
.contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin: 3px 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color .2s, box-shadow .2s;
  position: relative;
  min-height: 64px;
}

.contact-card:hover {
  background-color: rgba(255,255,255,.08);
}

.contact-card .avatar {
  flex-shrink: 0;
  width: clamp(44px, 8vh, 90px);
  height: clamp(44px, 8vh, 90px);
  min-width: 44px;
  min-height: 44px;
  max-width: 90px;
  max-height: 90px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid transparent;
  transition: border-color .2s;
}

.contact-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 2px;
}

.contact-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.contact-sub {
  font-size: 0.78rem;
  color: rgba(255,255,255,.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-badge {
  font-size: 16px !important;
  color: rgba(255,255,255,.35);
  flex-shrink: 0;
  font-variation-settings: 'FILL' 0, 'wght' 200, 'GRAD' 0, 'opsz' 24;
  transform: rotate(45deg);
}

/* ── Generic panels ── */
#persons, .messages {
  margin: 2vh 0;
  padding: 2vh 2vw;
  background-color: #fff;
  color: #000;
}

#persons {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
}

/* ── Chat panel (messages2 & messages3) ── */
/* display is set by JS (flex when visible, none when hidden) */
.chat-panel {
  flex-direction: column;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.messages {
  background-image: linear-gradient(#E5E5EA 10%, #E7FED2);
  background-color: #cccccc;
  text-align: left;
  height: 81vh;
  overflow: auto;
}

/* ── Scrollable chat bubble area ── */
#imessage0, #imessage1 {
  overflow-y: scroll;
  overflow-x: hidden;
  scroll-behavior: smooth;
  flex: 1;
}

/* Thin, styled scrollbar */
#imessage0::-webkit-scrollbar,
#imessage1::-webkit-scrollbar {
  width: 4px;
}
#imessage0::-webkit-scrollbar-track,
#imessage1::-webkit-scrollbar-track {
  background: transparent;
}
#imessage0::-webkit-scrollbar-thumb,
#imessage1::-webkit-scrollbar-thumb {
  background: rgba(135, 106, 183, .4);
  border-radius: 4px;
}
#imessage0::-webkit-scrollbar-thumb:hover,
#imessage1::-webkit-scrollbar-thumb:hover {
  background: rgba(135, 106, 183, .7);
}

/* ── Send bar ── */
.send-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  background: var(--sidebar-bg);
  border-top: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
  padding-bottom: calc(8px + var(--safe-bottom));
}

/* old class kept for safety */
.send-icon {
  cursor: pointer;
  color: #fff;
  opacity: .8;
  flex-shrink: 0;
}

/* ── Send button ── */
.send-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #9f7ad4 0%, var(--accent) 50%, #5a4080 100%);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 10px rgba(135, 106, 183, .45);
  transition: transform .18s cubic-bezier(.34,1.56,.64,1),
              box-shadow .18s ease,
              background .18s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.send-btn span {
  font-size: 1.25rem !important;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  line-height: 1;
  transform: rotate(-15deg) translateX(1px);
  display: block;
  transition: transform .18s cubic-bezier(.34,1.56,.64,1);
}

.send-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 18px rgba(135, 106, 183, .65);
  background: linear-gradient(135deg, #b08fe0 0%, #9a7dc4 50%, #6b4f9a 100%);
}

.send-btn:active {
  transform: scale(.93);
  box-shadow: 0 1px 6px rgba(135, 106, 183, .35);
  transition-duration: .08s;
}

.send-btn:active span {
  transform: rotate(0deg) translateX(2px) translateY(-1px);
  transition-duration: .08s;
}

/* ── Top right info bar ── */
#info_top {
  width: 120px;
  display: inline-block;
  font-size: 12pt;
}

.material-symbols-outlined {
  font-size: 14px !important;
}

/* ── Height utility classes ── */
.normal {
  flex: 1;
  min-height: 0;
  /* fallback for non-flex contexts */
  height: 70vh;
}

.grande {
  height: 100%;
  overflow: visible !important;
}

/* ── Dropdown menu ── */
#menuContainer {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding-right: 25px;
  width: 95%;
}

#menuContainer ul {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--sidebar-bg);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
  overflow: hidden;
}

#menuContainer ul li a {
  text-decoration: none;
  color: #fff;
  font-size: 24pt;
  background-color: var(--sidebar-bg);
  line-height: 0;
  display: flex;
  align-items: center;
  padding: 6px 10px;
  transition: background-color .15s;
}

#menuContainer ul li a:hover {
  background-color: rgba(255,255,255,.12);
}

/* ── Avatars ── */
#avatar_user, #avatar_top {
  border-radius: 50%;
  width: 10vh;
  min-width: 50px;
  max-width: 120px;
  margin: 0 10px;
  object-fit: cover;
  cursor: pointer;
  transition: opacity .2s;
}

#avatar_user:hover, #avatar_top:hover {
  opacity: .85;
}

.avatar {
  border-radius: 50%;
  height: 10vh;
  min-height: 50px;
  max-height: 120px;
  width: 10vh;
  min-width: 50px;
  max-width: 120px;
  margin: 0 10px;
  object-fit: cover;
}

.avatar2 {
  border-radius: 30%;
  width: 3vw;
  min-width: 55px;
  max-width: 120px;
}

.avatar3 {
  border-radius: 50%;
  width: 5vh;
  max-width: 120px;
  min-width: 36px;
  margin-top: -3vh;
}

.avatar4, .avatar5 {
  border-radius: 50%;
  width: 5vh;
  min-width: 36px;
  float: right;
  margin-top: -3vh;
  max-width: 120px;
}

/* ── Logos & social icons ── */
.logo3 {
  width: 10vw;
  min-width: 55px;
  max-width: 320px;
}

.logo4 {
  width: 12vw;
  min-width: 75px;
  max-width: 370px;
  border-radius: 50%;
}

.material-icons {
  font-size: 40pt !important;
}

.portada {
  height: 60vh;
  max-height: 500px;
}

/* ── Grupos panel ── */
#grupos {
  margin-top: 1vh;
  overflow-y: auto;
  overflow-x: hidden;
}

#grupos::-webkit-scrollbar { width: 3px; }
#grupos::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 3px; }

/* ── Grupos header (visible on mobile bottom-sheet) ── */
#grupos-header {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 8px 20px 14px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  margin-bottom: 6px;
}

#grupos-handle {
  width: 40px;
  height: 4px;
  background: rgba(255,255,255,.3);
  border-radius: 2px;
  margin-bottom: 14px;
}

#grupos-title {
  color: rgba(255,255,255,.6);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ── About & Info panels ── */
#messages4 {
  background-image: url("../images/pastilla.png");
  background-color: white;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 14pt;
}

#info-mar, #info-elia {
  background-image: url("../images/pastilla.png");
  background-color: white;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 18pt;
}

/* ── Expand/menu icon (hidden on desktop, shown on mobile) ── */
#expand_top {
  font-size: 22pt !important;
  display: none;
  cursor: pointer;
  color: rgba(255,255,255,.85);
  transition: color .2s;
}

#expand_top:hover { color: #fff; }

/* ── Social icons ── */
.social {
  width: 5vh;
  min-width: 80px;
}

.social2 {
  width: 4vh;
  min-width: 40px;
}

/* ── Links ── */
a {
  text-decoration: none;
  font-weight: bold;
  color: var(--accent);
  line-height: inherit;
}

a:hover { color: var(--accent-dark); }

/* ────────────────────────────────
   iMessage-style bubble system
   ──────────────────────────────── */
.imessage {
  background-color: #fff;
  border: 1px solid #e5e5ea;
  border-radius: 0.25rem;
  display: flex;
  flex-direction: column;
  font-family: "Mukta", sans-serif;
  font-size: 1.15rem;
  margin: 0;
  max-width: 100%;
  padding: 0.5rem 1rem;
  box-sizing: border-box;
}

.imessage p {
  border-radius: 1.15rem;
  line-height: 1.45;
  max-width: 80%;
  padding: 0.55rem .9rem;
  position: relative;
  word-wrap: break-word;
  white-space: pre-line;
  margin-bottom: .4rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.imessage p::before,
.imessage p::after {
  bottom: -0.1rem;
  content: "";
  height: 1rem;
  position: absolute;
}

/* User's own verse (coral) */
p.from-me2 {
  align-self: flex-end;
  background-color: var(--bubble-me);
  color: #fff;
}

p.from-me2::before {
  border-bottom-left-radius: 0.8rem 0.7rem;
  border-right: 1rem solid var(--bubble-me);
  right: -0.35rem;
  transform: translate(0, -0.1rem);
}

p.from-me2::after {
  background-color: #fff;
  border-bottom-left-radius: 0.5rem;
  right: -40px;
  transform: translate(-30px, -2px);
  width: 10px;
}

/* Poet's message (light gray) */
p.from-them {
  align-items: flex-start;
  background-color: var(--bubble-them);
  color: #000;
}

p.from-them:before {
  border-bottom-right-radius: 0.8rem 0.7rem;
  border-left: 1rem solid var(--bubble-them);
  left: -0.35rem;
  transform: translate(0, -0.1rem);
}

p.from-them::after {
  background-color: #fff;
  border-bottom-right-radius: 0.5rem;
  left: 20px;
  transform: translate(-30px, -2px);
  width: 10px;
}

/* Narrator / section header */
p.narrator {
  align-self: center;
  background-color: var(--bubble-narrator);
  color: #fff;
  font-style: italic;
  letter-spacing: .02em;
  max-width: 90%;
  text-align: center;
  border-radius: 0.6rem;
  font-size: .95rem;
  opacity: .92;
}

p[class^="from-"] {
  margin: 0.35rem 0;
  width: fit-content;
}

p[class^="from-"].emoji {
  background: none;
  font-size: 2.5rem;
  box-shadow: none;
}

p[class^="from-"].emoji::before { content: none; }

.no-tail::before { display: none; }

/* ── Delete button on user messages ── */
.delete {
  position: absolute;
  top: 0;
  right: 0;
  cursor: pointer;
  color: #ff6464;
  font-weight: bold;
}

/* ── Textarea input ── */
#input_msg1, #input_msg2 {
  flex: 1;
  font-size: 1.1rem;
  height: 2.5rem;
  min-height: 2.5rem;
  vertical-align: top;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  background: rgba(255,255,255,.12);
  color: #fff;
  outline: none;
  font-family: "Mukta", sans-serif;
  box-sizing: border-box;
}

#input_msg1::placeholder, #input_msg2::placeholder {
  color: rgba(255,255,255,.45);
  font-style: italic;
}

#input_msg1:focus, #input_msg2:focus {
  background: rgba(255,255,255,.18);
}

/* ── Expand icons (hidden by default) ── */
#expandIcon2 { display: none; }

/* ── Avatar folder/trash icons ── */
.icon {
  position: absolute;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 20pt !important;
}

#folder-icon {
  top: -11vh;
  left: 30pt;
  font-size: 4vh !important;
  position: relative;
}

#trash-icon {
  top: -9vh;
  left: 30pt;
  font-size: 5vh !important;
  position: relative;
}

/* ── Splash screen ── */
#splash-screen {
  position: fixed;
  inset: 0;
  background-color: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 1;
  z-index: 9999;
  transition: opacity 2s ease-in-out;
}

#splash-screen img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#splash-screen.fade-out {
  opacity: 0;
}

/* .info_person removed — replaced by .contact-body flex layout */

/* ── Selected group highlight ── */
.contact-card.resaltado {
  background: linear-gradient(90deg, rgba(135,106,183,.28) 0%, rgba(135,106,183,.12) 100%);
  box-shadow: inset 3px 0 0 var(--accent);
}

.contact-card.resaltado .avatar {
  border-color: var(--accent);
}

.contact-card.resaltado .contact-name {
  color: #c9b8f0;
}

/* ── Glow animation (user's turn) ── */
@keyframes glowing {
  0%   { box-shadow: 0 0 5px #f4ff6e; }
  50%  { box-shadow: 0 0 20px #f4ff6e, 0 0 40px #f4ff6e; }
  100% { box-shadow: 0 0 5px #f4ff6e; }
}

.brillo {
  animation: glowing 2s infinite;
}

/* ─────────────────────────────────
   Responsive: 1500px
   ───────────────────────────────── */
@media screen and (max-width: 1500px) {
  #input_msg1, #input_msg2 { width: auto; }
}

/* ─────────────────────────────────
   Responsive: 825px (mobile)
   ───────────────────────────────── */
@media screen and (max-width: 825px) {
  html {
    height: 100%;
    height: -webkit-fill-available;
    height: 100dvh;
  }

  body {
    font-size: 14pt;
    margin: 0;
    padding: 0;
    height: 100%;
    height: -webkit-fill-available;
    height: 100dvh;
  }

  #container {
    width: 100vw;
    height: 100%;
    height: -webkit-fill-available;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    max-width: 100vw;
    max-height: none;
    border-radius: 0;
    position: static;
    transform: none;
  }

  #grid {
    display: flex;
    flex-direction: column;
    padding: 0;
    height: 100%;
    height: -webkit-fill-available;
    height: 100dvh;
    height: var(--app-height, 100dvh);
  }

  #menu-left {
    position: fixed;
    right: 0;
    top: 10px;
    display: flex;
    z-index: 310;
  }

  #menu-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  /* Contact list as bottom-sheet on mobile */
  #grupos {
    display: none;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 72dvh;
    background: #2a2a2a;
    z-index: 300;
    padding: 0 0 calc(12px + var(--safe-bottom));
    box-shadow: 0 -8px 40px rgba(0,0,0,.55);
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
  }

  #grupos.open {
    display: block;
    animation: sheetUp .32s cubic-bezier(.32,.72,0,1) forwards;
  }

  @keyframes sheetUp {
    from { transform: translateY(100%); opacity: .6; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  #grupos-header { display: flex; }

  /* Backdrop when grupos is open */
  #grupos-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 250;
  }

  #grupos-backdrop.open { display: block; }

  /* Selected item stays visible on mobile, just styled */
  .contact-card.resaltado {
    background: linear-gradient(90deg, rgba(135,106,183,.35) 0%, rgba(135,106,183,.15) 100%);
    box-shadow: inset 3px 0 0 var(--accent);
  }

  .contact-card {
    min-height: 72px;
    padding: 12px 16px;
    margin: 4px 10px;
  }

  .contact-card .avatar {
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
    max-width: 52px;
    max-height: 52px;
  }

  .contact-name { font-size: 1.05rem; }
  .contact-sub  { font-size: 0.82rem; }

  .menu-right2 {
    flex-shrink: 0;
    min-height: var(--header-min);
    padding: 0 6px;
  }

  #expand_top {
    font-size: 20pt !important;
    display: block;
    z-index: 100;
    cursor: pointer;
  }

  #expandIcon2 { display: inline; }

  #persons { display: none; }

  #menu-top { font-size: 14pt; }

  .material-icons { font-size: 6.5vh !important; }

  .info_person { display: none; }

  /* Chat panel fills available height */
  .messages {
    margin: 0;
    height: auto;
    flex: 1;
    min-height: 0;
  }

  .chat-panel {
    flex: 1;
    height: auto !important;
    min-height: 0;
    overflow: hidden;
  }

  .normal {
    height: auto !important;
  }

  #imessage0, #imessage1 {
    flex: 1;
    min-height: 0;
    height: auto !important;
  }

  .send-bar { padding-bottom: calc(10px + var(--safe-bottom)); }

  .avatar3 {
    border-radius: 50%;
    width: 5vh;
    min-width: 36px;
    margin-top: -4vh;
    margin-left: -5vw;
  }

  .avatar4, .avatar5 {
    border-radius: 50%;
    width: 5vh;
    min-width: 36px;
    margin-top: -4vh;
    margin-right: -5vw;
    float: right;
  }

  .delete {
    top: 0;
    right: -30px;
  }

  #menuContainer { width: 87%; }

  .info_person { display: none; }
}

/* ─────────────────────────────────
   Responsive: 445px (very small)
   ───────────────────────────────── */
@media screen and (max-width: 445px) {
  #expand_top {
    font-size: 18pt !important;
    display: block;
  }

  #avatar_user, #avatar_top {
    width: 5vh;
    min-width: 46px;
    max-width: 60px;
    margin: 0 6px;
  }

  #avatar_user { margin-top: 12px; }

  .imessage { font-size: 1rem; }

  .imessage p { max-width: 88%; }
}

/* ─────────────────────────────────
   Large screens: 2000px+
   ───────────────────────────────── */
@media screen and (min-width: 2000px) {
  body { font-size: 18pt; }

  #input_msg1, #input_msg2 {
    font-size: 1.25rem;
    height: 2rem;
  }
}

/* ─────────────────────────────────
   PDF export helpers
   ───────────────────────────────── */
.pdf-exporting {
  overflow: visible !important;
  height: auto !important;
  max-height: none !important;
}
