/* DBChat — Inetum-branded UI.
   Brand palette:
     Strong Blue     #232D4B  (primary surfaces / header)
     Lemon Yellow    #F5F340  (highlight accents)
     Vibrant Magenta #E20074  (actions / user)                             */

:root {
  --blue: #232D4B;
  --blue-700: #1b2540;
  --blue-600: #2c3860;
  --blue-500: #3a4877;
  --yellow: #F5F340;
  --magenta: #E20074;
  --magenta-600: #b8005e;

  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --border: #dfe4ee;
  --text: #1f2637;
  --muted: #6b7590;
  --shadow: 0 1px 3px rgba(35, 45, 75, 0.08), 0 6px 20px rgba(35, 45, 75, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: var(--blue);
  color: #fff;
  border-bottom: 3px solid var(--yellow);
  box-shadow: var(--shadow);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand .logo { height: 18px; width: auto; display: block; }
.brand .app-name {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.3px;
  padding-left: 0.85rem;
  border-left: 1px solid rgba(255, 255, 255, 0.25);
}

.controls { display: flex; align-items: center; gap: 0.75rem; }
.field { display: flex; align-items: center; gap: 0.5rem; }
.field label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.7);
}
.select-wrap { position: relative; }
.select-wrap::after {
  content: "▾";
  position: absolute;
  right: 0.6rem; top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted);
  font-size: 0.7rem;
}
.controls select {
  appearance: none;
  background: #fff;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.4rem 1.8rem 0.4rem 0.65rem;
  min-width: 13rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.controls select:focus { outline: 2px solid var(--yellow); outline-offset: 1px; }

.icon-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  width: 2rem; height: 2rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.22); }

