:root{
  --bg: #f6f8ff;
  --card: #ffffffc3;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4386f2;
  --primary-weak: rgba(67,134,242,.12);
  --ai: #eef4ffe6;
  --user: #e9fbef;
  --border: #e2e8f0;
  --shadow: 0 8px 24px rgba(15,23,42,.08);
  --radius: 16px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(
    to bottom right,
    #4386f2 0%,     /* dark blue (top-left) */
    #9f7cff 40%,    /* dark purple (top-right) */
    #87affe 70%,    /* light blue (bottom-left) */
    #ca9cfb 100%    /* light purple (bottom-right) */
  );

}

.bettrai-page { display: grid; grid-template-rows: auto 1fr; min-height: 100dvh; }

.ai-header{
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(0deg, rgba(255,255,255,.8), rgba(255,255,255,.8)), var(--bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.ai-title{ display: flex; gap: 10px; align-items: center; }
.ai-title h1{ font-size: 18px; margin: 0;}
.ai-logo{ font-size: 20px; }

.ai-tools .btn{ margin-left: 8px; }

.chat-shell{
  max-width: 980px;
  margin: 0 auto;
  width: 100%;
  padding: 10px 14px 35px;

  /* NEW */
  height: calc(100dvh - 140px); 
  display: flex;
  flex-direction: column;
}


.chat-log{
  display: flex; flex-direction: column; gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-height: 52dvh;
  max-height: 70dvh;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.notice{
  align-self: center;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px dashed var(--border);
  margin: 6px 0 12px;
}

.msg{
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: flex-start;
}
.msg .avatar{
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 16px; color: var(--text);
  border: 1px solid var(--border);
  background: #fff;
}
.msg .bubble{
  position: relative;
  max-width: min(680px, 100%);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  word-wrap: break-word;
  line-height: 1.45;
  background: #ffffff;
}
.msg .meta{
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.msg.ai .bubble{ background: var(--ai); }
.msg.user{
  grid-template-columns: 1fr 36px;
}
.msg.user .bubble{
  justify-self: end;
  background: var(--user);
}
.msg.user .avatar{ order: 2; }

.actions{
  display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap;
}
.action-btn{
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
.action-btn:hover{ background: var(--primary-weak); border-color: var(--primary); }

.typing{
  display: inline-flex; gap: 6px; align-items: center;
  padding: 8px 12px; border-radius: 999px; background: var(--ai);
  border: 1px solid var(--border);
}
.dot{
  width: 6px; height: 6px; border-radius: 50%; background: #94a3b8;
  animation: bounce 1.2s infinite ease-in-out;
}
.dot:nth-child(2){ animation-delay: .15s; }
.dot:nth-child(3){ animation-delay: .3s; }

@keyframes bounce{
  0%,80%,100%{ transform: translateY(0); opacity: .6; }
  40%{ transform: translateY(-4px); opacity: 1; }
}

.composer {
  display: flex;
  align-items: flex-start;  /* align top edge of input + buttons */
  gap: 12px;
  margin-top: 14px;
}

#chat-input {
  width: 100%;
  min-height: 44px;
  max-height: 72px; /* ~3 rows */
  overflow-y: auto;
  resize: none;
  padding: 12px 16px;
  font-size: 1rem;
  color: #ffffff;
  border-radius: 14px;

  background: rgba(243, 248, 254, 0.573);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  transition: all 0.2s ease;
}

#chat-input:focus {
  background: rgba(255, 255, 255, 0.18);
  outline: none;
  border-color: rgba(91, 157, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(91, 157, 255, 0.25);
}


#chat-input:focus {
  outline: none;
  border-color: rgba(0, 186, 255, 0.7);
  box-shadow: 0 0 0 2px rgba(0, 186, 255, 0.25);
  background: rgba(255, 255, 255, 0.15);
}

.composer-actions{ display: flex; gap: 8px; align-items: center; }

.btn{
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; cursor: pointer;
}
.btn.primary {
  background: linear-gradient(to right, #4386f2, #65baff);
  color: white;
  box-shadow: 0 6px 20px rgba(67, 134, 242, 0.3);
}

.btn.primary:hover {
  background: linear-gradient(to right, #5ca4f5, #7dd5ff);
  transform: translateY(-1px);
}

.btn.primary:active {
  transform: scale(0.96);
}

.btn.ghost{ background: transparent; }
.btn:disabled{ opacity: .6; cursor: not-allowed; }

/* Focus Mode */
body.focus-mode .chat-log{ background: transparent; border-color: transparent; box-shadow: none; }
body.focus-mode .msg:not(.focused){ opacity: .25; filter: blur(0.2px); }
body.focus-mode .msg.focused .bubble{
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 12px 30px rgba(67,134,242,.15);
  max-width: min(900px, 92vw);
}
body.focus-mode .msg.focused{ transform: translateZ(0); }

/* Code blocks (basic) */
pre{
  background: #0f172a; color: #e2e8f0;
  border-radius: 10px; padding: 12px; overflow: auto;
  border: 1px solid #0b1220;
}

/* Mobile */
@media (max-width: 720px){
  .chat-log{ max-height: none; min-height: 54dvh; }
  .msg .bubble{ max-width: 92vw; }
  .ai-header{ padding: 12px; }
}


/* --- Centered BettrAI title above chat --- */
.bettrai-title-box {
  text-align: center;
  margin-top: 8px;
  margin-bottom: -25px;
}

.bettrai-title {
  font-size: 2.8rem;
  font-weight: 700;
  color: #c7deffda;
  letter-spacing: 1px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.15);
}


/* --- Focus Mode button inside chat shell --- */
.chat-header-tools {
  display: flex;
  justify-content: flex-end;
  padding: 8px 0;
}



.chat-focus-toggle {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 10;
}

.chat-log {
  flex: 1;                    /* TAKE ALL REMAINING SPACE */
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px;

  overflow-y: auto;
  scroll-behavior: smooth;

  background: rgba(243, 248, 254, 0.573);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
}


/* Chat Sidebar */

/* Chat Sidebar */
.chat-sidebar {
  position: fixed;
  top: 50px; /* below top bar */
  left: 0;
  width: 280px;
  height: calc(100vh - 50px);
  padding: 1.2rem 1.4rem;
  overflow-y: auto;
  z-index: 1000;

  /* Modern glass style */
  background: rgba(240, 245, 255, 0.15);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    6px 0 30px rgba(0, 0, 0, 0.15),
    inset 0 0 1px rgba(255, 255, 255, 0.12);

  border-top-right-radius: 16px;
  border-bottom-right-radius: 16px;

  /* Light entrance animation */
  opacity: 1;
  transform: translateX(0);
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: auto;
}

.chat-sidebar.hidden {
  opacity: 0;
  transform: translateX(-25px); /* slight slide left */
  pointer-events: none;
}




.chat-sidebar.hidden {
  transform: translateX(-100%);
}

/* Sidebar Toggle Button */
.sidebar-toggle {
  position: fixed;
  top: 58px;
  left: 14px;
  z-index: 1100;
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 8px 12px;
  height: 38px;
  font-size: 1.1rem;
  color: #333;
  cursor: pointer;
  border-radius: 10px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.1),
    inset 0 1px 2px rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px) saturate(180%);
  transition: background 0.2s ease, transform 0.2s ease;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: scale(1.05);
}



/* Sidebar Header */
.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: flex-start;
  padding-left: 59px;
  margin-top: -10px;  /* ← Adjust this as needed */
}



.sidebar-header h3 {
  font-size: 1.1rem;
  color: #eaf2ff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.15);
  margin-top: 0.5rem;
}

.sidebar-history {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}



/* History Item */
.history-entry {
  padding: 10px;
  background: #f1f5ff76;
  border: 1px solid #008cff63;
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  color: #232425;
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* smoother + more properties animated */
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.12s ease;

  /* gives a touch-friendly hit area feel */
  will-change: transform, box-shadow, background;
}
  


.history-entry:hover {
  /* slightly darker + mild lift */
  background: rgba(228, 235, 255, 0.70);
  border-color: rgba(205, 216, 255, 0.85);
  transform: translateY(-1px) scale(1.01);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.10);
}


