/* Sali chat. Light by default; [data-theme="dark"] on <html> switches. */

:root {
  /* Sali brand: mint #00e3b0, violet #8b5cf6, ink #0b0a14. On light
     backgrounds mint and violet are deepened to keep text contrast >= 4.5:1. */
  /* The >_ mark from the SaliCode logo (brand-mark tiles, chat avatars). */
  --logo-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 188 168'%3E%3Cdefs%3E%3ClinearGradient id='c' gradientUnits='userSpaceOnUse' x1='20' y1='10' x2='90' y2='84'%3E%3Cstop offset='0' stop-color='%2304dfb2'/%3E%3Cstop offset='1' stop-color='%2341a4d1'/%3E%3C/linearGradient%3E%3ClinearGradient id='b' gradientUnits='userSpaceOnUse' x1='107' y1='0' x2='188' y2='0'%3E%3Cstop offset='0' stop-color='%235e87df'/%3E%3Cstop offset='1' stop-color='%238466f2'/%3E%3C/linearGradient%3E%3C/defs%3E%3Cpath fill='url(%23c)' d='M0 11Q0 0 11 0L13 0Q20.5 0 27 5.7L106 75.5Q116 84 106 92.5L27 162.3Q20.5 168 13 168L11 168Q0 168 0 157L0 136Q0 131 4 127.5L52 84L4 40.5Q0 37 0 32Z'/%3E%3Crect fill='url(%23b)' x='107' y='126' width='81' height='35' rx='8'/%3E%3C/svg%3E");
  --bg: #f7f7fb;
  --surface: #ffffff;
  --sidebar: #efeef6;
  --hover: #0b0a140a;
  --active: #0b0a1412;
  --border: #0b0a1414;
  --border-strong: #0b0a1426;
  --text: #14121f;
  --text-soft: #4d4963;
  --text-faint: #6b6782;
  --accent: #007a61;
  --accent-ink: #ffffff;
  --accent-soft: #00e3b01f;
  --violet: #7444e8;
  --user-bubble: #ebe8f7;
  --danger: #c43d3d;
  --danger-soft: #c43d3d12;
  --shadow: 0 1px 2px #0b0a140a, 0 8px 28px #0b0a1414;
  --shadow-pop: 0 2px 6px #0b0a1412, 0 18px 48px #0b0a1426;
  --code-bg: #12101e;
  --code-head: #1b1830;
  --code-text: #e9e6f5;
  --radius: 16px;
  --font: ui-sans-serif, -apple-system, 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #100e1b;
  --surface: #181527;
  --sidebar: #0b0a14;
  --hover: #ffffff0d;
  --active: #ffffff17;
  --border: #ffffff12;
  --border-strong: #ffffff24;
  --text: #eeecf7;
  --text-soft: #b3aecb;
  --text-faint: #8f89aa;
  --accent: #00e3b0;
  --accent-ink: #0b0a14;
  --accent-soft: #00e3b01c;
  --violet: #8b5cf6;
  --user-bubble: #241f38;
  --danger: #ff8a8a;
  --danger-soft: #ff8a8a18;
  --shadow: 0 1px 2px #0000004d, 0 8px 28px #00000059;
  --shadow-pop: 0 2px 6px #00000059, 0 18px 48px #00000080;
  --code-bg: #0b0a14;
  --code-head: #151229;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
svg { display: block; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================ brand ============================ */

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 1.05rem; letter-spacing: -0.015em; }
.brand-mark {
  display: grid; place-items: center;
  width: 28px; height: 28px; flex: 0 0 28px;
  border-radius: 9px;
  background: #0b0a14 var(--logo-mark) center / 66% no-repeat;
  color: #fff;
  font-size: 0.86rem; font-weight: 750;
}
.brand-accent { color: var(--accent); }

/* ============================ auth ============================ */

.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 34px 32px 30px;
  box-shadow: var(--shadow);
}
.auth-card .brand { justify-content: center; margin-bottom: 18px; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head h1 { font-size: 1.45rem; font-weight: 650; margin: 0 0 6px; letter-spacing: -0.02em; }
.auth-head p, .auth-sub { color: var(--text-faint); font-size: 0.93rem; margin: 0; }
.auth-sub { text-align: center; margin-bottom: 20px; }

label { display: block; font-size: 0.83rem; font-weight: 550; color: var(--text-soft); margin: 16px 0 7px; }
input[type=email], input[type=password], input[type=text] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 0.96rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn-primary {
  width: 100%; margin-top: 22px;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: 11px;
  padding: 13px; font-weight: 650; font-size: 0.96rem;
  transition: filter 0.15s;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0 16px; color: var(--text-faint); font-size: 0.78rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border-strong); }