.model-badge {
  font-size: 0.68rem;
  color: var(--blue);
  background: var(--yellow);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.model-badge:empty { display: none; }

/* ---------- Chat ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem clamp(1rem, 6vw, 5rem);
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.msg { display: flex; gap: 0.7rem; align-items: flex-start; max-width: 100%; }
.msg.user { flex-direction: row-reverse; }

/* Selected-database description (from its SQL COMMENT) */
.db-hint {
  align-self: center;
  max-width: min(760px, 90%);
  background: #fffdf0;
  border: 1px solid var(--yellow);
  border-left: 4px solid var(--yellow);
  color: #5b5730;
  font-size: 0.82rem;
  line-height: 1.4;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
}

.avatar {
  flex: 0 0 auto;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
}
.avatar.bot { background: var(--blue); }
.avatar.me { background: var(--magenta); }

.bubble {
  max-width: min(760px, 82%);
  padding: 0.8rem 1rem;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.assistant .bubble { border-top-left-radius: 4px; }
.msg.user .bubble {
  background: var(--magenta);
  border-color: var(--magenta);
  color: #fff;
  border-top-right-radius: 4px;
}
.bubble.intro { background: var(--surface-2); white-space: normal; }
.msg.error .bubble {
  background: #fdecef;
  border-color: #f5b8c6;
  color: #a4123a;
}

/* ---------- Rendered markdown inside assistant bubbles ---------- */
.bubble.markdown { white-space: normal; }
.bubble.markdown > :first-child { margin-top: 0; }
.bubble.markdown > :last-child { margin-bottom: 0; }
.bubble.markdown p { margin: 0.5em 0; }
.bubble.markdown h1,
.bubble.markdown h2,
.bubble.markdown h3,
.bubble.markdown h4 {
  margin: 0.9em 0 0.4em;
  line-height: 1.25;
  color: var(--blue);
  font-weight: 700;
}
.bubble.markdown h1 { font-size: 1.25rem; }
.bubble.markdown h2 { font-size: 1.12rem; }
.bubble.markdown h3 { font-size: 1rem; }
.bubble.markdown h4 { font-size: 0.9rem; }
.bubble.markdown ul,
.bubble.markdown ol { margin: 0.5em 0; padding-left: 1.4em; }
.bubble.markdown li { margin: 0.2em 0; }
.bubble.markdown a { color: var(--magenta); text-decoration: underline; }
.bubble.markdown strong { font-weight: 700; }
.bubble.markdown hr { border: none; border-top: 1px solid var(--border); margin: 0.9em 0; }
.bubble.markdown blockquote {
  margin: 0.6em 0;
  padding: 0.2em 0.9em;
  border-left: 3px solid var(--yellow);
  background: var(--surface-2);
  color: var(--muted);
}
.bubble.markdown code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.35em;
}
.bubble.markdown pre {
  margin: 0.6em 0;
  padding: 0.75em 0.9em;
  background: var(--blue);
  color: #eef1f6;
  border-radius: 8px;
  overflow-x: auto;
}
.bubble.markdown pre code {
  background: none;
  border: none;
  color: inherit;
  padding: 0;
  font-size: 0.82em;
}
/* markdown tables emitted by the model */
.bubble.markdown table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6em 0;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.bubble.markdown thead th {
  background: var(--blue);
  color: #fff;
  border-bottom: 2px solid var(--yellow);
}
.bubble.markdown th,
.bubble.markdown td {
  border: 1px solid var(--border);
  padding: 0.4em 0.6em;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  vertical-align: top;
}
.bubble.markdown td { max-width: 34ch; }
.bubble.markdown tbody tr:nth-child(even) { background: var(--surface-2); }

.bubble .thinking { display: inline-flex; gap: 3px; }
.bubble .thinking span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--magenta);
  animation: bounce 1.2s infinite ease-in-out;
}
.bubble .thinking span:nth-child(2) { animation-delay: 0.15s; }
.bubble .thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- Result tables ---------- */
.result {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.result .meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.7rem;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.result .sql {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  color: var(--blue);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70%;
}
.result .count { font-weight: 600; color: var(--magenta); white-space: nowrap; }
.table-wrap { overflow: auto; max-height: 360px; }
table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
th, td {
  text-align: left;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { white-space: nowrap; }
td {
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: 32rem;
}
thead th {
  position: sticky; top: 0;
  background: var(--blue);
  color: #fff;
  font-weight: 600;
  border-bottom: 2px solid var(--yellow);
}
tbody tr:nth-child(even) { background: var(--surface-2); }
tbody tr:hover { background: #fdf1f6; }
td.null { color: var(--muted); font-style: italic; }

/* ---------- Composer ---------- */
.composer {
  display: flex;
  gap: 0.6rem;
  padding: 0.9rem clamp(1rem, 6vw, 5rem);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(35, 45, 75, 0.04);
}
.composer textarea {
  flex: 1;
  resize: none;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  max-height: 160px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--magenta);
  box-shadow: 0 0 0 3px rgba(226, 0, 116, 0.12);
}
.composer button {
  background: var(--magenta);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0 1.4rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.composer button:hover:not(:disabled) { background: var(--magenta-600); }
.composer button:active:not(:disabled) { transform: translateY(1px); }
.composer button:disabled { opacity: 0.45; cursor: not-allowed; }

/* Scrollbars */
.chat::-webkit-scrollbar, .table-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.chat::-webkit-scrollbar-thumb, .table-wrap::-webkit-scrollbar-thumb {
  background: #c7cfe0; border-radius: 6px;
}

/* ---------- Footer ---------- */
.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.25rem;
  background: var(--blue-700);
  color: rgba(255, 255, 255, 0.75);
  border-top: 2px solid var(--yellow);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}
.footer .footer-app { font-weight: 600; color: #fff; }
.footer .footer-app #footer-version { color: var(--yellow); font-weight: 500; }
.footer .footer-sep { color: rgba(255, 255, 255, 0.35); }
.footer .footer-link {
  color: #fff;
  text-decoration: none;
  border-bottom: 1px solid rgba(245, 243, 64, 0.5);
  padding-bottom: 1px;
  transition: border-color 0.15s, color 0.15s;
}
.footer .footer-link:hover { color: var(--yellow); border-bottom-color: var(--yellow); }
