/* Reset & Base */
body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #0b1120;
  color: #ffffff;
}

.container {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  background-color: #1b1f2a;
  width: 25%;
  min-width: 250px;
  max-width: 320px;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.brand {
  font-size: 1.65em;
  font-weight: 900;
  margin-bottom: 20px;
  background: linear-gradient(90deg, #00d2d3 0%, #1a8ae6 55%, #1e5ee7 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}

.brand span {
  font-weight: bold;
}

.btn-primary {
  background-color: #00d2d3;
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 20px;
  cursor: pointer;
  transition: outline 0.3s;
  font-weight: 600;
}

.btn-primary:hover {
  outline: 2px solid #00d2d3;
  background-color: transparent;
  color: #00d2d3;
}

.chat-list {
  flex-grow: 1;
  overflow-y: auto;
  margin-bottom: 14px;
}

.chat-item {
  background-color: #2e3440;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.3s, outline 0.3s;
  position: relative;
  min-height: 44px;
}

.chat-item:hover {
  background-color: #3b4252;
  outline: 1px solid #00d2d3;
}

.chat-item.active {
  background-color: #3b4252;
  outline: 2px solid #00d2d3;
}

.chat-title {
  font-size: 1.09em;
  font-weight: 500;
  letter-spacing: -0.3px;
  color: #e2f4fa;
}

.delete-btn {
  cursor: pointer;
  color: #d9534f;
  margin-left: 8px;
}

.model-selector {
  margin-top: 20px;
  font-size: 0.97em;
}

.uses-left {
  margin-top: 10px;
  font-size: 0.98em;
  color: #ccc;
}

.back-link {
  margin-top: auto;
  color: #00d2d3;
  text-decoration: none;
  font-size: 0.98em;
}

.back-link:hover {
  text-decoration: underline;
}

/* Main Chat Area */
.main {
  background-color: #0b1120;
  width: 75%;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 48px 0 0 0;
  min-height: 100vh;
  box-sizing: border-box;
}

.header h1 {
  margin: 0 0 22px 0;
  font-size: 1.54em;
  font-weight: bold;
  letter-spacing: -0.5px;
  color: #c6d7e6;
  text-align: center;
}

.chat-box {
  background: #191c28;
  border-radius: 32px;
  max-width: 960px;
  min-width: 520px;
  margin: 0 auto 18px auto;
  padding: 56px 56px 44px 56px;
  box-shadow: 0 8px 36px rgba(0,0,0,0.14);
  min-height: 470px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: background 0.18s;
  border: 1.7px solid #222941;
  overflow-y: auto;
}

.input-area {
  display: flex;
  align-items: center;
  justify-content: stretch;
  margin: 34px auto 0 auto;
  max-width: 960px;
  width: 100%;
  padding-bottom: 42px;
  gap: 12px;
}

.btn-gradient {
  background: linear-gradient(90deg, #00d2d3, #2e8bff);
  color: #000;
  border: none;
  border-radius: 22px;
  padding: 10px 26px;
  cursor: pointer;
  font-size: 1.08em;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(46,139,255,0.05);
  transition: background 0.16s, color 0.16s;
  white-space: nowrap;
}

.btn-gradient:hover {
  background: linear-gradient(90deg, #2e8bff 30%, #00d2d3 100%);
  color: #fff;
}

#userInput {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 18px;
  border-radius: 18px;
  border: 1.7px solid #222941;
  overflow-y: auto;
  outline: none;
  font-size: 1.07em;
  background-color: #232943;
  color: #fff;
  font-family: inherit;
  box-shadow: 0 1px 7px rgba(0,35,120,0.04);
  transition: border 0.16s;
  resize: none;
}

#userInput:focus {
  border: 1.7px solid #00d2d3;
}

#userInput::placeholder {
  color: #a7b4c3;
}

textarea#userInput::-webkit-resizer {
  display: none;
}

/* Edit functionality */
.message.editing {
  border-radius: 9px;
  background: #232943;
  box-shadow: 0 2px 14px rgba(32,150,255,0.06);
  outline: 1.8px solid #00d2d3;
  padding: 8px 12px;
}

.edit-input {
  font-size: 1.03em;
  border-radius: 6px;
  border: 1.8px solid #00d2d3;
  background: #222941;
  color: #fff;
  width: 100%;
  margin-right: 10px;
  padding: 8px 12px;
  outline: none;
  font-family: inherit;
  box-shadow: 0 1px 6px rgba(0,35,120,0.04);
}

.edit-controls {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: 8px;
  margin-top: 8px;
}

.edited-badge {
  background: #252940;
  color: #8ad5c7;
  font-size: 0.91em;
  border-radius: 6px;
  padding: 2px 10px;
  margin-left: 13px;
  opacity: 0.75;
  font-style: italic;
  font-weight: 400;
}

/* Three-dots chat menu for sidebar */
.chat-menu-btn {
  cursor: pointer;
  margin-left: 10px;
  font-size: 1.23em;
  color: #bbb;
  user-select: none;
  transition: color 0.2s;
  vertical-align: middle;
  display: none;
}

.chat-item:hover .chat-menu-btn {
  display: inline;
  color: #fff;
}

.chat-dropdown-menu {
  position: absolute;
  left: 40px;
  top: 32px;
  background: #18191c;
  color: #fff;
  border-radius: 8px;
  min-width: 70px;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.19);
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}

