:root {
  /* Light mode variables */
  --accent: #3D6A9B;
  --accent-hov: #315A8B;
  --radius: 8px;
  --bg-body: #f2f2f5;
  --sidebar-bg: #ffffff;
  --main-bg: #f9f9f9;
  --chat-bg: #ffffff;
  --border-color: #d1d1d6;
  --text-color: #1c1c1e;
  --text-muted: #6e6e73;
  --primary: #3D6A9B;
  --primary-hov: #315A8B;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark mode variables */
    --accent: #3D6A9B;
    --accent-hov: #315A8B;
    --bg-body: #1c1c1e;
    --sidebar-bg: #2c2c2e;
    --main-bg: #121212;
    --chat-bg: #1e1e1f;
    --border-color: #38383a;
    --text-color: #f2f2f5;
    --text-muted: #8e8e93;
    --primary: #3D6A9B;
    --primary-hov: #315A8B;
  }
}

body {
  display: flex;
  font-family: 'Inter', sans-serif;
  margin: 0;
  height: 100vh;
  background: var(--bg-body);
  color: var(--text-color);
}

/* ----- sidebar ----- */
#sidebar {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  flex-shrink: 0;
  flex-grow: 0;
  background: var(--sidebar-bg);
  box-shadow: 2px 0 8px rgba(0,0,0,0.05);
  padding: 1.5rem;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

#sidebar h2 { 
  font-size:1.2rem;
  margin:0 0 0.5rem; 
}

#modelSelect, #clearBtn, #newChatBtn, #renameBtn, #deleteBtn {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
}

#modelSelect {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--chat-bg);
  color: var(--text-color);
}

#newChatBtn,
#clearBtn,
#renameBtn,
#deleteBtn {
  padding: 0.55rem;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

#newChatBtn:hover,
#clearBtn:hover,
#renameBtn:hover,
#deleteBtn:hover {
  background: var(--primary-hov);
}

#chatList{
  list-style:none;
  padding:0;
  margin:0;
  flex:1 1 auto;
  overflow-y:auto;
}

#chatList li{
  padding:0.4rem 0.5rem;
  border-radius:var(--radius);
  cursor:pointer;
  user-select:none;
}

#chatList li:hover{ 
  background: var(--main-bg); 
}

#chatList li.active {
  font-weight: bold;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
}

/* ----- main chat area ----- */
#main {
  flex: 1 1 auto;
  background: var(--main-bg);
  padding: 1.5rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background 0.2s;
}

#log {
  background: var(--chat-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-y: auto;
  padding-bottom: 4rem;
  flex: 1 1 auto;
}

.user, .assistant {
  padding: 0.75rem;
  border-radius: var(--radius);
  max-width: 70%;
  margin: 0.5rem 0;
  color: var(--text-color);
}

.user {
  background: rgba(10, 132, 255, 0.1);
  margin-left: auto;
}

.assistant {
  background: rgba(142, 142, 147, 0.1);
  margin-right: auto;
}

/* ----- form ----- */
#form {
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: var(--chat-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-top: 1rem;
}

#input {
  flex: 1 1 auto;
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--chat-bg);
  color: var(--text-color);
  resize: none;
  overflow: hidden;
  line-height: 1.4;
  min-height: calc(1.4em * 1);
  max-height: calc(1.4em * 15);
  font-family: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
  font-size: 1rem;
}

.btn:hover {
  background: var(--primary-hov);
}

#form button[type="submit"]:hover {
  background: var(--primary-hov);
}

/* ----- file upload and previews ----- */
#imageInput, #textInput { 
  display:none; 
}

img.chat-preview {
  max-width: 150px;
  max-height: 150px;
  border-radius: var(--radius);
  margin: 0.5rem 0;
  border: 1px solid var(--border-color);
  background: var(--chat-bg);
}

.chat-images img.chat-preview{
  max-width: 160px;
  max-height: 120px;
}

#image-container, #text-files-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
}

/* Image preview container styles */
.image-preview-container {
  position: relative;
  display: inline-block;
}

.image-preview-container:hover .image-remove-btn {
  opacity: 1;
}

.image-remove-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: all 0.2s ease;
}

.image-remove-btn:hover {
  background: #ff4444 !important;
  opacity: 1;
}

/* Text file preview styles */
.text-file-preview {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: var(--chat-bg);
  max-width: 300px;
  position: relative;
}

.text-file-preview .file-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-weight: bold;
  font-size: 0.9rem;
}

.text-file-preview .file-name {
  color: var(--primary);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  flex: 1;
}

.text-file-preview .file-size {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-left: 0.5rem;
}

.text-file-preview .remove-btn {
  background: var(--text-muted);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.5rem;
  transition: background 0.2s ease;
}

.text-file-preview .remove-btn:hover {
  background: #ff4444;
}

.text-file-preview .file-content {
  background: var(--main-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.5rem;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.8rem;
  max-height: 100px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text-color);
}

/* ---------- Mobile tweaks ---------- */
@media (max-width: 600px) {
/* ---------- Drag and drop highlight ---------- */
#main.drag-over {
  outline: 4px dashed var(--primary);
  outline-offset: -4px;
  cursor: copy;
}
  body { 
    flex-direction: column; 
  }
  
  #sidebar {
    width: 100%; 
    min-width: 0; 
    max-width: none; 
    flex-direction: row;
    gap:0.5rem; 
    overflow-x:auto; 
    border-right:none; 
    border-bottom:1px solid var(--border-color);
    padding: 0.75rem 1rem;
  }
  
  #sidebar h2 { 
    display:none; 
  }
  
  #modelSelect, #newChatBtn, #clearBtn, #renameBtn, #deleteBtn { 
    flex: 0 0 auto; 
  }
  
  #chatList { 
    display:none; 
  }
  
  #main { 
    padding: 1rem; 
  }
  
  .user,.assistant{ 
    max-width:100%; 
  }
}

/* ----- copy button style ----- */
pre { 
  position: relative; 
}

.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

pre:hover .copy-btn { 
  opacity: 1; 
}

/* Spinner */
.spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid var(--border-color);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.spinner.hidden {
  display: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ----- sidebar card for Web Search ----- */
.sidebar-card {
  background: var(--chat-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.75rem;
}
.sidebar-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}
.sidebar-card-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
}
/* Web Search options within card */
#webSearchOptions {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
}
#webSearchOptions:not([hidden]) {
  display: flex;
}
#webSearchOptions label {
  font-size: 0.9rem;
}
#webSearchOptions select {
  width: 100%;
  padding: 0.45rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--chat-bg);
  color: var(--text-color);
  font-family: inherit;
}
