:root {
  /* CryptoPanic — exact visual from screenshots */
  --bg:        #0d0d0d;   /* near-black body */
  --bg2:       #141414;   /* header / sidebar / input bar */
  --bg3:       #1a1a1a;   /* inputs / slightly raised */
  --bg-hover:  #1e1e1e;
  --bg-sel:    #0f1a28;   /* selected — very dark blue tint */

  --line:      #1e1e1e;   /* news-item row separator */
  --line2:     #2a2a2a;   /* border, input edge */

  --ink:       #c8ccd4;   /* primary text */
  --ink-dim:   #767980;   /* timestamps, secondary */
  --ink-dim2:  #444850;   /* tertiary labels */

  /* cyan = links, tags (BTC ETH XRP), active state */
  --accent:     #5bc8e8;
  --accent-soft: #5bc8e818;

  /* semantic */
  --bull:  #4caf7d;   /* Bullish / green */
  --bear:  #e05c5c;   /* Bearish / red */
  --warn:  #f0a04b;   /* source name / orange / Important */
  --info:  #5bc8e8;   /* starting (same as accent) */

  --side-w:   260px;
  --bar-h:    44px;
  --radius:   2px;    /* CryptoPanic is very flat */
  --radius-sm: 2px;

  /* Courier-style monospace — the single most distinctive thing about CP */
  --font: "Courier New", Courier, "Lucida Console", ui-monospace, monospace;
  --font-ui: var(--font);  /* same — CP uses mono everywhere */
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font);
  font-size: 14px; line-height: 1.55;
  overscroll-behavior: none;
}
body { display: grid; grid-template-columns: var(--side-w) 1fr;
  grid-template-rows: calc(var(--bar-h) + env(safe-area-inset-top)) 1fr;
  grid-template-areas: "bar bar" "side main"; height: 100dvh; }

/* ---- header ---- */
#bar { grid-area: bar; display: flex; align-items: center; gap: 10px;
  padding-top: env(safe-area-inset-top);
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  background: var(--bg2); border-bottom: 1px solid var(--line2);
  z-index: 30; flex-wrap: nowrap; }
.logo { font-weight: 700; font-size: 14px; letter-spacing: .5px;
  color: var(--ink); flex-shrink: 0; }
.logo .hl { color: var(--accent); }
#here { font-size: 12px; color: var(--warn); flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-left: 4px; }
#resumeBtn { margin-left: auto; }

/* status pill — compact, semantic */
.status { padding: 3px 9px 3px 20px; border-radius: 2px; font-size: 11px;
  line-height: 1; display: inline-flex; align-items: center;
  flex-shrink: 0; letter-spacing: .3px;
  position: relative; border: 1px solid transparent; }
.status::before { content: ""; position: absolute; left: 8px; top: 50%;
  transform: translateY(-50%); width: 6px; height: 6px; border-radius: 50%; }
