/* Base */
html {
  scroll-behavior: smooth;
}

textarea {
  min-height: 200px;
  font-family: "Fira Code", monospace;
  transition: color 0.2s ease, background-color 0.2s ease,
    border-color 0.2s ease;
}

textarea#output-schema-textarea,
textarea#tool-definitions-textarea { /* Added tool textarea */
  min-height: 200px;
  font-family: "Fira Code", monospace;
  transition: color 0.2s ease, background-color 0.2s ease,
    border-color 0.2s ease;
}

/* Prose content styling */
.prose pre {
  border: 1px solid #e5e7eb; /* gray-200 */
  background-color: #f9fafb; /* gray-50 */
  color: #1f2937; /* gray-800 */
  border-radius: 0.5rem;
  padding: 1.25rem; /* p-5 */
  overflow-x: auto;
  font-size: 0.875rem; /* text-sm */
  line-height: 1.625; /* leading-relaxed */
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); /* shadow-sm */
  font-family: "Fira Code", monospace !important;
}

.dark .prose pre {
  border-color: #374151; /* gray-700 */
  background-color: #111827; /* gray-900 */
  color: #e5e7eb; /* gray-200 */
}

.prose :where(code):not(:where([class~="not-prose"] *)) {
  font-weight: 500 !important;
  font-family: "Fira Code", monospace !important;
}

.prose :where(code):not(:where([class~="not-prose"] *))::before,
.prose :where(code):not(:where([class~="not-prose"] *))::after {
  content: "" !important;
}

.prose :where(code):not(:where(pre *)) {
  font-size: 0.875rem !important;
  font-weight: 500 !important;
  background-color: #f3f4f6 !important; /* gray-100 */
  color: #0e7490 !important; /* cyan-700 */
  border-radius: 0.375rem !important;
  padding: 0.125rem 0.375rem !important; /* px-1.5 py-0.5 */
}

.dark .prose :where(code):not(:where(pre *)) {
  background-color: #1f2937 !important; /* gray-800 */
  color: #22d3ee !important; /* cyan-400 */
}

/* Scrollbar styling */
.overflow-y-auto::-webkit-scrollbar,
.sidebar-scrollbar::-webkit-scrollbar {
  width: 10px;
}

.overflow-y-auto::-webkit-scrollbar-track,
.sidebar-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.overflow-y-auto::-webkit-scrollbar-thumb,
.sidebar-scrollbar::-webkit-scrollbar-thumb {
  background-color: #d1d5db; /* gray-300 */
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.dark .overflow-y-auto::-webkit-scrollbar-thumb,
.dark .sidebar-scrollbar::-webkit-scrollbar-thumb {
  background-color: #374151; /* gray-700 */
}

.overflow-y-auto::-webkit-scrollbar-thumb:hover,
.sidebar-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: #9ca3af; /* gray-400 */
  background-clip: content-box;
}

.dark .overflow-y-auto::-webkit-scrollbar-thumb:hover,
.dark .sidebar-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: #4b5563; /* gray-600 */
}

/* Score bar animation */
.score-bar-fill {
  transition: width 0.7s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* Configuration sliders */
.config-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px; /* thicker track */
  border-radius: 9999px;
  background: linear-gradient(#06b6d4, #06b6d4) 0/0% 100% no-repeat, #e5e7eb;
  transition: background-size 0.2s ease;
}

.dark .config-slider {
  background: linear-gradient(#22d3ee, #22d3ee) 0/0% 100% no-repeat, #374151;
}

/* Update filled track size based on value via JS hook */
.config-slider[data-progress] {
  background-size: var(--progress, 0%) 100%;
}

.config-slider:focus {
  outline: none;
}

.config-slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 9999px;
  background: transparent;
}

.config-slider::-moz-range-track {
  height: 10px;
  border-radius: 9999px;
  background: transparent;
}

.config-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  background: #ffffff;
  border: 2px solid #06b6d4; /* cyan-500 */
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  margin-top: -4px; /* center on track */
}

