:root {
  --bg: #f6f7fb;
  --bg-2: #eceef5;
  --panel: #ffffff;
  --sidebar: #eef0f6;
  --border: #dcdfea;
  --text: #1b1e2b;
  --muted: #676d85;
  --accent: #6366f1;
  --accent-2: #0ea5e9;
  --accent-soft: rgba(99, 102, 241, 0.1);
  --user-bubble: #e6e8f3;
  --danger: #dc2626;
  --ok: #059669;
  --shadow: 0 10px 40px rgba(30, 35, 60, 0.12);
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0c0e14;
    --bg-2: #12151e;
    --panel: #151923;
    --sidebar: #0f1219;
    --border: #232838;
    --text: #e6e8f0;
    --muted: #8a90a8;
    --accent: #a5b4fc;
    --accent-2: #7dd3fc;
    --accent-soft: rgba(165, 180, 252, 0.1);
    --user-bubble: #1d2230;
    --danger: #f87171;
    --ok: #34d399;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0c0e14;
  --bg-2: #12151e;
  --panel: #151923;
  --sidebar: #0f1219;
  --border: #232838;
  --text: #e6e8f0;
  --muted: #8a90a8;
  --accent: #a5b4fc;
  --accent-2: #7dd3fc;
  --accent-soft: rgba(165, 180, 252, 0.1);
  --user-bubble: #1d2230;
  --danger: #f87171;
  --ok: #34d399;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0c0e14; border: none; font-weight: 600;
}
:root:not([data-theme='dark']) .btn.primary { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .btn.primary { color: #0c0e14; } }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center;
  border-radius: 9px; border: none; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--accent-soft); color: var(--text); }