.status.on  { color: var(--bull); border-color: #4caf7d44; background: #4caf7d12; }
.status.on::before  { background: var(--bull); }
.status.off { color: var(--bear); border-color: #e05c5c44; background: #e05c5c10; }
.status.off::before { background: var(--bear); }

/* ---- buttons — pill outline style like CP Buy/Sell ---- */
.barbtn, .primarybtn, .dangerbtn {
  font-family: inherit; font-size: 12px; cursor: pointer;
  border: 1px solid var(--line2); background: transparent; color: var(--ink-dim);
  padding: 5px 11px; border-radius: 999px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px;
  line-height: 1; flex-shrink: 0;
  transition: border-color .1s, color .1s;
}
.barbtn:hover { color: var(--ink); border-color: var(--ink-dim); }
.barbtn.icon { padding: 5px 8px; }
.primarybtn { border-color: var(--bull); color: var(--bull); }
.primarybtn:hover { background: #4caf7d18; }
.dangerbtn { border-color: var(--bear); color: var(--bear); }
.dangerbtn:hover { background: #e05c5c12; }

.hidden { display: none !important; }
#menuBtn { display: none; }
#userBadge { display: none !important; }
#foot { display: none !important; }

/* ---- side ---- */
#side { grid-area: side; background: var(--bg2);
  border-right: 1px solid var(--line2); overflow: hidden;
  display: flex; flex-direction: column; }
.sideHead { padding: 12px 14px 6px; font-size: 10px; letter-spacing: 1.5px;
  color: var(--ink-dim2); text-transform: uppercase; }
#sideList { overflow-y: auto; flex: 1;
  display: flex; flex-direction: column; }
.sItem { padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 3px;
  transition: background .1s; }
.sItem:hover { background: var(--bg-hover); }
.sItem.sel { background: var(--bg-sel); border-left: 2px solid var(--accent); }
.sItem .nm { font-size: 13px; color: var(--ink);
  display: flex; align-items: center; gap: 7px; }
.sItem .nm .nmTxt { flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sItem .nm .sKill {
  margin-left: auto; flex-shrink: 0;
  border: none; background: transparent;
  color: var(--ink-dim2); cursor: pointer;
  font-family: inherit; font-size: 14px; line-height: 1;
  padding: 4px 8px; border-radius: 2px;
  opacity: .6; transition: color .1s, opacity .1s, background .1s;
}
.sItem .nm .sKill:hover {
  color: var(--bear); background: #e05c5c14; opacity: 1;
}
.sItem .cwd { font-size: 11px; color: var(--ink-dim2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0; }
.dot.ready    { background: var(--bull); }
.dot.thinking { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
.dot.starting { background: var(--info); }
.dot.exited, .dot.error { background: var(--bear); }
@keyframes pulse { 50% { opacity: .3; } }
@keyframes spin  { to { transform: rotate(360deg); } }
.empty-side { padding: 16px 14px; color: var(--ink-dim2); font-size: 12px;
  text-align: center; }

/* ---- scrollbar (webkit) ---- */
#chat::-webkit-scrollbar { width: 6px; }
#chat::-webkit-scrollbar-track { background: transparent; }
#chat::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 0; }
#sideList::-webkit-scrollbar { width: 4px; }
#sideList::-webkit-scrollbar-track { background: transparent; }
#sideList::-webkit-scrollbar-thumb { background: var(--line2); }

/* ---- main / chat ---- */
#main { grid-area: main; display: flex; flex-direction: column;
  min-width: 0; min-height: 0; position: relative; overflow: hidden; }
#chat { flex: 1; overflow-y: auto; padding: 0;
  display: flex; flex-direction: column; }

/* Messages styled like CP news rows — separated by lines, not chat bubbles */
.msg { width: 100%; padding: 10px 18px;
  font-size: 14px; line-height: 1.6; white-space: pre-wrap;
  word-break: break-word; border-radius: 0;
  border-bottom: 1px solid var(--line); }
.msg.user { align-self: stretch; background: var(--bg2);
  color: var(--accent); text-align: right; }
.msg.user::before { content: "> "; color: var(--ink-dim2); }
.msg.assistant { align-self: stretch; background: var(--bg);
  color: var(--ink); }
.msg.tool { color: var(--ink-dim2); background: var(--bg);
  font-size: 12px; padding: 5px 18px 5px 30px;
  border-left: 2px solid var(--line2); border-bottom: none; }
.msg.sys { align-self: center; font-size: 11px; color: var(--ink-dim2);
  background: none; padding: 4px 18px; border-bottom: none;
  text-align: center; width: auto; }
.msg.thinking { background: var(--bg); color: var(--warn);
  font-size: 12px; display: flex; align-items: center; gap: 9px;
  padding: 8px 18px; border-bottom: 1px solid var(--line); }
.spin { display: inline-block; width: 10px; height: 10px;
  border: 1.5px solid #f0a04b44; border-top-color: var(--warn);
  border-radius: 50%; animation: spin .8s linear infinite; flex-shrink: 0; }

/* ---- scroll-to-bottom button ---- */
#scrollBtn {
  position: absolute; bottom: 110px; right: 18px;
  width: 30px; height: 30px; border-radius: 999px;
  border: 1px solid var(--line2); background: var(--bg2);
  color: var(--ink-dim); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, color .15s;
  z-index: 10;
}
#scrollBtn:hover { border-color: var(--accent); color: var(--accent); }
#scrollBtn.hidden { opacity: 0; pointer-events: none; }

/* ---- input ---- */
#chatForm { display: flex; flex-direction: column; gap: 0;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  border-top: 1px solid var(--line2); background: var(--bg2); }

/* image preview strip */
#imgPreview { display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 0 4px; }
#imgPreview.hidden { display: none; }
.previewThumb { position: relative; flex-shrink: 0; }
.previewThumb img { width: 64px; height: 64px; object-fit: cover;
  border-radius: 2px; border: 1px solid var(--line2); display: block; }
.previewThumb .rmBtn { position: absolute; top: -5px; right: -5px;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--line2); background: var(--bg2);
  color: var(--ink-dim); font-size: 10px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; font-family: inherit; }
.previewThumb .rmBtn:hover { background: var(--bear); border-color: var(--bear);
  color: #fff; }

#inputRow { display: flex; align-items: flex-end; gap: 8px; padding: 10px 0; }

.attachbtn { display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 2px;
  border: 1px solid var(--line2); background: transparent; cursor: pointer;
  font-size: 16px; flex-shrink: 0; user-select: none;
  transition: border-color .1s, color .1s; color: var(--ink-dim); }
.attachbtn:hover { border-color: var(--accent); color: var(--accent); }

#chatText { flex: 1; font-family: inherit; font-size: 14px; padding: 8px 12px;
  border-radius: 2px; border: 1px solid var(--line2);
  background: var(--bg3); color: var(--ink); resize: none;
  max-height: 30vh; line-height: 1.5;
  caret-color: var(--accent);
  transition: border-color .1s; }
#chatText::placeholder { color: var(--ink-dim2); }
#chatText:focus { outline: none; border-color: var(--accent); }
#chatText:disabled { opacity: .4; cursor: not-allowed; }

/* Send button — green pill outline like CP "Buy" */
#sendBtn { font-family: inherit; font-size: 12px;
  padding: 0 16px; height: 34px; cursor: pointer;
  border: 1px solid var(--bull); background: transparent;
  color: var(--bull); border-radius: 999px; letter-spacing: .3px; }
