/* ============================================================
   Chokess AI — stylesheet
   Design system: OLED dark / soft light, AI purple + pink accent
   ============================================================ */

:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --grad: linear-gradient(135deg, #8b5cf6 0%, #a855f7 45%, #ec4899 100%);
  --grad-soft: linear-gradient(135deg, rgba(139,92,246,.22), rgba(236,72,153,.18));

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 26px;

  --shadow-1: 0 1px 2px rgba(0,0,0,.25), 0 4px 14px rgba(0,0,0,.18);
  --shadow-2: 0 8px 30px rgba(0,0,0,.35);
  --glow: 0 0 22px rgba(139,92,246,.45);

  --ease: cubic-bezier(.22,.7,.3,1);
  --fast: 160ms var(--ease);
  --med: 260ms var(--ease);

  --topbar-h: 58px;
  --sb-w: 292px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07060e;
  --bg-tint-a: rgba(139,92,246,.16);
  --bg-tint-b: rgba(236,72,153,.09);
  --surface: #0f0d1e;
  --surface-2: #151230;
  --surface-3: #1c1740;
  --field: #131026;
  --border: rgba(163,148,255,.14);
  --border-strong: rgba(163,148,255,.28);
  --text: #ece9fb;
  --text-2: #a9a1d6;
  --text-3: #8f86bf;
  --primary: #8b5cf6;
  --primary-2: #a78bfa;
  --pink: #ec4899;
  --danger: #ef4444;
  --danger-soft: rgba(239,68,68,.14);
  --success: #34d399;
  --success-soft: rgba(52,211,153,.14);
  --warn: #fbbf24;
  --code-bg: #0a0916;
  --user-bub: linear-gradient(135deg, #7c3aed, #6366f1);
  --scroll-thumb: rgba(163,148,255,.22);
  --scrim: rgba(2,2,10,.6);
  --dot-glow: rgba(52,211,153,.5);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f5fd;
  --bg-tint-a: rgba(139,92,246,.12);
  --bg-tint-b: rgba(236,72,153,.07);
  --surface: #ffffff;
  --surface-2: #f1edfb;
  --surface-3: #e9e3f8;
  --field: #f5f2fc;
  --border: rgba(91,72,160,.15);
  --border-strong: rgba(91,72,160,.32);
  --text: #1d1a30;
  --text-2: #4f4a72;
  --text-3: #6e6896;
  --primary: #7c3aed;
  --primary-2: #6d28d9;
  --pink: #db2777;
  --danger: #dc2626;
  --danger-soft: rgba(220,38,38,.1);
  --success: #059669;
  --success-soft: rgba(5,150,105,.12);
  --warn: #d97706;
  --code-bg: #12101f;
  --user-bub: linear-gradient(135deg, #7c3aed, #5a54e8);
  --scroll-thumb: rgba(91,72,160,.25);
  --scrim: rgba(30,20,60,.42);
  --dot-glow: rgba(5,150,105,.45);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background:
    radial-gradient(1100px 500px at 85% -10%, var(--bg-tint-a), transparent 60%),
    radial-gradient(900px 480px at -10% 20%, var(--bg-tint-b), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

::selection { background: rgba(139,92,246,.35); }

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
textarea { resize: vertical; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

.ic { width: 20px; height: 20px; flex: none; }

/* ---------------- scrollbars ---------------- */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 20px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ================= buttons / inputs ================= */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; min-width: 40px;
  border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--text-2);
  transition: background var(--fast), color var(--fast), border-color var(--fast), transform var(--fast);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.92); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 14px; border: 1px solid transparent;
  font-size: 14.5px; font-weight: 600;
  transition: transform var(--fast), box-shadow var(--fast), background var(--fast), border-color var(--fast), filter var(--fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--primary), #a855f7 60%, var(--pink)); color: #fff; box-shadow: 0 4px 16px rgba(139,92,246,.35); }
.btn.primary:hover { box-shadow: var(--glow); filter: brightness(1.05); }
.btn.ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost.danger-ghost { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn .ic { width: 18px; height: 18px; }
.link { background: none; border: none; padding: 0; color: var(--primary-2); font-weight: 600; font-size: inherit; text-decoration: underline; text-underline-offset: 3px; }

.text-input {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--field); color: var(--text); font-size: 15px;
}
.text-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139,92,246,.18); }

/* ================= backdrop + sidebar ================= */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: var(--scrim);
  opacity: 0; visibility: hidden;
  transition: opacity var(--med), visibility var(--med);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.scrim.show { opacity: 1; visibility: visible; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
  width: var(--sb-w);
  display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  transform: translateX(-102%);
  transition: transform var(--med);
  padding-bottom: env(safe-area-inset-bottom);
}
.sidebar.open { transform: translateX(0); box-shadow: var(--shadow-2); }

.sb-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 6px; }
.sb-close { display: none; }
.sb-search {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 12px 10px; padding: 0 10px; height: 40px;
  border-radius: 12px; background: var(--field); border: 1px solid var(--border);
  color: var(--text-3);
}
.sb-search .ic { width: 16px; height: 16px; }
.sb-search input {
  flex: 1; background: none; border: none; outline: none; color: var(--text); font-size: 14px;
}
.sb-search input::placeholder { color: var(--text-3); }

