/* Design tokens */
:root {
  /* Colors */
  --color-bg: #222222; /* app background */
  --color-panel: #222222;
  --color-border: #ffffff;
  --color-answer-bg: #222222;
  --color-accent: #DB9B5B;
  --color-text: #ffffff;
  --color-text-dim: #dcdcdc;
  --color-user-bg: #DB9B5B;
  --color-user-border: #DB9B5B;
  --color-citation-bg: #f3f6fa;
  --color-ellipsis: #000000;
  --color-hl-bg: #fff59a55;
  --color-hl-outline: #fff59a80;

  /* Typography */
  --font-family: Inter, system-ui, sans-serif;
  --fs-xs: 11px;      /* footers, microcopy */
  --fs-sm: 12px;      /* muted text */
  --fs-subtle: 13px;  /* citations, helper text */
  --fs-body: 14px;    /* base body */
  --fs-header: 15px;  /* header title */
  --fs-button: 14px;  /* buttons */

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 6px;
  --space-3: 8px;
  --space-4: 10px;
  --space-5: 12px;
  --space-6: 14px;
  --space-7: 16px;
  --space-8: 18px;
  --space-9: 20px;
  --space-10: 30px;

  /* Layout */
  --container-max: 900px;
  --radius-0: 0;
  --shadow-modal: 0 8px 24px rgba(0,0,0,.08);

  /* Utilities */
  --text-rgb: 17,19,24; /* for gradient fades */
  --button-width: 140px; /* ensure reset and send buttons match size */
  --snippet-fade-px: 300px; /* pixel width of fade on both sides of the preview text */
  --snippet-fade-grey: #000000; /* black used for fade edges */
}

/* Base */
* { box-sizing: border-box; }
html, body { height: 100dvh; overflow: hidden; }
body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  height: 100dvh; /* prevent page scroll; we'll scroll only the messages list */
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: var(--container-max);
  width: 100%;
  margin: 0 auto;
  padding: 0; /* remove side and bottom padding */
  gap: 0; /* remove gap between chat-box and footer */
  overflow: hidden; /* ensure only inner messages can scroll */
}

/* Chat box: white panel that fills the available space */
.chat-box {
  background: var(--color-panel);
  border: none; /* remove all borders */
  display: flex;
  flex-direction: column;
  gap: var(--space-10);
  padding: var(--space-9);
  /* Make the box fill available vertical space within main */
  min-height: 0;
  flex: 1; /* fill the main area */
}

form { display: flex; flex-direction: column; gap: var(--space-4); }

.input-wrapper {
  position: relative;
  background: #1a1a1a;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: var(--space-4);
}

textarea {
  width: 100%;
  resize: none;
  min-height: 90px;
  max-height: 240px;
  padding: var(--space-4) var(--space-5);
  padding-right: 60px;
  font: inherit;
  border: none;
  background: transparent;
  color: #ffffff;
  outline: none;
  box-shadow: none;
}

textarea::placeholder {
  color: #999;
}

button {
  background: var(--color-accent);
  color: #fff;
  border: 1px solid var(--color-accent);
  padding: var(--space-5) var(--space-9);
  font-family: var(--font-family);
  font-weight: 600;
  font-size: var(--fs-button);
  line-height: 1;
  border-radius: var(--radius-0);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  width: var(--button-width);
  justify-content: center;
}

button:disabled { opacity: .6; cursor: not-allowed; }

.send-button {
  position: absolute;
  top: 50%;
  right: var(--space-4);
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  padding: 0 !important;
  margin: 0;
  border-radius: 50%;
  border: none !important;
  background: var(--color-accent) !important;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  gap: 0;
}

.send-button:hover:not(:disabled) {
  opacity: 0.9;
}

.send-button svg {
  width: 20px;
  height: 20px;
  transform: rotate(90deg);
}

#messages { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--space-8); overflow-y: auto; padding-right: var(--space-1); overscroll-behavior: contain; }

.bubble {
  background: #222222;
  color: #ffffff;
  padding: var(--space-6) var(--space-7);
  border: 1px solid #ffffff;
  border-radius: var(--radius-0);
  box-shadow: none;
}

/* Answer bubbles: explicit dark background with white text/border */
.bubble.answer {
  background: #222222;
  border: 1px solid #ffffff;
  color: #ffffff;
}

.user { align-self: flex-end; background: transparent; border: none; color: #ffffff; }

.answer h4 {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-body);
  font-weight: 600;
  color: #ffffff;
  letter-spacing: .3px;
  text-transform: uppercase;
}

.footer-content {
  /* Dark background box with white text */
  font-size: var(--fs-xs);
  color: #ffffff;
  text-align: center;
}

footer #resetBtn {
  align-self: center;
  display: none;
}

footer #resetBtn.show {
  display: inline-flex;
}

.citations { margin-top: var(--space-5); font-size: var(--fs-subtle); color: var(--color-text-dim); display: flex; flex-direction: column; gap: var(--space-2); }

.refs { margin-top: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.ref-item { display: flex; align-items: center; gap: var(--space-3); }

.muted { color: var(--color-text-dim); font-size: var(--fs-sm); }

.loading { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:.35} 50%{opacity:1} }