.dark .config-slider::-webkit-slider-thumb {
  background: #111827; /* gray-900 */
  border-color: #22d3ee; /* cyan-400 */
}

.config-slider:active::-webkit-slider-thumb,
.config-slider:hover::-webkit-slider-thumb {
  transform: scale(1.1);
  box-shadow: 0 4px 10px rgba(6, 182, 212, 0.3);
}

.config-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  background: #ffffff;
  border: 2px solid #06b6d4;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.dark .config-slider::-moz-range-thumb {
  background: #111827;
  border-color: #22d3ee;
}

.config-slider:active::-moz-range-thumb,
.config-slider:hover::-moz-range-thumb {
  transform: scale(1.1);
  box-shadow: 0 4px 10px rgba(6, 182, 212, 0.3);
}

/* History panel */
#history-panel {
  max-height: 24rem; /* max-h-96 */
  overflow-y: auto;
  background-color: #ffffff;
  border: 1px solid #e5e7eb; /* gray-200 */
  border-radius: 0.5rem; /* rounded-lg */
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  padding: 0.75rem; /* p-3 */
}

.dark #history-panel {
  background-color: #111827; /* gray-900 */
  border-color: #374151; /* gray-700 */
}

.history-item {
  padding: 0.75rem;
  border-radius: 0.5rem;
  transition: background-color 0.2s ease;
  cursor: pointer;
  display: flex; /* NEW: Flex for checkbox */
  align-items: center; /* NEW: Align items */
  gap: 0.75rem; /* NEW: Gap */
  border: 2px solid transparent; /* NEW: Border for selection */
}

.history-item:hover {
  background-color: #f3f4f6; /* gray-100 */
}

.dark .history-item:hover {
  background-color: #1f2937; /* gray-800 */
}

/* NEW: Style for selected history item */
.history-item.selected {
    border-color: #0ea5e9; /* cyan-500 */
    background-color: #f0f9ff; /* cyan-50 */
}
.dark .history-item.selected {
    border-color: #06b6d4; /* cyan-400 */
    background-color: #1f2937; /* gray-800 */
}


.history-item-content {
  flex-grow: 1; /* NEW: Allow content to grow */
}

.history-item-prompt {
  font-size: 0.875rem; /* text-sm */
  color: #374151; /* gray-700 */
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.dark .history-item-prompt {
  color: #d1d5db; /* gray-300 */
}

.history-item-time {
  font-size: 0.75rem; /* text-xs */
  color: #9ca3af; /* gray-400 */
}

.dark .history-item-time {
  color: #6b7280; /* gray-500 */
}

.history-item-load-button {
  font-size: 0.75rem; /* text-xs */
  font-weight: 600;
  color: #0891b2; /* cyan-600 */
  text-decoration: none;
}

.history-item-load-button:hover {
  text-decoration: underline;
}

.dark .history-item-load-button {
  color: #22d3ee; /* cyan-400 */
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(17, 24, 39, 0.75); /* gray-900 w/ opacity */
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.3s ease;
  padding: 1rem; /* p-4 */
}

.modal-content {
  background-color: #ffffff;
  color: #111827;
  padding: 1.5rem; /* p-6 */
  border-radius: 0.5rem; /* rounded-lg */
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 8px 10px -6px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 28rem; /* max-w-md */
  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  border: 1px solid #e5e7eb; /* improve light-mode contrast */
}

.dark .modal-content {
  background-color: #1f2937; /* gray-800 */
  color: #e5e7eb; /* gray-200 */
  border-color: #374151; /* gray-700 */
}

/* Icons and variants */
#cot-warning-icon {
  color: #eab308; /* yellow-500 */
}

.dark #cot-warning-icon {
  color: #facc15; /* yellow-400 */
}