.dropdown-option {
  padding: 7px 16px;
  cursor: pointer;
  font-size: 1em;
  text-align: left;
  white-space: nowrap;
  transition: background 0.13s;
}

.dropdown-option:hover {
  background: #25282e;
}

.chat-title-input {
  background: #232943;
  border: 1px solid #00d2d3;
  color: #fff;
  font-size: 1em;
  padding: 4px 8px;
  border-radius: 4px;
  outline: none;
  width: 100%;
}

.save-btn, .cancel-btn {
  background: #00d2d3;
  border: none;
  color: #000;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 4px;
  font-size: 0.9em;
}

.cancel-btn {
  background: #e74c3c;
  color: #fff;
}

/* Responsive Design */
@media (max-width: 1100px) {
  .main, .chat-box { max-width: 99vw; }
  .chat-box { 
    padding: 22px 3vw 22px 3vw; 
    min-width: 0; 
  }
}

@media (max-width: 700px) {
  .container {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 15px;
  }
  
  .main {
    width: 100%;
    max-width: none;
    padding: 20px 0 0 0;
  }
  
  .chat-box {
    max-width: 100vw;
    min-width: 0;
    padding: 20px 15px;
    margin: 0 10px 18px 10px;
    border-radius: 16px;
  }
  
  .input-area {
    flex-direction: column;
    gap: 10px;
    padding-bottom: 20px;
    margin: 20px 10px 0 10px;
    max-width: none;
  }
  
  .btn-gradient { 
    width: 100%; 
  }
}

/* Chat Message UI - ULTRA COMPACT (FINAL DEFINITIONS) */
.message {
  display: flex;
  align-items: flex-start;
  width: 100%;
  margin-bottom: 4px !important;
  gap: 8px;
  position: relative;
  padding: 2px 0;
}

.message .label {
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 1.1em;
  line-height: 1.2;
  min-width: 120px;
  margin: 0;
}

.message.user .label {
  color: #8fd7fa;
}

.message.ai .label {
  color: #c5a5ff;
}

.message .text {
  color: #f8f8f8;
  font-weight: 400;
  word-break: break-word;
  font-size: 1.1em;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
  /* white-space: pre-line; */
  margin: 0 !important;
  padding: 0;
}

/* Remove extra spacing from paragraphs in markdown */
.message .text p {
  margin: 0 0 4px 0 !important;
}

.message .text p:last-child {
  margin-bottom: 0 !important;
}

/* Chat markdown: Headings, lists, bold, blockquotes, tables, etc. */
.message h1, .message h2, .message h3 {
  color: #fff;
  font-weight: bold;
  margin: 8px 0 4px 0 !important;
  line-height: 1.2;
}

.message h1 { font-size: 1.5em; }
.message h2 { font-size: 1.3em; }
.message h3 { font-size: 1.13em; }

.message ul, .message ol {
  margin: 4px 0 4px 24px !important;
  padding-left: 18px;
}

.message li {
  margin-bottom: 2px !important;
  line-height: 1.3;
}

.message strong, .message b {
  color: inherit;
  font-weight: bold;
}

/* 1. Italic white for <em> and <i> */
.message em, .message i {
  color: #fff !important;
  font-style: italic;
  font-weight: 400;
}

/* 2. Numbered list items (ol) bold white */
.message ol > li {
  color: #fff;
  font-weight: bold;
}

.message ol {
  list-style-type: decimal;
  counter-reset: item;
}

.message ol li {
  display: list-item;
  text-align: left;
  margin-left: 0;
}

/* FIXED TABLE STYLES - Default tables with white background and dark text */
.message table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  background: #fff !important;
}

.message th, .message td {
  border: 1px solid #e2e2e2;
  padding: 8px 13px;
  text-align: left;
}

.message td {
  background: #fff !important;
  color: #1d2939 !important;
}

.message th {
  background: #f2f6fc !important;
  font-weight: 700;
  color: #23539d !important;
}