#sendBtn:hover { background: #4caf7d18; }
#sendBtn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- markdown rendered inside .msg.md (assistant) ---- */
.msg.md { white-space: normal; }  /* override pre-wrap — marked handles formatting */
.msg.md p { margin: 0 0 .7em; }
.msg.md p:last-child { margin-bottom: 0; }
.msg.md h1, .msg.md h2, .msg.md h3,
.msg.md h4, .msg.md h5, .msg.md h6 {
  margin: .8em 0 .3em; font-weight: 700; color: var(--ink);
  letter-spacing: .3px; }
.msg.md h1 { font-size: 1.1em; }
.msg.md h2 { font-size: 1em; color: var(--accent); }
.msg.md h3, .msg.md h4 { font-size: .95em; color: var(--warn); }
.msg.md ul, .msg.md ol { margin: .4em 0 .7em 1.4em; padding: 0; }
.msg.md li { margin: .15em 0; }
.msg.md code { font-family: var(--font); font-size: .92em;
  background: var(--bg3); border: 1px solid var(--line2);
  padding: 1px 5px; border-radius: 2px; color: var(--accent); }
.msg.md pre { background: var(--bg3); border: 1px solid var(--line2);
  border-radius: 2px; padding: 10px 14px; overflow-x: auto;
  margin: .5em 0; }
.msg.md pre code { background: none; border: none; padding: 0;
  color: var(--ink); font-size: 13px; }
.msg.md blockquote { border-left: 3px solid var(--line2);
  margin: .5em 0 .5em 0; padding: .3em 0 .3em 12px;
  color: var(--ink-dim); }
.msg.md a { color: var(--accent); text-decoration: none; }
.msg.md a:hover { text-decoration: underline; }
.msg.md hr { border: none; border-top: 1px solid var(--line2); margin: .8em 0; }
.msg.md strong { color: var(--ink); font-weight: 700; }
.msg.md em { color: var(--ink-dim); font-style: italic; }

/* ---- tables inside assistant messages ---- */
.msg.md .table-wrap { overflow-x: auto; margin: .6em 0; }
.msg.md table { border-collapse: collapse; min-width: 100%; font-size: 13px; }
.msg.md th, .msg.md td {
  padding: 5px 12px; text-align: left;
  border: 1px solid var(--line2); white-space: nowrap; }
.msg.md th { background: var(--bg3); color: var(--accent); font-weight: 700; }
.msg.md tr:nth-child(even) td { background: #ffffff06; }

/* image thumbnail inside a chat message */
.msgImgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msgImgs a { display: block; flex-shrink: 0; }
.msgImgs img { max-width: 200px; max-height: 180px; border-radius: 2px;
  border: 1px solid var(--line2); object-fit: cover; display: block;
  cursor: pointer; transition: opacity .1s; }
.msgImgs img:hover { opacity: .8; }

/* ---- footer ---- */
#foot { display: flex; align-items: center;
  padding: 5px max(14px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  border-top: 1px solid var(--line2); background: var(--bg2);
  font-size: 11px; color: var(--ink-dim2); gap: 10px; }
#footMeta { flex: 1; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; color: var(--warn); }

.empty { position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; padding: 24px; text-align: center;
  color: var(--ink-dim2); font-size: 12px; pointer-events: none;
  line-height: 1.8; }
.empty b { color: var(--accent); }

/* ---- modals ---- */
.modal { position: fixed; inset: 0; z-index: 50;
  background: #000000cc;
  display: flex; align-items: center; justify-content: center; padding: 16px; }
.modalCard { background: var(--bg2); border: 1px solid var(--line2);
  border-radius: 2px; padding: 20px; width: 380px; max-width: 100%;
  display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100dvh - 32px); }
