@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --ink: #111827;
  --ink-2: #374151;
  --ink-3: #6b7280;
  --ink-4: #9ca3af;
  --line: #e5e7eb;
  --line-2: #d1d5db;
  --dark: #1a1f2e;
  --dark-2: #252b3b;
  --dark-3: #2f3648;
  --dark-line: #334155;
  --dark-ink: #e2e8f0;
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --accent-soft: #e0f2fe;
  --accent-ring: rgba(14, 165, 233, 0.18);
  --success: #10b981;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --warn-bg: #fffbeb;
  --radius: 7px;
  --radius-sm: 5px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

body {
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: 52px 1fr;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 20px;
  background: var(--dark);
  border-bottom: 1px solid var(--dark-line);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-mark,
.auth-logo-mark {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--accent);
  color: #ffffff;
}

.logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.auth-logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.logo-mark svg,
.auth-logo-mark svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar-title,
.auth-logo-text {
  color: var(--dark-ink);
  font-weight: 700;
}

.topbar-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid rgba(14, 165, 233, 0.25);
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.12);
  color: var(--accent);
  font: 500 10px "JetBrains Mono", monospace;
  letter-spacing: 0;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--success);
}

.btn-ghost-dark {
  border: 1px solid var(--dark-line);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  background: transparent;
  color: rgba(226, 232, 240, 0.7);
  font-weight: 600;
}

.btn-ghost-dark:hover {
  background: var(--dark-2);
  color: var(--dark-ink);
}

.workspace {
  display: grid;
  grid-template-rows: 48px 1fr;
  min-height: 0;
}

.tabs {
  display: flex;
  align-items: end;
  gap: 4px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  height: 48px;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0 16px;
  background: transparent;
  color: var(--ink-3);
  font-weight: 700;
}

.tab-btn.active {
  border-bottom-color: var(--accent);
  color: var(--accent-dark);
}

.tab-panel {
  display: none;
  min-height: 0;
}

.tab-panel.active {
  display: grid;
}

#chat-panel {
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 0;
}

.chat-sidebar {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 16px;
  background: var(--dark);
  border-right: 1px solid var(--dark-line);
}

.btn-new-chat {
  width: 100%;
  border: 1px solid rgba(14, 165, 233, 0.35);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.btn-new-chat:hover,
.btn-run:hover,
.btn-upload:hover,
.btn-signin:hover {
  background: var(--accent-dark);
}

.chat-list {
  overflow-y: hidden;
  display: grid;
  align-content: start;
  gap: 6px;
}

.chat-sidebar:hover .chat-list,
.chat-sidebar:focus-within .chat-list {
  overflow-y: auto;
}

.chat-list-empty {
  padding: 14px 10px;
  color: rgba(226, 232, 240, 0.45);
  font-size: 12px;
}

.chat-list-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px;
  background: transparent;
  color: var(--dark-ink);
  text-align: left;
}

.chat-list-item:hover,
.chat-list-item.active {
  background: var(--dark-2);
  border-color: var(--dark-line);
}

