/* === GLOBAL BASE STYLES === */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  position: fixed;
  overscroll-behavior: none;
  touch-action: manipulation;
  font-family: 'Segoe UI', sans-serif;
}

* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

body.dark {
  background-color: #051024;
  color: white;
}

#app {
  height: 100%;
  width: 100%;
  display: flex;
  overflow: hidden;
  flex-direction: row;
}

.mobile-toggle {
  display: none;
}

/* === SIDEBAR === */
.sidebar {
  width: 260px;
  background-color: #020812;
  color: white;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.5);
  height: 100%;
  padding: 20px 10px 60px;
  overflow: hidden;
  position: relative;
}
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1px;
}

.sidebar.collapsed {
  width: 55px;
  padding: 0;
}

.sidebar-content {
  margin-top: 1cm;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sidebar.collapsed .sidebar-content,
.sidebar.collapsed 

.sidebar-search {
  width: 100%;
  margin: 10px auto;
  padding: 6px 10px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  background: #1a1f2b;
  color: white;
}
.sidebar.collapsed .sidebar-top {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 50px;
  padding-top: 10px;
}

.sidebar.collapsed #toggle-sidebar {
  margin: 0 auto;
}

.sidebar.collapsed #search-input,
.sidebar.collapsed #case-type,
.sidebar.collapsed #new-chat,
.sidebar.collapsed #chat-list,
.sidebar.collapsed .chat-item,
.sidebar.collapsed .chat-title,
.sidebar.collapsed .menu-btn,
.sidebar.collapsed .dropdown {
  display: none !important;
}

#toggle-sidebar {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1001;
  background: none;
  border: none;
  font-size: 24px;
  color: white;
  cursor: pointer;
}

#search-input, #case-type {
  width: 100%;
  margin: 10px auto;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
  border: none;
  background: #1a1f2b;
  color: white;
}

.case-display {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  color: #ccc;
  font-style: italic;
  z-index: 10;
  pointer-events: none;
}

#new-chat {
  width: 100%;
  margin-top: 20px;
  background-color: transparent;
  color: rgb(166, 165, 167);
  cursor: pointer;
  padding: 8px 12px;
  border: 1px solid white;
  border-radius: 4px;
  text-align: left;
}

#chat-list {
  width: 210px;
  list-style: none;
  padding: 0;
  margin: 10px;
  flex: 1;
  overflow-y: auto;         /* scroll only vertical */
  overflow-x: hidden;       /* prevent horizontal */
  position: relative;
  z-index: 1;
}

.chat-item {
  display: inline-flex;         /* shrink to content width */
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  color: white;
  border-radius: 4px;
  position: relative;
  box-sizing: border-box;
  transition: background-color 0.2s ease;
  margin: 4px auto;             /* center horizontally */
  background-color: transparent;
}

.chat-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
}
.chat-item.active:hover {
  background-color: #1f2a3c; /* Same as .active to prevent override */
}

.chat-item.active {
  background-color: #1f2a3c; /* or any highlight color */
  color: #fff;
}

.menu {
  position: relative;
}

.menu-btn {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  z-index: 20;
  position: relative;
}

.dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background-color: #121b2f;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 5px 0;
  z-index: 999;
  display: none;
  min-width: 100px;
}

.dropdown.show {
  display: block;
}

.dropdown button {
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  text-align: left;
  color: white;
  cursor: pointer;
  font-size: 13px;
}

.dropdown button:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.dropdown.upward {
  bottom: 100%;
  top: auto;
}

#voice-button {
  background: none;
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  margin-right: 6px;
}

#toggle-theme, #export-chat {
  background: none;
  border: none;
  font-size: 18px;
  color: white;
  cursor: pointer;
}

/* === CHAT WINDOW === */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 40px 20px 20px 20px; /* ⬅️ Top Right Bottom Left */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.user-message, .assistant-message {
  width: 100%;
  max-width: 700px;
  display: flex;
}

.user-message { justify-content: flex-end; }
.assistant-message { justify-content: flex-start; }