.btn-secondary {
  width: 100%; background: transparent;
  border: 1px solid var(--border-strong); color: var(--text);
  border-radius: 11px; padding: 12px; font-size: 0.93rem; font-weight: 550;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--hover); }

.auth-switch { margin-top: 22px; text-align: center; font-size: 0.89rem; color: var(--text-faint); }
.auth-switch button { background: none; border: none; color: var(--accent); font-size: 0.89rem; padding: 0; font-weight: 600; }
.msg { margin-top: 14px; font-size: 0.87rem; min-height: 20px; text-align: center; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--accent); }

/* ============================ shell ============================ */

.app { display: none; height: 100%; }
.app.active { display: grid; grid-template-columns: 272px 1fr; transition: grid-template-columns 0.2s ease; }
.app.active.collapsed { grid-template-columns: 0 1fr; }

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: 0 0 34px;
  background: transparent; border: none; border-radius: 9px;
  color: var(--text-soft);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

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

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden; min-width: 0;
}
.sidebar-head { padding: 14px 12px 6px; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 0 6px; }

.btn-new {
  display: flex; align-items: center; gap: 9px;
  width: 100%; margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 10px 12px;
  font-size: 0.92rem; font-weight: 600;
  box-shadow: 0 1px 2px #1c1b1808;
  transition: border-color 0.15s, transform 0.1s;
}
.btn-new:hover { border-color: var(--accent); }
.btn-new:active { transform: scale(0.99); }
.btn-new svg { color: var(--accent); }

.search {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; padding: 0 11px;
  border-radius: 10px;
  color: var(--text-faint);
  transition: background 0.12s;
}
.search:focus-within { background: var(--hover); }
.search input {
  flex: 1; background: transparent; border: none; box-shadow: none !important;
  padding: 9px 0; font-size: 0.89rem; border-radius: 0;
}
.search input::placeholder { color: var(--text-faint); }

.side-scroll { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 12px; }
.side-label { display: flex; align-items: center; justify-content: space-between; font-size: 0.72rem; font-weight: 650; color: var(--text-faint); padding: 12px 12px 4px 18px; letter-spacing: 0.02em; }
.project-list { padding: 0 8px; }
.proj-ic { display: grid; place-items: center; color: var(--text-faint); margin-right: 6px; }
.convo-act.always { display: grid; }
.convo-list { padding: 2px 8px 0; }
.convo-group { font-size: 0.72rem; font-weight: 650; color: var(--text-faint); padding: 14px 10px 6px; letter-spacing: 0.02em; }
.convo-none { padding: 18px 10px; font-size: 0.86rem; color: var(--text-faint); }
.convo {
  display: flex; align-items: center; gap: 2px;
  border-radius: 9px; padding: 8px 6px 8px 10px;
  font-size: 0.9rem; color: var(--text-soft);
  cursor: pointer; transition: background 0.12s;
}
.convo:hover { background: var(--hover); color: var(--text); }
.convo.active { background: var(--active); color: var(--text); font-weight: 550; }
.convo-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo input.rename {
  flex: 1; min-width: 0; padding: 3px 7px; font-size: 0.9rem;
  border-radius: 6px; background: var(--surface);
}
.convo-act {
  display: none; place-items: center;
  width: 24px; height: 24px; flex: 0 0 24px;
  background: none; border: none; border-radius: 6px; color: var(--text-faint);
}
.convo:hover .convo-act, .convo.active .convo-act { display: grid; }
.convo-act:hover { background: var(--active); color: var(--text); }
.convo-act.del:hover { color: var(--danger); }

