:root {
  color-scheme: light dark;
}

/* Base Utilities & Animations */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.015em; /* Slightly tighter for modern feel */
}

/* Ensure form elements inherit font settings */
input, button, select, textarea {
  font-family: inherit;
  font-feature-settings: inherit;
  font-variation-settings: inherit;
  letter-spacing: inherit;
}

.scrollbar-thin {
  scrollbar-width: thin;
}
.scrollbar-thin::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.scrollbar-thin::-webkit-scrollbar-track {
  background: transparent;
}
.scrollbar-thin::-webkit-scrollbar-thumb {
  background-color: rgba(161, 161, 170, 0.3);
  border-radius: 3px;
}
.dark .scrollbar-thin::-webkit-scrollbar-thumb {
  background-color: rgba(82, 82, 91, 0.3);
}

.tool-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.glass-panel {
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.dark .glass-panel {
  background-color: rgba(24, 24, 27, 0.8);
}

.msg p {
  white-space: pre-wrap;
}

/* Layout helpers for collapsible panels */
.layout-collapsed-left #left-panel {
  opacity: 0;
  pointer-events: none;
}

.layout-collapsed-right #right-panel {
  opacity: 0;
  pointer-events: none;
}

body.no-scroll {
  overflow: hidden;
  touch-action: none;
}

.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.mobile-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 1024px) {
  #main-layout {
    grid-template-columns: 0px 1fr 0px !important;
  }

  #main-layout.layout-mobile {
    grid-template-columns: 1fr !important;
  }

  #main-layout.layout-mobile > main {
    width: 100%;
    min-width: 0;
  }

  #main-layout.layout-mobile #left-panel,
  #main-layout.layout-mobile #right-panel {
    display: none;
  }

  #main-layout.layout-mobile.layout-mobile-left-open #left-panel {
    display: flex;
  }

  #main-layout.layout-mobile.layout-mobile-right-open #right-panel {
    display: block;
  }

  #left-panel,
  #right-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 40;
    width: 260px;
    max-width: 80vw;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.2);
  }

  #left-panel {
    left: 0;
    transform: translateX(-100%);
  }

  #right-panel {
    right: 0;
    transform: translateX(100%);
  }

  .layout-mobile-left-open #left-panel {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .layout-mobile-right-open #right-panel {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .layout-mobile-left-open main,
  .layout-mobile-right-open main {
    pointer-events: none;
  }

  #btnShowLeftPanel,
  #btnShowRightPanel {
    top: 5rem;
  }

  #view-templates .template-panel {
    border-right: none;
  }
}

@media (max-width: 768px) {
  #view-templates .template-layout {
    grid-template-columns: 1fr;
  }

  #view-templates .template-panel {
    height: 45vh;
    border-bottom: 1px solid rgba(228, 228, 231, 0.8);
  }

  #view-templates .template-detail {
    height: calc(55vh - 1px);
  }
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fadeIn 0.3s ease-out forwards;
}

@keyframes highlightPulse {
  0% {
    background-color: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.5);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.1);
  }
  100% {
    background-color: transparent;
    border-color: inherit; /* Fallback to default border */
    box-shadow: none;
  }
}

.just-updated input {
  animation: highlightPulse 3000ms ease-out forwards;
}

.recently-updated {
  /* Legacy class support if needed, but we use just-updated on inputs now */
  transition: all 0.5s ease;
}

/* Markdown Rendering Styles (Prose) */
.prose {
  color: inherit;
  max-width: none;
  font-size: 0.95rem;
  line-height: 1.6;
}

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 600;
  line-height: 1.25;
  margin-top: 1.5em;
  margin-bottom: 0.75em;
  color: inherit;
}

.prose h1 { font-size: 1.5em; }
.prose h2 { font-size: 1.25em; }
.prose h3 { font-size: 1.1em; }
.prose h4 { font-size: 1em; }

.prose p {
  margin-top: 0.75em;
  margin-bottom: 0.75em;
}

