:root {
  --bg-primary: #f8f9fb;
  --bg-surface: #ffffff;
  --bg-user-msg: #e8f0fe;
  --bg-ai-msg: #ffffff;
  --bg-code: #1e1e2e;
  --bg-input: #ffffff;
  --bg-chip: #f0f2f5;
  --bg-chip-hover: #e2e6ea;
  --bg-copy-btn: rgba(255, 255, 255, 0.12);
  --bg-copy-btn-hover: rgba(255, 255, 255, 0.2);

  --text-primary: #1a1a2e;
  --text-secondary: #5f6368;
  --text-muted: #9aa0a6;
  --text-code: #cdd6f4;
  --text-on-accent: #ffffff;

  --accent: #4a6cf7;
  --accent-hover: #3b5de7;
  --accent-light: #e8f0fe;

  --border: #e0e3e8;
  --border-input: #d1d5db;
  --border-input-focus: #4a6cf7;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;

  --max-width: 800px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-accent);
  font-weight: 700;
  font-size: 14px;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-new-chat {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-new-chat:hover {
  background: var(--bg-chip);
  color: var(--text-primary);
}

/* Messages area */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  scroll-behavior: smooth;
}

.messages-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 24px;
  text-align: center;
}

.welcome-icon {
  width: 56px;
  height: 56px;
  background: var(--accent-light);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 16px;
}

.welcome h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}

.welcome p {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 480px;
  line-height: 1.6;
  margin-bottom: 32px;
}

/* Example chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 600px;
}

.chip {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.chip:hover {
  background: var(--bg-chip-hover);
  color: var(--text-primary);
  border-color: var(--border-input);
}

.btn-refresh-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  transition: all 0.15s ease;
}

.btn-refresh-chips:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.btn-refresh-chips:active svg {
  transform: rotate(180deg);
}

.btn-refresh-chips svg {
  transition: transform 0.3s ease;
}

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.message-user .message-avatar {
  background: var(--accent);
  color: var(--text-on-accent);
}

.message-ai .message-avatar {
  background: var(--bg-chip);
  color: var(--text-secondary);
}

.message-content {
  max-width: 85%;
  line-height: 1.6;
  font-size: 14px;
}

.message-user .message-content {
  background: var(--bg-user-msg);
  padding: 10px 16px;
  border-radius: var(--radius-md) var(--radius-sm) var(--radius-md) var(--radius-md);
}

.message-ai .message-content {
  background: var(--bg-ai-msg);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius-md) var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-sm);
}

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

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

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

.message-content li {
  margin-bottom: 4px;
}

.message-content strong {
  font-weight: 600;
}

.message-content code:not(.hljs) {
  background: var(--bg-chip);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* SQL code blocks */
.sql-block {
  position: relative;
  margin: 12px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.sql-block-header {
  background: #181825;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sql-block-lang {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-copy {
  background: var(--bg-copy-btn);
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  color: #a6adc8;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-copy:hover {
  background: var(--bg-copy-btn-hover);
  color: #cdd6f4;
}

.btn-copy.copied {
  color: #a6e3a1;
}

.sql-block pre {
  margin: 0;
  padding: 14px 16px;
  background: var(--bg-code);
  overflow-x: auto;
}

.sql-block pre code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-code);
}

/* Thinking indicator */
.thinking {
  display: flex;
  gap: 12px;
  animation: fadeIn 0.25s ease;
}

.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
  background: var(--bg-ai-msg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius-md) var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.thinking-dot {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.thinking-dot:nth-child(1) { animation-delay: -0.32s; }
.thinking-dot:nth-child(2) { animation-delay: -0.16s; }
.thinking-dot:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.input-area {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 16px;
  flex-shrink: 0;
}

.input-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.input-wrapper textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-input);
  resize: none;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  min-height: 48px;
  max-height: 160px;
}

.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.input-wrapper textarea:focus {
  border-color: var(--border-input-focus);
  box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
}

.btn-send {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-send svg {
  width: 20px;
  height: 20px;
  fill: var(--text-on-accent);
}

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
}

/* Schema drawer toggle button */
.drawer-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.drawer-toggle:hover {
  background: var(--bg-chip);
  color: var(--text-primary);
}

.drawer-toggle--active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.drawer-toggle-count {
  font-size: 11px;
  background: var(--bg-chip);
  border-radius: var(--radius-full);
  padding: 1px 6px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}

.drawer-toggle--active .drawer-toggle-count {
  background: var(--accent);
  color: white;
}

/* Schema drawer panel */
.schema-drawer {
  position: fixed;
  top: 57px;
  left: 0;
  bottom: 0;
  width: 320px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

.schema-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.schema-drawer-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

.schema-drawer-badge {
  font-size: 11px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  font-weight: 600;
}

.schema-drawer-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.schema-drawer-close:hover {
  background: var(--bg-chip);
  color: var(--text-primary);
}

.schema-drawer-search {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.schema-drawer-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.schema-drawer-search input:focus {
  border-color: var(--border-input-focus);
}

.schema-drawer-search input::placeholder {
  color: var(--text-muted);
}

.schema-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* Schema groups */
.schema-group {
  margin-bottom: 2px;
}

.schema-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  transition: background 0.1s ease;
}

.schema-group-header:hover {
  background: var(--bg-chip);
}

.schema-group-arrow {
  transition: transform 0.15s ease;
  flex-shrink: 0;
  color: var(--text-muted);
}

.schema-group-arrow--open {
  transform: rotate(90deg);
}

.schema-group-name {
  flex: 1;
  text-align: left;
}

.schema-group-count {
  font-size: 10px;
  background: var(--bg-chip);
  border-radius: var(--radius-full);
  padding: 1px 6px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Schema field rows */
.schema-group-fields {
  padding: 0 8px 4px;
}

.schema-field {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s ease;
  text-align: left;
}

.schema-field:hover {
  background: var(--bg-chip);
}

.schema-field--copied {
  background: rgba(74, 108, 247, 0.08);
}

.schema-field-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.schema-field-type {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.schema-field-check {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  font-family: var(--font-sans);
  white-space: nowrap;
}

.schema-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* Domain Rules button */
.btn-domain-rules {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-domain-rules:hover {
  background: var(--bg-chip);
  color: var(--text-primary);
}

/* Domain Rules drawer */
.rules-drawer {
  position: fixed;
  top: 57px;
  right: 0;
  bottom: 0;
  width: 380px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.2s ease;
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.rules-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.rules-drawer-title {
  font-size: 14px;
  font-weight: 600;
}

.rules-drawer-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rules-drawer-close:hover {
  background: var(--bg-chip);
  color: var(--text-primary);
}

.rules-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.rules-drawer-loading {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 14px;
}

.rules-drawer-content {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-primary);
}

.rules-drawer-content h1 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.rules-drawer-content h2 {
  font-size: 13px;
  font-weight: 600;
  margin-top: 16px;
  margin-bottom: 6px;
  color: var(--accent);
}

.rules-drawer-content p {
  margin-bottom: 8px;
}

.rules-drawer-content ul,
.rules-drawer-content ol {
  margin: 6px 0;
  padding-left: 18px;
}

.rules-drawer-content li {
  margin-bottom: 3px;
}

.rules-drawer-content code {
  background: var(--bg-chip);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.rules-drawer-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 11.5px;
}

.rules-drawer-content th,
.rules-drawer-content td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  text-align: left;
}

.rules-drawer-content th {
  background: var(--bg-chip);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
}

.rules-drawer-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.rules-drawer-content strong {
  font-weight: 600;
}
