/* style.css — presentation layer.
 *
 * The design language is NextChat's (github.com/ChatGPTNextWeb/NextChat), the UI that
 * WebLLM Chat is built on: the app is a FLOATING ROUNDED WINDOW centred on a tinted page
 * rather than a full-bleed layout, with a tinted sidebar of chat *cards* and avatar+bubble
 * messages. Token values below are taken from that project's globals.scss so the look is
 * faithful rather than approximated.
 *
 * The accent is one variable (--primary). NextChat's muted slate-indigo is the default
 * because it's the look that was asked for; swapping in the Godfather amber (#d8a24a) is a
 * one-line change here and nothing else.
 *
 * No framework, no build step: plain CSS with custom properties, same constraint as the
 * rest of bin/dash.
 */

:root {
  --white: #fff;
  --black: rgb(48, 48, 48);
  --gray: rgb(240, 240, 240);
  --light-gray: rgb(120, 120, 120);
  --primary: rgb(90, 96, 135);
  --second: rgb(228, 229, 241);
  --hover-color: #f3f3f3;
  --bar-color: rgb(0 0 0 / 10%);
  --theme-color: var(--gray);

  --shadow: 50px 50px 100px 10px rgb(0 0 0 / 10%);
  --card-shadow: 0 2px 4px 0 rgb(0 0 0 / 5%);
  --border-in-light: 1px solid rgb(222, 222, 222);

  --good: rgb(63, 138, 96);
  --bad: rgb(190, 74, 66);

  /* The window is a card, not the viewport. This is the defining trait of the look. */
  --window-width: 90vw;
  --window-height: 90vh;
  --sidebar-width: 300px;
  --message-max-width: 80%;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --white: rgb(30, 30, 30);
    --black: rgb(187, 187, 187);
    --gray: rgb(21, 21, 21);
    --light-gray: rgb(120, 120, 120);
    --primary: rgb(96, 110, 190);        /* lifted from NextChat's dark primary for contrast on dark cards */
    --second: rgb(36, 40, 52);
    --hover-color: #323232;
    --bar-color: rgb(255 255 255 / 10%);
    --border-in-light: 1px solid rgb(255 255 255 / 19%);
    --good: rgb(104, 173, 135);
    --bad: rgb(222, 118, 110);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;                     /* the window scrolls internally, the page never does */
  background: var(--theme-color);
  color: var(--black);
  font-family: "Noto Sans", "SF Pro SC", "SF Pro Text", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Slim scrollbars everywhere — a full-width native bar breaks the card illusion. */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--bar-color); border-radius: 20px; }
* { scrollbar-width: thin; scrollbar-color: var(--bar-color) transparent; }

h1, h2, h3 { margin: 0; font-weight: 700; }
a { color: var(--primary); }

.muted { color: var(--light-gray); }
.fine { color: var(--light-gray); font-size: 12px; margin: 4px 0 0; }
.warn { color: var(--primary); font-size: 12px; margin: 6px 0 0; font-weight: 500; }
.bad { color: var(--bad); }

/* ---------- controls ---------- */

.btn {
  font: inherit;
  padding: 8px 14px;
  border: var(--border-in-light);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--black);
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: border-color .15s, background-color .15s;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:disabled:hover { border-color: rgb(222 222 222); }

/* Square icon button — the sidebar tail and header actions are built from these. */
.icon {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  font: inherit; font-size: 16px; line-height: 1;
  border: var(--border-in-light);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--black);
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: border-color .15s;
}
.icon:hover { border-color: var(--primary); }
.icon.bare { border: 0; box-shadow: none; background: transparent; color: var(--light-gray); }
.icon.bare:hover { background: var(--hover-color); color: var(--black); }

select, input, textarea {
  font: inherit;
  color: var(--black);
  background: var(--white);
  border: var(--border-in-light);
  border-radius: var(--radius);
  padding: 8px 10px;
}
select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--primary);
}

/* ---------- server-rendered login / deny pages ---------- */

body.center .card {
  width: min(420px, calc(100vw - 32px));
  background: var(--white);
  border: var(--border-in-light);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  text-align: center;
}
.card h1 { font-size: 24px; margin-bottom: 8px; }
.card .btn { margin-top: 20px; display: inline-block; text-decoration: none; }

/* ---------- the window ---------- */

.window {
  display: flex;
  width: var(--window-width);
  height: var(--window-height);
  min-width: 600px;
  max-width: 1200px;
  min-height: 370px;
  background: var(--white);
  border: var(--border-in-light);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;                     /* keeps children inside the rounded corners */
}

/* ---------- sidebar ---------- */

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  flex: none;
  padding: 20px;
  background: var(--second);
  box-shadow: inset -2px 0 2px 0 rgb(0 0 0 / 5%);
}

.sidebar-head { position: relative; padding-right: 40px; }
.sidebar-title { font-size: 20px; font-weight: 700; }
.sidebar-sub { font-size: 12px; color: var(--light-gray); margin-top: 2px; }
/* Mobile-only: closes the off-canvas sidebar. */
.sidebar-close { position: absolute; top: 0; right: 0; display: none; }

.sidebar-filter { margin: 16px 0 10px; }
.sidebar-filter input { width: 100%; }

/* min-height:0 is load-bearing: a flex child's default `min-height: auto` lets it grow
   past the container, so `overflow-y: auto` never engages and the list spills instead of
   scrolling. Same reason on .chat-body below. */
.chat-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }

.group {
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--light-gray);
  padding: 10px 4px 6px;
}

