/* Chat page (/chat). Own stylesheet: style.css styles inputs and buttons for the narrow checkout column. */
[hidden] { display: none !important; }
:root {
  --fg: #17181c; --muted: #626673; --bg: #fff; --side: #f7f7f8; --line: #e3e4e8; --soft: #f1f2f4;
  --accent: #f7931a; --accent-fg: #fff; --bad: #c62828; --ok: #1f9d55; --code: #f6f7f9; --user: #f1f2f4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e8e9ec; --muted: #9a9eaa; --bg: #1d1e23; --side: #16171b; --line: #2f3138; --soft: #2a2c33;
    --code: #15161a; --user: #2a2c33; --bad: #ef6b6b; --ok: #4cc38a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 16px/1.55 system-ui, -apple-system, "PingFang SC", sans-serif; color: var(--fg); background: var(--bg); }
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
input, textarea, select { font: inherit; color: inherit; background: var(--bg); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, monospace; }
.bad { color: var(--bad); }

.app { display: flex; height: 100dvh; }

/* ------------------------------------------------------------------ sidebar */
.side { width: 272px; flex: none; display: flex; flex-direction: column; gap: 10px; padding: 14px 12px; background: var(--side);
  border-right: 1px solid var(--line); }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--fg); text-decoration: none; font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.brand img { width: 34px; height: auto; }