.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.chat-list .empty-hint { color: var(--text-3); font-size: 13px; text-align: center; padding: 24px 12px; }

.chat-item {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 9px 8px 9px 10px;
  border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--text-2); text-align: left;
  transition: background var(--fast);
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 2px;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.chat-item .chat-ic { color: var(--text-3); width: 17px; height: 17px; }
.chat-item .chat-main { flex: 1; min-width: 0; }
.chat-item .chat-title {
  font-size: 13.5px; font-weight: 500; color: inherit;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item .chat-meta { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.chat-item .chat-menu-btn {
  opacity: 0; width: 30px; height: 30px; min-width: 30px; border-radius: 8px;
  transition: opacity var(--fast);
}
.chat-item:hover .chat-menu-btn, .chat-item .chat-menu-btn:focus-visible { opacity: 1; }
.chat-item .chat-menu-btn .ic { width: 16px; height: 16px; }
@media (hover: none) { .chat-item .chat-menu-btn { opacity: 1; } }

.sb-foot {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; border-top: 1px solid var(--border);
}
.sb-foot-row {
  flex: 1; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 8px 10px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--text);
  transition: background var(--fast);
  min-height: 44px;
}
.sb-foot-row:hover { background: var(--surface-2); }
.sb-foot-row .kstatus { position: relative; display: inline-flex; }
.sb-foot-row .kstatus .ic { width: 19px; height: 19px; color: var(--text-2); }
.key-dot {
  position: absolute; top: -3px; right: -3px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--warn); border: 2px solid var(--surface);
}
.key-dot.ok { background: var(--success); box-shadow: 0 0 8px var(--dot-glow); }
.row-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-txt b { font-size: 13px; font-weight: 600; }
.row-txt small { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { width: 16px !important; height: 16px !important; color: var(--text-3); }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--grad);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; box-shadow: 0 4px 12px rgba(139,92,246,.4);
}
.logo .ic { width: 18px; height: 18px; }
.brand-name { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.brand-name em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.brand.mini .brand-name { font-size: 16px; }
.brand.mini .logo { width: 30px; height: 30px; border-radius: 9px; }
.sb-head .brand { flex: 1; padding-left: 4px; }

.new-chat-btn { flex: 1; margin: 8px 4px 0; justify-content: flex-start; padding: 0 14px; }
.sb-head { flex-wrap: wrap; }
.sb-head .new-chat-btn { flex-basis: 100%; order: 3; margin: 4px 0 8px; }

/* ================= main layout ================= */
.main {
  height: 100dvh;
  display: flex; flex-direction: column;
  position: relative;
  margin-left: 0;
}

/* topbar */
.topbar {
  flex: none; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: relative; z-index: 20;
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 6px; }
.tb-model {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 12px 0 10px;
  border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--text-2); font-size: 13.5px; font-weight: 500;
  max-width: 60vw; transition: background var(--fast);
}
.tb-model:hover { background: var(--surface-2); color: var(--text); }
.tb-model .model-txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.provider-dot { width: 8px; height: 8px; min-width: 8px; border-radius: 50%; background: var(--warn); }
.provider-dot.ok { background: var(--success); box-shadow: 0 0 8px var(--dot-glow); }