.variant-item {
  padding: 0.75rem; /* p-3 */
  background-color: #f3f4f6; /* gray-100 */
  border-radius: 0.5rem; /* rounded-lg */
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.875rem; /* text-sm */
  cursor: pointer;
  transition: background-color 0.2s ease;
  border: 1px solid #e5e7eb; /* better visibility in light */
}

.variant-item:hover {
  background-color: #e5e7eb; /* gray-200 */
}

.dark .variant-item {
  background-color: #1f2937; /* gray-800 */
  border-color: #374151; /* gray-700 */
}

/* Ensure links are clearly visible in light mode within prose */
.prose a {
  color: #0e7490; /* cyan-700 */
}

.prose a:hover {
  text-decoration: underline;
}

.dark .variant-item:hover {
  background-color: #374151; /* gray-700 */
}

/* Smooth, Apple-like button interactions */
button {
  border-radius: 0.75rem; /* 12px */
  transition: background-color 0.2s ease, color 0.2s ease,
    border-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

button:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.06);
}

button:active {
  transform: translateY(1px);
  filter: brightness(0.98);
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.35),
    0 6px 16px rgba(0, 0, 0, 0.08);
}

/* Icon buttons in header */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem; /* 36px */
  height: 2.25rem;
  border-radius: 9999px;
  background-color: rgba(243, 244, 246, 0.6); /* gray-100 */
  color: #374151; /* gray-700 */
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease,
    transform 0.1s ease;
}

.dark .btn-icon {
  background-color: rgba(31, 41, 55, 0.6); /* gray-800 */
  color: #d1d5db; /* gray-300 */
}

.btn-icon:hover {
  background-color: rgba(229, 231, 235, 0.9); /* gray-200 */
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.dark .btn-icon:hover {
  background-color: rgba(55, 65, 81, 0.9); /* gray-700 */
}

.btn-icon:active {
  transform: translateY(1px) scale(0.98);
}

/* Template buttons */
.btn-template {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 9999px;
  background: #eef2ff; /* indigo-50 */
  color: #4338ca; /* indigo-700 */
  font-weight: 600;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease,
    transform 0.1s ease;
}

.dark .btn-template {
  background: #1f2937; /* gray-800 */
  color: #a5b4fc; /* indigo-300 */
}

.btn-template:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.btn-template:active {
  transform: translateY(1px);
}

/* Text-like small buttons */
.history-item-load-button {
  transition: color 0.2s ease, text-underline-offset 0.2s ease;
  text-underline-offset: 2px;
}

.history-item-load-button:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  button,
  .btn-icon,
  .btn-template {
    transition: none;
  }
}

/* Smooth toggle knob (white circle) animation */
.config-toggle {
  transition: background-color 0.5s ease;
}

.config-toggle > span {
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1); /* iOS-like ease-out */
  will-change: transform;
}

/* Thinking dots animation for loading state */
.thinking-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.thinking-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background-color: #6b7280; /* gray-500 */
  opacity: 0.4;
  animation: dotPulse 1.4s infinite ease-in-out;
}

.dark .thinking-dots .dot {
  background-color: #9ca3af; /* gray-400 */
}

.thinking-dots .dot:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking-dots .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dotPulse {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* === Compare Modal Specific Styles (ปรับปรุง) === */

/* 1. สไตล์สำหรับหัวข้อ (Timestamp, System Prompt, etc.) */
#compare-view-container h3,
#compare-view-container h4 {
    font-size: 0.875rem; /* text-sm */
    font-weight: 600;
    color: #4b5563; /* gray-600 */
    border-bottom: 1px solid #e5e7eb; /* gray-200 */
    padding-bottom: 0.25rem; /* pb-1 */
    margin-bottom: 0.5rem; /* mb-2 */
}
.dark #compare-view-container h3,
.dark #compare-view-container h4 {
    color: #d1d5db; /* gray-300 */
    border-color: #4b5563; /* gray-600 */
}