#new-chat-btn {
  height: 38px;
  padding: 8px 14px;
  font-size: 0.92rem;
  font-weight: 500;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 10px;
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.15),
    inset 0 1px 2px rgba(255, 255, 255, 0.2);

  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

#new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.05);
}

#new-chat-btn:active {
  transform: scale(0.95);
}


.btn {
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}


@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg {
  animation: fadeInUp 0.25s ease both;
}


.history-entry.active {
  border-color: rgba(0, 186, 255, 0.6);
  background: rgba(255, 255, 255, 0.766);
  box-shadow: inset 0 0 0 1px rgba(0, 186, 255, 0.35);
}

.history-entry:active {
  transform: translateY(0) scale(0.99);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.10);
  background: rgba(224, 234, 248, 0.841);

}

/* Keyboard accessibility (if you later add tabindex/role via JS/HTML) */
.history-entry:focus-visible {
  outline: 2px solid rgba(0, 186, 255, 0.65);
  outline-offset: 2px;

}

/* Optional: nicer thin scrollbar for sidebar history */
.sidebar-history {
  scrollbar-width: thin;
  scrollbar-color: rgba(205, 216, 255, 0.36) transparent;
}
.sidebar-history::-webkit-scrollbar {
  width: 5px;
}
.sidebar-history::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-history::-webkit-scrollbar-thumb {
  background: rgba(205, 216, 255, 0.437);
  border-radius: 8px;
}
.sidebar-history::-webkit-scrollbar-thumb:hover {
  background: rgba(205, 216, 255, 0.566);
}


.popup-alert {
  position: fixed;
top: 70px;
  right: 20px;
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 500;
  color: #ffffffde;
  z-index: 9999;
  border-radius: 14px;

  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  box-shadow:
    0 8px 30px rgba(0, 0, 0, 0.25),
    inset 0 1px 2px rgba(255, 255, 255, 0.2);

  border: 1px solid rgba(255, 255, 255, 0.28);
  display: none;
  animation: fadeInOut 3s ease forwards;
}

.popup-alert i {
  margin-right: 10px;
  color: #00c46a;
}

.fade-in {
  animation: fadeInOut 3s ease forwards;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(-10px); }
  10% { opacity: 1; transform: translateY(0); }
  90% { opacity: 1; }
  100% { opacity: 0; }
}


#chat-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
}



/* Inside each chat history entry, trash/delete button */
.history-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px; /* slight spacing between title and icon */
}

/* Text (title) inside the entry */
.history-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Delete icon button */
.history-delete-btn {
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.2s ease, background 0.2s ease, transform 0.1s ease;
}

/* On hover: red icon + faint background */
.history-delete-btn:hover {
  color: #6b38d9; 
  background: rgba(229, 62, 62, 0.1);
  transform: scale(1.1);
}

/* On click/tap */
.history-delete-btn:active {
  transform: scale(0.95);
}


.ai-char-counter {
  font-size: 0.9rem;
  text-align: right;
  margin-top: 4px;
  margin-right: 8px;
  color: #bebebe;
}


@media (max-width: 720px) {
  .chat-sidebar {
    height: calc(100vh - 190px); /* 50px top bar + ~70px floating nav */
  }
}
