/* Coder — code.kriskraw.com */
:root {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #141920;
  --panel-2: #1b222b;
  --border: #27313d;
  --text: #e6ebf1;
  --muted: #8d99a8;
  --accent: #3ddc84;
  --accent-ink: #05240f;
  --danger: #ef5350;
  --danger-ink: #fff;
  --user-bubble: #1d2733;
  --code-bg: #0a0d11;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #ffffff;
    --panel: #f5f6f8;
    --panel-2: #eceef2;
    --border: #d3d8df;
    --text: #14181d;
    --muted: #5c6773;
    --accent: #2e7d32;
    --accent-ink: #ffffff;
    --danger: #c62828;
    --user-bubble: #edf1f5;
    --code-bg: #f6f8fa;
    --shadow: 0 10px 40px rgba(0, 0, 0, .18);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1 1 auto; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: 9px;
  background: var(--panel-2); cursor: pointer; white-space: nowrap; text-decoration: none;
  font-weight: 600; font-size: 14px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: var(--danger-ink, #fff); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); }
.btn-small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.toggle.on { border-color: var(--accent); color: var(--accent); }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-size: 18px; }
.icon-btn:hover { background: var(--panel-2); }
.only-mobile { display: none; }

/* ---------- shell ---------- */
.app { height: 100dvh; display: grid; grid-template-columns: 272px minmax(0, 1fr); overflow: hidden; }
.sidebar {
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 10px;
  padding: 14px 12px; background: var(--panel); border-right: 1px solid var(--border); min-height: 0;
}
.side-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 800; font-size: 17px; letter-spacing: .2px; }
.conv-list { overflow-y: auto; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.conv-empty { padding: 8px 6px; font-size: 13px; }
.conv { display: flex; align-items: center; border-radius: 8px; }
.conv:hover, .conv.active { background: var(--panel-2); }
.conv.active { box-shadow: inset 2px 0 0 var(--accent); }
.conv-open {
  flex: 1 1 auto; min-width: 0; padding: 8px 10px; border: 0; background: transparent; cursor: pointer;
  text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px;
}
.conv-act { flex: none; width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; opacity: 0; font-size: 13px; }
.conv:hover .conv-act, .conv.active .conv-act, .conv-act:focus-visible { opacity: .75; }
.conv-act:hover { opacity: 1; background: var(--border); }
.side-foot { display: flex; align-items: center; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); min-width: 0; }
.avatar { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.user-email { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--muted); }

/* The middle row is the only scroller: minmax(0,1fr) keeps the chat from growing to its content. */
.main { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); min-width: 0; }
.chat-title { margin: 0; font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.model-select { max-width: 46vw; height: 34px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--accent); }
.dot.bad { background: var(--danger); }