/* 2. เพิ่มระยะห่างระหว่างแต่ละ Section (ยกเว้น Timestamp แรก) */
#compare-view-container h4 {
    margin-top: 1.25rem; /* mt-5 */
}

/* 3. สไตล์สำหรับเส้นคั่น <hr> */
#compare-view-container hr {
    border-color: #e5e7eb; /* gray-200 */
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}
.dark #compare-view-container hr {
    border-color: #374151; /* gray-700 */
}

/* 4. สไตล์สำหรับ <p> (Prompt, Duration) */
#compare-view-container .compare-value {
    font-size: 0.875rem; /* text-sm */
    font-family: 'Fira Code', monospace;
    color: #111827; /* gray-900 */
    white-space: pre-wrap;
    word-break: break-all;
}
.dark #compare-view-container .compare-value {
    color: #e5e7eb; /* gray-200 */
}

/* 5. (ใหม่) สไตล์สำหรับ <pre> ใน Config (Schema, Tools) */
#compare-view-container pre.compare-value {
    background-color: #f9fafb; /* gray-50 */
    border: 1px solid #e5e7eb; /* gray-200 */
    padding: 0.75rem; /* p-3 */
    border-radius: 0.375rem; /* rounded-md */
    overflow-x: auto;
    /* ใช้สไตล์ scrollbar แบบเดียวกับที่อื่น */
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}
.dark #compare-view-container pre.compare-value {
    background-color: #111827; /* gray-900 */
    border: 1px solid #374151; /* gray-700 */
    scrollbar-color: #374151 transparent;
}
#compare-view-container pre.compare-value::-webkit-scrollbar { width: 10px; }
#compare-view-container pre.compare-value::-webkit-scrollbar-track { background: transparent; }
#compare-view-container pre.compare-value::-webkit-scrollbar-thumb {
    background-color: #d1d5db;
    border-radius: 10px;
    border: 3px solid transparent;
    background-clip: content-box;
}
.dark #compare-view-container pre.compare-value::-webkit-scrollbar-thumb {
    background-color: #374151;
}


/* 6. (ปรับปรุง) สไตล์สำหรับ <div> ของ Output */
#compare-view-container .compare-output {
    white-space: pre-wrap;
    word-break: break-all;
    border: 1px solid #d1d5db; /* (ปรับเป็น solid) */
    padding: 0.75rem; /* p-3 */
    border-radius: 0.375rem; /* rounded-md */
    max-height: 250px; /* (เพิ่มความสูง) */
    overflow-y: auto;
    
    /* (เพิ่ม) สไตล์ Prose ให้อ่าน Markdown ง่าย */
    font-size: 0.875rem;
    color: #374151;
    line-height: 1.625;
}
.dark #compare-view-container .compare-output {
    border-color: #4b5563; /* gray-600 */
    color: #d1d5db;
}

/* 7. (เพิ่ม) สไตล์ Scrollbar สำหรับ Output (เหมือน .sidebar-scrollbar) */
.compare-output::-webkit-scrollbar { width: 10px; }
.compare-output::-webkit-scrollbar-track { background: transparent; }
.compare-output::-webkit-scrollbar-thumb {
    background-color: #d1d5db; /* gray-300 */
    border-radius: 10px;
    border: 3px solid transparent;
    background-clip: content-box;
}
.dark .compare-output::-webkit-scrollbar-thumb {
    background-color: #374151; /* gray-700 */
}
.compare-output::-webkit-scrollbar-thumb:hover {
    background-color: #9ca3af; /* gray-400 */
}
.dark .compare-output::-webkit-scrollbar-thumb:hover {
    background-color: #4b5563; /* gray-600 */
}