/* A chat CARD, not a list row — the trait that makes the sidebar read as NextChat. */
.chat-item {
  position: relative;
  display: block; width: 100%; text-align: left;
  font: inherit; color: inherit;
  padding: 10px 14px;
  background: var(--white);
  border: var(--border-in-light);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.chat-item:hover { border-color: var(--primary); }
.chat-item.on { border-color: var(--primary); border-width: 2px; padding: 9px 13px; }
.chat-item.readonly { opacity: .6; }

.chat-item-title {
  font-size: 14px; font-weight: 600;
  display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding-right: 16px;                  /* room for the pin star */
}
.chat-item-meta {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--light-gray);
  margin-top: 4px;
}
.chat-item-count { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-date { flex: none; }
.chat-item-pin { position: absolute; top: 8px; right: 10px; color: var(--primary); font-size: 12px; }

.sidebar-tail {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 16px;
}
.sidebar-actions { display: flex; gap: 8px; }

/* ---------- main panel ---------- */

.window-content {
  display: flex; flex-direction: column;
  width: calc(100% - var(--sidebar-width));
  height: 100%;
}

.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: var(--border-in-light);
}
.chat-head-menu { display: none; }      /* mobile-only sidebar opener */
.chat-head-text { flex: 1; min-width: 0; }
.chat-head-title {
  font-size: 16px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-head-sub { font-size: 12px; color: var(--light-gray); margin-top: 1px; }
.chat-head-actions { display: flex; gap: 8px; flex: none; }

.notice {
  margin: 14px 20px 0;
  padding: 10px 12px;
  background: var(--second);
  border: var(--border-in-light);
  border-radius: var(--radius);
  color: var(--black);
  font-size: 13px;
}

.chat-body { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; }
.empty { color: var(--light-gray); text-align: center; padding: 48px 16px; }

/* ---------- messages ---------- */

.msg { display: flex; flex-direction: column; margin-bottom: 20px; }
.msg.mine { align-items: flex-end; }

.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.msg.mine .msg-head { flex-direction: row-reverse; }

.avatar {
  display: grid; place-items: center;
  width: 30px; height: 30px; flex: none;
  font-size: 15px;
  background: var(--white);
  border: var(--border-in-light);
  border-radius: 11px;                  /* NextChat's avatar radius — squarer than a circle */
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
/* Filled rather than emoji: a top-hat glyph rendered dark-on-dark in dark mode. */
.avatar.bot { background: var(--primary); border-color: var(--primary); color: #fff; font-size: 13px; font-weight: 700; }
.msg-who { font-size: 12px; color: var(--light-gray); }

.bubble {
  position: relative;
  max-width: var(--message-max-width);
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--white);
  border: var(--border-in-light);
  box-shadow: var(--card-shadow);
  /* pre-wrap is what makes textContent-only rendering readable: the agent's newlines,
     indentation and code blocks survive without any markup being interpreted. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--second); }

.msg-foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 4px; padding: 0 2px;
  font-size: 10px; color: var(--light-gray);
  opacity: 0;
  transition: opacity .15s;
}
.msg.mine .msg-foot { flex-direction: row-reverse; }
.msg:hover .msg-foot, .msg:focus-within .msg-foot { opacity: 1; }
.msg-act {
  font: inherit; font-size: 10px;
  background: none; border: 0; padding: 0;
  color: var(--light-gray); cursor: pointer; text-decoration: underline;
}
.msg-act:hover { color: var(--black); }

/* ---------- composer ---------- */

.composer { border-top: var(--border-in-light); padding: 10px 20px 20px; }

/* Small pill buttons above the textarea, as in NextChat's chat-input-actions. */
.composer-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.composer-actions .pill {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12px;
  padding: 4px 10px;
  background: var(--white);
  border: var(--border-in-light);
  border-radius: 20px;
  box-shadow: var(--card-shadow);
  color: var(--black);
  cursor: pointer;
}
.composer-actions .pill:hover { border-color: var(--primary); }
/* A select that sits INSIDE a pill label, so the pill supplies the chrome. Defined here
   rather than as a style attribute: the CSP is `style-src 'self'`, which blocks inline
   style attributes outright. */
.bare-select {
  border: 0; box-shadow: none; background: transparent;
  padding: 0 0 0 4px;
  font: inherit; color: inherit;
  cursor: pointer;
}
.composer-hint { font-size: 11px; color: var(--light-gray); margin-left: auto; }

.composer-box { position: relative; }
.composer-box textarea {
  width: 100%;
  min-height: 68px;
  max-height: 40vh;
  resize: vertical;
  padding: 10px 100px 10px 14px;        /* right padding clears the overlaid Send button */
  background: var(--white);
}
.composer-send { position: absolute; right: 10px; bottom: 10px; }

/* ---------- profile dialog ---------- */

.sheet {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  color: var(--black);
  background: var(--white);
  border: var(--border-in-light);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgb(0 0 0 / 45%); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: var(--border-in-light);
}
.sheet-head h2 { font-size: 17px; }
.sheet-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.sheet-body label { display: block; font-size: 12px; font-weight: 600; margin: 18px 0 6px; }
.sheet-body select, .sheet-body input { width: 100%; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 24px; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 18px;
  font-size: 13px;
  background: var(--white);
  border: var(--border-in-light);
  border-radius: 20px;
  box-shadow: var(--shadow);
  z-index: 2000;
}
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }

/* ---------- mobile: window goes full-bleed, sidebar goes off-canvas ---------- */

@media (max-width: 600px) {
  .window {
    width: 100vw; height: 100%;
    min-width: 0; max-width: none;
    border: 0; border-radius: 0;
  }
  .sidebar {
    position: absolute; inset: 0 auto 0 -100%;
    width: 100%;
    z-index: 1000;
    transition: left ease .25s;
  }
  .sidebar.open { left: 0; }
  .sidebar-close { display: grid; }
  .window-content { width: 100%; }
  .chat-head-menu { display: grid; }
  .bubble { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
