/* chatJPt theme — palette derived from jpaul.me (daily3 theme):
   primary blue #326693, accent green #a3bb43, slate text #313131. */
:root {
  --jp-primary: #326693;
  --jp-primary-dark: #284f73;
  --jp-accent: #a3bb43;
  --jp-bg: #f3f4f5;
  --jp-surface: #ffffff;
  --jp-text: #313131;
  --jp-muted: #6b7280;
  --jp-border: #dcdcde;
  --jp-danger: #dd3737;
  --jp-radius: 12px;
  --jp-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans,
    Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
/* the hidden attribute must win over display:flex etc. (same specificity) — keeps
   the sidebar + chat composer fully hidden until the user signs in. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--jp-font);
  color: var(--jp-text);
  background: var(--jp-bg);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: var(--jp-primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.brand-jp { color: #cfe0ee; }
.brand-t { color: var(--jp-accent); }
.tagline { font-size: 13px; opacity: 0.85; }
.logout {
  margin-left: auto;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.logout:hover { background: rgba(255, 255, 255, 0.12); }

/* Fill the screen — full width with responsive side padding (was a narrow centered column). */
.wrap { flex: 1; width: 100%; max-width: none; margin: 0; padding: 18px clamp(16px, 3vw, 44px); display: flex; }

/* Email gate */
.gate { margin: auto; background: var(--jp-surface); border: 1px solid var(--jp-border); border-radius: var(--jp-radius); padding: 32px; max-width: 460px; }
.gate h1 { margin: 0 0 8px; font-size: 22px; color: var(--jp-primary-dark); }
.muted { color: var(--jp-muted); font-size: 14px; line-height: 1.5; }
#gate-form { display: flex; gap: 8px; margin-top: 18px; }
#gate-form input { flex: 1; padding: 11px 12px; border: 1px solid var(--jp-border); border-radius: 8px; font-size: 15px; }
#gate-form input:focus { outline: 2px solid var(--jp-primary); border-color: var(--jp-primary); }
.gate-msg { margin-top: 12px; font-size: 14px; min-height: 1.2em; }
.gate-msg.ok { color: var(--jp-primary-dark); }
.gate-msg.err { color: var(--jp-danger); }

/* Chat */
.chat { flex: 1; display: flex; flex-direction: column; width: 100%; }
.transcript { flex: 1; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 14px; padding-bottom: 12px; }
.msg { display: flex; min-width: 0; }
.msg.user { justify-content: flex-end; }
/* assistant column capped at a readable measure while the app fills the screen */
.msg.assistant { flex-direction: column; align-items: flex-start; gap: 6px; max-width: 1000px; }
.bubble {
  max-width: 100%;
  padding: 11px 14px;
  border-radius: var(--jp-radius);
  line-height: 1.55;
  font-size: 15px;
  overflow-wrap: anywhere;
}
.msg.user .bubble { max-width: 70%; background: var(--jp-primary); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--jp-surface); border: 1px solid var(--jp-border); border-bottom-left-radius: 4px; }
.bubble a { color: var(--jp-primary); word-break: break-word; }
.bubble pre { background: #1f2733; color: #e6edf3; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
/* code block with a copy button in the corner */
.code-wrap { position: relative; }
.copy-btn { position: absolute; top: 6px; right: 6px; z-index: 1; font-size: 11px; font-family: inherit; color: #cbd5e1; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 6px; padding: 2px 9px; cursor: pointer; opacity: 0.7; transition: opacity 0.15s, color 0.15s; }
.code-wrap:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.copy-btn.copied { color: var(--jp-accent); border-color: var(--jp-accent); }
.bubble code { background: rgba(50, 102, 147, 0.1); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.bubble pre code { background: none; padding: 0; }
/* rendered markdown inside an assistant bubble */
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 6px 0; }
.bubble blockquote { margin: 10px 0; padding: 6px 14px; border-left: 4px solid var(--jp-accent); background: rgba(163, 187, 67, 0.1); border-radius: 0 8px 8px 0; }
.bubble blockquote p { margin: 4px 0; }
.bubble h3, .bubble h4, .bubble h5 { margin: 12px 0 4px; line-height: 1.3; color: var(--jp-primary-dark); }
.bubble h3 { font-size: 17px; }
.bubble h4 { font-size: 15px; }
.bubble h5 { font-size: 14px; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble hr { border: 0; border-top: 1px solid var(--jp-border); margin: 12px 0; }
.bubble table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 14px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--jp-border); padding: 6px 10px; text-align: left; vertical-align: top; }
.bubble thead th { background: #eef1f4; color: var(--jp-primary-dark); }
.bubble tbody tr:nth-child(even) { background: #fafbfc; }
/* tool pills: a wrap row ABOVE the bubble (not flex siblings of it) */
.tools { display: flex; flex-wrap: wrap; gap: 6px; max-width: 80%; }
.tool-chip { font-size: 12px; color: var(--jp-muted); background: #eef1f4; border: 1px solid var(--jp-border); border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.cursor::after { content: "▍"; color: var(--jp-accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer { display: flex; gap: 8px; margin-top: 10px; }
.composer textarea { flex: 1; resize: none; padding: 11px 12px; border: 1px solid var(--jp-border); border-radius: 10px; font-family: inherit; font-size: 15px; max-height: 160px; }
.composer textarea:focus { outline: 2px solid var(--jp-primary); border-color: var(--jp-primary); }
.composer button, #gate-form button {
  background: var(--jp-primary); color: #fff; border: 0; border-radius: 10px;
  padding: 0 18px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.composer button:hover, #gate-form button:hover { background: var(--jp-primary-dark); }
.composer button:disabled { background: var(--jp-muted); cursor: default; }
.disclaimer { color: var(--jp-muted); font-size: 12px; text-align: center; margin: 8px 0 0; }

/* ---------- layout + history sidebar ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.wrap, .chat { min-height: 0; }
.icon-btn { background: transparent; border: 0; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 4px 6px; border-radius: 6px; opacity: 0.7; }
.icon-btn:hover { opacity: 1; background: rgba(0, 0, 0, 0.06); }
.topbar .icon-btn { color: #fff; }

.sidebar { width: 270px; flex-shrink: 0; background: var(--jp-surface); border-right: 1px solid var(--jp-border); display: flex; flex-direction: column; overflow: hidden; }
.new-chat { margin: 12px; padding: 10px 12px; border: 1px solid var(--jp-border); background: #fff; color: var(--jp-primary-dark); border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; text-align: left; }
.new-chat:hover { border-color: var(--jp-primary); background: #f7fafd; }
.convo-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.convo { display: flex; align-items: center; border-radius: 8px; }
.convo:hover { background: #eef1f4; }
.convo.active { background: #e3edf5; }
.convo-title { flex: 1; min-width: 0; background: transparent; border: 0; cursor: pointer; text-align: left; padding: 9px 10px; font-size: 14px; color: var(--jp-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-actions { display: none; padding-right: 4px; }
.convo:hover .convo-actions, .convo.active .convo-actions { display: flex; }

/* ---------- export buttons under an answer ---------- */
.msg-actions { display: flex; gap: 6px; margin-top: 4px; }
.act { font-size: 12px; color: var(--jp-primary-dark); background: #eef1f4; border: 1px solid var(--jp-border); border-radius: 8px; padding: 3px 10px; cursor: pointer; }
.act:hover { background: #e3edf5; border-color: var(--jp-primary); }

/* ---------- responsive: sidebar becomes a drawer ---------- */
@media (min-width: 860px) { #sidebar-toggle { display: none; } }
@media (max-width: 859px) {
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 30; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15); }
  .sidebar.open { transform: translateX(0); }
}
