@import url("components/_layout.css");
@import url("components/_header.css");
@import url("components/_sidebar.css");
@import url("components/_chat.css");
@import url("components/_modal.css");

/*@import url("components/_footer.css");
    ========================================
    Gerri Stylesheet
    ========================================

    Structure:
    1.  ROOT, VARIABLES & BASE STYLES
    2.  THEME DEFINITIONS (Moved to /themes) 
    3.  GENERAL ELEMENT STYLING
    4.  CORE APP LAYOUT
    5.  SIDEBAR & CHAT LIST
    6.  MAIN CONTENT AREA
    7.  SETTINGS & NEW CHAT MODALS
    8.  MOBILE & RESPONSIVE
    9.  UTILITIES & ANIMATIONS
    10. IMAGE HANDLING & PREVIEWS
    11. IMAGE MODAL
*/

/* ==== 1. ROOT, VARIABLES & BASE STYLES ==== */
:root {
  --font-primary: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-monospace: 'Fira Code', Menlo, Monaco, Consolas, "Courier New", monospace;

  /* Purples */
  --purple-500: #8A2BE2;
  --purple-600: #7B1FA2;
  --purple-700: #6A1B9A;
  --purple-100: #E1BEE7;
  --purple-50: #F3E5F5;
  --thinking-text-color-light: #9370DB;
  --thinking-text-color-dark: #C8A2C8;

  /* Grays */
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;
  --gray-950: #0d1117;

  /* Misc Colors */
  --white: #FFFFFF;
  --black: #000000;
  --error-color: #EF4444;
  --success-color: #10B981;

  /* Sizing & Effects */
  --border-radius-sm: 0.375rem;
  --border-radius-md: 0.5rem;
  --border-radius-lg: 0.75rem;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  font-size: 16px;
}

html { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-primary);
  line-height: 1.6;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s, color 0.3s;
  display: flex;
  height: 100%;
}

/* ==== 2. THEME DEFINITIONS ==== 

    --bg-primary:             Main background.
    --bg-secondary:           Background for the sidebar and modals.
    --bg-tertiary:            Background for smaller elements like AI messages, buttons, and inputs.
    --bg-hover:               Background color for elements in their hover state (e.g., list items).

    --text-primary:           The default text color for all primary content.
    --text-secondary:         A lighter text color for UI labels, placeholders, and author names.
    --text-accent:            Color for text links and other highlighted text elements.
    --button-text-primary:    Text color specifically for buttons with an accent-colored background.

    --border-color:           The color for all borders on inputs, panels, and code blocks.

    --accent-gradient:        Gradient used for user message bubbles and primary button hovers.
    --accent-color-static:    The solid, default accent color for buttons and UI highlights.
    --accent-color-active:    Accent color for elements when clicked.
    --accent-shadow-color:    Semi-transparent glow effect on focused elements.
    --thinking-text-color:    Color for expandable "thinking..."  text.
*/

/* ==== 3. GENERAL ELEMENT STYLING ==== */
button, select, textarea, input {
  font-family: inherit;
  font-size: 1rem;
  border-radius: var(--border-radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  padding: 0.65em 1em;
  transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
button:focus-visible,
select:focus-visible,
.chat-item:focus-visible {
    outline: none;
    border-color: var(--accent-color-static);
    box-shadow: 0 0 0 3px var(--accent-shadow-color);
}
textarea {
  resize: none;
  min-height: 40px;
}

button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  font-weight: 500;
  border: 1px solid transparent;
}

button.button-primary {
  background: transparent;
  color: var(--text-accent);
  border: 1px solid var(--accent-color-static);
  transition: background-color 0.2s, color 0.2s;
}
button.button-primary:hover {
  background: var(--accent-gradient);
  color: var(--button-text-primary);
  border-color: transparent;
}

button.button-secondary {
  background-color: var(--bg-tertiary);
  border-color: var(--border-color);
  color: var(--text-primary);
}
button.button-secondary:hover {
  background-color: var(--bg-hover);
  border-color: var(--gray-500);
}

#delete-all-chats-btn:hover {
  background-color: var(--error-color);
  border-color: var(--error-color);
  color: var(--button-text-primary);
}