.message-bubble {
  max-width: 80%;
  padding: 5px;
  border-radius: 12px;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  background: rgba(255, 255, 255, 0.05);
  color: white;
}

.user-message .message-bubble.text-message {
  background: rgba(255, 255, 255, 0.08);
  border-bottom-right-radius: 2px;
}

.assistant-message .message-bubble {
  background-color: #2c2f3a;
  border-bottom-left-radius: 2px;
}
.uploading-placeholder .message-bubble {
  opacity: 0.6;
  font-style: italic;
}

#input-container {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background-color: #0f172a;
  border: 1px solid #3c3c3c;
  border-radius: 25px;
  max-width: 800px;
  margin: 0 auto 20px;
  box-sizing: border-box;
  width: 100%;
  gap: 10px;
}

.icon-button {
  background: none;
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#chat-input {
  resize: none;
  padding: 12px 14px;
  border: none;
  border-radius: 16px;
  font-size: 1rem;
  flex: 1;
  background-color: var(--input-bg);
  color: var(--text-color);
  outline: none;
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  line-height: 1.5;
  min-height: 48px;
  box-sizing: border-box;
  scrollbar-width: none; /* Firefox */
  width: 100%;
  text-align: left;
}

#chat-input::placeholder {
  color: #ccc;
  text-align: left;
}

#chat-input::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.upload-label {
  cursor: pointer;
  font-size: 20px;
  margin-right: 8px;
}

#send-button {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
}

.uploaded-thumb, .chat-image-preview {
  max-width: 200px;
  max-height: 200px;
  border-radius: 5px;
  cursor: pointer;
  object-fit: cover;
}
/* ✅ Drag-and-drop visual indicator */
#messages.dragging {
  outline: 3px dashed #4caf50;
  background-color: rgba(76, 175, 80, 0.05);
  transition: background-color 0.3s ease;
}

/* ✅ Fix image modal so it doesn’t block sidebar clicks and closes correctly */
#image-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(0, 0, 0, 0.85);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  pointer-events: none; /* Disable all interaction unless .show is present */
}

#image-modal.show {
  display: flex;
  pointer-events: auto; /* Enable interaction */
}

#image-modal img {
  max-width: 90%;
  max-height: 90%;
  border-radius: 10px;
}

.close-button {
  position: absolute;
  top: 20px;
  right: 30px;
  font-size: 32px;
  color: white;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 1001;
}

/* Align model selector and case display in a top bar */
.top-bar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem 0.5rem;
}

.model-selector-container label {
  margin-right: 0.5rem;
  font-size: 0.9rem;
}

/* === MOBILE RESPONSIVE === */
@media (max-width: 768px) {
  html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow-x: hidden !important;
    overflow-y: auto;
    position: fixed;
    overscroll-behavior: none;
    touch-action: pan-y;
  }

  #app {
    flex-direction: column;
  }
   .top-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
}

  .model-selector-container,
  .case-display {
    width: 100%;
  }

  .model-selector-container select,
  .case-display {
    font-size: 14px;
  }

  #sidebar-toggle {
    align-self: flex-start;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
  }

  .sidebar.mobile-visible {
    transform: translateX(0);
  }

  
.chat-item {
   position: relative;
   z-index: 10;
 }

 .menu-btn {
   position: relative;
   z-index: 20;
   pointer-events: auto;
 }

 .dropdown {
   z-index: 9999 !important;
   pointer-events: auto !important;
   position: absolute;
 }

  #overlay {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.4);
  z-index: 999;
}

  #overlay.active {
    display: block;
  }

  #input-container {
    position: fixed;
    bottom: 0;
    width: 100%;
    left: 0;
    background: inherit;
  }

  #messages {
    padding-bottom: 70px;
  }
}
  .icon-button {
    font-size: 1rem;
  }

  #chat-input {
    font-size: 0.95rem;
  }

.chat-item {
  position: relative; /* ✅ Needed for absolute-positioned dropdown */
  overflow: visible !important; /* ✅ Allow dropdown to overflow */
}