.prose ul, .prose ol {
  margin-top: 0.75em;
  margin-bottom: 0.75em;
  padding-left: 1.5em;
}
.prose ul { list-style-type: disc; }
.prose ol { list-style-type: decimal; }

.prose li {
  margin-top: 0.25em;
  margin-bottom: 0.25em;
}

.prose strong { font-weight: 600; }
.prose em { font-style: italic; }

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85em;
  padding: 0.2em 0.4em;
  border-radius: 0.375em;
  background-color: rgba(156, 163, 175, 0.15);
  font-weight: 500;
}
.dark .prose code {
  background-color: rgba(156, 163, 175, 0.2);
}

.prose pre {
  margin-top: 1em;
  margin-bottom: 1em;
  padding: 1em;
  border-radius: 0.5em;
  background-color: rgba(39, 39, 42, 0.05);
  overflow-x: auto;
  border: 1px solid rgba(0,0,0,0.05);
}
.dark .prose pre {
  background-color: rgba(24, 24, 27, 0.6);
  border-color: rgba(255,255,255,0.05);
}

.prose pre code {
  background-color: transparent;
  padding: 0;
  font-size: inherit;
  border: none;
}

.prose table {
  width: 100%;
  margin-top: 1em;
  margin-bottom: 1em;
  border-collapse: collapse;
  font-size: 0.9em;
}

.prose thead {
  border-bottom: 2px solid rgba(212, 212, 216, 0.8);
}
.dark .prose thead {
  border-color: rgba(82, 82, 91, 0.8);
}

.prose th {
  padding: 0.5em 0.75em;
  text-align: left;
  font-weight: 600;
}

.prose td {
  padding: 0.5em 0.75em;
  border-bottom: 1px solid rgba(212, 212, 216, 0.5);
}
.dark .prose td {
  border-color: rgba(82, 82, 91, 0.5);
}

.prose blockquote {
  margin-top: 1em;
  margin-bottom: 1em;
  padding-left: 1em;
  border-left: 3px solid rgba(212, 212, 216, 0.8);
  font-style: italic;
  opacity: 0.8;
}
.dark .prose blockquote {
  border-color: rgba(82, 82, 91, 0.8);
}

.prose a {
  color: rgb(79, 70, 229);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.dark .prose a {
  color: rgb(129, 140, 248);
}
.prose a:hover {
  color: rgb(67, 56, 202);
}
.dark .prose a:hover {
  color: rgb(165, 180, 252);
}

.prose hr {
  margin-top: 2em;
  margin-bottom: 2em;
  border: 0;
  border-top: 1px solid rgba(212, 212, 216, 0.5);
}
.dark .prose hr {
  border-color: rgba(82, 82, 91, 0.5);
}

/* Tooltip / Popover Helpers */
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  margin-bottom: 5px;
  z-index: 50;
}

/* ========= KB Dashboard Styles ========= */

/* Upload drop zone */
.kb-drop-zone {
  transition: border-color 0.2s, background-color 0.2s;
}
.kb-drop-active {
  border-color: rgb(99, 102, 241) !important;
  background-color: rgba(99, 102, 241, 0.08) !important;
}

/* Toast notifications */
.kb-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  padding: 0.75rem 1.25rem;
  border-radius: 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: white;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 2.7s forwards;
  pointer-events: none;
}
.kb-toast.success { background-color: rgb(16, 185, 129); }
.kb-toast.error   { background-color: rgb(239, 68, 68); }
.kb-toast.info    { background-color: rgb(99, 102, 241); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(10px); }
}

/* Confirm modal backdrop */
.kb-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease-out;
}
.kb-modal-box {
  background: white;
  border-radius: 1rem;
  padding: 1.5rem;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}
.dark .kb-modal-box {
  background: rgb(24, 24, 27);
  border: 1px solid rgb(63, 63, 70);
}

/* Progress bar animation */
.kb-progress-bar {
  transition: width 0.5s ease-in-out;
}

/* Layout Fixes */
.dvh-screen {
  height: 100dvh;
}
