/* ============================================================
   style.css — the look of NEXUS (inspired by Claude's design:
   warm cream background, coral accent, serif headings)
   ============================================================ */

/* ---------- Colors (light mode) ---------- */
:root {
  --primary: #cc785c;        /* coral — buttons, accents */
  --primary-dark: #a9583e;
  --bg: #faf9f5;             /* cream page background */
  --sidebar: #f5f0e8;
  --card: #efe9de;
  --user-bubble: #efe9de;
  --border: #e6dfd8;
  --text: #141413;
  --text-soft: #3d3d3a;
  --muted: #6c6a64;
  --code-bg: #181715;
  --code-text: #faf9f5;
  --error: #c64545;
  --ok: #5db872;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", Consolas, monospace;
}

/* ---------- Colors (dark mode) ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1e1b; --sidebar: #181715; --card: #252320; --user-bubble: #2f2c28;
    --border: #34312c; --text: #faf9f5; --text-soft: #dcd8cf; --muted: #a09d96; --code-bg: #141413;
  }
}
:root[data-theme="dark"] {
  --bg: #1f1e1b; --sidebar: #181715; --card: #252320; --user-bubble: #2f2c28;
  --border: #34312c; --text: #faf9f5; --text-soft: #dcd8cf; --muted: #a09d96; --code-bg: #141413;
}

/* ---------- Page layout: sidebar on the left, chat on the right ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--sans);
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 270px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 10px; }
.brand span { font: 500 22px var(--serif); letter-spacing: .5px; flex: 1; }

.new-chat {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: left;
}
.new-chat:hover { background: var(--card); }
.plus {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 600;
}

.search {
  padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px; outline: none;
}
.search:focus { border-color: var(--primary); }

.list-label { font-size: 12px; color: var(--muted); padding: 8px 8px 0; }
#chatList { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }

.chat-item {
  display: flex; align-items: center;
  padding: 7px 10px; border-radius: 8px;
  font-size: 14px; color: var(--text-soft);
  cursor: pointer;
}
.chat-item:hover, .chat-item.active { background: var(--card); color: var(--text); }
.chat-item .name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item .actions { display: none; gap: 2px; }
.chat-item:hover .actions { display: flex; }
.chat-item .actions button { border: 0; background: none; padding: 0 2px; font-size: 12px; opacity: .7; }
.chat-item .actions button:hover { opacity: 1; }
.chat-group { margin-bottom: 4px; }
.chat-group summary { cursor: pointer; list-style: none; padding: 8px 8px 4px; }
.chat-group summary::-webkit-details-marker { display: none; }
@media (hover: none) { .chat-item .actions { display: flex; } }   /* phones: always show the buttons */

.sidebar-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; border-top: 1px solid var(--border); padding-top: 8px; }
.side-btn { text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 8px; font-size: 14px; }
.side-btn:hover { background: var(--card); }

/* ---------- Main chat area ---------- */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
#modelPick {
  max-width: 340px;
  padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px;
}
#chatTitle { color: var(--muted); font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

#messages { flex: 1; overflow-y: auto; padding: 24px 16px; }

/* Welcome screen */
#welcome { max-width: 680px; margin: 10vh auto 0; text-align: center; }
#welcome h1 { font: 400 40px/1.15 var(--serif); letter-spacing: -.5px; margin: 14px 0 8px; }
#welcome p { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.chip {
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg);
  font-size: 14px; color: var(--text-soft);
}
.chip:hover { border-color: var(--primary); color: var(--text); }

/* One message */
.msg { max-width: 760px; margin: 0 auto 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble);
  padding: 10px 16px; border-radius: 18px;
  max-width: 85%; white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant { display: flex; gap: 14px; }
