/* ─────────────────────────────────────────────────────────────────────────
   PREMISE — UI
   Font: Inter (Google Fonts)
   Accent: #1D9E75  ← swap this one variable to change the whole palette
   To try alternatives:
     Electric indigo-blue → #4F7FFA
     Soft violet          → #C17CEB
───────────────────────────────────────────────────────────────────────── */

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

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  /* Core palette */
  --bg:            #0a0a0a;
  --surface:       #111;
  --surface-2:     #161616;
  --border:        #1e1e1e;
  --border-bright: #2a2a2a;

  /* Text */
  --text-primary:  #ebebeb;
  --text-secondary:#999;
  --text-muted:    #555;

  /* Accent — the single source of truth */
  --accent:        #1D9E75;
  --accent-dim:    rgba(29, 158, 117, 0.15);
  --accent-glow:   rgba(29, 158, 117, 0.08);

  /* User message tint */
  --user-bg:       rgba(20, 40, 60, 0.55);
  --user-border:   rgba(60, 100, 140, 0.25);

  /* Document panel */
  --doc-bg:        #0e0e0e;
  --doc-text:      #d8d8d8;

  /* Misc */
  --font:          'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm:     6px;
  --radius-md:     12px;
  --radius-lg:     20px;
  --header-h:      56px;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  flex-shrink: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg);
  position: relative;
  z-index: 10;
}

/* Gradient accent line under header — fades right */
.header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    var(--accent) 0%,
    rgba(29, 158, 117, 0.3) 25%,
    transparent 65%
  );
}

/* ── Wordmark ────────────────────────────────────────────────────────────── */
.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.logo-mark {
  flex-shrink: 0;
  display: block;
}

.wordmark-text {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-primary);
}

/* ── Status indicator ────────────────────────────────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Pulsing green dot */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  flex-shrink: 0;
}

/* Pulse animation while thinking */
.status-dot.thinking {
  animation: dot-pulse 1.4s ease-in-out infinite;
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1;   transform: scale(1);    box-shadow: 0 0 6px var(--accent); }
  50%       { opacity: 0.3; transform: scale(0.75); box-shadow: none; }
}

.status-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Mobile "View Document" button in header */
.view-doc-btn-mobile {
  display: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  letter-spacing: 0.01em;
}

/* ── App layout ──────────────────────────────────────────────────────────── */
#app {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ── Chat pane ───────────────────────────────────────────────────────────── */
.chat-pane {
  flex: 1 1 100%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
  position: relative;      /* anchor for .scroll-to-bottom */
  transition: flex-basis 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#app.has-doc .chat-pane {
  flex: 0 0 40%;
}

/* ── Thread ──────────────────────────────────────────────────────────────── */
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 36px 32px 24px;
}

/* ── Empty / welcome state ───────────────────────────────────────────────── */
.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 0;
}

.empty-logo {
  margin-bottom: 20px;
  opacity: 0.95;
}

.empty-wordmark {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.empty-tagline {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  max-width: 340px;
  line-height: 1.6;
  margin-bottom: 32px;
}

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

.chip {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 450;
  padding: 8px 15px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-bright);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  letter-spacing: 0.01em;
}

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

/* ── Messages ────────────────────────────────────────────────────────────── */
.message {
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 0 14px;
  align-items: start;
}

.message:first-child {
  border-top: 1px solid var(--border);
}

.message-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-top: 3px;
  color: var(--text-muted);
}

/* User label slightly brighter */
.message.user .message-label {
  color: #666;
}

/* ── User message — subtle dark tinted background ────────────────────────── */
.message.user .message-body {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  white-space: pre-wrap;
}

/* ── Agent message — thin accent left border ─────────────────────────────── */
.message.assistant .message-body {
  border-left: 2px solid var(--accent);
  padding-left: 14px;
}

.message-body {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  word-break: break-word;
}

/* Markdown elements inside message body */
.message-body p { margin-bottom: 0.65em; }
.message-body p:last-child { margin-bottom: 0; }

.message-body h1, .message-body h2, .message-body h3 {
  font-weight: 600;
  color: var(--text-primary);
  margin: 1em 0 0.4em;
  line-height: 1.3;
}