@keyframes revealClip {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

footer {
  /* Footer inherits width from main parent */
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.footer-content {
  /* Dark background box with white text */
  background: #222222;
  border: none; /* remove all borders */
  padding: calc(var(--space-2) * 2) var(--space-9);
  font-size: var(--fs-xs);
  color: #ffffff;
  text-align: center;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.toolbar { display: none; }
.btn-outline {
  background: var(--color-panel);
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
  padding: var(--space-8) var(--space-9);
  font-family: var(--font-family);
  font-weight: 400;
  font-size: 16px;
  line-height: 1;
  border-radius: var(--radius-0);
  cursor: pointer;
  width: 100%;
  max-width: 250px;
  justify-content: center;
}

.ask-layout { display: flex; flex-direction: column; gap: var(--space-4); }
.ask-layout .input-wrapper { position: relative; }
.ask-layout #turnInfo { text-align: center; font-size: var(--fs-sm); }

/* Slight light grey background for AI answers */
/* Disabled for dark theme: answer bubbles already set above */

/* Modal */
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,.35); }
.modal.open { display: flex; }
.modal-card { width: min(900px, 90vw); max-height: 80vh; overflow: auto; background: var(--color-panel); border: 1px solid var(--color-border); border-radius: var(--radius-0); box-shadow: var(--shadow-modal); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-4); border-bottom: 1px solid var(--color-border); position: sticky; top: 0; background: inherit; }
.modal-body { padding: var(--space-4) var(--space-4); }
.modal-body p { margin: 8px 0 0; font-size: var(--fs-body); }

/* Make the confirm reset popup a perfect square without affecting other modals */
#confirmResetModal .modal-card {
  width: 420px;
  height: 420px;
  max-height: none;
  overflow: hidden;            /* prevent outer scrollbars; body will scroll if needed */
  display: flex;               /* keep header fixed at top, body scrollable */
  flex-direction: column;
}
#confirmResetModal .modal-body {
  flex: 1;
  overflow: auto;
  /* Center content */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#confirmResetModal .modal-head .title { margin: 0 auto; text-align: center; }
#confirmResetModal .modal-actions {
  display: flex;
  flex-direction: column; /* stack buttons vertically */
  gap: var(--space-4);
  justify-content: center;
  align-items: center; /* center buttons horizontally */
  margin-top: var(--space-4);
}
#confirmResetModal .modal-actions button {
  width: 100%;
  max-width: 360px; /* make them wider and same size */
  font-weight: 400;  /* normal font weight */
  font-size: 14px;
  padding: var(--space-6) var(--space-9);
}

.hl { background: var(--color-hl-bg); outline: 2px solid var(--color-hl-outline); border-radius: var(--radius-0); padding: 2px 1px; }

/* Cropped preview snippet */
.snippet { position: relative; white-space: pre-wrap; line-height: 1.5; font-size: var(--fs-body); color: var(--color-text); }
.snippet .snippet-fade {
  /* Pixel-based color fade on text to light grey at edges */
  background: linear-gradient(
    to right,
    var(--snippet-fade-grey) 0%,
    var(--color-text) var(--snippet-fade-px),
    var(--color-text) calc(100% - var(--snippet-fade-px)),
    var(--snippet-fade-grey) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.fade-start {
  background: linear-gradient(
    90deg,
    rgba(var(--text-rgb), 0.20) 0%,
    rgba(var(--text-rgb), 0.35) 30%,
    rgba(var(--text-rgb), 0.70) 65%,
    var(--color-text) 90%
  );
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.fade-end {
  background: linear-gradient(
    270deg,
    rgba(var(--text-rgb), 0.20) 0%,
    rgba(var(--text-rgb), 0.35) 30%,
    rgba(var(--text-rgb), 0.70) 65%,
    var(--color-text) 90%
  );
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.ellipsis { color: var(--color-ellipsis); }

/* Modal close button tweaks */
.modal-head .close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: var(--color-panel);
  color: var(--color-text-dim);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
}
.modal-head .close:hover { background: #f4f4f6; }

/* --- Responsive: Tablets and smaller screens (below 900px) --- */
@media (max-width: 900px) {
  body { font-size: 13px; }
  
  .btn-outline {
    font-size: 13px;
    padding: var(--space-5) var(--space-7);
    max-width: 180px;
  }
  
  textarea { font-size: 13px; }
  .muted { font-size: 11px; }
  .answer h4 { font-size: 13px; }
  .bubble { padding: var(--space-5) var(--space-6); }
}

/* --- Responsive: Mobile portrait layout tweaks --- */
@media (max-width: 640px) {
  main { padding: 0; }
  .chat-box { padding: var(--space-6); padding-top: calc(var(--space-6) * 0.9 - 2px); }

  /* Keep ask layout stacked on mobile */
  .ask-layout { display: flex; flex-direction: column; gap: var(--space-3); }
  .input-wrapper { padding: var(--space-4); }
  textarea { padding-right: 50px; }
  .send-button { width: 40px; height: 40px; }
  .send-button svg { width: 18px; height: 18px; }

  /* Adjust footer layout */
  footer { padding: var(--space-5) var(--space-6); }
  .footer-content { font-size: var(--fs-xs); }
}
