/* Same cozy colours as the dashboard */
:root {
  --bg: #131d16;
  --side: #18241b;
  --card: #1f2c23;
  --border: rgba(246, 190, 150, 0.10);
  --divider: rgba(246, 210, 180, 0.07);
  --ink: #efe6d3;
  --ink-soft: #a5ae9a;
  --ink-faint: #7d8676;      /* hints: pale and small */
  --peach: #f4ad82;
  --on-accent: #2b1a10;
  --mint: #aed49a;
  --amber: #e9bc94;
  --ember: #ea7d5c;
  --hover: rgba(239, 230, 211, 0.06);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; color: var(--ink); background: var(--bg); font: 15px/1.6 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif; }
[hidden] { display: none !important; }
b { font-weight: 650; }
.error { color: var(--ember); margin: 8px 4px 0; font-size: 13px; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled { cursor: default; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; display: block; }
.icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; color: var(--ink-soft); transition: background .15s, color .15s; }
.icon:hover { background: var(--hover); color: var(--ink); }
.round { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--peach); color: var(--on-accent); transition: opacity .15s, filter .15s; flex: none; }
.round svg { width: 18px; height: 18px; stroke-width: 2.2; }
.round:hover { filter: brightness(1.08); }
.round:disabled { opacity: .3; filter: none; }
.link { color: var(--ink-faint); font-size: 13px; }
.link:hover { color: var(--peach); }

input, textarea { font: inherit; color: var(--ink); background: none; border: 0; outline: none; width: 100%; }
::placeholder { color: var(--ink-faint); opacity: 1; }

/* Login: just the code box */
.login-wrap { display: grid; place-content: center; height: 100%; padding: 0 16px; }
.login { display: flex; align-items: center; gap: 8px; width: min(360px, 100%); background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 6px 6px 6px 16px; }
.login:focus-within { border-color: rgba(244,173,130,.35); }
#code { letter-spacing: .08em; font-weight: 550; }
#code:not(:placeholder-shown) { text-transform: uppercase; }

/* Layout: chat list left (can be closed), chat right */
.app { display: flex; height: 100vh; height: 100dvh; }
.side { width: 260px; flex: none; background: var(--side); border-right: 1px solid var(--divider); display: flex; flex-direction: column; padding: 10px 8px; transition: margin-left .2s ease; }
.app.side-closed .side { margin-left: -260px; }
.side-top { display: flex; justify-content: space-between; margin-bottom: 8px; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; scrollbar-width: thin; scrollbar-color: rgba(239,230,211,.12) transparent; }
.chat-item { display: flex; align-items: center; gap: 8px; text-align: left; color: var(--ink-soft); font-size: 14px; padding: 7px 10px; border-radius: 9px; width: 100%; }
.chat-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item:hover { background: var(--hover); color: var(--ink); }
.chat-item.cur { background: rgba(244,173,130,.10); color: var(--ink); }
.chat-item i { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); flex: none; }
.side-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 10px 4px; font-size: 13px; color: var(--ink-faint); }
.backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-height: 54px; }
.top-buttons { display: flex; gap: 2px; }
.app:not(.side-closed) .top-buttons { display: none; }   /* the sidebar has its own buttons while it's open */
.top-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--ink-soft); }
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
.status i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); }
.status.on i { background: var(--mint); box-shadow: 0 0 6px var(--mint); animation: pulse 1.6s infinite; }
.status.busy i { background: var(--amber); }
.status.ready i { background: var(--mint); }
.status.err i { background: var(--ember); }
@keyframes pulse { 50% { opacity: .35; } }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 8px 20px 20px; scrollbar-width: thin; scrollbar-color: rgba(239,230,211,.12) transparent; }
.thread { max-width: 720px; margin: 0 auto; }
.msg { margin-bottom: 22px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .text { background: var(--card); border: 1px solid var(--border); padding: 9px 14px; border-radius: 18px 18px 6px 18px; max-width: 80%; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.text .h { color: var(--mint); }
.text code { background: rgba(239,230,211,.07); border-radius: 5px; padding: 1px 5px; font-size: .92em; }
.text pre { background: rgba(0,0,0,.22); border-radius: 10px; padding: 10px 12px; overflow-x: auto; white-space: pre; margin: 8px 0; }
.text pre code { background: none; padding: 0; }
.meta { display: flex; gap: 12px; align-items: center; margin-top: 5px; font-size: 12px; color: var(--ink-faint); }
.msg.assistant .meta { opacity: 0; transition: opacity .15s; }
.msg.assistant:hover .meta, .msg.assistant:focus-within .meta { opacity: 1; }
.waiting { color: var(--ink-faint); font-size: 14px; }
.waiting .link { margin-left: 10px; }
details { margin-bottom: 10px; color: var(--ink-faint); font-size: 13.5px; }
summary { cursor: pointer; font-size: 13px; width: fit-content; }
summary:hover { color: var(--ink-soft); }

/* Message box at the bottom */
.composer { padding: 0 20px 18px; }
.box { max-width: 720px; margin: 0 auto; background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 12px 10px 8px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.22); }
.box:focus-within { border-color: rgba(244,173,130,.3); }
#text { resize: none; max-height: 40vh; display: block; padding: 2px 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 6px; }
.modes { display: flex; gap: 2px; margin-left: -6px; }
.mode { font-size: 12.5px; color: var(--ink-faint); padding: 3px 10px; border-radius: 8px; }
.mode:hover { color: var(--ink-soft); }
.mode[aria-checked="true"] { color: var(--peach); background: rgba(244,173,130,.10); }
.composer .error { max-width: 720px; margin: 8px auto 0; }

/* Phones: the chat list slides over the chat */
@media (max-width: 720px) {
  .side { position: fixed; inset: 0 auto 0 0; z-index: 5; width: min(290px, 85vw); margin-left: 0 !important; transform: none; transition: transform .2s ease; }
  .app.side-closed .side { transform: translateX(-100%); }
  .app:not(.side-closed) .backdrop { display: block; position: fixed; inset: 0; z-index: 4; background: rgba(0,0,0,.45); }
  .app .top-buttons { display: flex !important; }
  .top { padding: 8px 10px; }
  .messages { padding: 4px 16px 16px; }
  .composer { padding: 0 12px 12px; }
  .msg.user .text { max-width: 88%; }
  .msg.assistant .meta { opacity: 1; }   /* no hovering on phones */
}