.message-body ul, .message-body ol {
  margin: 0.4em 0 0.8em 1.2em;
}

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

.message-body strong {
  font-weight: 600;
  color: var(--text-primary);
}

.message-body code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  background: #1c1c1c;
  border: 1px solid var(--border-bright);
  padding: 1px 5px;
  border-radius: 4px;
}

.message-body pre {
  background: #141414;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 10px 0;
  overflow-x: auto;
}

.message-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}

/* ── Document chip card — appears in chat after a doc is generated ───────── */
.doc-chip {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  margin-top: 12px;
  padding: 10px 14px 10px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-bright);
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
  width: 100%;
  max-width: 300px;
  font-family: var(--font);
  transition: border-color 0.15s, background 0.15s;
}

.doc-chip:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.doc-chip-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: rgba(29, 158, 117, 0.12);
  border: 1px solid rgba(29, 158, 117, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.doc-chip-info {
  flex: 1;
  min-width: 0;
}

.doc-chip-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.doc-chip-meta {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.01em;
}

/* "View Document" button — mobile only, appears in chat */
.view-doc-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 7px 13px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.view-doc-btn:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Streaming cursor */
.cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: middle;
  border-radius: 1px;
  animation: blink 0.9s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Scroll-to-bottom button ─────────────────────────────────────────────── */
.scroll-to-bottom {
  position: absolute;
  bottom: 100px;           /* sits just above the input bar */
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-bright);
  background: var(--surface-2);
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: opacity 0.2s, border-color 0.15s, color 0.15s;
  opacity: 0;
}

/* JS toggles hidden attr; fade in via opacity so the transition plays */
.scroll-to-bottom:not([hidden]) {
  opacity: 1;
}

.scroll-to-bottom[hidden] {
  display: flex !important;  /* keep in layout for transition */
  opacity: 0;
  pointer-events: none;
}

.scroll-to-bottom:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Input bar ───────────────────────────────────────────────────────────── */
.input-bar {
  flex-shrink: 0;
  padding: 14px 20px 20px;
  background: var(--bg);
}

.input-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);          /* rounded pill shape */
  padding: 10px 10px 10px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* Teal glow on focus */
.input-form:focus-within {
  border-color: rgba(29, 158, 117, 0.45);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-field {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  max-height: 200px;
  overflow-y: auto;
}

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

/* Send button — filled circle */
.send-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;                       /* circle */
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.1s;
}

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

.send-btn:not(:disabled):hover {
  opacity: 0.88;
  transform: scale(1.04);
}

.send-btn:not(:disabled):active {
  transform: scale(0.96);
}

/* ── Document pane (desktop) ─────────────────────────────────────────────── */
.doc-pane {
  flex: 0 0 60%;
  display: none;
  flex-direction: column;
  background: var(--doc-bg);
  min-width: 0;
}

#app.has-doc .doc-pane {
  display: flex;
}

.doc-header {
  flex-shrink: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 0 32px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

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

/* Match the header accent line */
.doc-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(29, 158, 117, 0.2) 40%,
    var(--accent) 100%
  );
}

.doc-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Close panel button */
.doc-close-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.doc-close-btn:hover {
  color: var(--text-primary);
  border-color: #444;
  background: var(--surface);
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  letter-spacing: 0.01em;
}

.download-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* iframe for HTML document rendering — hidden until an HTML doc is loaded */
.doc-frame {
  display: none;
  flex: 1;
  min-height: 0;          /* required for flex children to shrink correctly */
  width: 100%;
  border: none;
  background: #fff;
}

/* Placeholder shown in chat while an HTML document is streaming */
.generating-placeholder {
  color: var(--text-muted);
  font-style: normal;
}

/* ── Document content / typography ───────────────────────────────────────── */
.doc-content {
  flex: 1;
  overflow-y: auto;
  padding: 44px 52px;
  color: var(--doc-text);
  font-size: 15px;
  line-height: 1.8;
}

.doc-content h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 6px;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.doc-content h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 40px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-bright);
  letter-spacing: -0.01em;
}