input[type="text"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-color-static);
  box-shadow: 0 0 0 3px var(--accent-shadow-color);
}

.btn-icon svg {
  width: 1.2em;
  height: 1.2em;
  fill: currentColor;
}
#send-button .btn-text {
    display: none;
}
.hidden-input { display: none; }
button:active,
.chat-item:active,
.model-option:active {
    transform: translateY(1px);
    transition: transform 0.05s;
}

button.button-primary:active {
    filter: brightness(1); /* Disable general filter */
    border-color: var(--accent-color-active);
    border-color: var(--accent-color-active);
}
/* ==== 5. SIDEBAR & CHAT LIST ==== */
#sidebar {
  display: flex;
  flex-direction: column;
  width: 280px;
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  z-index: 1200;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), filter 0.2s ease-in-out; /* Modified for smooth blur */
}
@media (min-width: 769px) {
  #sidebar {
    position: relative;
    flex-shrink: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), filter 0.2s ease-in-out; /* Modified for smooth blur */
  }
  body.sidebar-visible #sidebar {
    margin-left: 0;
  }
  body:not(.sidebar-visible) #sidebar {
    margin-left: -280px;
  }
}
body.sidebar-visible #sidebar {
  transform: translateX(0);
}
.sidebar-content {
  padding: 1em;
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 1em;
  box-sizing: border-box;
}
.sidebar-content > nav {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#sidebar #new-chat-btn { width: 100%; }
#chat-list-header {
  font-size: 0.875em;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.5em 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#chat-list {
  flex-grow: 1;
  overflow-y: auto;
  margin-right: -0.5em;
  padding-right: 0.5em;
}
.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75em 1em;
  margin: 0.25em 0;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
  border: 1px solid transparent;
}
.chat-item:hover {
  background-color: var(--bg-hover);
}
.chat-item.active {
  background: transparent;
  color: var(--text-accent);
  border: 2px solid var(--accent-color-static);
  font-weight: 500;
  transition: background-color 0.2s, color 0.2s;
}
.chat-item.active:hover {
  background: var(--accent-gradient);
  color: var(--button-text-primary);
}
.chat-title {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 0.5em;
}
.chat-item-controls {
  display: flex;
}
.chat-item-controls button {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.35em;
  border-radius: var(--border-radius-sm);
}
.chat-item-controls button:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}
.chat-item-controls button svg {
  width: 1em;
  height: 1em;
}
.chat-item.active .chat-item-controls button {
  color: var(--button-text-primary);
  opacity: 0.8;
}
.chat-item.active .chat-item-controls button:hover {
  opacity: 1;
  background-color: rgba(255,255,255,0.1);
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 1em;
  display: flex;
  flex-direction: column;
  gap: 0.75em;
}
.sidebar-footer button { width: 100%; }

/* -- Footer & User Input -- */
#footer {
  grid-row: 4;
  display: flex;
  align-items: center;
  gap: 0.75em;
  background-color: transparent;
  box-shadow: none;
  z-index: 20;
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  border-radius: var(--border-radius-lg);
}

/* Desktop */
@media (min-width: 769px) {
  #footer {
    padding: 1em 1em 1.75em;
  }
}

