/* Custom resets and styling for React Markdown */
* { box-sizing: border-box; }
.prose {
    font-size: 0.95rem;
    letter-spacing: -0.01em;
}

/* Ensure code blocks don't overflow on small screens */
.code-container {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
}

/* Keep the header visible and attached to the top of the code container */
.code-container .code-header {
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Ensure pre renders responsively and can scroll horizontally without pushing layout */
.code-container pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre;
  word-break: normal;
}

/* Make iframe preview responsive */
.code-container iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
}

/* Improve mobile spacing */
@media (max-width: 640px) {
  .code-container { padding: 0; }
  .code-container .code-header { padding: 0.5rem 0.75rem; font-size: 0.8rem; }
  .code-container pre { padding: 0.75rem; font-size: 0.9rem; }
}

/* Mobile-friendly code block adjustments */
@media (max-width: 640px) {
  .code-container pre {
    font-size: 0.9rem;
    padding: 0.75rem;
  }
  .code-header {
    font-size: 0.75rem;
    padding: 0.5rem;
    gap: 0.25rem;
  }
  .code-header button {
    padding: 0.3rem;
  }
  .code-container .bg-white {
    height: auto !important;
  }
}

/* Typewriter visual caret and subtle timing shimmer */
.typewriter-wrapper { position: relative; display: inline-block; }
.typewriter-caret {
  width: 2px;
  height: 1.1em;
  background: linear-gradient(180deg,#fff,#cbd5e1);
  position: absolute;
  right: 0;
  top: 0.12em;
  animation: blink 1s steps(2, start) infinite;
  opacity: 0.9;
}
@keyframes blink { 50% { opacity: 0 } }

/* ensure copy button comfortable on touch */
.code-header button { min-width: 44px; min-height: 36px; display: inline-flex; align-items:center; justify-content:center; }

/* Enhanced code block styling */
.code-container {
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(2,6,23,0.6);
  border: 1px solid rgba(255,255,255,0.04);
}

.code-header {
  background: linear-gradient(90deg, rgba(15,23,42,0.96), rgba(10,15,25,0.96));
  padding: 0.6rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", monospace;
  font-size: 0.8rem;
  gap: 0.5rem;
}

.code-header button {
  background: transparent;
  border: 0;
  color: #9ca3af;
  padding: 0.3rem 0.5rem;
  border-radius: 0.5rem;
}

.code-header button:hover {
  color: #fff;
  background: rgba(255,255,255,0.03);
}

.code-container pre {
  background: linear-gradient(180deg, rgba(12,18,28,0.95), rgba(6,9,14,0.95));
  padding: 1rem;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", monospace;
  font-size: 0.85rem;
  color: #e6eef8;
  line-height: 1.45;
  overflow-x: auto;
}

/* small label for selected model */
.model-badge {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  color: #e6eef8;
  border: 1px solid rgba(255,255,255,0.03);
}

/* keep existing rules */

.prose pre {
    background-color: #0f172a !important;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 0.75rem;
    padding: 1.25rem;
    margin: 0.75rem 0;
    overflow-x: auto;
    direction: ltr;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.prose code {
    color: #93c5fd;
    background-color: rgba(59, 130, 246, 0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-family: monospace;
}

.prose p {
    margin-bottom: 0.5rem;
    line-height: 1.7;
}

.prose ul, .prose ol {
    padding-right: 1.5rem;
    margin: 0.5rem 0;
}

.prose li {
    margin-bottom: 0.25rem;
}

/* Animations */
@keyframes fade-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fade-in 0.3s ease-out forwards;
}

/* Inappropriate message blur + label styling */
.inappropriate-container {
  position: relative;
  overflow: visible;
}

/* blur the message content while keeping layout */
.inappropriate-container > *:not(.inappropriate-overlay) {
  filter: blur(6px) saturate(0.9);
  opacity: 0.95;
  pointer-events: none;
}

/* overlay label centered on the message */
.inappropriate-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.inappropriate-overlay .label {
  background: rgba(0,0,0,0.6);
  color: #ffcccc;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  backdrop-filter: blur(4px);
  pointer-events: none;
}

/* RTL Specific Overrides */
[dir="rtl"] .message-user {
    border-top-right-radius: 1rem;
    border-top-left-radius: 1rem;
    border-bottom-left-radius: 1rem;
    border-bottom-right-radius: 0.25rem;
}

[dir="rtl"] .message-ai {
    border-top-right-radius: 1rem;
    border-top-left-radius: 1rem;
    border-bottom-right-radius: 1rem;
    border-bottom-left-radius: 0.25rem;
}

/* Light-mode contrast fixes: ensure icons, header text and small labels remain readable */
body.light-mode .glass-panel,
body.light-mode .history-sidebar,
body.light-mode .code-header {
    /* stronger visible backgrounds and borders for light mode */
    background: rgba(255,255,255,0.94) !important;
    color: #0f172a !important;
    border-color: rgba(16,24,40,0.08) !important;
    box-shadow: 0 10px 30px rgba(2,6,23,0.06) !important;
}

/* Make history sidebar stand out in light mode */
body.light-mode .history-sidebar {
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(248,249,250,0.98)) !important;
    border-left: 1px solid rgba(16,24,40,0.04) !important;
    color: #0b1220 !important;
}

/* Improve code header contrast in light mode */
body.light-mode .code-header {
    background: linear-gradient(90deg, rgba(255,255,255,0.98), rgba(250,250,250,0.98)) !important;
    color: #0f172a !important;
}

/* Ensure interactive elements inside panels are readable and get clear focus */
body.light-mode .glass-panel button,
body.light-mode .history-sidebar button,
body.light-mode .code-header button {
    color: #0f172a !important;
    background: rgba(16,24,40,0.03);
    border-radius: 10px;
}

body.light-mode .history-sidebar.open { 
    transform: translateX(0);
    /* make sidebar shadow subtle but present on top of light background */
    box-shadow: -8px 0 24px rgba(2,6,23,0.06);
}

/* make header controls and small interactive text darker and higher-contrast in light mode */
body.light-mode .glass-panel button,
body.light-mode header .flex.items-center .text-slate-400,
body.light-mode .model-badge,
body.light-mode .code-header button,
body.light-mode .code-header span,
body.light-mode .typewriter-caret {
    color: #0f172a !important;
}

/* ensure placeholder & muted labels are visible in light mode */
body.light-mode ::placeholder {
    color: #94a3b8 !important;
}

/* increase contrast for icon buttons in light mode */
body.light-mode .glass-panel button svg,
body.light-mode .glass-panel .p-2 svg,
body.light-mode .message-user svg,
body.light-mode .message-ai svg {
    color: #0b1220 !important;
    opacity: 0.95;
    filter: none;
}

/* ensure message backgrounds contrast well in light mode */
body.light-mode .message-user {
    background: linear-gradient(145deg, #2563eb, #1d4ed8);
    color: white;
}
body.light-mode .message-ai {
    background: #ffffff;
    color: #0f172a;
    border: 1px solid rgba(16,24,40,0.06);
}

/* make small metadata and helper text darker in light mode */
body.light-mode .text-slate-400,
body.light-mode .text-slate-500,
body.light-mode .text-slate-600 {
    color: #334155 !important;
}

/* button backgrounds that used subtle light tints get clearer outlines */
body.light-mode .glass-panel .rounded-xl,
body.light-mode .glass-panel .rounded-2xl {
    border: 1px solid rgba(16,24,40,0.04);
}

/* ensure the typewriter caret remains visible in light mode */
body.light-mode .typewriter-caret {
    background: linear-gradient(180deg,#0f172a,#334155) !important;
}

/* small adjustments for account / modal components in light mode */
body.light-mode .glass-panel img,
body.light-mode .glass-panel .w-12 {
    filter: none;
    opacity: 1;
}

/* Ensure SVG icon visibility in light mode while preserving original icon colors and full opacity */
body.light-mode svg {
    /* keep icons visible without overriding their intrinsic fill/stroke */
    opacity: 1 !important;
    filter: none !important;
}

/* Target common interactive icon containers: ensure visibility but preserve original icon color where intended */
body.light-mode .glass-panel button svg,
body.light-mode header svg,
body.light-mode .history-sidebar svg,
body.light-mode .code-header button svg,
body.light-mode .message-user svg,
body.light-mode .message-ai svg {
    color: inherit !important;
    opacity: 1 !important;
    filter: none !important;
}

/* Force header to remain transparent (no background, border or shadow) in both themes */
header {
    background: transparent !important;
    box-shadow: none !important;
    border-bottom: none !important;
}

/* Ensure header stays transparent in light mode as well */
body.light-mode header {
    background: transparent !important;
    box-shadow: none !important;
    border-bottom: none !important;
}

/* Give the three header control buttons distinct visible backgrounds while keeping header transparent */
header .flex.items-center > button {
  padding: 8px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: background-color .18s ease, color .18s ease, transform .06s ease;
  border: 1px solid rgba(255,255,255,0.04);
}

/* first button (theme toggle) */
header .flex.items-center > button:nth-child(1) {
  background: rgba(255,255,255,0.03);
  color: inherit;
}
header .flex.items-center > button:nth-child(1):hover { background: rgba(255,255,255,0.06); }

/* second button (settings) */
header .flex.items-center > button:nth-child(2) {
  background: rgba(2,6,23,0.45);
  color: inherit;
}
header .flex.items-center > button:nth-child(2):hover { background: rgba(2,6,23,0.6); }

/* third button (history/menu) */
header .flex.items-center > button:nth-child(3) {
  background: rgba(15,23,42,0.45);
  color: inherit;
}
header .flex.items-center > button:nth-child(3):hover { background: rgba(15,23,42,0.6); }

/* Adjust button contrast for light mode while preserving header transparency */
body.light-mode header .flex.items-center > button {
  border: 1px solid rgba(16,24,40,0.06);
  color: #0f172a !important;
}
body.light-mode header .flex.items-center > button:nth-child(1) {
  background: rgba(255,255,255,0.9);
}
body.light-mode header .flex.items-center > button:nth-child(2) {
  background: rgba(250,250,250,0.9);
}
body.light-mode header .flex.items-center > button:nth-child(3) {
  background: rgba(245,245,245,0.9);
}

/* Light-mode: add a subtle blue-gradient ring around the selected tone button in settings
   Uses a pseudo-element so the gradient appears around the button without breaking layout.
   Target the existing selected state which uses bg-blue-600 (set in App.js rendering). */
body.light-mode .glass-panel .grid button.bg-blue-600 {
  position: relative;
  z-index: 1;
  overflow: visible;
  /* slightly stronger fill so gradient ring reads clearly */
  background: linear-gradient(90deg, #2563eb, #1d4ed8);
  color: #fff !important;
  border: 1px solid rgba(29,78,216,0.9);
}

/* pseudo-element for gradient ring */
body.light-mode .glass-panel .grid button.bg-blue-600::before {
  content: "";
  position: absolute;
  inset: -4px;
  z-index: -1;
  border-radius: 12px;
  padding: 2px;
  background: linear-gradient(90deg, rgba(37,99,235,0.18), rgba(59,130,246,0.14) 40%, rgba(99,102,241,0.12));
  /* subtle blur to feel like a glow/ring */
  filter: blur(6px);
  opacity: 0.95;
  transition: opacity .18s ease, transform .18s ease;
}

/* ensure the ring shrinks a bit on active press for tactile feedback */
body.light-mode .glass-panel .grid button.bg-blue-600:active::before {
  transform: scale(0.98);
  opacity: 0.9;
}

/* keep accessibility: increase contrast for focus */
body.light-mode .glass-panel .grid button.bg-blue-600:focus {
  outline: 2px solid rgba(37,99,235,0.18);
  outline-offset: 3px;
}