#chat-list {
  overflow-y: auto;
  overflow-x: hidden; /* ✅ Prevent horizontal scroll */
}

.menu {
  position: relative;
}

/* Proper dropdown positioning */
.chat-item {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 6px 10px;
  box-sizing: border-box;
}

.menu-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0 5px;
  font-size: 16px;
}
.dropdown.upward {
  bottom: 100%;
  top: auto;
}
/* ✅ Fix image modal from blocking sidebar clicks */
#image-modal {
  pointer-events: none; /* Don't block anything by default */
}
#image-modal.show {
  pointer-events: auto; /* Only allow pointer events when active */
}
.model-selector-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  background-color: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  gap: 8px;
}

.model-selector-container select {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 14px;
  border: 1px solid var(--border-color);
  background-color: var(--input-bg);
  color: var(--text-color);
}
/* Fix model dropdown colors */
select#model-selector {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: white;
  font-size: 0.9rem;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
}

select#model-selector option {
  background-color: #0f172a;
  color: white;
}
.top-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
}
.ocr-text {
  font-family: monospace;
  font-size: 13px;
  white-space: pre-wrap;
  background: #0a0a0a20;
  padding: 8px;
  border-radius: 6px;
  margin-top: 6px;
  display: block;
}
.ocr-text-block {
  background-color: #101820;
  padding: 12px 16px;
  border-radius: 8px;
  line-height: 1.6;
  font-size: 14px;
  color: #f2f2f2;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Segoe UI", sans-serif;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.ocr-text-block p {
  margin-bottom: 1em;
}

.ocr-text-block p {
  margin-bottom: 1em;
}

.ocr-image-wrapper {
  text-align: center;
  margin-bottom: 8px;
}

.ocr-text-wrapper strong {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}
.ocr-controls {
  margin: 8px 0 12px;
  display: flex;
  gap: 8px;
}

.ocr-controls button {
  background-color: #1e1e1e;
  border: 1px solid #444;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.ocr-controls button:hover {
  background-color: #333;
}

.ocr-text-wrapper {
  background: #111;
  padding: 12px;
  margin-top: 10px;
  border: 1px solid #333;
  border-radius: 8px;
  color: #ddd;
  font-size: 14px;
  position: relative;
}

.ocr-text-wrapper strong {
  display: block;
  margin-bottom: 8px;
  color: #fff;
}

.ocr-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.ocr-controls button {
  background: #222;
  border: 1px solid #444;
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.ocr-controls button:hover {
  background: #333;
}

.ocr-text-block {
  white-space: pre-wrap;
  line-height: 1.5;
  background: #000;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #444;
}
/* === Icon Button Base Style (Used by all export/import buttons) === */
.icon-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background-color: #1e1e1e;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
  text-align: left;
}

.icon-btn:hover {
  background-color: #333;
}

/* === Sidebar Bottom Buttons === */
.sidebar-bottom button,
.sidebar-bottom label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  background-color: #1e1e1e;
  color: white;
  border: none;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  margin: 0;
  transition: background-color 0.2s ease;
}

.sidebar-bottom button:hover,
.sidebar-bottom label:hover {
  background-color: #333;
}
#export-chat {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  background-color: #1e1e1e;
  color: white;
  border: none;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  margin: 0;
  transition: background-color 0.2s ease;
}

#export-chat:hover {
  background-color: #333;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  background-color: #1e1e1e;
  color: white;
  border: none;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background-color 0.2s ease;
}

.sidebar-btn:hover {
  background-color: #333;
}
#export-chat.sidebar-btn::before {
  content: "📤";
  margin-right: 8px;
}
#export-chat {
  padding: 8px 12px !important;
  font-size: 14px !important;
  line-height: 1 !important;
  display: inline-flex !important;
  align-items: center !important;
  white-space: nowrap !important;
  background: #111 !important;
  border: 1px solid #555 !important;
  color: #eee !important;
}
.sidebar-bottom {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #111;
  position: sticky;
  bottom: 0;
}

.sidebar.collapsed .sidebar-content,
.sidebar.collapsed .sidebar-bottom {
  display: none !important;
}
