/* =========================================================
   EmpathEra-AI Chat — MASTER-49 INPUT + SIDEBAR STABLE
   (Safe MVP UI polish – no logic impact)
========================================================= */

/* ================= VARIABLES ================= */

:root {
  --bg-main: #050010;
  --accent: #7b2bff;
  --accent-soft: #3b0078;
  --accent-strong: #ff2b70;
  --text-main: #ffffff;
  --sidebar-w: 180px;
}

/* ================= BASE ================= */

body.chat-page {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(circle at top, #1b0040 0%, #050010 60%);
  color: var(--text-main);
  height: 100dvh;
  overflow: hidden;
}

/* ================= APP ================= */

.chat-app {
  display: flex;
  height: 100dvh;
  position: relative;
}

/* ================= SIDEBAR ================= */

.chat-sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #070015, #15002e);
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease;
  overflow: hidden;
}

body.sidebar-collapsed .chat-sidebar {
  width: 0;
}

/* ================= SIDEBAR CONTENT ================= */

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-top {
  padding: 12px;
}

.sidebar-logo {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 10px;
}

.sidebar-button {
  width: 100%;
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 6px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #fff;
  cursor: pointer;
}

.sidebar-button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
}

.sidebar-button.danger {
  background: rgba(255,80,80,0.15);
}

.sidebar-bottom {
  margin-top: auto;
  padding: 12px;
}

/* ================= THREAD LIST ================= */

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.chat-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  background: rgba(255,255,255,0.05);
}

.chat-list-item.active {
  background: rgba(123,43,255,0.35);
}

.chat-delete {
  opacity: 0.6;
  cursor: pointer;
}

.chat-delete:hover {
  opacity: 1;
  color: #ff5b5b;
}

/* ================= SIDEBAR TOGGLE ================= */

.sidebar-toggle-btn {
  position: fixed;
  left: calc(var(--sidebar-w) - 19px);
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle, #ff7be0, #7b2bff);
  color: #fff;
  cursor: pointer;
  z-index: 60;
}

body.sidebar-collapsed .sidebar-toggle-btn {
  left: 10px;
}

/* ================= MAIN ================= */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* critical for flex stability */
  position: relative;
}

/* ================= HEADER ================= */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
}

.mode-selector {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 6px;
}
/* ================= MODE SELECT FIX ================= */

.mode-selector {
  appearance: none;
  background: linear-gradient(135deg, #2a0a55, #120022);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
}

/* Dropdown list */
.mode-selector option {
  background: #120022;
  color: #fff;
}

/* Hover / selected */
.mode-selector option:hover,
.mode-selector option:checked {
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: #fff;
}

.voice-toggle-btn {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

/* ================= CHAT SCROLL ================= */

.chat-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 18px 24px;
}

/* ================= MESSAGES ================= */

.message {
  max-width: 75%;
  padding: 12px 16px;
  margin-bottom: 8px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}

.message.user {
  margin-left: auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
}

.message.ai {
  margin-right: auto;
  background: linear-gradient(135deg, #1f1537, #401f6a);
}

/* ================= TYPING ================= */

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 6px;
}

.typing-indicator.hidden {
  display: none;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #bbb;
  border-radius: 50%;
  animation: blink 1.4s infinite both;
}

@keyframes blink {
  0% { opacity: 0.2; }
  20% { opacity: 1; }
  100% { opacity: 0.2; }
}

/* ================= INPUT BAR ================= */

.chat-input-bar {
  position: sticky;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  margin: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--accent-soft), #1e0035);
  z-index: 80;
}

/* ================= INPUT ================= */

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  outline: none;
  resize: none;
  font-size: 14px;
}
.chat-input {
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.4;
}

/* ================= BUTTONS ================= */

.square-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle, #ffe0ff, var(--accent));
  cursor: pointer;
}

.send-btn {
  background: radial-gradient(circle, #ffd4e5, var(--accent-strong));
}

/* ================= DISCLAIMER ================= */

.chat-warning {
  font-size: 11px;
  opacity: 0.7;
  text-align: center;
  margin: 4px 0 6px;
}

/* ================= MOBILE ================= */

@media (max-width: 768px) {
  .message {
    max-width: 88%;
  }

  .chat-container {
    padding: 12px 12px 16px;
  }
}

/* ================= CLICK SAFETY ================= */

button,
textarea,
input {
  pointer-events: auto !important;
  position: relative;
  z-index: 100;
}

.chat-page::before,
.chat-page::after,
.chat-app::before,
.chat-app::after,
.chat-main::before,
.chat-main::after {
  pointer-events: none !important;
}
/* ================= SIDEBAR OVERFLOW FIX ================= */

/* Make sidebar a vertical layout */
.chat-sidebar {
  display: flex;
  flex-direction: column;
}

/* Inner container fills height */
.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Top section scrolls */
.sidebar-top {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 12px;
}

/* Bottom section pinned */
.sidebar-bottom {
  flex-shrink: 0;
  padding: 10px;
  background: linear-gradient(180deg, #120025, #080012);
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* Prevent scrollbars from overlapping buttons */
.sidebar-top::-webkit-scrollbar {
  width: 6px;
}
.sidebar-top::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 6px;
}