.menu-wrap { position: relative; }
.dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  min-width: 230px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-2);
  padding: 6px; display: flex; flex-direction: column;
  transform-origin: top right;
  animation: popIn var(--fast);
}
.dropdown button {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: none; background: transparent; color: var(--text-2);
  font-size: 14px; border-radius: 10px; text-align: left;
  transition: background var(--fast), color var(--fast);
}
.dropdown button:hover { background: var(--surface-2); color: var(--text); }
.dropdown button .ic { width: 17px; height: 17px; }
.dropdown button[data-act="clear"] { color: var(--danger); }
.dropdown button[data-act="clear"]:hover { background: var(--danger-soft); }
.dropdown-sep { height: 1px; background: var(--border); margin: 5px 8px; }
@keyframes popIn { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }

/* chat scroll area */
.chat-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  scroll-behavior: smooth;
  outline: none;
}
.chat-inner {
  max-width: 860px; margin: 0 auto;
  padding: 22px 16px 8px;
  display: flex; flex-direction: column; gap: 20px;
}

/* ---------------- welcome ---------------- */
.welcome-wrap { flex: 1; min-height: 0; overflow-y: auto; display: none; }
body.empty .welcome-wrap { display: flex; align-items: center; justify-content: center; padding: 20px 16px 30px; }
body.empty .chat-scroll { display: none; }
.welcome { text-align: center; max-width: 600px; width: 100%; animation: rise var(--med); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.w-logo {
  width: 78px; height: 78px; margin: 0 auto 18px;
  border-radius: 24px; background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  color: #fff; box-shadow: var(--glow), 0 10px 34px rgba(139,92,246,.45);
  animation: floaty 5s ease-in-out infinite;
}
.w-logo .ic { width: 40px; height: 40px; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.w-title { font-size: clamp(34px, 6vw, 46px); font-weight: 800; letter-spacing: -.03em; margin: 0 0 8px; }
.w-title em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.w-sub { color: var(--text-2); margin: 0 auto 20px; max-width: 440px; font-size: 16px; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; margin-top: 8px; }
.starter {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 16px; border-radius: 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); font-size: 13.5px; font-weight: 500;
  text-align: left; max-width: 100%;
  transition: border-color var(--fast), color var(--fast), transform var(--fast), box-shadow var(--fast);
}
.starter:hover { border-color: var(--primary); color: var(--text); box-shadow: 0 4px 18px rgba(139,92,246,.25); transform: translateY(-1px); }
.starter .ic { width: 17px; height: 17px; color: var(--primary-2); }

/* ================= messages ================= */
.msg { display: flex; gap: 12px; animation: msgIn var(--med); }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: min(78%, 620px);
  background: var(--user-bub); color: #fff;
  padding: 11px 16px; border-radius: 20px 20px 6px 20px;
  white-space: pre-wrap; word-break: break-word;
  box-shadow: 0 6px 18px rgba(99,80,237,.25);
  font-size: 15.5px; line-height: 1.55;
}
.msg.error .bubble { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); border-radius: 16px; padding: 12px 14px; font-size: 14px; max-width: 80%; }
.msg.error .bubble .e-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 4px; }
.msg.error .bubble .e-title .ic { width: 17px; height: 17px; }