.chat { overflow-y: auto; padding: 22px 18px 10px; scroll-behavior: auto; overscroll-behavior: contain; }
.msg { max-width: 860px; margin: 0 auto 18px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 14px 14px 4px 14px; background: var(--user-bubble); border: 1px solid var(--border); }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.attachments { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.bubble > .attachments:first-child { margin-top: 0; }
.thumb img { display: block; max-width: 180px; max-height: 140px; border-radius: 8px; border: 1px solid var(--border); }
.filechip { display: inline-flex; align-items: center; max-width: 260px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--panel); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filechip.bad, .attachchip.bad { border-color: var(--danger); color: var(--danger); }

/* ---------- assistant markdown ---------- */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .8em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.1em 0 .5em; line-height: 1.25; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.22em; } .md h3 { font-size: 1.08em; }
.md ul, .md ol { margin: 0 0 .8em; padding-left: 1.5em; }
.md li { margin: .15em 0; }
.md blockquote { margin: 0 0 .8em; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md table { display: block; overflow-x: auto; border-collapse: collapse; margin: 0 0 .8em; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.md th { background: var(--panel); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.md code { font-family: var(--mono); font-size: .9em; padding: .12em .38em; border-radius: 5px; background: var(--panel-2); }
.md pre { margin: 0; padding: 12px 14px; overflow-x: auto; background: var(--code-bg); font-size: 13px; line-height: 1.5; tab-size: 2; }
.md pre code, .md pre code.hljs { padding: 0; background: transparent; font-size: inherit; display: block; white-space: pre; }
.md > pre { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 .9em; }
.codeblock { margin: 0 0 .9em; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.code-head { display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 12px; background: var(--panel); border-bottom: 1px solid var(--border); }
.code-name { font: 600 12.5px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-head button, .msg-foot button {
  border: 0; border-radius: 6px; padding: 4px 9px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.code-head button:hover, .msg-foot button:hover { background: var(--panel-2); color: var(--text); }
.code-head button[data-act="preview"] { color: var(--accent); }

/* ---------- laptop tool cards ---------- */
.seg + .seg, .tool + .seg, .seg + .tool { margin-top: 10px; }
.tool { margin: 8px 0; border: 1px solid var(--border); border-left: 3px solid var(--muted); border-radius: 10px; background: var(--panel); font-size: 13.5px; overflow: hidden; }
.tool.ok { border-left-color: var(--accent); }
.tool.bad { border-left-color: var(--danger); }
.tool.asking { border-color: var(--accent); }
.tool summary { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; min-width: 0; }
.tool-state { flex: none; width: 1.2em; text-align: center; }
.tool.ok .tool-state { color: var(--accent); } .tool.bad .tool-state { color: var(--danger); }
.tool-name { flex: none; font-weight: 700; }
.tool-desc { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.tool-why { padding: 0 12px 6px; color: var(--muted); }
.tool pre { margin: 0; padding: 8px 12px; max-height: 300px; overflow: auto; border-top: 1px solid var(--border); background: var(--code-bg); font: 12.5px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.tool-approve { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; border-top: 1px solid var(--border); font-weight: 600; }
.tool-img { display: block; max-width: min(100%, 420px); max-height: 320px; margin: 8px 12px 10px; border: 1px solid var(--border); border-radius: 8px; }
.toggle.warn { border-color: var(--danger); color: var(--danger); }
.steps { margin: 10px 0; padding-left: 1.4em; }
.steps li { margin: 4px 0; }
.laptop-status { margin: 10px 0 !important; padding: 8px 10px; border: 1px solid var(--danger); border-radius: 9px; color: var(--danger); font-size: 13.5px; }
.laptop-status.ok { border-color: var(--accent); color: var(--accent); }
.small { font-size: 12.5px; }

.think { margin: 0 0 10px; border: 1px dashed var(--border); border-radius: 10px; padding: 6px 12px; color: var(--muted); font-size: 13.5px; }
.think summary { cursor: pointer; font-weight: 600; }
.think-body { white-space: pre-wrap; margin-top: 6px; max-height: 320px; overflow-y: auto; }
.msg-note { margin-top: 8px; font-size: 13px; color: var(--muted); font-style: italic; }
.msg-error { margin-top: 8px; padding: 9px 12px; border: 1px solid var(--danger); border-radius: 10px; color: var(--danger); font-size: 14px; }
.msg-error .btn { margin-left: 6px; vertical-align: middle; }
.msg-foot { display: flex; align-items: center; gap: 4px; margin-top: 6px; min-height: 26px; }
.stats { font-size: 12px; color: var(--muted); }
.msg.assistant:not(:last-child) [data-act="regen"] { display: none; }

.typing { display: inline-flex; gap: 4px; vertical-align: middle; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .18s; } .typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .7; } }

.empty { max-width: 640px; margin: 9vh auto 0; text-align: center; }
.empty h2 { margin: 14px 0 6px; font-size: 26px; letter-spacing: -.3px; }
.starters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; text-align: left; }
.starter { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); cursor: pointer; font-size: 14px; text-align: left; }
.starter:hover { border-color: var(--accent); }

/* ---------- composer ---------- */
.composer-wrap { padding: 8px 18px max(14px, env(safe-area-inset-bottom)); }
.notice { max-width: 860px; margin: 0 auto 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); font-size: 13.5px; }
.notice.error { border-color: var(--danger); color: var(--danger); }
.composer { max-width: 860px; margin: 0 auto; padding: 10px; border: 1px solid var(--border); border-radius: 16px; background: var(--panel); }
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  display: block; width: 100%; min-height: 44px; max-height: 40vh; padding: 6px 8px; border: 0; outline: 0; resize: none;
  background: transparent; font-size: 15px; line-height: 1.5;
}
.composer-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.hint { font-size: 12.5px; color: var(--muted); }
.attach-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 4px 8px; }
.attachchip { display: inline-flex; align-items: center; gap: 7px; max-width: 280px; padding: 4px 6px 4px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 13px; }
.attachchip img { width: 30px; height: 30px; object-fit: cover; border-radius: 6px; }
.attachchip .an { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachchip .asz { color: var(--muted); font-size: 12px; white-space: nowrap; }
.attachchip .ax { border: 0; background: transparent; cursor: pointer; color: var(--muted); border-radius: 6px; width: 22px; height: 22px; }
.attachchip .ax:hover { background: var(--panel-2); color: var(--text); }

.drop-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 82%, transparent); pointer-events: none; }
.drop-overlay div { padding: 26px 40px; border: 2px dashed var(--accent); border-radius: 18px; font-size: 20px; font-weight: 700; color: var(--accent); background: var(--panel); }

/* ---------- dialogs ---------- */
.dlg { width: min(440px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0, 0, 0, .55); }
.dlg h2 { margin: 0 0 8px; font-size: 18px; }
.dlg p { margin: 0 0 4px; overflow-wrap: anywhere; }
.dlg input[type="text"] { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg-preview { width: min(1200px, calc(100vw - 24px)); height: calc(100dvh - 24px); max-height: none; padding: 0; overflow: hidden; }
.dlg-preview[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.preview-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--border); }
.dlg-preview iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* ---------- cookie notice ---------- */
.consent {
  /* at the top: at the bottom it covered the message box and its buttons */
  position: fixed; left: 16px; right: 16px; top: 12px; z-index: 60; max-width: 760px; margin: 0 auto;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow);
}
.consent p { margin: 0; flex: 1 1 320px; font-size: 13.5px; }
.consent-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login-card { width: min(400px, 100%); padding: 32px 28px; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); text-align: center; }
.login-card h1 { margin: 12px 0 8px; font-size: 26px; }
.gsi { display: flex; justify-content: center; min-height: 44px; margin-top: 20px; }
.login-status { margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.login-status.error { color: var(--danger); }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  .only-mobile { display: inline-block; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(300px, 86vw); transform: translateX(-102%); transition: transform .18s ease; box-shadow: var(--shadow); }
  .app.side-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .5); }
  .chat { padding: 16px 12px 8px; }
  .composer-wrap { padding: 6px 10px max(10px, env(safe-area-inset-bottom)); }
  .topbar { padding: 8px 10px; }
  .starters { grid-template-columns: 1fr; }
  .bubble { max-width: 96%; }
  .conv-act { opacity: .6; }
  .model-select { max-width: 40vw; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