.msg.assistant .avatar { width: 26px; height: 26px; flex-shrink: 0; margin-top: 3px; }
.msg.assistant .body { flex: 1; min-width: 0; }
.msg.assistant .content { font-family: var(--serif); font-size: 16.5px; line-height: 1.65; color: var(--text); }
.content h1, .content h2, .content h3 { font-family: var(--serif); font-weight: 500; line-height: 1.25; margin: 1.2em 0 .5em; }
.content p { margin: 0 0 .8em; }
.content a { color: var(--primary); }
.content img { max-width: 100%; border-radius: 12px; }
.content table { border-collapse: collapse; margin: 1em 0; font-family: var(--sans); font-size: 14px; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.content code { font-family: var(--mono); font-size: 13.5px; background: var(--card); padding: 2px 5px; border-radius: 5px; }
.content pre { background: var(--code-bg); color: var(--code-text); padding: 14px 16px; border-radius: 12px; overflow-x: auto; position: relative; }
.content pre code { background: none; padding: 0; color: inherit; }
.copy-code {
  position: absolute; top: 8px; right: 8px;
  font-size: 12px; padding: 3px 8px; border-radius: 6px;
  border: 1px solid #ffffff30; background: #ffffff10; color: #faf9f5;
}

.content .status { font-family: var(--sans); font-size: 14px; color: var(--muted); font-style: italic; }
/* 📊 Charts */
.chart-box { margin: 12px 0; padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--bg); font-family: var(--sans); }
.chart-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.chart-actions button { font-size: 12px; padding: 3px 10px; border-radius: 8px; border: 1px solid var(--border); background: none; color: var(--muted); }
.chart-actions button:hover { color: var(--text); border-color: var(--primary); }
.chart-table { overflow-x: auto; }

/* ▶ Run Python */
.run-code {
  position: absolute; top: 8px; right: 64px;
  font-size: 12px; padding: 3px 10px; border-radius: 6px;
  border: 1px solid #5db87280; background: #5db87220; color: #b8f0c4;
}
.run-code:disabled { opacity: .5; }
.run-output { margin: -6px 0 12px; padding: 10px 14px; border: 1px solid var(--border); border-top: 0; border-radius: 0 0 12px 12px; background: var(--card); font-family: var(--mono); font-size: 13px; }
.run-output pre { margin: 0; white-space: pre-wrap; background: none; color: var(--text); padding: 0; }
.run-output img { max-width: 100%; margin-top: 8px; border-radius: 8px; background: #fff; }

.thinking { font-family: var(--sans); font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.thinking summary { cursor: pointer; }
.thinking div { white-space: pre-wrap; border-left: 2px solid var(--border); padding-left: 10px; margin-top: 6px; }

.meta { display: flex; gap: 12px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.meta button { border: 0; background: none; color: var(--muted); padding: 0; font-size: 12px; }
.meta button:hover { color: var(--text); }
.error-text { color: var(--error); font-family: var(--sans); font-size: 14px; }

/* blinking cursor while NEXUS is typing */
.typing::after { content: "▍"; color: var(--primary); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Message box at the bottom ---------- */
#composer { padding: 0 16px 14px; }
.box {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 10px 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 2px 12px #0000000d;
}
.box:focus-within { border-color: var(--primary); }
#input {
  flex: 1; resize: none; border: 0; outline: none;
  background: transparent; color: var(--text);
  font: inherit; font-size: 15.5px; max-height: 240px; padding: 6px 0;
}
.tools-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: none; font-size: 17px;
  filter: grayscale(1); opacity: .55;
}
.tools-btn.on { filter: none; opacity: 1; border-color: var(--primary); background: var(--card); }
.used-tools { color: var(--primary); }
#micBtn.recording { background: var(--error); border-color: var(--error); animation: blink 1s infinite; }

/* Attachment chips (above the message box, and inside your message bubbles) */
#attachments { max-width: 760px; margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 8px;
  background: var(--card); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-soft); max-width: 260px;
}
.file-chip span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.file-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.file-chip button { border: 0; background: none; color: var(--muted); padding: 0; }
.bubble .files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.bubble .file-chip { background: var(--bg); }
.bubble img.sent-image { max-width: 220px; border-radius: 10px; display: block; margin-top: 8px; }
#send {
  width: 36px; height: 36px; border-radius: 10px; border: 0;
  background: var(--primary); color: #fff; font-size: 18px; font-weight: 600;
}
#send:hover { background: var(--primary-dark); }
#send:disabled { opacity: .45; cursor: default; }
.hint { max-width: 760px; margin: 6px auto 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Pop-up windows ---------- */
dialog {
  width: min(560px, calc(100% - 32px));
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--bg); color: var(--text);
  padding: 22px;
}
dialog::backdrop { background: #00000066; }
dialog h2 { font: 400 24px var(--serif); margin: 0 0 6px; }
dialog textarea, dialog input {
  width: 100%; padding: 10px 12px; margin: 10px 0;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--sidebar); color: var(--text); font: inherit; font-size: 14px;
}
.row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.primary { padding: 8px 18px; border: 0; border-radius: 10px; background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.ghost { padding: 8px 18px; border: 1px solid var(--border); border-radius: 10px; background: none; }
.muted { color: var(--muted); font-size: 14px; }
.doctor-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.doctor-row small { color: var(--muted); }

.icon-btn { border: 0; background: none; font-size: 20px; padding: 2px 6px; }
#openExport { margin-left: auto; font-size: 17px; }

/* Documents list */
.doc-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.doc-row span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-row small { color: var(--muted); }
.doc-row button { border: 0; background: none; color: var(--muted); }
.doc-row button:hover { color: var(--error); }

/* Skills grid */
.skills-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.skill-card {
  position: relative; text-align: left; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--sidebar); font-size: 14px;
}
.skill-card:hover, .skill-card.active { border-color: var(--primary); background: var(--card); }
.skill-card .del { position: absolute; top: 4px; right: 6px; font-size: 12px; color: var(--muted); }
.new-skill { margin-top: 6px; font-size: 14px; }
.new-skill summary { cursor: pointer; color: var(--primary); }
.skill-chip { border-color: var(--primary); }

