/* ── Reset + Variables ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --teal:       #00897B;
  --teal-dark:  #00695C;
  --teal-light: #E0F2F1;
  --white:      #FFFFFF;
  --grey-bg:    #F5F5F5;
  --grey-text:  #757575;
  --grey-border:#E0E0E0;
  --user-bg:    #00897B;
  --user-text:  #FFFFFF;
  --bot-bg:     #FFFFFF;
  --bot-text:   #212121;
  --status-text:#9E9E9E;
  --error-text: #D32F2F;
  --max-width:  720px;
  --header-h:   56px;
  --input-h:    68px;
  --debug-h:    48px;  /* updated by JS — full debug panel height incl. toggle */
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  color: #212121;
  background: var(--grey-bg);
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--teal);
  color: var(--white);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
}

.header-icon  { font-size: 22px; }
.header-title { font-size: 16px; font-weight: 600; flex: 1; }
.header-sub   { font-size: 12px; opacity: .75; }

/* ── Chat area ───────────────────────────────────────────────────────────── */
.chat-area {
  position: fixed;
  top: var(--header-h);
  bottom: calc(var(--input-h) + var(--debug-h));
  left: 0; right: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Centre on wide screens */
.chat-area > * {
  max-width: var(--max-width);
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

/* ── Bubbles ─────────────────────────────────────────────────────────────── */
.bubble {
  border-radius: 16px;
  padding: 12px 16px;
  line-height: 1.55;
  font-size: 15px;
  word-break: break-word;
  max-width: 85%;
}

.bot-bubble {
  background: var(--bot-bg);
  color: var(--bot-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.user-bubble {
  background: var(--user-bg);
  color: var(--user-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

/* Status / typing indicator */
.status-bubble {
  background: transparent;
  color: var(--status-text);
  font-style: italic;
  font-size: 13px;
  align-self: flex-start;
  padding: 4px 8px;
  box-shadow: none;
}

/* Clarify option buttons */
.clarify-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.clarify-btn {
  background: var(--teal-light);
  color: var(--teal-dark);
  border: 1.5px solid var(--teal);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}

.clarify-btn:hover {
  background: var(--teal);
  color: var(--white);
}

/* ── Debug panel ─────────────────────────────────────────────────────────── */
.debug-panel {
  position: fixed;
  bottom: var(--input-h);
  left: 0; right: 0;
  background: #263238;
  color: #CFD8DC;
  z-index: 90;
  font-size: 12px;
}

.debug-toggle {
  width: 100%;
  background: #37474F;
  color: #CFD8DC;
  border: none;
  padding: 6px 16px;
  text-align: left;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
}

.debug-toggle:hover { background: #455A64; }

.debug-content {
  padding: 10px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 24px;
  max-width: var(--max-width);
  margin: 0 auto;
  max-height: 240px;
  overflow-y: auto;
}

.debug-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.debug-label {
  font-size: 10px;
  text-transform: uppercase;
  color: #78909C;
  letter-spacing: .06em;
}

.debug-value {
  font-size: 13px;
  color: #E0F2F1;
  word-break: break-all;
}

.debug-value.warn { color: #FFB74D; }
.debug-value.ok   { color: #81C784; }

.debug-divider {
  grid-column: 1 / -1;
  border-top: 1px solid #37474F;
  margin: 2px 0;
}

.debug-row--full {
  grid-column: 1 / -1;
}

/* Timings chart — spans full width of debug panel */
.timings-chart {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 2px;
}

.timing-row {
  display: grid;
  grid-template-columns: 90px 1fr 52px;
  align-items: center;
  gap: 8px;
}

.timing-label {
  font-size: 11px;
  color: #90A4AE;
  white-space: nowrap;
}

.timing-bar-wrap {
  height: 8px;
  background: #37474F;
  border-radius: 4px;
  overflow: hidden;
}

.timing-bar {
  height: 100%;
  border-radius: 4px;
  background: #4DB6AC;
  transition: width 0.3s ease;
}

.timing-bar.bar-rerank { background: #FF8A65; }
.timing-bar.bar-llm    { background: #64B5F6; }
.timing-bar.bar-zero   { background: transparent; }

.timing-ms {
  font-size: 11px;
  color: #B0BEC5;
  text-align: right;
}

.timing-ms.timing-skipped {
  color: #546E7A;
  font-style: italic;
}

/* ── Input bar ───────────────────────────────────────────────────────────── */
.input-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--input-h);
  background: var(--white);
  border-top: 1px solid var(--grey-border);
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  gap: 10px;
  z-index: 100;
}

.message-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--grey-border);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
  transition: border-color .15s;
}

.message-input:focus {
  border-color: var(--teal);
}

.send-btn {
  background: var(--teal);
  color: var(--white);
  border: none;
  border-radius: 24px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}

.send-btn:hover  { background: var(--teal-dark); }
.send-btn:disabled {
  background: var(--grey-border);
  cursor: not-allowed;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-thumb { background: #BDBDBD; border-radius: 2px; }

/* ── Mode toggle ─────────────────────────────────────────────────────────── */
.mode-toggle {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--teal);
  border-radius: 20px;
  overflow: hidden;
  flex-shrink: 0;
}

.mode-btn {
  background: transparent;
  color: var(--teal);
  border: none;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
  font-family: inherit;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--teal);
  color: var(--white);
}

.mode-btn:not(.active):hover {
  background: var(--teal-light);
}

/* ── Compare area ────────────────────────────────────────────────────────── */
.compare-area {
  position: fixed;
  top: var(--header-h);
  bottom: calc(var(--input-h) + var(--debug-h));
  left: 0; right: 0;
  overflow-y: auto;
  padding: 16px;
  display: none;
  background: var(--grey-bg);
}

.compare-placeholder {
  text-align: center;
  color: var(--grey-text);
  font-size: 14px;
  margin-top: 40px;
}

.compare-query {
  background: var(--user-bg);
  color: var(--white);
  border-radius: 16px 16px 4px 16px;
  padding: 12px 16px;
  font-size: 15px;
  max-width: 600px;
  margin: 0 auto 12px auto;
  word-break: break-word;
}

.compare-status {
  text-align: center;
  color: var(--grey-text);
  font-size: 13px;
  font-style: italic;
  margin-bottom: 16px;
}

.compare-status.done  { color: var(--teal-dark); font-style: normal; font-weight: 600; }
.compare-status.error { color: var(--error-text); font-style: normal; }

/* ── Compare card grid ───────────────────────────────────────────────────── */
.compare-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .compare-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .compare-grid { grid-template-columns: 1fr; }
}

/* ── Individual compare card ─────────────────────────────────────────────── */
.compare-card {
  background: var(--white);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: cardIn .2s ease;
}

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

.compare-card.loading {
  min-height: 100px;
  justify-content: space-between;
}

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

.provider-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 2px 7px;
  border-radius: 10px;
  flex-shrink: 0;
}

.badge-groq       { background: #e8f5e9; color: #2e7d32; }
.badge-cerebras   { background: #ede7f6; color: #5e35b1; }
.badge-openrouter { background: #fff3e0; color: #e65100; }

.provider-sub-label {
  font-size: 10px;
  font-weight: 600;
  color: #888;
  padding: 2px 5px;
  background: #f5f5f5;
  border-radius: 8px;
  flex-shrink: 0;
}

.card-model-name {
  font-size: 12px;
  color: var(--grey-text);
  word-break: break-all;
  flex: 1;
}

.card-meta {
  font-size: 11px;
  color: #9E9E9E;
}

.card-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--bot-text);
  word-break: break-word;
  white-space: pre-wrap;
}

/* ── Spinner (loading state) ─────────────────────────────────────────────── */
.card-spinner {
  display: flex;
  gap: 5px;
  justify-content: center;
  padding: 12px 0;
}

.dot {
  width: 7px; height: 7px;
  background: var(--teal-light);
  border-radius: 50%;
  animation: bounce .9s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: .5; }
  40%            { transform: scale(1);   opacity: 1; }
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .header-sub { display: none; }
  .bubble     { max-width: 92%; }
  .debug-content { grid-template-columns: 1fr; }
  .mode-btn   { padding: 6px 10px; font-size: 12px; }
}