/* Mobile */
@media (max-width: 768px) {
  #footer {
    gap: 0.5em;
    padding: 1.0em 1em 2em;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  #footer:has(#user-input:focus) {
    padding: 1em 1em 1em;
  }

  #user-input { padding: 0.6em 0.8em; min-height: 40px; }
  #send-button, .file-input-label { width: 40px; height: 40px; }
  .file-input-label svg, #send-button svg { width: 1.1em; height: 1.1em; }
  #file-name-display { display: none; }
}
#user-input {
  flex-grow: 1;
  padding: 0.75em 0.6em;
  min-height: 24px;
  max-height: 150px;
  overflow-y: auto;
  box-sizing: border-box;
  scrollbar-width: none;
}
#user-input::-webkit-scrollbar {
  display: none; /* For Chrome, Safari, Opera */
}
.file-input-label {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  margin-right: 0px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--border-radius-md);
  transition: color 0.2s, background-color 0.2s, box-shadow 0.2s;
  cursor: pointer;
}
.file-input-label svg {
  width: 16px;
  height: 16px;
  display: block;
  pointer-events: none;
}
.file-input-label:hover,
.file-input-label:focus {
  color: var(--button-text-primary);
  background-color: var(--accent-color-static);
  box-shadow: 0 0 0 2px var(--accent-color-static, #8A2BE2, 0.25);
}
#send-button {
  flex-shrink: 0;
  width: 44px; height: 44px;
  padding: 0;
  background: transparent;
  color: var(--accent-color-static);
  border: 1px solid var(--accent-color-static);
  border-radius: var(--border-radius-md);
  transition: background-color 0.2s, color 0.2s;
}
#send-button:hover {
  background: var(--accent-color-static);
  color: var(--button-text-primary);
}
#send-button:disabled {
  background: transparent;
  border-color: var(--gray-600);
  color: var(--gray-600);
  cursor: not-allowed;
}
#file-name-display {
  font-size: 0.8em;
  color: var(--text-secondary);
  margin-left: 0.5em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
  align-self: center;
}
/* debugger (unchanged styles kept below) */
.debug-options h4 {
  margin-top: 1.5em;
  margin-bottom: 0.75em;
  color: var(--text-accent);
}
.debug-controls { display: flex; flex-direction: column; gap: 0.75em; margin-bottom: 1em; }
.debug-filters { display: flex; flex-wrap: wrap; gap: 0.5em; }
.debug-filters button {
  padding: 0.4em 0.8em;
  font-size: 0.85em;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}
.debug-filters button.active {
  background: var(--accent-gradient);
  color: var(--button-text-primary);
  border-color: transparent;
}
.debug-filters button:hover:not(.active) { background-color: var(--bg-hover); }
#debug-log-container {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 1em;
  max-height: 300px;
  overflow-y: auto;
  font-family: var(--font-monospace);
  font-size: 0.85em;
  margin-bottom: 1em;
}
.debug-log-entry {
  padding: 0.5em;
  border-bottom: 1px dashed var(--border-color);
  cursor: pointer;
  word-break: break-all;
}
.debug-log-entry:last-child { border-bottom: none; }
.debug-log-entry.error { color: var(--error-color); font-weight: bold; }
.debug-log-entry pre {
  display: none;
  background-color: var(--bg-tertiary);
  padding: 0.5em;
  border-radius: var(--border-radius-sm);
  margin-top: 0.5em;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}
.debug-log-entry.expanded pre { display: block; }
.debug-actions { display: flex; gap: 1em; margin-top: 1em; }
.debug-actions button { flex-grow: 1; }

/* ==== 9. UTILITIES & ANIMATIONS ==== */
/* Scrollbar Styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-600); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes typingDots {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

/* ==== 10. IMAGE HANDLING & PREVIEWS ==== */
@keyframes spin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

#image-preview-container {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    border-top: 1px solid var(--border-color);
    order: -1; 
}

.image-preview {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius-md);
    overflow: hidden;
    background-color: var(--bg-tertiary);
}

.image-preview.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.image-preview.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 3px solid transparent;
    border-top-color: var(--accent-color-static);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 2;
}

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    padding: 0;
    line-height: 1;
}

.remove-image:hover {
    background: rgba(0,0,0,0.8);
}

.message-bubble .image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.message-bubble .chat-image {
    width: 100%;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
}

/* Add responsive behavior for the image grid */
@media (max-width: 768px) {
    .message-bubble .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

/* ==== 11. IMAGE MODAL ==== */
.image-modal-overlay {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
    cursor: pointer;
}

.image-modal-content {
    margin: auto;
    display: block;
    width: auto;
    max-width: 90%;
    height: auto;
    max-height: 90%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-name: zoom;
    animation-duration: 0.3s;
    cursor: default;
}

.image-modal-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}

.image-modal-close:hover,
.image-modal-close:focus {
    color: #bbb;
    text-decoration: none;
}

@keyframes zoom {
    from {transform: translate(-50%, -50%) scale(0.9)}
    to {transform: translate(-50%, -50%) scale(1)}
}
@keyframes token-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.token-stream-span {
  display: inline;
  white-space: pre-wrap;
  animation: token-fade 120ms linear both;
}