.message pre, .message code {
  background: #242834;
  color: #f7f7f7;
  font-size: 0.96em;
  padding: 6px 12px;
  border-radius: 7px;
  margin: 6px 0;
  font-family: 'JetBrains Mono', 'Fira Mono', 'Consolas', monospace;
  overflow-x: auto;
  display: block;
}

/* Make links obvious */
.message a {
  color: #2185d5;
  text-decoration: underline;
  word-break: break-all;
}

/* BuildScaleAI specific heading spacing */
.message.BuildScaleAI h1, 
.message.BuildScaleAI h2, 
.message.BuildScaleAI h3 {
  color: #2692ff !important;
  background: none !important;
  font-weight: 800;
  margin: 8px 0 4px 0 !important;
  line-height: 1.2;
}

/* Links: bright blue */
.message.BuildScaleAI a {
  color: #2097f3 !important;
  text-decoration: underline;
  font-weight: 600;
}

/* Blockquotes: light blue left border */


/* ENHANCED BuildScaleAI TABLE STYLES - Ensure proper colors */
.message.BuildScaleAI table {
  background: #fff !important;
  border: 1px solid #e2e2e2 !important;
  border-collapse: collapse;
}

.message.BuildScaleAI td {
  color: #1d2939 !important;
  background: #fff !important;
  font-weight: 500;
  border: 1px solid #e2e2e2 !important;
}

.message.BuildScaleAI th {
  background: #005099 !important;
  color: #fff !important;
  border: 1px solid #e2e2e2 !important;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.message.BuildScaleAI tr:hover td {
  background: #f2f8fc !important;
}

/* Edit button positioning */
.edit-message-btn {
  display: none;
  margin-left: 16px;
  background: #33394c;
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 4px 10px;
  cursor: pointer;
  align-self: flex-start;
  font-size: 0.9em;
  transition: background 0.2s;
}

.edit-message-btn:hover {
  background: #19c5be;
}

.message.user:hover .edit-message-btn {
  display: inline-block;
}

@media (max-width: 700px) {
  .edit-message-btn {
    margin-left: 0;
    margin-top: 8px;
  }
}

/* --- Pro Chat/Markdown Formatting: White Section Headers, Modern Spacing --- */

/* MAIN BODY TEXT */
.message, .message .text, .message p {
  font-size: 1.03em !important;
  font-weight: 400;
  color: #f8f8f8;
  line-height: 1.5 !important;
  margin: 0 0 16px 0 !important;
  padding: 0 !important;
}

/* SECTION HEADERS - Bold, White, Larger */
.message h1, .message h2, .message h3 {
  color: #fff !important;
  font-weight: 900 !important;
  font-size: 1.28em !important;
  margin: 40px 0 22px 0 !important; /* Big space above, nice space below */
  line-height: 1.22 !important;
  letter-spacing: -1px;
  padding: 0 !important;
}

/* Numbered Lists - Spacious and Aligned */
.message ol {
  margin: 0 0 0 32px !important;  /* List aligns with text but not flush left */
  padding-left: 0 !important;
  font-size: 1.03em !important;
  font-weight: 400 !important;
  color: #f8f8f8;
}

.message ol > li {
  margin-bottom: 32px !important;     /* Lots of space after each point! */
  line-height: 1.48 !important;
  font-size: 1.03em !important;
  font-weight: 400 !important;
  color: #f8f8f8;
  padding-left: 2px;
}

/* Bold Title inside List - Prominent, Block Style */
.message ol > li strong,
.message ol > li b {
  font-weight: 800 !important;
  font-size: 1.07em !important;
  color: #fff;
  display: block;
  margin-bottom: 9px;       /* Creates space between bold line and detail text */
}

/* List body after bold (if wrapped in <p> by markdown-it) */
.message ol > li p {
  margin: 0 0 0 0 !important;
  font-weight: 400 !important;
  font-size: 1.01em !important;
  color: #e2e6ea;
  line-height: 1.48 !important;
  display: block;
}

/* Bullet Lists - Keep Consistent */
.message ul {
  margin: 14px 0 20px 28px !important;
  padding-left: 0 !important;
}
.message ul > li {
  margin-bottom: 12px !important;
  line-height: 1.44 !important;
  font-size: 1.01em !important;
  font-weight: 400 !important;
  color: #f8f8f8;
}

/* Why it matters, etc: Italic, not larger */
.message em, .message i {
  color: #fff !important;
  font-style: italic;
  font-weight: 400;
}

/* Horizontal rule - More breathing room */
.message hr {
  margin: 32px 0 20px 0 !important;
  border: none;
  border-top: 2px solid #ececec;
}


/* ---- FINAL POLISH: HEADER & LIST SPACING ---- */

