/* ── Reset & base ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #171717;
  --bg-secondary: #212121;
  --bg-sidebar: #171717;
  --bg-input: #2a2a2a;
  --bg-user-msg: #303030;
  --bg-assistant-msg: transparent;
  --text-primary: #ececec;
  --text-secondary: #a0a0a0;
  --border-color: #333;
  --accent: #10a37f;
  --accent-hover: #0d8c6d;
  --danger: #ef4444;
  --radius: 12px;
  --sidebar-width: 280px;
  --max-chat-width: 768px;
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

body {
  display: flex;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 3px;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.2s ease;
  overflow: hidden;
}

.sidebar.hidden {
  margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-header button {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-header button:hover {
  background: var(--accent);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversation-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.conversation-item:hover {
  background: var(--bg-input);
}

.conversation-item.active {
  background: var(--bg-input);
}

.conversation-item .delete-btn {
  display: none;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}

.conversation-item:hover .delete-btn {
  display: inline-block;
}

/* ── SPARQL editor in sidebar ── */
.sparql-editor {
  border-top: 1px solid var(--border-color);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sparql-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sparql-editor-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#sparql-input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 12px;
  padding: 8px;
  resize: vertical;
  min-height: 120px;
  max-height: 300px;
  outline: none;
  line-height: 1.5;
}

#sparql-input:focus {
  border-color: var(--accent);
}

#sparql-run-btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}

#sparql-run-btn:hover {
  background: var(--accent-hover);
}

#sparql-run-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Graph overlay ── */
.graph-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.graph-overlay.hidden {
  display: none;
}

.graph-panel {
  width: 90vw;
  height: 85vh;
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.graph-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.graph-container {
  flex: 1;
  width: 100%;
  min-height: 500px;
  background: #0d0d0d;
  position: relative;
}

.graph-error {
  padding: 16px;
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}

.graph-error.hidden {
  display: none;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  text-align: center;
}

.brand {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Chat area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  height: 52px;
}

.chat-header h1 {
  font-size: 16px;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.icon-btn:hover {
  background: var(--bg-input);
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.welcome {
  text-align: center;
  margin: auto;
  max-width: 500px;
}

.welcome h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.welcome p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}

.message-row {
  display: flex;
  justify-content: center;
  width: 100%;
}

.message {
  max-width: var(--max-chat-width);
  width: 100%;
  padding: 16px 20px;
  line-height: 1.6;
  font-size: 15px;
  border-radius: var(--radius);
}

.message.user {
  background: var(--bg-user-msg);
  margin-left: auto;
  max-width: 85%;
  width: fit-content;
  align-self: flex-end;
}

.message.assistant {
  background: var(--bg-assistant-msg);
}

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

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

.message pre {
  background: #1a1a2e;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  margin: 8px 0;
}

.message code {
  font-family: "Fira Code", "Consolas", monospace;
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Figure images ── */
.figure-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.figure-image {
  max-width: 100%;
  max-height: 400px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: opacity 0.15s;
  object-fit: contain;
  background: #1a1a1a;
}

.figure-image:hover {
  opacity: 0.85;
}

/* ── SPARQL badge ── */
.sparql-badge {
  max-width: var(--max-chat-width);
  width: 100%;
  background: #1a2332;
  border: 1px solid #2a3a4a;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 4px;
}

.sparql-badge-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #6cb4ee;
  font-weight: 500;
}

.sparql-toggle {
  background: none;
  border: 1px solid #2a3a4a;
  color: #6cb4ee;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.sparql-toggle:hover {
  background: #2a3a4a;
}

.sparql-code {
  margin-top: 8px;
  background: #0d1620;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 12px;
  color: #c0d0e0;
  white-space: pre-wrap;
}

.sparql-code.hidden {
  display: none;
}

/* ── Input area ── */
.input-area {
  padding: 16px;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.input-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 10px 16px;
  width: 100%;
  max-width: var(--max-chat-width);
  transition: border-color 0.15s;
}

.input-form:focus-within {
  border-color: var(--accent);
}

.input-form textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
}

.input-form textarea::placeholder {
  color: var(--text-secondary);
}

.input-form button[type="submit"] {
  background: var(--accent);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.input-form button[type="submit"]:hover {
  background: var(--accent-hover);
}

.input-form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.disclaimer {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
  text-align: center;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    z-index: 100;
    height: 100%;
  }

  .sidebar.hidden {
    margin-left: calc(-1 * var(--sidebar-width));
  }
}
