:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #111318;
  --muted: #5c6470;
  --line: #d9dde6;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.35;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 251, 0.9);
  backdrop-filter: blur(8px);
}

.brand { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.dot { width: 8px; height: 8px; border: 1px solid var(--muted); border-radius: 2px; display: inline-block; }

.right { display: flex; gap: 8px; align-items: center; }

.model {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 6px 26px 6px 8px;
  border-radius: 10px;
  font-size: 12px;
  outline: none;
}

.iconbtn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  cursor: pointer;
}
.iconbtn svg { width: 16px; height: 16px; fill: var(--muted); }
.iconbtn:hover svg { fill: var(--ink); }

.chat {
  padding: 10px;
  padding-bottom: 88px;
  max-width: 900px;
  margin: 0 auto;
}

.msg {
  position: relative;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 14px;
  padding: 10px;
  margin: 8px 0;
  overflow-wrap: anywhere;
}
.msg .meta { color: var(--muted); margin-bottom: 6px; font-size: 11px; }
.msg.user { border-color: #cfd6ea; }
.msg.assistant { border-color: #cfe6d4; }

.msg .content { white-space: normal; }
.msg .content.plain { white-space: pre-wrap; }

/* Composer */
.composer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: rgba(246, 247, 251, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 14px;
  padding: 10px;
  font-size: 13px;
  outline: none;
  min-height: 40px;
  max-height: 140px;
}

/* Right-side composer buttons stacked */
.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* icon buttons in composer (send + clear) */
.actionbtn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.actionbtn svg { width: 18px; height: 18px; fill: var(--muted); }
.actionbtn:hover svg { fill: var(--ink); }

/* Modal */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  display: grid;
  place-items: center;
  padding: 16px;
}
.hidden { display: none; }

.modal {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  padding: 12px;
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.modalTitle { color: var(--ink); font-size: 12px; letter-spacing: 0.5px; text-transform: uppercase; }

.label { display: block; color: var(--muted); margin: 8px 0 6px; font-size: 11px; }
.label.checkbox { display: flex; align-items: center; gap: 8px; margin: 2px 0 6px; }
.label.checkbox input { margin: 0; }

.divider {
  height: 1px;
  background: var(--line);
  margin: 10px 0;
}

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.textinput {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px;
  outline: none;
  font-size: 12px;
}

.keyrow {
  display: flex;
  gap: 8px;
  align-items: center;
}
.keyrow .textinput { flex: 1; }
.modal textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px;
  outline: none;
  font-size: 12px;
}

.modalActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}
.btn {
  border: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 12px;
}
.btn.ghost { color: var(--muted); }
.btn:hover { border-color: #b9c1d3; }

.hint { margin-top: 10px; color: var(--muted); font-size: 11px; }

/* Markdown */
.content code {
  background: #f2f4f8;
  border: 1px solid var(--line);
  padding: 1px 4px;
  border-radius: 8px;
  font-size: 12px;
}

.content pre {
  position: relative;
  background: #f2f4f8;
  border: 1px solid var(--line);
  padding: 34px 10px 10px;
  border-radius: 14px;
  overflow: auto;
}

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

/* Copy button inside code blocks */
.content pre .codecopybtn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0.65;
}

.content pre .codecopybtn svg { width: 13px; height: 13px; fill: var(--muted); }

.content pre:hover .codecopybtn,
.content pre:focus-within .codecopybtn {
  opacity: 1;
}

@media (hover: none) {
  .content pre .codecopybtn { opacity: 1; }
}

/* Tables */
.tablewrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tablewrap table {
  width: max-content;
  min-width: 100%;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  background: #e7f3ff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  font-size: 11px;
}

.content th,
.content td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  vertical-align: top;
}

.content th {
  background: rgba(255, 255, 255, 0.5);
  font-weight: 600;
}

.content a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.content ul, .content ol {
  padding-left: 18px;
  margin: 6px 0;
}

.content p { margin: 6px 0; }

.content blockquote {
  margin: 6px 0;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  color: var(--muted);
}

/* Copy button inside assistant bubble */
.msg .copybtn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 30px;
  height: 30px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease;
}

.msg .copybtn svg { width: 14px; height: 14px; fill: var(--muted); }

.msg.assistant:hover .copybtn,
.msg.assistant:focus-within .copybtn {
  opacity: 1;
}

/* Mobile/touch: no hover, so keep copy button visible */
@media (hover: none) {
  .msg.assistant .copybtn {
    opacity: 1;
  }
}

.copytoast {
  position: absolute;
  right: 44px;
  bottom: 12px;
  font-size: 11px;
  color: var(--muted);
}