.icon-btn svg, .btn svg { width: 18px; height: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-2); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 80px; }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- Logo / mist ---------- */
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.logo svg { width: 28px; height: 28px; }
.mist-bg { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.mist-bg::before, .mist-bg::after {
  content: ''; position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%;
  filter: blur(80px); opacity: .18; animation: drift 24s ease-in-out infinite alternate;
}
.mist-bg::before { background: var(--accent); top: -30vmax; left: -20vmax; }
.mist-bg::after { background: var(--accent-2); bottom: -35vmax; right: -25vmax; animation-delay: -12s; }
@keyframes drift { to { transform: translate(8vmax, 6vmax) scale(1.1); } }
@media (prefers-reduced-motion: reduce) { .mist-bg::before, .mist-bg::after { animation: none; } }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; position: relative; }
.auth-card {
  position: relative; z-index: 1; width: 100%; max-width: 400px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow);
}
.auth-card .logo { justify-content: center; font-size: 24px; margin-bottom: 4px; }
.auth-card .logo svg { width: 36px; height: 36px; }
.auth-card .tagline { text-align: center; color: var(--muted); margin: 0 0 24px; }
.tabs { display: flex; background: var(--bg-2); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tabs button { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.auth-card .btn.primary { width: 100%; padding: 11px; }
.social-auth { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }
.btn.social { width: 100%; padding: 11px; font-weight: 500; background: var(--panel); color: var(--text); }
.btn.social svg { width: 18px; height: 18px; }
.btn.social:disabled { opacity: .6; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 8px 0 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-notice { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
.method-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.method-row:last-of-type { border-bottom: none; }
.method-row .method-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--bg-2); flex-shrink: 0; }
.method-row .method-icon svg { width: 18px; height: 18px; }
.method-row .info { flex: 1; min-width: 0; font-size: 14px; }
.method-row .info small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.method-connect { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- App layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 272px; flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 10px; gap: 10px; z-index: 20;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.new-chat { width: 100%; justify-content: flex-start; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.conv-group { font-size: 12px; color: var(--muted); padding: 12px 10px 4px; font-weight: 600; }
.conv-item {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-radius: 9px; cursor: pointer;
  color: var(--text); font-size: 14px;
}
.conv-item:hover { background: var(--accent-soft); }
.conv-item.active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.conv-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .actions { display: none; }
.conv-item:hover .actions, .conv-item.active .actions { display: flex; }
.conv-item .actions .icon-btn { width: 26px; height: 26px; }
.conv-item .actions svg { width: 14px; height: 14px; }
.user-box {
  border-top: 1px solid var(--border); padding-top: 10px; display: flex; align-items: center; gap: 10px; position: relative;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-weight: 600; font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0c0e14;
}
.user-box .who { flex: 1; min-width: 0; font-size: 14px; }
.user-box .who small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu {
  position: absolute; bottom: 52px; left: 0; right: 0; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 30;
}
.menu button, .menu a {
  display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 10px; border: none; background: none;
  border-radius: 8px; cursor: pointer; color: var(--text); font-size: 14px; text-align: left;
}
.menu button:hover, .menu a:hover { background: var(--accent-soft); }
.menu svg { width: 16px; height: 16px; color: var(--muted); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid transparent;
  position: relative; z-index: 2;
}
.model-select {
  appearance: none; border: 1px solid var(--border); background: var(--panel); border-radius: 10px;
  padding: 7px 34px 7px 12px; font-weight: 600; cursor: pointer; max-width: 70vw;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a90a8' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.menu-toggle { display: none; }

.messages { flex: 1; overflow-y: auto; position: relative; z-index: 1; scroll-behavior: smooth; }
.messages-inner { max-width: 780px; margin: 0 auto; padding: 16px 16px 40px; }
.msg { display: flex; gap: 14px; padding: 14px 0; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); padding: 10px 16px; border-radius: 18px 18px 4px 18px;
  max-width: 85%; white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant .bot-icon { width: 30px; height: 30px; flex-shrink: 0; margin-top: 2px; }
.msg.assistant .body { flex: 1; min-width: 0; }
.msg-tools { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-tools, .msg.last .msg-tools { opacity: 1; }
.msg-tools .icon-btn { width: 30px; height: 30px; }
.msg-tools svg { width: 15px; height: 15px; }
.msg .error-box {
  border: 1px solid var(--danger); color: var(--danger); background: rgba(220, 38, 38, .08);
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
}

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3 { line-height: 1.3; margin: 20px 0 10px; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md ul, .md ol { padding-left: 24px; margin: 0 0 12px; }
.md li { margin: 4px 0; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--bg-2); padding: 2px 6px; border-radius: 6px; }
.md pre { margin: 12px 0; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: #0d1117; }
.md pre code { display: block; padding: 14px 16px; overflow-x: auto; background: none; font-size: 13px; line-height: 1.55; color: #e6edf3; }
.md .code-head {
  display: flex; justify-content: space-between; align-items: center; padding: 6px 10px 6px 14px;
  background: #161b22; color: #8b949e; font-size: 12px; font-family: var(--mono);
}
.md .code-head button { background: none; border: none; color: #8b949e; cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.md .code-head button:hover { color: #e6edf3; background: #30363d; }
.md blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.md table { border-collapse: collapse; margin: 0 0 12px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md th { background: var(--bg-2); }
.md a { text-decoration: underline; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.cursor::after {
  content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 4px;
  background: var(--accent); animation: pulse 1s ease-in-out infinite; vertical-align: middle;
}
@keyframes pulse { 50% { opacity: .2; transform: scale(.7); } }
.thinking { display: flex; gap: 5px; padding: 8px 0; }
.thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s infinite; }
.thinking span:nth-child(2) { animation-delay: .2s; } .thinking span:nth-child(3) { animation-delay: .4s; }

/* Empty state */
.empty { max-width: 680px; margin: 0 auto; padding: 12vh 16px 24px; text-align: center; }
/* Animated mascot (see mascot.js) */
.mascot { position: relative; width: 140px; height: 140px; margin: -10px auto 4px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.mascot::before {
  content: ''; position: absolute; inset: 14%; border-radius: 50%;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  opacity: .45; filter: blur(14px); animation: glow 3.2s ease-in-out infinite;
}
.mascot[data-mood='happy']::before { opacity: .7; }
.mascot[data-mood='sleepy']::before { opacity: .2; animation-duration: 6s; }
.mascot svg { position: relative; width: 100%; height: 100%; overflow: visible; }
.mascot .m-eye, .mascot .m-mouth { fill: #0c0e14; }
.mascot .m-mouth { stroke: #0c0e14; stroke-width: .7; stroke-linejoin: round; }
.mascot .m-glint { fill: #fff; transition: opacity .1s; }
.mascot .m-happy { fill: none; stroke: #0c0e14; stroke-width: .9; stroke-linecap: round; }
.mascot .m-shadow { fill: var(--accent); filter: blur(.6px); }
.mascot .m-zzz { opacity: 0; transition: opacity .6s; fill: var(--muted); font: 600 4px var(--font); }
.mascot[data-mood='sleepy'] .m-zzz { opacity: 1; }
.mascot .m-zzz text { animation: zzz 2.4s ease-in infinite; }
@keyframes zzz {
  0% { opacity: 0; transform: translate(0, 2px); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translate(3px, -5px); }
}
@keyframes glow { 50% { transform: scale(1.15); opacity: .6; } }
@media (prefers-reduced-motion: reduce) {
  .mascot::before, .mascot .m-zzz text { animation: none; }
}
.empty h1 { font-size: 28px; margin: 0 0 6px; font-weight: 650; }
.empty p { color: var(--muted); margin: 0 0 28px; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; text-align: left; }
.suggestion {
  border: 1px solid var(--border); background: var(--panel); border-radius: 12px; padding: 12px 14px;
  cursor: pointer; font-size: 14px; transition: border-color .15s, transform .15s;
}
.suggestion:hover { border-color: var(--accent); transform: translateY(-1px); }
.suggestion b { display: block; font-weight: 600; }
.suggestion span { color: var(--muted); }

/* Composer */
.composer-wrap { padding: 0 16px 16px; position: relative; z-index: 2; }
.composer {
  max-width: 780px; margin: 0 auto; background: var(--panel); border: 1px solid var(--border);
  border-radius: 22px; padding: 8px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow); transition: border-color .15s;
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer-row .icon-btn { width: 38px; height: 38px; flex-shrink: 0; }
.composer-row textarea { margin: 0 4px; }
#mic-btn.recording { color: #fff; background: var(--danger); border-radius: 50%; }

/* Attachment tray above the text box */
.att-tray { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 4px 2px; }
.att-chip {
  position: relative; display: flex; align-items: center; gap: 8px; max-width: 240px; padding: 6px 4px 6px 6px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}
.att-chip img, .att-chip .att-icon { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.att-icon { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.att-icon svg { width: 18px; height: 18px; }
.att-icon.pdf { background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .5px; }
.att-meta { min-width: 0; flex: 1; line-height: 1.3; }
.att-meta b { display: block; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-meta small { display: block; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip.error { border-color: var(--danger); }
.att-chip.error small { color: var(--danger); }
.att-chip:not(.ready):not(.error):not(.recording) small { color: var(--accent); }
.att-chip .icon-btn { width: 26px; height: 26px; }
.att-chip .icon-btn svg { width: 14px; height: 14px; }
.att-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); transition: width .2s; }
.att-chip.recording { border-color: var(--danger); }
.rec-dot { width: 12px; height: 12px; margin: 0 6px 0 8px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.drop-overlay {
  position: absolute; inset: 12px; z-index: 40; border: 2px dashed var(--accent); border-radius: 18px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid; place-items: center;
  font-size: 18px; font-weight: 600; color: var(--accent); pointer-events: none;
}

/* Attachments inside sent messages */
.user-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: 85%; }
.msg.user .user-stack .bubble { max-width: 100%; }
.msg-atts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.att-image img { display: block; max-width: 260px; max-height: 260px; border-radius: 14px; border: 1px solid var(--border); object-fit: cover; }
.att-media { display: flex; flex-direction: column; gap: 4px; max-width: 360px; }
.att-media audio { width: 300px; max-width: 100%; }
.att-media video { width: 360px; max-width: 100%; border-radius: 14px; background: #000; }
.att-transcript { font-size: 13px; color: var(--muted); }
.att-transcript summary { cursor: pointer; }
.att-transcript p { margin: 4px 0 0; white-space: pre-wrap; color: var(--text); }
.att-doc {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; border-radius: 12px; min-width: 200px; max-width: 300px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text); text-decoration: none;
}
.att-doc .att-icon { width: 38px; height: 38px; border-radius: 8px; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; border: none; outline: none; background: transparent; resize: none; max-height: 220px;
  padding: 8px 0; line-height: 1.5;
}
.send-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0c0e14;
}
.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn svg { width: 18px; height: 18px; }
.foot-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 100; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(5, 7, 12, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 24px; width: 100%;
  max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 18px; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Top bar: Skills / Code ---------- */
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--muted); font-size: 13.5px; font-weight: 500;
}
.chip-btn svg { width: 15px; height: 15px; }
.chip-btn:hover { color: var(--text); border-color: var(--accent); }
.chip-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.chip-btn.locked::after { content: '🔒'; font-size: 11px; }
.chip-count { background: var(--accent); color: #0c0e14; border-radius: 99px; font-size: 11px; padding: 0 6px; }
@media (max-width: 560px) { .chip-btn span { display: none; } .chip-btn { padding: 7px 9px; } }

.skills-pop {
  position: absolute; top: 52px; right: 16px; width: min(360px, calc(100vw - 32px)); max-height: 70vh; overflow-y: auto; z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 12px;
}
.skills-head b { display: block; }
.skills-head small { color: var(--muted); font-size: 12.5px; }
.skills-group { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 14px 4px 6px; }
.skill-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.skill-row:hover { background: var(--accent-soft); }
.skill-row input { accent-color: var(--accent); width: 16px; height: 16px; flex-shrink: 0; }
.skill-icon { font-size: 18px; width: 22px; text-align: center; }
.skill-text { flex: 1; min-width: 0; }
.skill-text b { display: block; font-size: 14px; font-weight: 500; }
.skill-text small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skill-row .icon-btn { width: 28px; height: 28px; }
.skills-empty { color: var(--muted); font-size: 13px; margin: 4px; }
.skills-pop .new-skill { width: 100%; margin-top: 10px; }
.skill-view { white-space: pre-wrap; font-family: var(--mono); font-size: 13px; background: var(--bg-2); padding: 12px; border-radius: 10px; max-height: 50vh; overflow: auto; }

/* ---------- File cards in replies ---------- */
.file-card { border: 1px solid var(--border); border-radius: 12px; margin: 10px 0; background: var(--panel); overflow: hidden; }
.fc-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; cursor: pointer; font-size: 14px; }
.fc-head > svg { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
.fc-head b { font-family: var(--mono); font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-head small { color: var(--muted); margin-right: auto; white-space: nowrap; }
.file-card.writing { border-color: var(--accent); }
.fc-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.file-card .fc-code { margin: 0; border: none; border-top: 1px solid var(--border); border-radius: 0; max-height: 360px; overflow: auto; }

/* ---------- Workspace panel ---------- */
.workspace {
  width: min(46vw, 820px); min-width: 420px; flex-shrink: 0; border-left: 1px solid var(--border); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0; z-index: 10;
}
.ws-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--border); }
.ws-logo { width: 18px; height: 18px; color: var(--accent); flex-shrink: 0; }
.ws-name { flex: 1; min-width: 0; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 5px 8px; font-weight: 600; outline: none; }
.ws-name:hover:not(:disabled), .ws-name:focus { border-color: var(--border); background: var(--bg-2); }
.ws-head-actions { display: flex; align-items: center; gap: 2px; }
.ws-head-actions .btn.primary { margin-right: 4px; }
.ws-head-actions .btn.danger { background: var(--danger); color: #fff; }
.ws-head-actions svg { width: 17px; height: 17px; }
a.icon-btn.disabled { opacity: .35; pointer-events: none; }
.ws-tabs { display: flex; align-items: center; gap: 2px; padding: 6px 10px 0; border-bottom: 1px solid var(--border); }
.ws-tabs button { border: none; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.ws-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.ws-status { margin-left: auto; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.ws-body { flex: 1; display: flex; min-height: 0; }
.ws-files { width: 190px; flex-shrink: 0; border-right: 1px solid var(--border); overflow-y: auto; padding: 6px; font-size: 13px; }
.ws-files-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px 6px; color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.ws-files-head .icon-btn { width: 26px; height: 26px; }
.ws-dir { display: flex; align-items: center; gap: 5px; padding: 6px 6px 2px; color: var(--muted); font-size: 12px; }
.ws-dir svg { width: 13px; height: 13px; }
.ws-file { display: flex; align-items: center; gap: 4px; padding: 5px 4px 5px 8px; border-radius: 7px; cursor: pointer; font-family: var(--mono); font-size: 12.5px; }
.ws-file.nested { padding-left: 20px; }
.ws-file span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-file:hover, .ws-file.active { background: var(--accent-soft); }
.ws-file.active { color: var(--accent); }
.ws-file-acts { display: none; }
.ws-file:hover .ws-file-acts { display: flex; }
.ws-file-acts .icon-btn { width: 22px; height: 22px; }
.ws-file-acts svg { width: 12px; height: 12px; }
.ws-hint { color: var(--muted); font-size: 12.5px; padding: 6px; line-height: 1.5; }
.ws-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ws-pane { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.ws-pane iframe { flex: 1; width: 100%; border: none; background: #fff; }
.ws-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); font-size: 14px; background: var(--panel); }
.ws-editor-head { display: flex; justify-content: space-between; padding: 6px 12px; font-family: var(--mono); font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
#ws-editor {
  flex: 1; width: 100%; border: none; outline: none; resize: none; padding: 12px 14px; tab-size: 2;
  font: 13px/1.6 var(--mono); background: #0d1117; color: #e6edf3; white-space: pre; overflow: auto;
}
.ws-console { border-top: 1px solid var(--border); display: flex; flex-direction: column; max-height: 36%; min-height: 34px; }
.ws-console-head { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px; font-size: 12px; color: var(--muted); font-weight: 600; }
.ws-console-head span { margin-right: auto; }
.ws-console-head .icon-btn { width: 26px; height: 26px; }
.ws-console-head svg { width: 14px; height: 14px; }
.ws-console-body { overflow-y: auto; padding: 0 12px 8px; font: 12.5px/1.5 var(--mono); flex: 1; }
.ws-console:not(.has-output) .ws-console-body { display: none; }
.ws-console.has-output { height: 36%; }
.ws-log { white-space: pre-wrap; word-break: break-word; padding: 1px 0; border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
.ws-log.error { color: var(--danger); }
.ws-log.warn { color: #d97706; }
.ws-log.info { color: var(--accent); }
.ws-plot { max-width: 100%; background: #fff; border-radius: 8px; margin: 6px 0; }
@media (max-width: 1000px) {
  .workspace { position: fixed; inset: 0; width: auto; min-width: 0; z-index: 25; }
  .ws-files { width: 150px; }
}
@media (max-width: 600px) {
  .ws-body { flex-direction: column; }
  .ws-files { width: auto; max-height: 120px; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ---------- Plans & billing ---------- */
.upgrade-btn {
  width: 100%; justify-content: flex-start; border-color: transparent;
  background: linear-gradient(135deg, var(--accent-soft), rgba(125, 211, 252, .12)); color: var(--accent); font-weight: 600;
}
.plan-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  padding: 1px 7px; border-radius: 99px; background: var(--bg-2); color: var(--muted); vertical-align: 1px;
}
.plan-badge.paid { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0c0e14; }
.modal.wide { max-width: 880px; }
.modal.narrow { max-width: 420px; }
.plans-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.plans-head h2 { margin: 0 0 4px; }
.plans-head p { margin: 0; }
.plans-reason { color: var(--accent); font-weight: 500; }
.plan-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.plan-card {
  border: 1px solid var(--border); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-2);
}
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.plan-top { display: flex; align-items: center; justify-content: space-between; }
.plan-card h3 { margin: 0; font-size: 18px; }
.plan-card .badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.plan-price { font-size: 30px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.plan-price span { font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.plan-card p { margin: 0; font-size: 14px; }
.plan-card ul { list-style: none; padding: 0; margin: 8px 0 14px; display: flex; flex-direction: column; gap: 7px; font-size: 14px; }
.plan-card li { display: flex; gap: 8px; align-items: flex-start; }
.plan-card li svg { width: 16px; height: 16px; color: var(--ok); flex-shrink: 0; margin-top: 3px; }
.plan-pay { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.plans-note { font-size: 13px; color: var(--muted); margin: 16px 0 0; }
.pay-history { margin-top: 14px; font-size: 14px; }
.pay-history summary { cursor: pointer; color: var(--muted); }
.pay-history > div { margin-top: 10px; overflow-x: auto; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th, .mini-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.mini-table th { color: var(--muted); font-weight: 500; }
.pay-status { font-weight: 600; font-size: 12px; }
.pay-status.paid { color: var(--ok); }
.pay-status.failed, .pay-status.underpaid, .pay-status.refunded { color: var(--danger); }
.pay-status.pending, .pay-status.processing { color: var(--accent); }
.pay-result { text-align: center; }
.pay-result .pay-icon { font-size: 40px; min-height: 52px; display: grid; place-items: center; }
.pay-result h2 { margin: 8px 0 6px; }
.spinner {
  width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.msg .error-box.upsell { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }

/* ---------- Mobile ---------- */
.scrim { display: none; }
@media (max-width: 800px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 15; }
  .menu-toggle { display: inline-grid; }
  .suggestions { grid-template-columns: 1fr; }
  .empty { padding-top: 6vh; }
  .msg.user .bubble { max-width: 92%; }
  .user-stack { max-width: 92%; }
  .att-chip { max-width: 100%; }
  .att-image img { max-width: 200px; max-height: 200px; }
}

/* GitHub dialog */
.gh-user { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: -6px 0 14px; color: var(--muted); }
.gh-user b { color: var(--text); }
.gh-user .btn { margin-left: auto; }
.gh-choice { display: flex; gap: 18px; margin-bottom: 12px; font-size: 14px; }
.gh-choice input { accent-color: var(--accent); }
.gh-ok { color: var(--ok); font-size: 14px; }
.gh-ok a { color: var(--ok); text-decoration: underline; }
.file-card.invalid { border-color: var(--danger); opacity: .75; }
.file-card.invalid small { color: var(--danger); }

/* ---------- Chat avatar: round buddy with moving eyes ---------- */
wisp-buddy { display: inline-block; width: 30px; height: 30px; flex-shrink: 0; }
wisp-buddy svg { display: block; width: 100%; height: 100%; overflow: visible; }
.wb-body { transform-box: fill-box; transform-origin: 50% 100%; animation: wb-bob 3.4s ease-in-out infinite; }
.wb-eyes { animation: wb-look 9s cubic-bezier(.65, 0, .2, 1) infinite; }
.wb-eye { fill: #0c0e14; transform-box: fill-box; transform-origin: center; animation: wb-blink 5s infinite; }
/* Quick glances with pauses in between, like Grok's mascot */
@keyframes wb-look {
  0%, 12% { transform: translate(0, 0); }
  15%, 27% { transform: translate(-2.8px, -.6px); }
  30%, 41% { transform: translate(2.8px, -.4px); }
  44%, 55% { transform: translate(1.5px, 2px); }
  58%, 69% { transform: translate(-1.3px, -2.2px); }
  72%, 100% { transform: translate(0, 0); }
}
@keyframes wb-blink {
  0%, 91%, 100% { transform: scaleY(1); }
  94% { transform: scaleY(.1); }
  97% { transform: scaleY(1); }
}
@keyframes wb-bob {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-.7px) scale(1.015, .985); }
}
/* While a reply is being written: eyes up, darting side to side */
wisp-buddy.thinking .wb-eyes { animation: wb-think 1.5s ease-in-out infinite; }
wisp-buddy.thinking .wb-body { animation-duration: 1.3s; }
@keyframes wb-think {
  0%, 100% { transform: translate(2px, -2.4px); }
  50% { transform: translate(-2px, -2.4px); }
}
@media (prefers-reduced-motion: reduce) {
  wisp-buddy * { animation: none !important; }
}