.brand i { font-style: normal; color: var(--accent); }
.new-chat { padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); text-align: left; font-weight: 600; }
.new-chat:hover { border-color: var(--muted); }
.chats { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.chat-item { display: flex; align-items: center; border-radius: 8px; }
.chat-item a { flex: 1; min-width: 0; padding: 7px 10px; color: var(--fg); text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item:hover, .chat-item.on { background: var(--soft); }
.chat-item .del { visibility: hidden; border: 0; background: none; color: var(--muted); padding: 4px 8px; }
.chat-item:hover .del, .chat-item.on .del { visibility: visible; }
.chats-day { margin: 12px 10px 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.wallet { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--bg); display: grid; gap: 8px; }
.wallet-row { display: flex; align-items: center; gap: 8px; }
.wallet-row b { font-variant-numeric: tabular-nums; }
.wallet-row .linkish { margin-left: auto; }
.wallet-row .icon { margin-left: auto; }
.bar { height: 4px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .4s; }
.bar.low i { background: var(--accent); }
.bar.out i { background: var(--bad); }
.side-foot { margin: 0; padding: 0 4px; }
.side-foot a { color: var(--muted); }

.btn { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; }
.btn.accent { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.accent:hover { filter: brightness(.95); }
.icon { border: 0; background: none; padding: 6px 8px; border-radius: 8px; font-size: 18px; line-height: 1; color: var(--muted); }
.icon:hover { background: var(--soft); color: var(--fg); }
.icon.small { font-size: 15px; padding: 2px 6px; }
.linkish { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; font-size: 13px; }
.only-narrow { display: none; }
.scrim { display: none; }

/* ------------------------------------------------------------------ main column */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.bar-top { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.picker { position: relative; }
.model-btn { border: 0; background: none; font-weight: 700; font-size: 17px; padding: 6px 10px; border-radius: 8px; }
.model-btn:hover, .model-btn[aria-expanded="true"] { background: var(--soft); }
.caret { color: var(--muted); font-size: 13px; }
.price { margin-right: auto; font-variant-numeric: tabular-nums; }
.pop { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: min(420px, calc(100vw - 32px)); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px #0003; padding: 8px; }
.pop input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.model-list { max-height: min(60vh, 460px); overflow-y: auto; margin-top: 6px; }
.model-list .vendor { font-size: 12px; font-weight: 700; color: var(--muted); margin: 10px 8px 2px; text-transform: uppercase; letter-spacing: .04em; }
.model-opt { display: flex; width: 100%; align-items: baseline; gap: 10px; border: 0; background: none; text-align: left; padding: 7px 8px; border-radius: 8px; }
.model-opt:hover, .model-opt.active { background: var(--soft); }
.model-opt.on { font-weight: 700; }
.model-opt .p { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 400; }
.pop-foot { margin: 8px 8px 2px; }
.sys { padding: 10px 16px 12px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; font-size: 14px; }
.sys textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; }

/* welcome / key form */
.welcome { margin: auto; max-width: 560px; padding: 24px 20px 40px; }
.welcome h1 { font-size: clamp(26px, 4vw, 34px); letter-spacing: -.03em; line-height: 1.15; margin: 0 0 10px; }
.key-form { margin: 22px 0 14px; display: grid; gap: 8px; }
.key-form label { font-weight: 600; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.key-form p { margin: 0; }
.buy-line { font-weight: 600; }

/* ------------------------------------------------------------------ thread */
.thread { flex: 1; overflow-y: auto; padding: 18px 16px 8px; scroll-behavior: auto; }
.thread:empty { display: none; }
.empty { margin: auto; max-width: 720px; padding: 10vh 0 0; text-align: center; }
.empty h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.02em; }
.ideas { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 22px; text-align: left; }
.ideas button { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 14px; color: var(--muted); }
.ideas button:hover { color: var(--fg); border-color: var(--muted); }
.msg { max-width: 760px; margin: 0 auto 18px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .body { background: var(--user); border-radius: 16px; padding: 9px 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .imgs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-bottom: 6px; }
.msg .imgs img { max-width: 180px; max-height: 180px; border-radius: 10px; border: 1px solid var(--line); object-fit: cover; }
.msg.bot .who { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.msg.bot .body { overflow-wrap: anywhere; }
.msg.bot .body > :first-child { margin-top: 0; }
.msg.bot .body > :last-child { margin-bottom: 0; }
.body p, .body ul, .body ol, .body blockquote, .body .table, .body .code { margin: .6em 0; }
.body h1, .body h2, .body h3, .body h4 { margin: 1em 0 .4em; line-height: 1.3; }
.body h1 { font-size: 1.35em; } .body h2 { font-size: 1.2em; } .body h3, .body h4 { font-size: 1.05em; }
.body ul, .body ol { padding-left: 1.5em; }
.body li + li { margin-top: .2em; }
.body li > ul, .body li > ol { margin: .2em 0; }
.body blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: 12px; color: var(--muted); }
.body hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.body code { font: .88em ui-monospace, Menlo, monospace; background: var(--code); border: 1px solid var(--line); border-radius: 5px; padding: .05em .3em; }
.body .code { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--code); }
.body .code-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.body .code-head button { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.body .code-head button:hover { background: var(--soft); color: var(--fg); }
.body pre { margin: 0; padding: 10px 12px; overflow-x: auto; }
.body pre code { background: none; border: 0; padding: 0; font-size: 13px; line-height: 1.5; }
.body .table { overflow-x: auto; }
.body table { border-collapse: collapse; font-size: 14px; }
.body th, .body td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
.body th { background: var(--soft); }
.think { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.think summary { cursor: pointer; user-select: none; }
.think div { border-left: 2px solid var(--line); padding: 2px 0 2px 12px; margin-top: 4px; white-space: pre-wrap; max-height: 320px; overflow-y: auto; }
.meta { display: flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta button { border: 0; background: none; color: var(--muted); padding: 3px 7px; border-radius: 6px; font-size: 12px; }
.meta button:hover { background: var(--soft); color: var(--fg); }
.meta .cost { margin-left: 4px; }
.err { border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); background: color-mix(in srgb, var(--bad) 7%, transparent);
  border-radius: 10px; padding: 9px 12px; font-size: 14px; }
.err .btn { margin-top: 8px; font-size: 14px; padding: 6px 12px; }
.cursor::after { content: "▍"; color: var(--muted); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ------------------------------------------------------------------ composer */
.composer { padding: 6px 16px 12px; }
.compose-box, .attach-list, .compose-hint { max-width: 760px; margin-left: auto; margin-right: auto; }
.compose-box { display: flex; align-items: flex-end; gap: 6px; border: 1px solid var(--line); border-radius: 18px; padding: 6px 6px 6px 8px; background: var(--bg);
  box-shadow: 0 2px 12px #0000000d; }
.compose-box:focus-within { border-color: var(--muted); }
.compose-box textarea { flex: 1; border: 0; outline: 0; resize: none; max-height: 40vh; padding: 7px 4px; line-height: 1.45; background: none; }
.attach { cursor: pointer; }
.send { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--fg); color: var(--bg); font-size: 18px; font-weight: 700; }
.send.stop { font-size: 13px; }
.compose-hint { margin-top: 6px; text-align: center; }
.attach-list { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.thumb { position: relative; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.thumb button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--fg); color: var(--bg); font-size: 11px; line-height: 20px; padding: 0; }
.main.drop::after { content: "Drop images to attach"; position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 16px;
  display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 85%, transparent); font-weight: 700; pointer-events: none; }

/* ------------------------------------------------------------------ free chat (no key) */
a.btn { display: inline-block; text-align: center; text-decoration: none; }
.wallet .btn.accent { color: var(--accent-fg); }
.small-btn { padding: 6px 12px; font-size: 14px; }
.tag-free { font-size: 11px; font-weight: 700; color: var(--ok); border: 1px solid currentColor; border-radius: 6px; padding: 0 5px; margin-left: 6px; }
.model-opt.locked > span:first-child { color: var(--muted); }
.model-opt.locked .p::before { content: "🔑 "; }
.need-key { max-width: 760px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--line); background: var(--soft); border-radius: 12px; padding: 8px 10px 8px 14px; font-size: 14px; }
.need-key-actions { display: flex; gap: 6px; }
.need-key .btn { padding: 6px 12px; font-size: 14px; }
.need-key .btn.accent { color: var(--accent-fg); }
.hero-empty h2 { font-size: clamp(26px, 4vw, 34px); letter-spacing: -.03em; line-height: 1.15; }
.hero-empty .cta { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.hero-empty .cta .btn.accent { color: var(--accent-fg); }
.key-form { margin: 8px 0 10px; }

/* ------------------------------------------------------------------ top-up dialog */
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 16px; width: min(420px, calc(100vw - 32px)); background: var(--bg); color: var(--fg); }
.dlg::backdrop { background: #0006; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin: 0 0 4px; }
.dlg select { margin-left: 6px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); }
.amounts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.amounts .primary { padding: 10px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-fg); }
.amounts .primary b { font-size: 17px; }
.amounts .primary small, .amounts .primary em { display: block; font-size: 12px; font-style: normal; opacity: .9; }

/* ------------------------------------------------------------------ phones */
@media (max-width: 760px) {
  .only-narrow { display: inline-block; }
  .side { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px #0004; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: #0005; }
  .bar-top { padding: 8px 10px; }
  .price { display: none; }
  .need-key { padding: 8px 10px; }
  .picker { margin-right: auto; }
  .thread { padding: 14px 12px 6px; }
  .composer { padding: 4px 10px 10px; }
  .ideas { grid-template-columns: 1fr; }
  .msg.user .body { max-width: 92%; }
  .compose-hint { display: none; }
}
