:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --user-bubble: #2563eb;
  --user-bubble-text: #ffffff;
  --assistant-bubble: #eef1f5;
  --assistant-bubble-text: #1a1d23;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app {
  display: flex;
  height: 100vh;
}

.app[hidden] {
  display: none;
}

/* -- sidebar -------------------------------------------------------------------------------- */

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.sidebar-header-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.customer-label {
  overflow-wrap: anywhere;
}

/* -- login ---------------------------------------------------------------------------------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
}

.login-hint {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.login-card label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.login-card input {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--panel);
  color: var(--text);
}

.login-error {
  margin: 0;
  padding: 8px 12px;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: var(--radius);
  font-size: 14px;
}

.login-error[hidden] {
  display: none;
}

.login-card .btn-primary {
  margin-top: 8px;
}

.sidebar-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 16px 0 8px;
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 2px;
}

.conversation-delete-btn {
  flex: none;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.conversation-delete-btn:hover,
.conversation-delete-btn:focus-visible {
  background: #fde8e8;
  color: #b3261e;
}

.conversation-item-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-item-btn:hover {
  background: var(--bg);
}

.conversation-item-btn.active {
  background: #e8f0fe;
}

.conversation-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-updated {
  font-size: 11px;
  color: var(--text-muted);
}

/* -- main chat area --------------------------------------------------------------------- */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.chat-header h1 {
  font-size: 18px;
  margin: 0;
}

.status-banner {
  margin: 12px 24px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 70%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message.role-user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.role-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message-role {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.message-text {
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.5;
}

.message.role-user .message-text {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
}

.message.role-assistant .message-text {
  background: var(--assistant-bubble);
  color: var(--assistant-bubble-text);
}

.message.thinking .message-text {
  color: var(--text-muted);
  font-style: italic;
}

.message-basis {
  font-size: 11px;
  color: var(--text-muted);
  align-self: center;
}

.message-actions {
  display: flex;
  gap: 8px;
}

.message-sql {
  max-width: 100%;
  overflow-x: auto;
  background: #0f172a;
  color: #e2e8f0;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 12px;
}

/* -- suggestions / match options ------------------------------------------------------------ */

.suggestions,
.match-options {
  padding: 0 24px 12px;
}

.suggestions-label,
.match-options-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.suggestion-chips,
.match-options-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 13px;
  cursor: pointer;
  max-width: 100%;
  text-align: left;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* -- ask form --------------------------------------------------------------------------- */

.ask-form {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.question-input {
  flex: 1;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
}

/* -- buttons ---------------------------------------------------------------------------- */

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-link {
  background: none;
  color: var(--text-muted);
  text-decoration: underline;
  padding: 4px 0;
}

/* -- 404 page (error.html) ---------------------------------------------------------------- */

.error-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.error-page main {
  text-align: center;
}