/* 8. (เพิ่ม) สไตล์ Prose ภายใน Output (Code, Pre, Lists) */
.compare-output ul, .compare-output ol { list-style-position: inside; margin-bottom: 1em; }
.compare-output p { margin-bottom: 1em; }
.compare-output code { 
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    background-color: #f3f4f6 !important; 
    color: #0e7490 !important; 
    border-radius: 0.375rem !important;
    padding: 0.125rem 0.375rem !important;
}
.dark .compare-output code {
    background-color: #1f2937 !important; 
    color: #22d3ee !important; 
}
.compare-output pre {
    border: 1px solid #e5e7eb; 
    background-color: #f9fafb; 
    color: #1f2937; 
    border-radius: 0.5rem;
    padding: 1rem; /* p-4 */
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.625; 
}
.dark .compare-output pre {
    border-color: #374151; 
    background-color: #111827; 
    color: #e5e7eb;
}
.compare-output pre code {
    background-color: transparent !important;
    color: inherit !important;
    padding: 0 !important;
    font-weight: 400 !important;
}

/* === สิ้นสุด Compare Modal Styles === */

/* === History Action Buttons (Export, Import, Clear) === */
.btn-history-action {
  padding: 0.375rem 0.75rem; /* 6px 12px */
  font-size: 0.75rem; /* text-xs */
  font-weight: 600;
  border-radius: 9999px;
  background: #eef2ff; /* indigo-50 */
  color: #4338ca; /* indigo-700 */
  transition: all 0.2s ease;
}
.dark .btn-history-action {
  background: #374151; /* gray-700 */
  color: #a5b4fc; /* indigo-300 */
}
.btn-history-action:hover {
  background: #e0e7ff; /* indigo-100 */
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}
.dark .btn-history-action:hover {
  background: #4b5563; /* gray-600 */
}
.btn-history-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-history-action:active {
  transform: translateY(1px);
}
/* Danger button style for Clear All */
.btn-history-danger {
  background-color: #fee2e2; /* red-100 */
  color: #b91c1c; /* red-700 */
}
.dark .btn-history-danger {
  background-color: #7f1d1d; /* red-900 */
  color: #fca5a5; /* red-300 */
}
.btn-history-danger:hover {
  background-color: #fecaca; /* red-200 */
}
.dark .btn-history-danger:hover {
  background-color: #b91c1c; /* red-700 */
}

/* === History Item Layout Fix === */

.history-item {
  min-height: 80px; 
  align-items: stretch; 
}


.history-item-content {
  flex: 1; 
  display: flex;
  flex-direction: column;
  justify-content: space-between; 
}


.history-item-prompt {
  font-size: 0.875rem; /* text-sm */
  color: #374151; /* gray-700 */
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  

  white-space: normal;  
  word-break: break-word; 
  overflow: visible;     
  text-overflow: clip;   
 
}

.dark .history-item-prompt {
  color: #d1d5db; /* gray-300 */
}


.history-item-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem; /* 8px */
  padding-top: 0.5rem; /* 8px */
  border-top: 1px solid #e5e7eb; /* gray-200 */
}
.dark .history-item-controls {
  border-top-color: #374151; /* gray-700 */
}

.history-item-buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem; /* 8px */
  flex-shrink: 0; 
}

/* PASTE CSS นี้ (จาก mdaa/css/style.css) */
#password-strength-progress.strength-0 {
  width: 0%;
}
#password-strength-progress.strength-1 {
  width: 25%;
  background-color: #ef4444; /* red-500 */
}
#password-strength-progress.strength-2 {
  width: 50%;
  background-color: #f97316; /* orange-500 */
}
#password-strength-progress.strength-3 {
  width: 75%;
  background-color: #eab308; /* yellow-500 */
}
#password-strength-progress.strength-4 {
  width: 100%;
  background-color: #22c55e; /* green-500 */
}

.typing-cursor {
  display: inline-block;
 
  width: 10px; 
  height: 1.5rem; 
  
 
  background-color: #0ea5e9; 
  

  animation: blink 1s infinite; 
  
  vertical-align: bottom; 
  margin-left: 8px; 
  border-radius: 2px; 
}

.dark .typing-cursor {
  background-color: #06b6d4;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