.msg.ai { align-items: stretch; }
.ai-avatar {
  width: 32px; height: 32px; min-width: 32px;
  border-radius: 11px; background: var(--grad);
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
  box-shadow: 0 3px 10px rgba(139,92,246,.35);
  margin-top: 2px;
}
.ai-avatar .ic { width: 17px; height: 17px; }
.ai-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.ai-meta { display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.ai-meta .nm { font-size: 14px; font-weight: 700; }
.ai-meta .model-tag {
  font-size: 11px; color: var(--text-3);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px;
}
.ai-time { font-size: 11.5px; color: var(--text-3); }

.md { min-width: 0; font-size: 15.5px; line-height: 1.68; color: var(--text); word-wrap: break-word; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: .7em 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.1em 0 .5em; line-height: 1.3; letter-spacing: -.01em; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.28em; } .md h3 { font-size: 1.12em; }
.md ul, .md ol { padding-left: 1.4em; margin: .6em 0; }
.md li { margin: .25em 0; }
.md li::marker { color: var(--primary-2); }
.md blockquote {
  margin: .8em 0; padding: 6px 16px;
  border-left: 3px solid var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  border-radius: 0 10px 10px 0; color: var(--text-2);
}
.md code { font-family: var(--font-mono); font-size: .88em; background: color-mix(in srgb, var(--primary) 14%, var(--surface-2)); padding: .15em .45em; border-radius: 6px; }
.md a { color: var(--primary-2); text-decoration: underline; text-underline-offset: 2px; }
.md table { border-collapse: collapse; margin: .8em 0; width: 100%; font-size: .93em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.md th { background: var(--surface-2); font-weight: 600; }
.md img { max-width: 100%; border-radius: 12px; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

/* streaming caret */
.streaming .caret { display: inline-block; width: 9px; height: 17px; border-radius: 2px; background: var(--primary-2); vertical-align: text-bottom; margin-left: 2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* thinking dots */
.typing { display: inline-flex; gap: 5px; padding: 14px 4px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity:.5 } 30% { transform: translateY(-5px); opacity:1 } }

/* msg action row */
.msg-actions { display: flex; gap: 4px; opacity: .55; transition: opacity var(--fast); }
.msg-actions:hover { opacity: 1; }
.msg-actions .icon-btn { width: 32px; height: 32px; min-width: 32px; border-radius: 9px; }
.msg-actions .icon-btn .ic { width: 16px; height: 16px; }
.msg-actions .copied { color: var(--success) !important; }

/* artifact card: review / download hasil website */
.artifact {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 12px 0 2px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  background:
    linear-gradient(135deg, rgba(139,92,246,.14), rgba(236,72,153,.11)),
    var(--surface-2);
  animation: artifactIn var(--med);
}
@keyframes artifactIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.artifact .art-icon {
  width: 44px; height: 44px; min-width: 44px; border-radius: 13px;
  background: var(--grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(139,92,246,.4);
}
.artifact .art-icon .ic { width: 22px; height: 22px; }
.artifact .art-txt { flex: 1; min-width: 150px; display: flex; flex-direction: column; }
.artifact .art-txt b { font-size: 14px; letter-spacing: -.01em; }
.artifact .art-txt small { font-size: 12px; color: var(--text-2); }
.artifact .art-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.artifact .art-actions .btn { min-height: 40px; padding: 0 15px; font-size: 13.5px; border-radius: 12px; }
.artifact .art-actions .btn .ic { width: 16px; height: 16px; }
@media (max-width: 560px) {
  .artifact { flex-direction: column; align-items: stretch; }
  .artifact .art-icon { align-self: center; }
  .artifact .art-txt { min-width: 0; text-align: center; }
  .artifact .art-actions { justify-content: stretch; }
  .artifact .art-actions .btn { flex: 1; justify-content: center; }
}

/* ================= code blocks ================= */
.code-block { margin: .9em 0; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); background: var(--code-bg); box-shadow: 0 4px 18px rgba(0,0,0,.18); }
.code-head {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px 7px 14px;
  background: color-mix(in srgb, var(--surface-2) 80%, var(--code-bg));
  border-bottom: 1px solid var(--border);
}
.code-lang { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-2); text-transform: lowercase; letter-spacing: .02em; }
.code-dot { width: 8px; height: 8px; border-radius: 50%; opacity: .8; }
.code-body { overflow-x: auto; }
.code-body pre { margin: 0; padding: 14px 16px; }
.code-body code { font-family: var(--font-mono); font-size: 13px; line-height: 1.6; background: none !important; padding: 0; }
.code-body .hljs { background: transparent; padding: 0; }
.code-actions { display: flex; gap: 4px; margin-left: auto; }
.code-actions .icon-btn { width: 30px; height: 30px; min-width: 30px; border-radius: 8px; color: var(--text-3); }
.code-actions .icon-btn:hover { color: var(--text); background: color-mix(in srgb, #fff 8%, transparent); }
.code-actions .icon-btn .ic { width: 15px; height: 15px; }
.code-actions .preview-btn { color: var(--primary-2); }
.code-head .spacer { flex: 1; }
.code-title { display:flex; align-items:center; gap:8px; min-width:0; }
.code-title .ic { width: 15px; height: 15px; color: var(--text-3); }

/* ================= composer ================= */
.composer-wrap { flex: none; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
body.empty .composer-wrap { max-width: 780px; width: 100%; margin: 0 auto; }
.composer {
  max-width: 860px; margin: 0 auto;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 6px 26px rgba(0,0,0,.18);
  transition: border-color var(--fast), box-shadow var(--fast);
  overflow: hidden;
}
.composer:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139,92,246,.16), 0 8px 28px rgba(0,0,0,.16); }
.composer-inner { display: flex; align-items: flex-end; gap: 6px; padding: 10px 10px 10px 16px; }
#inputBox {
  flex: 1; border: none; outline: none; resize: none;
  background: transparent; color: var(--text);
  font-size: 15.5px; line-height: 1.5;
  max-height: 200px; min-height: 24px; padding: 8px 0;
}
#inputBox::placeholder { color: var(--text-3); }
.composer-actions { display: flex; align-items: flex-end; gap: 6px; }
.send {
  width: 44px; height: 44px; border: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--grad); color: #fff;
  box-shadow: 0 4px 14px rgba(139,92,246,.4);
  transition: transform var(--fast), filter var(--fast), box-shadow var(--fast);
}
.send:hover { filter: brightness(1.08); box-shadow: var(--glow); }
.send:active { transform: scale(.9); }
.send:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.send .ic { width: 20px; height: 20px; }
.send.stop { background: var(--danger); box-shadow: 0 4px 14px rgba(239,68,68,.35); }
.send.stop .ic { width: 16px; height: 16px; }
.composer-note { margin: 0; padding: 0 16px 10px; font-size: 11px; color: var(--text-3); text-align: center; }

/* ================= modals & sheets ================= */
.modal { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-back { position: absolute; inset: 0; background: var(--scrim); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade var(--fast); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: relative; width: 100%; max-width: 640px; max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-2);
  animation: sheetUp var(--med);
  overflow: hidden;
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); flex: none; }
.sheet-title { display: flex; align-items: center; gap: 10px; }
.sheet-title h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.sheet-title .accent { color: var(--primary); }
.sheet-title .ic { width: 20px; height: 20px; }