.chat-list-main {
  min-width: 0;
  display: grid;
  gap: 3px;
  border: 0;
  border-radius: 4px;
  padding: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.chat-list-title {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.chat-pin {
  flex-shrink: 0;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(14, 165, 233, 0.14);
  color: var(--accent);
  font: 600 9px "JetBrains Mono", monospace;
  text-transform: uppercase;
}

.chat-list-date {
  color: rgba(226, 232, 240, 0.45);
  font-size: 11px;
}

.chat-item-menu {
  position: relative;
}

.chat-menu-trigger {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: rgba(226, 232, 240, 0.52);
  font-weight: 700;
  line-height: 1;
}

.chat-menu-trigger:hover {
  background: var(--dark-3);
  color: var(--dark-ink);
}

.chat-menu {
  position: absolute;
  top: 31px;
  right: 0;
  z-index: 20;
  display: none;
  width: 132px;
  padding: 5px;
  border: 1px solid var(--dark-line);
  border-radius: var(--radius-sm);
  background: var(--dark-2);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.26);
}

.chat-menu.open {
  display: grid;
}

.chat-menu button {
  width: 100%;
  border: 0;
  border-radius: 4px;
  padding: 7px 8px;
  background: transparent;
  color: var(--dark-ink);
  text-align: left;
  font-weight: 600;
}

.chat-menu button:hover {
  background: var(--dark-3);
}

.chat-menu button.danger {
  color: #fca5a5;
}

.chat-shell {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-head,
.upload-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.section-kicker {
  margin-bottom: 3px;
  color: var(--ink-4);
  font: 600 10px "JetBrains Mono", monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

.chat-messages {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 24px;
}

.message {
  max-width: min(760px, 92%);
  display: grid;
  gap: 7px;
}

.message.user {
  align-self: end;
}

.message.assistant {
  align-self: start;
}

.message-role {
  color: var(--ink-4);
  font: 600 10px "JetBrains Mono", monospace;
  text-transform: uppercase;
}

.message.user .message-role {
  text-align: right;
}

.message-body {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-2);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .message-body {
  border-color: rgba(14, 165, 233, 0.25);
  background: var(--accent-soft);
}

.message.loading .message-body {
  color: var(--ink-4);
  font-style: italic;
}

.message-sources {
  display: grid;
  gap: 5px;
}

.message-source-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-3);
  font-size: 12px;
}

.message-source-row span {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.source-asset-link {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
}

.source-asset-link:hover {
  text-decoration: underline;
}

.source-thumb {
  grid-column: 1 / -1;
  max-width: 180px;
  max-height: 120px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  object-fit: contain;
  background: var(--surface-2);
}

.source-visual-caption,
.source-visual-tags {
  grid-column: 1 / -1;
  color: var(--ink-3);
  font-size: 11px;
}

.source-visual-tags {
  color: var(--ink-4);
  font-family: "JetBrains Mono", monospace;
}

.message-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 9px;
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-sm);
  background: #ecfdf5;
  color: #047857;
  font-size: 12px;
}

.message-action code {
  color: #047857;
  font: 500 11px "JetBrains Mono", monospace;
}

.message-source-row code {
  color: var(--ink-4);
  font: 500 11px "JetBrains Mono", monospace;
}

.chat-composer {
  display: grid;
  gap: 0;
  margin: 0 24px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

#question {
  width: 100%;
  min-height: 84px;
  max-height: 220px;
  border: 0;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.query-options {
  display: flex;
  align-items: center;
  gap: 14px;
}

.opt-field,
.toggle-wrap,
.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
}

.opt-label {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

#top-k {
  width: 52px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 4px 7px;
  background: var(--surface);
  text-align: center;
  outline: none;
}

.toggle-wrap {
  cursor: pointer;
}

