/* =================== */
/*     GLOBAL STYLES   */
/* =================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: Arial, sans-serif;
  transition: background-color 0.3s, color 0.3s;
}

/* Light & Dark Mode Variables */
body.light-mode {
  --bg-color: #f0f0f0;
  --text-color: #333;
  --sidebar-bg: #ffffff;
  --sidebar-border: #ccc;
  --chat-bg: #ffffff;
  --chat-text: #000000;
  --accent-color: #3b82f6;
  --code-panel-bg: #f2f2f2;
  --input-bg: #f7f7f7;
  --input-text: #111111;
  --control-bg: #e5e5e5;
}

body.dark-mode {
  --bg-color: #1f1f1f;
  --text-color: #f9fafb;
  --sidebar-bg: #2a2a2a;
  --sidebar-border: #3b82f6;
  --chat-bg: #18181b;
  --chat-text: #f3f4f6;
  --accent-color: #3b82f6;
  --code-panel-bg: #1e1e1e;
  --input-bg: #333333;
  --input-text: #ffffff;
  --control-bg: #111111;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* =================== */
/*     APP LAYOUT      */
/* =================== */
.app-container {
  display: flex;
  flex: 1;
  height: 100%;
}

/* =================== */
/*     SIDEBAR         */
/* =================== */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  border-right: 2px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 10px;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sidebar-btn {
  background: var(--accent-color);
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.sidebar-btn:hover {
  opacity: 0.9;
}

.session-list {
  list-style: none;
  margin-bottom: 10px;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px;
  border-radius: 4px;
  margin-bottom: 4px;
  cursor: pointer;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.session-title {
  flex: 1;
  margin-right: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-delete-btn,
.session-edit-btn {
  background: none;
  border: none;
  color: #ff6666;
  cursor: pointer;
  font-size: 16px;
  margin-left: 4px;
}

.sidebar-label {
  margin-top: 8px;
  display: block;
  font-weight: bold;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.sidebar-select {
  width: 100%;
  padding: 6px;
  border-radius: 4px;
  border: 1px solid #999;
  margin-bottom: 8px;
  background-color: var(--chat-bg);
  color: var(--chat-text);
}

/* Theme Toggle */
.switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 0.9rem;
  cursor: pointer;
}

.switch-label input[type="checkbox"] {
  cursor: pointer;
}

/* Divider */
.divider {
  border: none;
  border-bottom: 1px solid var(--sidebar-border);
  margin: 10px 0;
}

/* =================== */
/*     CHAT LAYOUT     */
/* =================== */
.chat-layout {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  background: var(--chat-bg);
  color: var(--chat-text);
}

/* Chat Box */
.chat-box {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Chat Input */
.chat-input-container {
  display: flex;
  padding: 10px;
  background: var(--input-bg);
}

#chat-input {
  flex-grow: 1;
  background: var(--input-bg);
  color: var(--input-text);
  border: none;
  border-radius: 4px;
  font-size: 14px;
  padding: 10px;
  resize: none;
  overflow-y: auto;
}

#send-button {
  margin-left: 10px;
  background: var(--accent-color);
  border: none;
  border-radius: 4px;
  color: #fff;
  padding: 8px 14px;
  cursor: pointer;
}

#send-button:disabled {
  background: #666;
  cursor: not-allowed;
}

/* Chat Controls */
.chat-controls {
  display: flex;
  justify-content: flex-end;
  padding: 8px;
  background: var(--control-bg);
  border-top: 1px solid #333;
}

.control-btn {
  background: var(--accent-color);
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  margin-left: 8px;
}

.control-btn:hover {
  opacity: 0.9;
}

/* Messages */
.message {
  max-width: 70%;
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: 8px;
  animation: fadeIn 0.3s ease;
  word-break: break-word;
}

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

.user-message {
  align-self: flex-end;
  background-color: #3b82f6;
  color: #fff;
}

.ai-message {
  align-self: flex-start;
  background-color: #374151;
  color: #e2e8f0;
}

/* Images within messages */
.message img {
  max-width: 100%;
  border-radius: 4px;
  margin-top: 8px;
}

/* =================== */
/*    SCREENSAVER      */
/* =================== */
.screensaver {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: black;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.screensaver img {
  max-width: 80%;
  max-height: 80%;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* Extended Screensaver Controls */
.screensaver-controls {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 80%;
  max-width: 500px;
  background: rgba(0,0,0,0.6);
  padding: 10px;
  border-radius: 8px;
}

.screensaver-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
}

.screensaver-settings label {
  font-size: 0.8rem;
  color: #fff;
  flex: 1 1 45%;
}

.screensaver-settings input,
.screensaver-settings select {
  width: 100%;
  padding: 4px;
  border-radius: 4px;
  border: 1px solid #999;
}

.screensaver-btn-group {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.screensaver-btn {
  background: rgba(59, 130, 246, 0.5);
  border: none;
  padding: 8px 12px;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
}

/* Hidden Utility */
.hidden {
  display: none !important;
}

/* =================== */
/*   DONATION MODAL    */
/* =================== */
.donation-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent-color);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 4px;
  cursor: pointer;
  z-index: 200;
}

.donation-modal {
  position: fixed;
  bottom: 80px;
  right: 20px;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  padding: 20px;
  border-radius: 8px;
  z-index: 300;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.donation-modal.hidden {
  display: none;
}

.donation-modal-header {
  display: flex;
  justify-content: flex-end;
}

.donation-modal-header .close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
}

.donation-modal-body {
  margin-top: 10px;
}

/* Code Block Styling */
.code-block-container {
  margin: 10px 0;
  background: var(--code-panel-bg);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #1e1e1e;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.code-language {
  font-size: 0.8rem;
  color: #aaa;
  text-transform: uppercase;
}

.copy-code-btn, 
.expand-code-btn {
  background: rgba(59, 130, 246, 0.3);
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  margin-left: 8px;
  transition: background-color 0.2s;
}

.copy-code-btn:hover,
.expand-code-btn:hover {
  background: rgba(59, 130, 246, 0.6);
}

.code-block {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  max-height: 400px;
  background: #282c34;
  border-radius: 0 0 6px 6px;
}

.code-block code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  tab-size: 2;
}

/* Message text and structure improvements */
.message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-message .message-text a {
  color: #4299e1;
  text-decoration: underline;
}

.message-image-container {
  margin: 10px 0;
  text-align: center;
}

.message-image {
  max-width: 100%;
  max-height: 500px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* Error popup styling */
.error-popup {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #ef4444;
  color: white;
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 0.9rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
}

.error-popup.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Override Prism.js default styles for better dark mode compatibility */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #6a9955;
}

.token.punctuation {
  color: #d4d4d4;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
  color: #b5cea8;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: #ce9178;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: #d4d4d4;
}

.token.atrule,
.token.attr-value,
.token.keyword {
  color: #569cd6;
}

.token.function,
.token.class-name {
  color: #dcdcaa;
}

.token.regex,
.token.important,
.token.variable {
  color: #d16969;
}

/* Light mode overrides */
body.light-mode .code-block-container {
  border: 1px solid #ddd;
}

body.light-mode .code-block-header {
  background: #f0f0f0;
  border-bottom: 1px solid #ddd;
}

body.light-mode .code-language {
  color: #555;
}

body.light-mode .code-block {
  background: #f5f5f5;
}

body.light-mode .copy-code-btn,
body.light-mode .expand-code-btn {
  background: rgba(59, 130, 246, 0.2);
  color: #333;
}

body.light-mode .copy-code-btn:hover,
body.light-mode .expand-code-btn:hover {
  background: rgba(59, 130, 246, 0.4);
}

/* Light mode Prism.js overrides */
body.light-mode .token.comment,
body.light-mode .token.prolog,
body.light-mode .token.doctype,
body.light-mode .token.cdata {
  color: #008000;
}

body.light-mode .token.punctuation {
  color: #333;
}

body.light-mode .token.property,
body.light-mode .token.tag,
body.light-mode .token.boolean,
body.light-mode .token.number {
  color: #098658;
}

body.light-mode .token.selector,
body.light-mode .token.attr-name,
body.light-mode .token.string,
body.light-mode .token.char {
  color: #a31515;
}

body.light-mode .token.keyword {
  color: #0000ff;
}

body.light-mode .token.function {
  color: #795e26;
}