/* Forms inside pop-ups */
dialog.wide { width: min(720px, calc(100% - 32px)); }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 6px 0; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-row label.check { flex-direction: row; align-items: center; }
.form-row label.check input { width: auto; margin: 0; }
.form-row select, .form-row input { margin: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--sidebar); color: var(--text); font: inherit; font-size: 14px; }
.form-row input#remText { flex: 1; min-width: 160px; }

/* Image gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; max-height: 50vh; overflow-y: auto; }
.gallery a { display: block; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--card); }

/* Usage bars */
.usage-row { display: grid; grid-template-columns: 120px 1fr 80px; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.bar { height: 8px; border-radius: 4px; background: var(--card); overflow: hidden; }
.bar div { height: 100%; background: var(--primary); }
.bar div.high { background: var(--error); }
.week { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin-top: 14px; }
.week div { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.week small { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--muted); }

/* Little pop-up message (toast) */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 6px 24px #0004;
}

/* Printing (for "Download as PDF"): only the conversation */
@media print {
  #sidebar, .topbar, #composer, .meta, .copy-code, #overlay { display: none !important; }
  body, main, #messages { display: block; height: auto; overflow: visible; background: #fff; color: #000; }
  .msg.user .bubble { background: #f3efe8; color: #000; }
  .content pre { white-space: pre-wrap; }
}
.only-mobile { display: none; }
#overlay { display: none; }

/* ---------- Phones and small screens ---------- */
@media (max-width: 800px) {
  .only-mobile { display: inline-block; }
  #sidebar {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%); transition: transform .2s;
  }
  body.menu-open #sidebar { transform: none; }
  body.menu-open #overlay { display: block; position: fixed; inset: 0; z-index: 10; background: #00000055; }
  #welcome h1 { font-size: 30px; }
  .msg.assistant .avatar { display: none; }
  #modelPick { max-width: 200px; }
  .box { gap: 4px; padding-left: 8px; }
  .tools-btn, #send { width: 32px; height: 32px; font-size: 15px; }
  #chatTitle { display: none; }
}