/* Section headers - big, white, and plenty of margin below! */
.message h1, .message h2, .message h3 {
  color: #fff !important;
  font-weight: 700 !important;
  font-size: 1.28em !important;
  margin: 44px 0 42px 0 !important; /* MASSIVE space below the header, before list starts */
  line-height: 1.22 !important;
  padding: 0 !important;
}

/* For very top-of-chat sections, add top margin to the first h1 (optional) */
.message .text h1:first-child,
.message .text h2:first-child,
.message .text h3:first-child {
  margin-top: 36px !important;
}

/* Numbered list and list items: keep spacing below points, but not too much above */
.message ol {
  margin: 0 0 0 32px !important;
  padding-left: 0 !important;
}

.message ol > li {
  margin-bottom: 32px !important;
  line-height: 1.48 !important;
  font-size: 1.03em !important;
  font-weight: 400 !important;
  color: #f8f8f8;
  padding-left: 2px;
}

/* Bold title in list item */
.message ol > li strong,
.message ol > li b {
  font-weight: 800 !important;
  font-size: 1.07em !important;
  color: #fff;
  display: block;
  margin-bottom: 9px;
}


.ai-helper-menu {
  position: absolute;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 4px 18px rgba(30,120,210,0.08);
  z-index: 100;
}
.ai-helper-menu button {
  display: block;
  width: 100%;
  background: linear-gradient(90deg,#2692ff 80%,#00d2d3 100%);
  color: #fff;
  border: none;
  border-radius: 7px;
  margin: 5px 0;
  padding: 7px 10px;
  cursor: pointer;
  font-weight: 700;
}
#ai-helper-btn {
  background: #2692ff;
  color: #fff;
  border-radius: 50%;
  border: none;
  font-size: 1.35em;
  width: 35px;
  height: 35px;
  margin-right: 10px;
  cursor: pointer;
  font-weight: 700;
  vertical-align: middle;
}


.ai-toast {
  position: fixed;
  bottom: 38px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg,#00d2d3 30%,#2692ff 90%);
  color: #fff;
  font-size: 1.18em;
  font-weight: 700;
  padding: 15px 30px;
  border-radius: 23px;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 10px 28px rgba(30,120,210,0.14);
  z-index: 1001;
  transition: opacity 0.28s;
}
.ai-toast.show { opacity: 1; }

/* === Chat layout fix (desktop) === */
@media (min-width: 900px){
  /* Use grid so both columns share full height */
  .container{
    display: grid !important;
    grid-template-columns: 280px minmax(0,1fr);
    column-gap: 24px;
    min-height: 100dvh !important;
    height: auto !important;
    align-items: start;
  }
  .sidebar{
    position: sticky; top: 0;
    height: 100dvh; overflow: auto;
  }
  .main{
    min-height: 100dvh;
    overflow: visible !important;
    max-width: 1120px;     /* a hair wider shell */
    margin: 0 auto;
    padding-top: 48px;
    padding-bottom: 96px;  /* buffer so you never see bottom seam */
  }
  .chat-box{
    max-width: 920px !important;
    margin: 0 auto 24px auto !important;
    padding: 48px 48px 40px !important;
  }
  /* input stays reachable but doesn’t overlap content */
  .input-area{ position: sticky; bottom: 0; }
}

/* === Chat layout: full-height sidebar + internal scroll in messages === */

/* Desktop layout with grid columns */
@media (min-width: 900px){
  .container{
    display: grid !important;
    grid-template-columns: 280px minmax(0,1fr);
    column-gap: 24px;
    min-height: 100dvh !important; /* dvh fixes iOS address-bar jumps */
    height: auto !important;
    align-items: start;
  }

  /* Sidebar always to the floor; scrolls independently if long */
  .sidebar{
    position: sticky; top: 0;
    height: 100dvh; overflow-y: auto;
  }

  /* Right column uses 3-row grid: header / messages / input */
  .main{
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100dvh;
    max-width: 1120px;   /* tune to your taste */
    margin: 0 auto;
    gap: 16px;
    padding-top: 24px;
    padding-bottom: 24px;
  }

  /* Your chat “card” keeps its style; just avoid nested scroll here */
  .chat-box{
    overflow: hidden;               /* the inner messages scroll */
    max-width: 920px;
    margin: 0 auto;
    padding: 48px 48px 40px;
    border-radius: 18px;            /* keep whatever you had */
  }

  /* The transcript becomes the scroll container */
  .messages{
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;  /* smooth iOS scroll */
    padding-right: 6px;                 /* avoid scrollbar overlay on text */
  }

  /* Keep the input reachable without covering content */
  .input-area{
    position: sticky; bottom: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    background: transparent; /* keep your look */
  }
}

/* Viewport fit for iPhone notch (safe to have on all pages) */
@media (max-width: 640px){
  .messages{ max-height: none; } /* mobile relies on page scroll */
}
