* { box-sizing: border-box; font-family: system-ui, Arial; }

html, body { height: 100%; }
body { margin: 0; background: #f6f7fb; overflow: hidden; } /* prevent page scroll */

.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100dvh;   /* modern */
  /*height: 100vh;*/    /* fallback */
  overflow: hidden; /* IMPORTANT */
}

/* Sidebar */
.sidebar {
  background: #fff;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  min-height: 0;     /* IMPORTANT */
}

.header { padding: 14px 16px; font-weight: 700; border-bottom: 1px solid #e5e7eb; }

.search {
  margin: 12px 16px;
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  flex: 0 0 auto;
}

.list {
  flex: 1 1 auto;
  min-height: 0;     /* IMPORTANT */
  overflow-y: auto;  /* sidebar scrolls internally */
  padding: 0 8px 12px;
}

/* Conversation item */
.item { padding: 10px 12px; border-radius: 10px; cursor: pointer; margin: 6px 8px; }
.item:hover { background: #f3f4f6; }
.item.active { background: #e9f2ff; }
.item .num { font-weight: 700; }
.item .meta { font-size: 12px; color: #6b7280; margin-top: 2px; }

/* Chat */
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;    /* IMPORTANT */
  overflow: hidden; /* IMPORTANT */
}

.chat-header {
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 700;
  flex: 0 0 auto;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;     /* IMPORTANT */
  overflow-y: auto;  /* messages scroll internally */
  padding: 16px;
}

/* Bubbles */
.bubble {
  max-width: 70%;
  padding: 10px 12px;
  margin: 8px 0;
  border-radius: 14px;          /* FIXED (was 14p) */
  line-height: 1.35;
  overflow-wrap: break-word;    /* modern */
  word-wrap: break-word;        /* legacy */
}

.bubble .content { white-space: pre-wrap; }

.inbound { background: #fff; border: 1px solid #e5e7eb; }
.outbound { background: #dbeafe; margin-left: auto; }

.time { font-size: 11px; color: #6b7280; margin-top: 6px; }

/* Composer */
.composer {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  flex: 0 0 auto; /* ALWAYS visible */
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

#msg { flex: 1; padding: 10px; border: 1px solid #e5e7eb; border-radius: 10px; }
#sendBtn { padding: 10px 14px; border: 0; border-radius: 10px; background: #111827; color: #fff; cursor: pointer; }
#sendBtn:disabled { opacity: .5; cursor: not-allowed; }

.att { margin-top: 8px; }
.att-img { max-width: 100%; border-radius: 12px; display: block; }
.att-video { max-width: 100%; border-radius: 12px; display: block; }

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr; /* single column */
  }

  /* default: show sidebar, hide chat */
  .chat { display: none; }

  /* when chat is open: hide sidebar, show chat */
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .chat { display: flex; }
    
}
