/* shadcn/ui design tokens - dark mode */
:root {
  --background: 224 71% 4%;
  --foreground: 213 31% 91%;
  --card: 224 71% 4%;
  --card-foreground: 213 31% 91%;
  --popover: 224 71% 4%;
  --popover-foreground: 213 31% 91%;
  --primary: 210 40% 98%;
  --primary-foreground: 222.2 47.4% 11.2%;
  --secondary: 222.2 47.4% 11.2%;
  --secondary-foreground: 210 40% 98%;
  --muted: 223 47% 11%;
  --muted-foreground: 215.4 16.3% 56.9%;
  --accent: 216 34% 17%;
  --accent-foreground: 210 40% 98%;
  --destructive: 0 63% 31%;
  --destructive-foreground: 210 40% 98%;
  --border: 216 34% 17%;
  --input: 216 34% 17%;
  --ring: 216 34% 17%;
  --radius: 0.5rem;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border-color: hsl(var(--border));
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout --- */

#app {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* --- Left Sidebar --- */

#sidebar {
  width: 260px;
  background: hsl(var(--card));
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar-header {
  padding: 16px;
  border-bottom: 1px solid hsl(var(--border));
}

#sidebar-header h2 {
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#conversation-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.convo-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  color: hsl(var(--foreground));
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}

.convo-item:hover {
  background: hsl(var(--accent));
}

.convo-item.active {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

#sidebar-footer {
  padding: 12px;
  border-top: 1px solid hsl(var(--border));
}

#new-chat-btn {
  width: 100%;
  padding: 10px 16px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

#new-chat-btn:hover {
  background: hsl(var(--accent));
}

/* --- Main Content --- */

#main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid hsl(var(--border));
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: hsl(var(--foreground));
}

.subtitle {
  font-size: 0.8rem;
  color: hsl(var(--muted-foreground));
  margin-top: 2px;
}

#chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* --- Messages --- */

.message {
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  max-width: 80%;
  font-size: 0.9rem;
}

.message.streaming::after {
  content: "\25CF";
  animation: blink 1s infinite;
  margin-left: 4px;
  color: hsl(var(--muted-foreground));
}

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

.message.user {
  background: hsl(217 91% 60%);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  border-bottom-left-radius: 4px;
  color: hsl(var(--foreground));
}

.message.assistant pre {
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.82rem;
}

.message.assistant code {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.82rem;
}

.message.assistant :not(pre) > code {
  background: hsl(var(--background));
  padding: 2px 5px;
  border-radius: 3px;
  border: 1px solid hsl(var(--border));
}

.message.assistant p {
  margin-bottom: 8px;
}

.message.assistant p:last-child {
  margin-bottom: 0;
}

.message.assistant h2,
.message.assistant h3,
.message.assistant h4 {
  margin: 12px 0 6px;
  color: hsl(var(--foreground));
}

.message.assistant ul,
.message.assistant ol {
  margin: 4px 0;
  padding-left: 20px;
}

.message.assistant li {
  margin-bottom: 2px;
}

.message.assistant strong {
  color: hsl(var(--foreground));
  font-weight: 600;
}

/* --- Tool Status --- */

.tool-status {
  display: none;
  padding: 8px 12px;
  background: hsl(var(--accent));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: hsl(217 91% 70%);
  margin-bottom: 8px;
  animation: pulse 1.5s ease-in-out infinite;
}

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

/* --- Query Traces --- */

.queries-section {
  margin-top: 12px;
  border-top: 1px solid hsl(var(--border));
  padding-top: 8px;
}

.queries-section summary {
  font-size: 0.78rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
}

.query-trace {
  margin-top: 8px;
  padding: 8px 10px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  font-size: 0.78rem;
}

.query-trace .sql {
  font-family: "SF Mono", "Fira Code", monospace;
  white-space: pre-wrap;
  color: hsl(var(--foreground));
}

.query-trace .meta {
  color: hsl(var(--muted-foreground));
  margin-top: 4px;
}

.query-trace .error {
  color: hsl(0 63% 50%);
}

.query-trace .cached {
  color: hsl(142 76% 46%);
  font-weight: 500;
}

/* --- Chat Form --- */

#chat-form {
  padding: 16px 24px;
  border-top: 1px solid hsl(var(--border));
}

.input-row {
  display: flex;
  gap: 8px;
}

#input {
  flex: 1;
  padding: 10px 14px;
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  color: hsl(var(--foreground));
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  outline: none;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

#input::placeholder {
  color: hsl(var(--muted-foreground));
}

#input:focus {
  border-color: hsl(217 91% 60%);
  box-shadow: 0 0 0 2px hsl(217 91% 60% / 0.2);
}

#send-btn {
  padding: 10px 20px;
  background: hsl(217 91% 60%);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

#send-btn:hover {
  background: hsl(217 91% 50%);
}

#send-btn:disabled {
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  cursor: not-allowed;
}

.input-hints {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  margin-top: 6px;
}

/* --- Right Sidebar --- */

#right-sidebar {
  width: 320px;
  background: hsl(var(--card));
  border-left: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#right-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid hsl(var(--border));
}

#right-sidebar-header h2 {
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#ontology-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#auto-send-footer {
  border-top: 1px solid hsl(var(--border));
  padding: 12px 16px;
  background: hsl(var(--card));
}

.auto-send-toggle {
  font-size: 0.8rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.auto-send-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: hsl(217 91% 60%);
  cursor: pointer;
}

/* --- Ontology Tree --- */

.ontology-category {
  border-radius: var(--radius);
  margin-bottom: 1px;
}

.ontology-category > summary {
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.15s;
  list-style: none;
}

.ontology-category > summary::before {
  content: "\25B8  ";
  font-size: 0.7rem;
  color: hsl(var(--muted-foreground));
}

.ontology-category[open] > summary::before {
  content: "\25BE  ";
}

.ontology-category > summary:hover {
  background: hsl(var(--accent));
}

.ontology-category .ontology-category {
  margin-left: 8px;
  border-left: 1px solid hsl(var(--border));
  padding-left: 4px;
}

.ontology-questions {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ontology-question {
  padding: 5px 12px 5px 28px;
  font-size: 0.78rem;
  color: hsl(217 91% 70%);
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.ontology-question:hover {
  background: hsl(var(--accent));
}

/* --- Scrollbar Styling --- */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground));
}

/* --- Responsive --- */

@media (max-width: 1024px) {
  #right-sidebar {
    display: none;
  }
}

@media (max-width: 768px) {
  #sidebar {
    display: none;
  }
}