.sidebar-foot { border-top: 1px solid var(--border); padding: 10px; position: relative; }
.acct {
  display: flex; align-items: center; gap: 10px;
  width: 100%; background: transparent; border: none;
  padding: 8px 9px; border-radius: 10px; text-align: left;
  transition: background 0.12s;
}
.acct:hover { background: var(--hover); }
.avatar {
  display: grid; place-items: center;
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 50%;
  background: var(--violet); color: #fff;
  font-size: 0.82rem; font-weight: 700; text-transform: uppercase;
}
.acct-text { flex: 1; min-width: 0; }
.acct-email { font-size: 0.87rem; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-plan { font-size: 0.75rem; color: var(--text-faint); }

.pop {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  z-index: 50;
}
.acct-pop { bottom: calc(100% - 2px); left: 10px; right: 10px; }
.pop-section { padding: 10px 11px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pop-title { font-size: 0.74rem; font-weight: 650; color: var(--text-faint); letter-spacing: 0.02em; margin-bottom: 10px; }
.usage-row { margin-bottom: 11px; }
.usage-row:last-child { margin-bottom: 0; }
.usage-top { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 5px; }
.usage-top span:last-child { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.bar { height: 5px; background: var(--active); border-radius: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.bar.hot span { background: var(--danger); }
.pop-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; background: transparent; border: none;
  border-radius: 9px; padding: 9px 11px;
  font-size: 0.9rem; text-align: left;
  transition: background 0.12s;
}
.pop-item:hover { background: var(--hover); }
.pop-item.danger:hover { color: var(--danger); }
.pop-item svg { color: var(--text-faint); }

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

.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }

.topbar { display: flex; align-items: center; gap: 6px; padding: 9px 12px; min-height: 52px; }
.topbar-title {
  flex: 1; min-width: 0;
  font-size: 0.93rem; font-weight: 550; color: var(--text-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding-left: 4px;
}
.app:not(.collapsed) #btn-expand { display: none; }

.messages { flex: 1; overflow-y: auto; min-height: 0; }
.thread { max-width: 748px; margin: 0 auto; padding: 18px 24px 12px; }

/* ---------- empty / greeting ---------- */

.main.is-empty { justify-content: center; }
.main.is-empty .topbar { position: absolute; top: 0; left: 0; right: 0; }
.main.is-empty .messages { flex: 0 0 auto; overflow: visible; }
.main.is-empty .thread { padding-bottom: 6px; }
.main.is-empty .composer { padding-bottom: 12px; }
.main.is-empty .composer-hint { display: none; }
.main:not(.is-empty) .starters { display: none; }

.greet { text-align: center; padding: 0 0 22px; }
.greet .brand-mark { width: 44px; height: 44px; border-radius: 14px; font-size: 1.25rem; margin: 0 auto 18px; }
.greet .brand-mark.bally { background: linear-gradient(140deg, #d97706, #f59e0b); }
.greet h2 { font-size: 2rem; font-weight: 600; letter-spacing: -0.03em; margin: 0 0 8px; line-height: 1.2; }
.greet p { color: var(--text-faint); margin: 0; font-size: 1rem; max-width: 520px; margin-left: auto; margin-right: auto; }
.greet .starter-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; max-width: 620px; margin-left: auto; margin-right: auto; }
.greet .starter-chips .chip.starter { border-radius: 999px; padding: 8px 16px; font-size: 0.88rem; background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-soft); cursor: pointer; }
.greet .starter-chips .chip.starter:hover { border-color: #d97706; color: #d97706; }

.starters {
  max-width: 748px; margin: 0 auto;
  padding: 4px 24px 12vh;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.starter {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 0.87rem; font-weight: 500;
  transition: all 0.14s;
}
.starter:hover { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.starter svg { color: var(--accent); }

/* ---------- turns ---------- */

.turn { margin-bottom: 26px; }

.turn.user { display: flex; flex-direction: column; align-items: flex-end; }
.turn.user .bubble {
  background: var(--user-bubble);
  border-radius: 18px 18px 5px 18px;
  padding: 11px 17px;
  max-width: 85%;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.turn.user .bubble p { margin: 0; }
.turn-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; max-width: 85%; }

.user-acts { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity 0.15s; }
.turn.user:hover .user-acts, .user-acts:focus-within { opacity: 1; }
/* Touch screens have no hover: keep Copy and Edit visible. */
@media (hover: none) { .user-acts { opacity: 1; } }

.edit-box { width: 100%; background: var(--surface); border: 1px solid var(--accent); border-radius: 14px; padding: 12px 14px; box-shadow: 0 0 0 3px var(--accent-soft); }
.edit-box textarea { min-height: 60px; }
.edit-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.btn-sm { border-radius: 9px; padding: 7px 14px; font-size: 0.86rem; font-weight: 600; border: 1px solid var(--border-strong); background: transparent; }
.btn-sm:hover { background: var(--hover); }
.btn-sm.solid { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-sm.solid:hover { filter: brightness(1.07); }

.turn.assistant { display: flex; gap: 14px; }
.turn.assistant .av {
  display: grid; place-items: center;
  width: 28px; height: 28px; flex: 0 0 28px; margin-top: 1px;
  border-radius: 9px;
  background: #0b0a14 var(--logo-mark) center / 66% no-repeat;
  color: #fff; font-size: 0.8rem; font-weight: 750;
}
.turn.assistant .body { flex: 1; min-width: 0; }

.bubble { line-height: 1.72; overflow-wrap: break-word; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 14px; }
.bubble ul, .bubble ol { margin: 0 0 14px; padding-left: 24px; }
.bubble li { margin-bottom: 6px; }
.bubble li::marker { color: var(--text-faint); }
.bubble h1, .bubble h2, .bubble h3 { margin: 24px 0 10px; line-height: 1.3; font-weight: 650; letter-spacing: -0.015em; }
.bubble h1 { font-size: 1.32rem; }
.bubble h2 { font-size: 1.16rem; }
.bubble h3 { font-size: 1.03rem; }
.bubble code { background: var(--active); padding: 2px 6px; border-radius: 5px; font-family: var(--mono); font-size: 0.86em; }
.bubble blockquote { margin: 0 0 14px; padding: 2px 0 2px 16px; border-left: 3px solid var(--border-strong); color: var(--text-soft); }
.bubble hr { border: none; border-top: 1px solid var(--border-strong); margin: 22px 0; }
.bubble strong { font-weight: 650; }

.code-wrap { margin: 0 0 16px; border-radius: 12px; overflow: hidden; background: var(--code-bg); border: 1px solid var(--border); }
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 8px 7px 14px;
  background: var(--code-head);
  font-size: 0.75rem; color: #a49fb4; font-family: var(--mono);
}
.code-copy {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: none; color: #a49fb4;
  font-size: 0.75rem; padding: 4px 8px; border-radius: 6px; font-family: var(--font);
}
.code-copy:hover { background: #ffffff14; color: #fff; }
.code-wrap pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-wrap pre code { background: none; padding: 0; font-size: 0.855rem; line-height: 1.62; color: var(--code-text); }

.turn-foot { display: flex; align-items: center; gap: 2px; margin-top: 8px; margin-left: -7px; min-height: 30px; }
.act {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text-faint); font-size: 0.8rem; padding: 6px 8px;
  transition: background 0.12s, color 0.12s;
}
.act:hover { background: var(--hover); color: var(--text); }
.turn-meta { font-size: 0.74rem; color: var(--text-faint); font-family: var(--mono); margin-left: 8px; opacity: 0; transition: opacity 0.15s; }
.turn.assistant:hover .turn-meta { opacity: 1; }

.notice { background: var(--accent-soft); border-radius: 10px; padding: 10px 13px; font-size: 0.86rem; color: var(--text-soft); margin-bottom: 12px; }
.turn-error {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--danger-soft); border-radius: 11px;
  padding: 11px 14px; font-size: 0.9rem; color: var(--danger);
}

.thinking { display: flex; gap: 5px; padding: 9px 0; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: bob 1.2s ease-in-out infinite; }
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bob { 0%, 60%, 100% { transform: none; opacity: 0.4; } 30% { transform: translateY(-4px); opacity: 1; } }

.cursor { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 5px; vertical-align: baseline; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; transform: scale(0.8); } }

.to-bottom {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 138px; z-index: 5;
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); color: var(--text-soft);
}
.to-bottom:hover { color: var(--text); }

/* ---------- images ---------- */

.turn-images { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-bottom: 6px; max-width: 85%; }
.thumb {
  display: block; max-width: 260px; max-height: 220px;
  border-radius: 14px; border: 1px solid var(--border);
  object-fit: cover; cursor: zoom-in; background: var(--active);
}
.thumb.missing { display: grid; place-items: center; width: 160px; height: 90px; font-size: 0.8rem; color: var(--text-faint); cursor: default; }
.lightbox {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 28px;
  background: #000000d9; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

.chip-img { position: relative; width: 62px; height: 62px; border-radius: 11px; overflow: hidden; border: 1px solid var(--border-strong); background: var(--active); }
.chip-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chip-img.busy img { opacity: 0.45; }
.chip-img.busy::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.chip-img.failed { border-color: var(--danger); }
.chip-img.failed img { opacity: 0.35; }
.chip-img button {
  position: absolute; top: 3px; right: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center;
  background: #000000a6; color: #fff; border: none;
  font-size: 0.8rem; line-height: 1; padding: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

.composer { padding: 6px 24px 14px; }
.composer-inner { max-width: 748px; margin: 0 auto; }
.composer-box {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 14px 12px 10px 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-box:focus-within { border-color: var(--accent); }
.composer-box.drag { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

textarea {
  display: block; width: 100%;
  background: transparent; border: none; outline: none; resize: none;
  color: var(--text); font-family: inherit;
  font-size: 1rem; line-height: 1.6;
  max-height: 260px; padding: 0;
}
textarea::placeholder { color: var(--text-faint); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; align-items: flex-end; }
.chip {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: 9px; padding: 5px 6px 5px 9px;
  font-size: 0.8rem; color: var(--text-soft); max-width: 220px;
}
.chip svg { color: var(--accent); flex: 0 0 auto; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { background: none; border: none; color: var(--text-faint); padding: 0 3px; font-size: 1rem; line-height: 1; border-radius: 4px; }
.chip button:hover { color: var(--danger); }
.chip.static { padding-right: 9px; }

.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; margin-left: -8px; }
.row-left, .row-right { display: flex; align-items: center; gap: 4px; }

.tier-wrap { position: relative; }
.tier-btn-main {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: none; border-radius: 9px;
  color: var(--text-soft); padding: 7px 10px;
  font-size: 0.87rem; font-weight: 550;
  transition: background 0.12s, color 0.12s;
}
.tier-btn-main:hover { background: var(--hover); color: var(--text); }
.tier-btn-main svg { color: var(--text-faint); }

.tier-menu { bottom: calc(100% + 8px); right: 0; width: 300px; }
.main.is-empty .tier-menu { bottom: auto; top: calc(100% + 8px); }
.tier-opt {
  display: block; width: 100%; text-align: left;
  background: transparent; border: none; border-radius: 10px;
  padding: 10px 11px; transition: background 0.12s;
}
.tier-opt:hover:not(:disabled) { background: var(--hover); }
.tier-opt:disabled { opacity: 0.5; cursor: not-allowed; }
.tier-opt-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tier-opt-name { font-size: 0.92rem; font-weight: 600; }
.tier-badge { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.04em; border-radius: 4px; padding: 1px 5px; text-transform: uppercase; }
.tier-badge.free { background: #d9770618; color: #d97706; }
.tier-opt-check { color: var(--accent); }
.tier-opt-desc { font-size: 0.8rem; color: var(--text-faint); margin-top: 2px; line-height: 1.45; }
.tier-btn-main.bally { color: #d97706; }
.tier-btn-main.bally:hover { background: #d9770612; }
.tier-opt .bar { margin-top: 8px; height: 4px; }

.btn-send {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: 0 0 36px;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: 11px;
  transition: filter 0.14s, opacity 0.14s, transform 0.1s;
}
.btn-send:hover:not(:disabled) { filter: brightness(1.08); }
.btn-send:active:not(:disabled) { transform: scale(0.95); }
.btn-send:disabled { opacity: 0.3; cursor: default; }
.btn-stop {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: 0 0 36px;
  background: var(--text); color: var(--bg);
  border: none; border-radius: 11px;
}

.composer-hint { margin: 9px 0 0; font-size: 0.74rem; color: var(--text-faint); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 11px;
  font-size: 0.87rem; box-shadow: var(--shadow-pop); z-index: 80;
}

/* ============================ web search ============================ */

.search-toggle {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: none; border-radius: 9px;
  color: var(--text-soft); padding: 7px 10px; font-size: 0.87rem; font-weight: 550;
  transition: background 0.12s, color 0.12s;
}
.search-toggle:hover { background: var(--hover); color: var(--text); }
.search-toggle.on { background: var(--accent-soft); color: var(--accent); }

.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.sources-label { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 600; color: var(--text-faint); margin-right: 2px; }
.source {
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.8rem; text-decoration: none; color: var(--text-soft);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 4px 11px;
}
.source:hover { border-color: var(--accent); color: var(--accent); }

/* ============================ artifact panel ============================ */

.panel { display: none; min-width: 0; min-height: 0; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); }
.app.active.has-panel { grid-template-columns: 272px minmax(0, 1fr) minmax(340px, 46%); }
.app.active.has-panel.collapsed { grid-template-columns: 0 minmax(0, 1fr) minmax(340px, 50%); }
.app.has-panel .panel { display: flex; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px 9px 14px; min-height: 52px; border-bottom: 1px solid var(--border); }
.panel-tabs { display: flex; gap: 2px; background: var(--active); border-radius: 9px; padding: 3px; }
.panel-tabs button { background: transparent; border: none; border-radius: 7px; padding: 5px 13px; font-size: 0.84rem; font-weight: 550; color: var(--text-soft); }
.panel-tabs button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px #1c1b1814; }
.panel-acts { display: flex; gap: 2px; }
.panel-body { flex: 1; min-height: 0; display: flex; }
.panel-body iframe { flex: 1; width: 100%; border: none; background: #fff; }
.panel-code { flex: 1; margin: 0; padding: 16px 18px; overflow: auto; background: var(--code-bg); }
.panel-code code { font-family: var(--mono); font-size: 0.84rem; line-height: 1.62; color: var(--code-text); white-space: pre; }
.code-tools { display: flex; gap: 2px; }

/* ============================ modal ============================ */

.modal-scrim { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; background: #00000066; }
.modal { width: 100%; max-width: 520px; max-height: 88vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; box-shadow: var(--shadow-pop); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 22px; }
.modal-head h3 { margin: 0; font-size: 1.08rem; font-weight: 650; letter-spacing: -0.01em; }
.modal-body { padding: 4px 22px 20px; overflow-y: auto; }
.m-field { margin-top: 14px; }
.m-field label { margin: 0 0 6px; }
.m-field select, .m-area {
  width: 100%; background: var(--bg); border: 1px solid var(--border-strong); border-radius: 11px;
  color: var(--text); padding: 11px 13px; font-size: 0.94rem; font-family: inherit; outline: none;
}
.m-area { min-height: 120px; max-height: 300px; resize: vertical; line-height: 1.5; }
.m-field select:focus, .m-area:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.m-hint { font-size: 0.78rem; color: var(--text-faint); margin-top: 6px; line-height: 1.45; }
.m-text { font-size: 0.92rem; color: var(--text-soft); line-height: 1.6; margin: 8px 0 0; }
.m-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.m-files .chip { max-width: 100%; }
.m-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.btn-sm.danger { color: var(--danger); margin-right: auto; }
.btn-sm.danger:hover { background: var(--danger-soft); }
.btn-sm:disabled { opacity: 0.55; cursor: default; }

.icon-btn.live { background: var(--danger-soft); color: var(--danger); animation: pulse 1.2s ease-in-out infinite; }

/* ============================ mobile ============================ */

@media (max-width: 820px) {
  .app.active, .app.active.collapsed { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 284px; z-index: 60;
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: #00000073; z-index: 55; }
  .app.active.has-panel, .app.active.has-panel.collapsed { grid-template-columns: 1fr; }
  .app.has-panel .panel { position: fixed; inset: 0; z-index: 65; border-left: none; }
  #btn-expand { display: grid !important; }
  .thread { padding: 12px 16px; }
  .composer { padding: 6px 12px 12px; }
  .starters { padding: 4px 16px 6vh; }
  .greet h2 { font-size: 1.55rem; }
  .turn.user .bubble, .turn-files, .turn-images { max-width: 92%; }
  .thumb { max-width: 200px; }
  .tier-menu { width: 272px; }
  .turn-meta { display: none; }
}

/* ---- billing ---- */
.tier-upgrade { display: block; width: 100%; margin-top: 4px; padding: 9px 12px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--accent); font-weight: 600; font-size: 0.86rem; text-align: left; cursor: pointer; }
.tier-upgrade:hover { background: var(--hover); }
.bill-current { padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.bill-label { font-size: 0.74rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); }
.bill-plan { font-size: 1.15rem; font-weight: 700; margin-top: 2px; }
.bill-plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-top: 16px; }
.bill-card { display: flex; flex-direction: column; gap: 10px; padding: 16px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); }
.bill-card.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.bill-card-name { font-weight: 700; }
.bill-amount { font-size: 1.3rem; font-weight: 700; }
.bill-per { color: var(--text-faint); font-size: 0.85rem; white-space: nowrap; }
.bill-buy { margin-top: auto; min-height: 40px; }
.bill-history-title { margin-top: 22px; margin-bottom: 8px; }
.bill-history { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.bill-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); }
.bill-row:first-child { border-top: 0; }
.bill-row .m-hint { margin-top: 2px; }
.bill-status { font-size: 0.78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--hover); color: var(--text-soft); white-space: nowrap; }
.bill-status.successful { background: var(--accent-soft); color: var(--accent); }
.bill-status.failed { background: var(--danger-soft); color: var(--danger); }
.bill-wait { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 28px 8px; }
.bill-wait .m-actions { justify-content: center; }
.bill-spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: bill-spin 0.9s linear infinite; }
@keyframes bill-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .bill-spinner { animation: none; } }
.bill-done { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 1.2rem; }

/* Code highlighting (md.js). Code blocks are dark in both themes. */
.tk-k { color: #c4a5ff; }
.tk-s { color: #7ee8c8; }
.tk-c { color: #8580a3; font-style: italic; }
.tk-n { color: #ffb86b; }
.tk-b { color: #ff9ac1; }
.tk-f { color: #8ecbff; }
.tk-t { color: #ffd479; }
.tk-p { color: #9fd8ff; }
.tk-tag { color: #ff8fb1; }
.tk-add { color: #7ee8a5; background: #2ea04326; display: inline-block; min-width: 100%; }
.tk-del { color: #ff9a9a; background: #f8514926; display: inline-block; min-width: 100%; }

/* Script errors reported by a live preview. */
.preview-err { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); background: var(--danger-soft); color: var(--text); font-size: 0.85rem; line-height: 1.45; }
.preview-err-text { flex: 1; min-width: 0; overflow-wrap: anywhere; max-height: 6.5em; overflow: auto; }
.preview-err-text strong { color: var(--danger); font-weight: 600; }
.preview-err .btn-sm { flex: none; white-space: nowrap; }

/* Plan ending / payment due banner */
.plan-banner {
  display: flex; align-items: center; gap: 12px; margin: 10px auto 0; width: min(760px, calc(100% - 32px));
  padding: 9px 10px 9px 14px; border-radius: 12px; font-size: 0.88rem;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.plan-banner span { flex: 1; min-width: 0; }
.plan-banner.due { background: #f5b94222; border-color: #f5b94266; }
.limit-bar { margin: 0 auto 8px; width: auto; max-width: 748px; box-sizing: border-box; }
.m-hint.warn { color: #b7791f; }
[data-theme="dark"] .m-hint.warn { color: #f5b942; }

/* Plan cards: what hosting each plan includes */
.bill-feats { list-style: none; padding: 0; margin: 2px 0 10px; display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--text-soft); text-align: left; }
.bill-feats li::before { content: '✓ '; color: var(--accent); font-weight: 700; }

/* Domains */
.dom-note { font-size: 0.8rem; padding: 7px 11px; border-radius: 9px; background: #f5b94222; margin-bottom: 12px; }
.dom-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.dom-tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; font-size: 0.9rem; color: var(--text-soft); cursor: pointer; }
.dom-tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.dom-empty { text-align: center; padding: 26px 10px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.dom-list, .dom-results { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.dom-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.dom-row.off { opacity: 0.6; }
.dom-row-main { flex: 1; min-width: 0; }
.dom-name { font-weight: 600; overflow-wrap: anywhere; }
.dom-price { font-weight: 700; white-space: nowrap; }
.dom-row-acts { display: flex; gap: 6px; }
.dom-status { font-size: 0.74rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--hover); color: var(--text-soft); white-space: nowrap; }
.dom-status.active { background: var(--accent-soft); color: var(--accent); }
.dom-status.expired, .dom-status.failed { background: var(--danger-soft); color: var(--danger); }
.dom-search { display: flex; gap: 8px; margin-bottom: 12px; }
.dom-search input { flex: 1; }
.dom-back { background: none; border: 0; padding: 0; margin-bottom: 10px; font: inherit; font-size: 0.85rem; color: var(--text-soft); cursor: pointer; }
.dom-back:hover { color: var(--text); }
.dom-head { margin-bottom: 6px; }
.dom-owner { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.dom-owner .m-actions { grid-column: 1 / -1; }
@media (max-width: 560px) { .dom-owner { grid-template-columns: 1fr; } .dom-row { flex-wrap: wrap; } }
.dom-section { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 16px; }
.dom-section h4 { margin: 0 0 4px; font-size: 0.95rem; }
.dom-preset { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.dom-preset select, .dom-preset input { flex: 1; min-width: 160px; }
.dom-records { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 10px; }
.dom-rec { display: grid; grid-template-columns: 58px minmax(0, 0.7fr) minmax(0, 2.3fr) auto auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 9px; background: var(--hover); font-size: 0.83rem; }
.dom-rec-type { font-weight: 700; font-size: 0.75rem; }
.dom-rec-host, .dom-rec-val { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dom-recform { display: grid; grid-template-columns: 110px 1fr 2fr 90px; gap: 0 10px; align-items: end; margin: 10px 0; padding: 12px; border: 1px solid var(--border); border-radius: 12px; }
.dom-recform .m-actions { grid-column: 1 / -1; }
@media (max-width: 640px) { .dom-recform { grid-template-columns: 1fr 1fr; } .dom-rec { grid-template-columns: 50px 1fr auto auto; } .dom-rec-val { grid-column: 2 / 3; grid-row: 2; } }
.dom-mono { font-family: var(--mono); font-size: 0.84rem; white-space: pre-wrap; padding: 8px 10px; border-radius: 9px; background: var(--hover); margin: 6px 0 10px; overflow-wrap: anywhere; }
.dom-code, .dom-authcode { margin-top: 10px; }
.dom-code input { max-width: 140px; font-family: var(--mono); letter-spacing: 0.15em; }
/* Domain forms reuse the standard field look. */
.dom-search input, .dom-owner input, .dom-preset input, .dom-preset select, .dom-recform input, .dom-recform select, .dom-section textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border-strong); border-radius: 11px;
  color: var(--text); padding: 10px 12px; font-size: 0.92rem; font-family: inherit; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.dom-section textarea { resize: vertical; min-height: 70px; font-family: var(--mono); font-size: 0.85rem; line-height: 1.5; max-height: none; }
.dom-preset select:focus, .dom-recform select:focus, .dom-section textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
/* Hosting-only plans in Plan & billing */
.bill-hosting { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.bill-allow { font-size: 0.88rem; margin: 4px 0 12px; padding: 9px 12px; border-radius: 10px; background: var(--accent-soft); }
.bill-amount { white-space: nowrap; }

/* Publishing and My apps */
.panel-publish { display: inline-flex; align-items: center; gap: 6px; margin-right: 4px; }
.panel-publish svg { flex: none; }
.m-hint.ok { color: var(--accent); }
.m-actions.center { justify-content: center; }
.btn-sm.danger, .btn-sm.danger:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.app-choice { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.app-pick { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.app-pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.app-pick input { margin-top: 3px; }
.app-pick-title { font-weight: 600; }
.app-addr { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.app-addr input { flex: 1; min-width: 0; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; }
.app-addr-suffix { display: flex; align-items: center; padding: 0 10px; background: var(--hover); color: var(--text-soft); font-size: 0.85rem; white-space: nowrap; }
.app-err { display: flex; align-items: center; gap: 10px; margin: 10px 0 0; padding: 9px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 0.86rem; }
.app-err span { flex: 1; }
.app-done { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 0; }
.app-link { font-weight: 600; font-size: 1.05rem; color: var(--accent); overflow-wrap: anywhere; }
.app-usage { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.84rem; color: var(--text-soft); margin-bottom: 12px; }
.app-host { font-size: 0.84rem; color: var(--accent); text-decoration: none; overflow-wrap: anywhere; }
.app-host:hover { text-decoration: underline; }
.app-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.app-data { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; align-items: flex-start; }
.app-data-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; width: 100%; box-sizing: border-box; padding: 6px 10px; border-radius: 9px; background: var(--hover); }
.app-data-row .dom-name { flex: 1 1 200px; min-width: 0; font-size: 0.88rem; overflow-wrap: anywhere; }
.app-sub { font-size: 0.8rem; font-weight: 600; margin-top: 6px; }
.app-dom { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.app-dom-top { display: flex; align-items: center; gap: 10px; }
.app-dom-top .dom-name { flex: 1; min-width: 0; }
.app-recs { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.app-rec { display: grid; grid-template-columns: 52px minmax(0, 1fr) minmax(0, 2fr) auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 9px; background: var(--hover); font-size: 0.82rem; }
.app-rec code { overflow-wrap: anywhere; font-size: 0.8rem; }
@media (max-width: 560px) { .app-rec { grid-template-columns: 46px 1fr auto; } .app-rec code:nth-of-type(1) { grid-column: 2; } .app-rec code:nth-of-type(2) { grid-column: 1 / -1; } }
.app-keyform { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 10px; padding: 12px; border: 1px dashed var(--border); border-radius: 12px; }
.app-keyform .m-actions, .app-keyform .check { grid-column: 1 / -1; }
@media (max-width: 560px) { .app-keyform { grid-template-columns: 1fr; } }
.app-kind { margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--text-soft); font-size: 0.72rem; font-weight: 500; vertical-align: middle; }
.app-log { max-height: 260px; overflow: auto; margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: #0f1117; color: #d6dae3; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }
