/* ClearCourse Insights — chat UI
   Adapted from the ClearCourse house style:
   --cc-orange #ff4f00 reserved for CTAs/active
   --cc-cream  #fffefb page bg
   --cc-ink    #201515 body + headings
   --cc-ink-soft #5a4f4f secondary
   --cc-sand   #c5c0b1 borders
*/

:root {
  --cc-orange: #ff4f00;
  --cc-cream: #fffefb;
  --cc-ink: #201515;
  --cc-ink-soft: #5a4f4f;
  --cc-sand: #c5c0b1;
  --cc-sand-soft: #e8e4d8;

  --radius: 4px;
  --max-width: 920px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cc-cream);
  color: var(--cc-ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  height: 100%;
}

body { display: flex; flex-direction: column; }

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--cc-cream);
}

/* --- Header --- */

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: inline-block;
  width: 14px;
  height: 14px;
  background: var(--cc-orange);
  border-radius: 2px;
}

.header-meta {
  display: flex;
  gap: 8px;
}

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  background: var(--cc-sand-soft);
  border: 1px solid var(--cc-sand);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--cc-ink-soft);
  cursor: pointer;
}

.status-pill.ok { background: #e8f0e3; border-color: #b8d8a8; color: #2d5016; }
.status-pill.error { background: #f5e3e3; border-color: #d8a8a8; color: #6b1a1a; }

/* --- Chat area --- */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

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

.message-body {
  max-width: 86%;
  padding: 12px 16px;
  border: 1px solid var(--cc-sand);
  border-radius: var(--radius);
  background: var(--cc-cream);
}

.message--user .message-body {
  background: var(--cc-ink);
  color: var(--cc-cream);
  border-color: var(--cc-ink);
}

.message--system .message-body {
  background: var(--cc-sand-soft);
  border-color: var(--cc-sand);
  color: var(--cc-ink-soft);
  max-width: 100%;
}

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

.muted { color: var(--cc-ink-soft); font-size: 0.9rem; }

/* --- SQL editor block --- */

.sql-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.sql-block-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cc-ink-soft);
  font-weight: 600;
}

.sql-editor {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  padding: 12px;
  border: 1px solid var(--cc-sand);
  border-radius: var(--radius);
  background: #fcfaf3;
  color: var(--cc-ink);
  resize: vertical;
  min-height: 60px;
}

.sql-editor:focus {
  outline: none;
  border-color: var(--cc-orange);
  background: var(--cc-cream);
}

.sql-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sql-status { font-size: 0.85rem; color: var(--cc-ink-soft); margin-left: auto; }

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--cc-sand);
  border-radius: var(--radius);
  background: var(--cc-cream);
  color: var(--cc-ink);
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn:hover { border-color: var(--cc-ink); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary {
  background: var(--cc-orange);
  border-color: var(--cc-orange);
  color: var(--cc-cream);
}

.btn--primary:hover { background: #e84600; border-color: #e84600; }
.btn--primary:disabled { background: var(--cc-sand); border-color: var(--cc-sand); color: var(--cc-ink-soft); }

.btn--small { padding: 4px 10px; font-size: 0.8rem; }

/* --- Results table --- */

.results-block {
  margin: 12px 0;
  border: 1px solid var(--cc-sand);
  border-radius: var(--radius);
  overflow: hidden;
}

.results-meta {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--cc-sand-soft);
  font-size: 0.78rem;
  color: var(--cc-ink-soft);
  border-bottom: 1px solid var(--cc-sand);
}

.results-table-wrap {
  max-height: 320px;
  overflow: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.results-table th, .results-table td {
  padding: 6px 12px;
  text-align: left;
  border-bottom: 1px solid var(--cc-sand-soft);
  white-space: nowrap;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-table th {
  font-weight: 700;
  background: var(--cc-cream);
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--cc-sand);
}

.results-table tr:nth-child(even) td { background: #fcfaf3; }

/* --- Composer --- */

.composer {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--cc-sand);
  background: var(--cc-cream);
  flex-shrink: 0;
}

#question-input {
  flex: 1;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--cc-sand);
  border-radius: var(--radius);
  background: var(--cc-cream);
  color: var(--cc-ink);
  resize: none;
}

#question-input:focus { outline: none; border-color: var(--cc-ink); }

/* --- Status / errors --- */

.status-line {
  font-size: 0.78rem;
  color: var(--cc-ink-soft);
  font-style: italic;
  margin: 4px 0;
}

.error-block {
  padding: 10px 14px;
  background: #f5e3e3;
  border: 1px solid #d8a8a8;
  border-radius: var(--radius);
  color: #6b1a1a;
  font-size: 0.9rem;
  margin: 8px 0;
}

/* --- Streaming cursor --- */

.streaming-cursor::after {
  content: "▍";
  color: var(--cc-orange);
  animation: blink 1s step-end infinite;
  margin-left: 1px;
}

@keyframes blink { 50% { opacity: 0; } }

/* --- Mobile --- */

@media (max-width: 720px) {
  .app-header { padding: 12px 16px; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px; }
  .message-body { max-width: 92%; }
}