.sheet-body { overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 20px; }
.sheet-foot { flex: none; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 90%, transparent); }

.set-sec { display: flex; flex-direction: column; gap: 8px; }
.set-sec h3 { margin: 0 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--text-3); font-weight: 700; }

.f-label { font-size: 13.5px; font-weight: 600; color: var(--text); }
.f-label .req { color: var(--pink); }
.f-label .opt { color: var(--text-3); font-weight: 500; font-size: 12px; }
.helper { margin: 0; font-size: 12.5px; color: var(--text-3); line-height: 1.5; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 5px; border-radius: 14px; border: 1px solid var(--border); }
.seg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; border: none; background: transparent; color: var(--text-2);
  font-size: 13.5px; font-weight: 600; border-radius: 10px; padding: 0 8px;
  transition: background var(--fast), color var(--fast), box-shadow var(--fast);
  text-align: center;
}
.seg-btn .ic { width: 17px; height: 17px; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.seg-btn.active .ic { color: var(--primary); }

.input-row { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 8px 0 14px; border: 1px solid var(--border); border-radius: 13px; background: var(--field); transition: border-color var(--fast), box-shadow var(--fast); }
.input-row:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139,92,246,.16); }
.input-row > .ic { width: 18px; height: 18px; color: var(--text-3); }
.input-row input { flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--text); font-size: 14.5px; padding: 12px 0; }
.input-row input::placeholder { color: var(--text-3); }
.input-row .icon-btn { width: 38px; height: 38px; min-width: 38px; }

.adv { border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); overflow: hidden; }
.adv summary { display: flex; align-items: center; gap: 10px; padding: 13px 16px; cursor: pointer; font-size: 14px; font-weight: 600; list-style: none; user-select: none; }
.adv summary::-webkit-details-marker { display: none; }
.adv summary .ic { width: 18px; height: 18px; color: var(--text-3); }
.adv[open] summary { border-bottom: 1px solid var(--border); }
.adv-body { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.adv-body textarea, .set-sec textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 13px; background: var(--field);
  color: var(--text); font-size: 14px; padding: 12px 14px; outline: none;
}
.adv-body textarea:focus, .set-sec textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139,92,246,.16); }
.adv-body input[type="range"] { width: 100%; accent-color: var(--primary); height: 26px; }