.doc-content h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  margin: 28px 0 8px;
  text-transform: uppercase;
}

.doc-content p { margin: 0 0 14px; }

.doc-content ul, .doc-content ol {
  margin: 0 0 14px 20px;
}

.doc-content li { margin-bottom: 6px; }

.doc-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

.doc-content em { color: #aaa; }

.doc-content hr {
  border: none;
  border-top: 1px solid var(--border-bright);
  margin: 32px 0;
}

/* Tables */
.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 14px;
}

.doc-content th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-bright);
}

.doc-content td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.doc-content tr:last-child td { border-bottom: none; }

.doc-content code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  background: #1a1a1a;
  border: 1px solid var(--border-bright);
  padding: 1px 5px;
  border-radius: 4px;
}

.doc-content pre {
  background: #141414;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 12px 0;
  overflow-x: auto;
}

.doc-content pre code {
  background: none;
  border: none;
  padding: 0;
}

/* ── Mobile document overlay ─────────────────────────────────────────────── */
.doc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--doc-bg);
  flex-direction: column;
}

.doc-overlay.open { display: flex; }

.doc-overlay-header {
  flex-shrink: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.doc-overlay-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.close-overlay-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #252525; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #333; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Doc pane never shows inline on mobile */
  #app.has-doc .chat-pane { flex: 1 1 100%; }
  #app.has-doc .doc-pane  { display: none; }

  .view-doc-btn-mobile { display: inline-flex !important; }

  .message {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .message-label { font-size: 10px; }

  /* On mobile, agent left border becomes a top border */
  .message.assistant .message-body {
    border-left: none;
    border-top: 2px solid var(--accent);
    padding-left: 0;
    padding-top: 10px;
  }

  .header { padding: 0 16px; }

  .thread { padding: 24px 16px 16px; }

  .input-bar { padding: 10px 14px 16px; }

  .doc-content { padding: 28px 20px; }

  .prompt-chips { gap: 7px; }
}

/* ── Print styles (triggered by window.print() on Download PDF) ──────────── */
@media print {
  /* Let the page reflow naturally */
  html, body {
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
  }

  /* Hide everything that isn't the document content */
  .header,
  .chat-pane,
  .doc-header,
  .doc-overlay,
  .scroll-to-bottom,
  .view-doc-btn-mobile { display: none !important; }

  /* Expand the doc pane to fill the full page */
  #app {
    display: block !important;
    height: auto !important;
  }

  .doc-pane {
    display: block !important;
    width: 100% !important;
    flex: none !important;
    background: #fff !important;
  }

  /* The content area itself */
  #docContent {
    padding: 0 !important;
    background: #fff !important;
    color: #1a1a1a !important;
    overflow: visible !important;
    max-width: 720px;
    margin: 0 auto;
    font-size: 13pt;
    line-height: 1.7;
  }

  /* Typography reset for print */
  #docContent h1 {
    font-size: 22pt;
    color: #000 !important;
    margin-bottom: 6pt;
    border: none;
  }

  #docContent h2 {
    font-size: 14pt;
    color: #000 !important;
    border-bottom: 1pt solid #ccc;
    padding-bottom: 4pt;
    margin-top: 0;
    /* Each major section starts on its own page — except the very first */
  }

  /* Every h2 after the first gets a page break */
  #docContent h2 ~ h2 {
    page-break-before: always;
    break-before: page;
  }

  /* Keep headings with the content that follows them */
  #docContent h2, #docContent h3 {
    page-break-after: avoid;
    break-after: avoid;
  }

  /* Avoid breaking inside list items and table rows */
  #docContent li,
  #docContent tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  #docContent table {
    border-collapse: collapse;
    width: 100%;
    font-size: 11pt;
  }

  #docContent th,
  #docContent td {
    border: 1pt solid #ccc;
    padding: 6pt 8pt;
    color: #1a1a1a !important;
  }

  #docContent th {
    background: #f5f5f5 !important;
    font-weight: 600;
  }

  #docContent code {
    background: #f5f5f5 !important;
    border: 1pt solid #ddd;
    color: #333 !important;
  }

  #docContent a { color: #1a1a1a; text-decoration: none; }
}