.checkbox-wrap {
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.checkbox-wrap input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

.toggle-wrap input {
  display: none;
}

.toggle-track {
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: var(--line-2);
  position: relative;
  transition: background 0.2s;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
}

.toggle-wrap input:checked ~ .toggle-track {
  background: var(--accent);
}

.toggle-wrap input:checked ~ .toggle-track .toggle-thumb {
  transform: translateX(13px);
}

.btn-run,
.btn-upload,
.btn-secondary,
.btn-signin {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.btn-secondary {
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink-2);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.btn-run[data-loading="true"] {
  opacity: 0.7;
  pointer-events: none;
}

#upload-panel {
  align-items: start;
  padding: 24px;
  overflow-y: auto;
}

.upload-shell {
  width: min(900px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.upload-head {
  display: block;
}

.upload-form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field-label {
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
}

.required {
  color: var(--danger);
}

.field-input,
.field-textarea,
.field-select {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

.field-textarea {
  resize: vertical;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.field-input:focus,
.field-textarea:focus,
.field-select:focus,
#question:focus,
#top-k:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.field-select {
  min-width: 170px;
}

.prompt-shell {
  width: min(1000px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.prompt-editor {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.prompt-actions {
  align-content: end;
}

.prompt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.prompt-import,
.prompt-save {
  display: flex;
  align-items: center;
  gap: 10px;
}

.prompt-import {
  flex: 1;
}

.prompt-import .field-input {
  max-width: 320px;
}

.prompt-save {
  justify-content: end;
  flex: 1;
}

.prompt-status {
  min-height: 20px;
  color: var(--ink-3);
  font-size: 12px;
}

#prompts-panel,
#functions-panel {
  align-items: start;
  padding: 24px;
  overflow-y: auto;
}

.function-shell {
  width: min(1000px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.function-list {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.function-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.function-card-head,
.function-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.function-title {
  margin-bottom: 3px;
  color: var(--ink);
  font-weight: 700;
}

.function-card code {
  color: var(--ink-4);
  font: 500 11px "JetBrains Mono", monospace;
}

.function-description {
  color: var(--ink-3);
  max-width: 760px;
}

.function-company-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
}

.function-company {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-weight: 600;
}

.function-company input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

.function-status {
  min-height: 20px;
  color: var(--ink-3);
  font-size: 12px;
}

.upload-notice {
  margin: 0 20px 20px;
  padding: 11px 13px;
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-sm);
  background: #ecfdf5;
  color: #047857;
}

.empty-state {
  flex: 1;
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--ink-4);
  text-align: center;
}

.empty-state.compact {
  min-height: 180px;
}

.empty-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.empty-icon svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

.chat-error {
  padding: 14px;
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: #b91c1c;
}

.auth-page {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-left {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 40px 48px;
  background: var(--dark);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-left-eyebrow {
  margin-bottom: 12px;
  color: var(--accent);
  font: 600 10px "JetBrains Mono", monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.auth-left-title {
  margin-bottom: 14px;
  color: var(--dark-ink);
  font-size: 26px;
  line-height: 1.25;
}

.auth-left-desc {
  max-width: 340px;
  color: rgba(226, 232, 240, 0.62);
}

.auth-features {
  display: grid;
  gap: 9px;
  margin-top: 28px;
}

.auth-feature {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(226, 232, 240, 0.7);
  font-size: 12px;
}

.auth-feature-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.auth-left-footer {
  color: rgba(226, 232, 240, 0.28);
  font: 500 11px "JetBrains Mono", monospace;
}

.auth-right {
  display: grid;
  place-items: center;
  padding: 40px;
}

.auth-form-shell {
  width: min(100%, 360px);
}

.auth-form-head {
  margin-bottom: 28px;
}

.auth-form-head h1 {
  margin-bottom: 4px;
}

.auth-form-head p {
  color: var(--ink-3);
}

.auth-field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.auth-field-label {
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
}

.auth-input {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  outline: none;
}

.auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.btn-signin {
  width: 100%;
  margin-top: 6px;
}

.auth-error,
.auth-warn {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.auth-error {
  border: 1px solid rgba(239, 68, 68, 0.22);
  background: var(--danger-bg);
  color: #b91c1c;
}

.auth-warn {
  border: 1px solid rgba(245, 158, 11, 0.25);
  background: var(--warn-bg);
  color: #92400e;
}

.auth-warn code {
  font: 500 11px "JetBrains Mono", monospace;
}

@media (max-width: 900px) {
  #chat-panel {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--dark-line);
  }

  .form-grid,
  .auth-page {
    grid-template-columns: 1fr;
  }

  .auth-left {
    display: none;
  }

  .composer-footer,
  .chat-head,
  .chat-head-actions,
  .prompt-footer,
  .prompt-import,
  .prompt-save {
    align-items: stretch;
    flex-direction: column;
  }

  .prompt-import .field-input {
    max-width: none;
  }

  .field-select {
    min-width: 0;
  }
}