.test-btn { align-self: flex-start; }
.test-btn.busy { pointer-events: none; opacity: .7; }
.test-status { font-size: 13px; padding: 10px 14px; border-radius: 12px; display: none; }
.test-status.ok { display: block; background: var(--success-soft); color: var(--success); border: 1px solid color-mix(in srgb, var(--success) 35%, transparent); }
.test-status.err { display: block; background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }

/* tiny modal boxes */
.tiny-modal { align-items: center; }
.tiny-box {
  position: relative; z-index: 1;
  width: min(92vw, 400px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 26px 24px 22px;
  box-shadow: var(--shadow-2); text-align: center;
  animation: popIn var(--med);
  display: flex; flex-direction: column; gap: 10px;
}
.tiny-box h3 { margin: 0; font-size: 17px; }
.tiny-box p { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.55; }
.tiny-icon { width: 52px; height: 52px; margin: 0 auto 2px; border-radius: 50%; background: var(--danger-soft); color: var(--danger); display: flex; align-items: center; justify-content: center; }
.tiny-icon .ic { width: 24px; height: 24px; }
.tiny-icon.alt { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.tiny-icon.grad { background: var(--grad); color: #fff; box-shadow: var(--glow); }
.tiny-actions { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.tiny-actions.center { justify-content: center; }
.tiny-box .text-input { margin: 4px 0; }
.about-list { list-style: none; margin: 6px 0 0; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 7px; }
.about-list li { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; color: var(--text-2); }
.about-list .ic { width: 17px; height: 17px; color: var(--success); margin-top: 2px; }
.about-box em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

/* model preset picker */
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.custom-slot { display: flex; flex-direction: column; gap: 8px; }
.preset {
  display: flex; flex-direction: column; gap: 3px; text-align: left;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 13px;
  background: transparent; color: var(--text); cursor: pointer;
  font-family: inherit; transition: border-color var(--fast), background var(--fast), transform var(--fast);
}
.preset:hover { border-color: var(--border-strong); background: color-mix(in srgb, var(--primary) 7%, transparent); }
.preset:active { transform: scale(.985); }
.preset.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 16%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 45%, transparent); }
.preset-name { display: flex; align-items: center; gap: 7px; font-weight: 650; font-size: 13.5px; }
.preset-name .ic { width: 15px; height: 15px; color: var(--text-3); }
.preset.active .preset-name .ic { color: var(--primary-2); }
.preset-hint { font-size: 11.5px; color: var(--text-3); }
.rec-badge {
  font-style: normal; font-weight: 600; font-size: 9.5px; margin-left: auto;
  color: var(--primary-2); border: 1px solid color-mix(in srgb, var(--primary) 45%, transparent);
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  padding: 1px 7px; border-radius: 999px; letter-spacing: .2px; text-transform: uppercase;
}
.preset-custom { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
.preset-custom .preset-name { color: var(--text-2); }
.preset-custom.active .preset-name { color: var(--text); }
.preset-input { display: none; }
.preset-input.show { display: flex; }

/* preview modal */
.pv-sheet { max-width: 920px; height: 92dvh; }
.pv-actions { display: flex; gap: 6px; }
.pv-body { flex: 1; min-height: 0; background: #fff; }
#pvFrame { width: 100%; height: 100%; border: none; background: #fff; }

/* ================= toasts ================= */
.toasts { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 14px; padding: 11px 18px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-2);
  animation: toastIn var(--med);
  max-width: min(92vw, 420px);
}
.toast.out { animation: toastOut var(--fast) forwards; }
.toast .ic { width: 18px; height: 18px; }
.toast.ok .ic { color: var(--success); }
.toast.err .ic { color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ================= responsive ================= */
@media (min-width: 960px) {
  .sidebar { transform: none; border-radius: 0; }
  .sb-close { display: none; }
  .scrim { display: none !important; }
  .main { margin-left: var(--sb-w); }
  #menuBtn { display: none; }
  .sheet { border-radius: 26px; margin-bottom: 3vh; }
  .welcome-wrap { align-items: center; }
}

@media (max-width: 959px) {
  .chat-inner { padding-top: 16px; }
}

@media (min-width: 640px) {
  .modal { align-items: center; }
  .sheet { max-height: 88dvh; border-radius: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; scroll-behavior: auto !important; }
}
