/* Minimal, clean chat layout */

:root {
  --bg: #0b0c10;
  --panel: #111318;
  --text: #e6e6e6;
  --muted: #9aa0a6;
  --bubble-you: #8a95a9;
  --bubble-other: #262a33;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  overflow: hidden; /* Prevent body scrolling */
}

#app.container {
  max-width: none;
  width: 100vw;
  height: 100dvh;
  padding: 0;
  display: grid;
  grid-template-columns: 280px 1fr; /* Sidebar and main content */
  gap: 0;
}

/* --- Auth (Login) Layout --- */
#auth.container.auth-container {
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100dvh;
  padding: 24px;
}

.auth-brand {
  text-align: center;
  margin-bottom: 24px;
}
.auth-brand .brand-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.auth-brand .brand-subtitle {
  font-size: 14px;
  color: var(--muted);
  margin-top: 6px;
}

.auth-status {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
}

.auth-form {
  width: 100%;
  max-width: 420px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.auth-form input {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #1b1f2a;
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
}

.auth-form button {
  background: var(--bubble-you);
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
}

.auth-form button.secondary-btn {
  background: var(--bubble-other);
  color: var(--text);
  border: 1px solid #1b1f2a;
}

.auth-error {
  color: #ff6b6b;
  font-size: 12px;
  margin-top: 8px;
  text-align: center;
}

#sidebar {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  padding: 16px;
  border-right: 1px solid #1b1f2a;
}

.thread-list {
  flex-grow: 1;
  overflow-y: auto;
  margin-top: 16px;
}

.thread-item {
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: background 0.2s;
}

.thread-item:hover {
  background: #1a1f2a;
}

.thread-item.active {
  background: var(--bubble-you);
  color: white;
}

.new-chat-button {
  background: var(--bubble-you);
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
}

#chat-container {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 16px;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
#chat-container .topbar h2 {
  text-align: center;
  flex-grow: 1;
}
#authStatus, #appStatus { color: var(--muted); font-size: 12px; }

/* Budget indicator styles */
.budget-indicator {
  display: flex;
  gap: 6px;
  align-items: center;
}
.budget-circle {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid currentColor;
}
.budget-circle.filled { background-color: currentColor; }
.budget-circle.hollow { background-color: transparent; }
.budget-circle.red { color: #ead0d1; }
.budget-circle.redCritical { color: #ff6b6b; }
.budget-circle.yellow { color: #faead3; }
.budget-circle.green { color: #b5c4b1; }
.budget-circle.white { color: #ffffff; }

#close-sidebar-button {
  display: none; /* Hidden by default */
}

/* Remove old nav styles */
.chat-nav { display: none; }

.sender {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  cursor: pointer;
}
.sender:hover {
  color: var(--bubble-you);
}

.messages {
  background: var(--panel);
  border-radius: 12px;
  padding: 12px;
  overflow-y: auto;
  /* Let the container control the height */
}

.msg {
  display: flex;
  margin: 8px 0;
  flex-wrap: wrap; /* allow timestamp/gift to sit above/below bubble */
}
.msg.you { justify-content: flex-end; }
.msg .bubble {
  max-width: 80%;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.3;
}
.msg.you .bubble {
  background: var(--bubble-you);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg.vea .bubble, .msg.other .bubble {
  background: var(--bubble-other);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.text { white-space: pre-wrap; word-wrap: break-word; }

/* Timestamp and gift meta styles */
.bubble .meta {
  font-size: 11px;
  color: var(--muted);
}
.meta.meta-top { /* now outside the bubble */
  margin: 0 4px 4px 4px;
  font-size: 11px;
  color: var(--muted);
}
.msg > .meta.meta-top, .msg > .meta.meta-gift { flex-basis: 100%; }
.msg.you > .meta.meta-top { text-align: right; }
.msg.vea > .meta.meta-top, .msg.other > .meta.meta-top { text-align: left; }
.bubble .meta-bottom { margin-top: 6px; }

/* Gift label below bubble (user only) */
.meta.meta-gift {
  margin: 6px 4px 0 4px;
  font-size: 11px;
  color: var(--muted);
}
.msg.you > .meta.meta-gift { text-align: right; }

/* Gifted messages from you turn bubble orange (match super send) */
.msg.you .bubble.gifted {
  background: #d89c7a;
  color: #fff;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  position: relative; /* For positioning the bubble */
}
.composer input, .composer textarea {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #1b1f2a;
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
}
.composer textarea {
  resize: vertical;
  min-height: 44px;
  max-height: 200px;
}
.composer button {
  background: var(--bubble-you);
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 600;
  cursor: pointer; /* Ensure cursor is a pointer */
  transition: background-color 0.2s; /* Smooth transition */
}
.composer button:disabled { opacity: 0.6; }

/* Super Send styles */
.composer button.super-send-active {
  background-color: #d89c7a; /* Orange color for super send */
}

.super-send-bubble {
  position: absolute;
  bottom: 100%; /* Position above the composer */
  right: 0;
  margin-bottom: 10px; /* Space between bubble and input */
  background-color: var(--panel);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  border: 1px solid #1b1f2a;
  z-index: 10;
}

.super-send-option {
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
  font-weight: 500;
  text-align: center;
}

.super-send-option:hover {
  background-color: var(--bubble-you);
  color: white;
}


/* Modal Styles */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--panel);
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  border: 1px solid #1b1f2a;
}

.modal-content h2 {
  margin-top: 0;
}

.vea-selection-list {
  margin-top: 16px;
  max-height: 200px;
  overflow-y: auto;
}

.vea-selection-item {
  display: block;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: background 0.2s;
}

.vea-selection-item:hover {
  background: #1a1f2a;
}

.modal-actions {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.modal-actions button {
  background: var(--bubble-other);
  color: var(--text);
  border: 1px solid #1b1f2a;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}

.modal-actions button#create-thread-btn {
  background: var(--bubble-you);
  color: white;
  border: none;
}

.form-group {
  margin-top: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
}

.form-group select,
.form-group input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid #1b1f2a;
  border-radius: 8px;
  padding: 10px;
  font-size: 16px;
}

#menu-button {
  display: none; /* Hidden by default on desktop */
}

@media (max-width: 768px) {
  #app.container {
    grid-template-columns: 1fr; /* Single column layout */
  }

  #sidebar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    box-shadow: 2px 0 5px rgba(0,0,0,0.5);
  }

  #sidebar.sidebar-visible {
    transform: translateX(0);
  }
  
  #menu-button {
    display: block; /* Show menu button on mobile */
    background: none;
    border: none;
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
  }

  #close-sidebar-button {
    display: block; /* Show on mobile */
    background: none;
    border: none;
    color: var(--text);
    font-size: 28px;
    cursor: pointer;
  }

  #chat-container {
    width: 100%;
    padding: 4px;
    gap: 8px;
  }
}