.modalCard.wide { width: 540px; }
.modalHead { display: flex; align-items: center; justify-content: space-between; }
.modalCard h3 { margin: 0; color: var(--ink); font-size: 15px; font-weight: 700; }
.modalCard label { display: flex; flex-direction: column; gap: 5px;
  font-size: 11px; color: var(--ink-dim); letter-spacing: .3px;
  text-transform: uppercase; }
.modalCard input, .modalCard select, .modalCard textarea {
  font-family: inherit; font-size: 14px; padding: 8px 12px;
  border-radius: 2px; border: 1px solid var(--line2);
  background: var(--bg3); color: var(--ink); text-transform: none; }
.modalCard input:focus, .modalCard select:focus {
  outline: none; border-color: var(--accent); }
.modalbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.err { color: var(--bear); font-size: 11px; min-height: 14px; margin: 0; }
.modelRow { flex-direction: row !important; align-items: center;
  gap: 10px !important; text-transform: none !important; }
.modelRow select { flex: 1; }

#resumeFilter { font-family: inherit; font-size: 14px; padding: 8px 12px;
  border-radius: 2px; border: 1px solid var(--line2);
  background: var(--bg3); color: var(--ink); width: 100%; }
#resumeFilter:focus { outline: none; border-color: var(--accent); }

.resumeList { overflow-y: auto; flex: 1; min-height: 200px;
  border: 1px solid var(--line); border-radius: 2px;
  display: flex; flex-direction: column; background: var(--bg); }
.rItem { padding: 9px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line); transition: background .1s; }
.rItem:hover { background: var(--bg-hover); }
.rItem .rTop { display: flex; gap: 8px; align-items: baseline;
  font-size: 11px; color: var(--ink-dim2); }
.rItem .rCwd { color: var(--warn); flex: 1; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.rItem .rWhen { white-space: nowrap; color: var(--ink-dim2); }
.rItem .rPrev { font-size: 13px; color: var(--ink); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.4; }

/* ---- mobile (iPhone 17 Pro: 393pt wide) ---- */
@media (max-width: 700px) {
  :root { --bar-h: 54px; }
  html { overflow-x: hidden; }
  body { grid-template-columns: minmax(0, 1fr); grid-template-areas: "bar" "main"; }
  #menuBtn { display: inline-flex; }
  .barbtn .lbl { display: none; }
  .logo .lbl { display: none; }

  /* tighter header so buttons fit on 393pt */
  #bar { gap: 4px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right)); }

  #status { padding: 4px 10px 4px 20px; font-size: 12px; }
  #resumeBtn, #newBtn { padding: 0; justify-content: center; width: 44px; }

  /* center logo + status between the left (☰ ⌂) and right (↺ ＋ 🔑) groups */
  .logo { margin-left: auto; }

  /* sidebar as overlay drawer */
  #side {
    position: fixed;
    top: calc(var(--bar-h) + env(safe-area-inset-top));
    bottom: 0; left: 0; width: 82vw; max-width: 300px;
    transform: translateX(-100%);
    transition: transform .2s ease; z-index: 25;
    border-right: 1px solid var(--line2);
  }
  #side.open { transform: translateX(0); box-shadow: 6px 0 20px #000c; }
  #here { display: none; }

  /* touch targets ≥ 44px tall; trim horizontal padding to fit */
  .barbtn, .primarybtn, .dangerbtn {
    min-height: 44px; min-width: 44px;
    padding: 0 10px; font-size: 14px;
  }
  /* header buttons: brighter outline + larger icon glyph (circle size unchanged) */
  .barbtn {
    color: var(--ink);
    border-color: var(--ink-dim);
    font-size: 20px;
  }
  .barbtn.icon { padding: 0; width: 44px; justify-content: center; }
  #sendBtn { min-height: 44px; font-size: 14px; padding: 0 20px; }
  .attachbtn { width: 44px; height: 44px; font-size: 20px; }
  .sItem { padding: 12px 14px; }

  /* prevent iOS Safari auto-zoom on input focus */
  #chatText { font-size: 16px; }
  .modalCard input, .modalCard select, .modalCard textarea,
  #resumeFilter { font-size: 16px; }

  /* break long URLs/IPs so messages stay in viewport */
  .msg { font-size: 14px; padding: 10px 14px; overflow-wrap: anywhere; }

  #scrollBtn { bottom: calc(80px + env(safe-area-inset-bottom)); }

  .modalCard { width: 100%; }
  .modalCard.wide { width: 100%; }
}
