:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel2: #162238;
  --line: #22314f;
  --text: #e8eefc;
  --muted: #8ea0c4;
  --green: #3fc46a;
  --green2: #6ee0a8;
  --blue: #2f9bea;
  --navy: #1b1745;
  --danger: #ff6b6b;
  --grad: linear-gradient(135deg, #2fa6f0 0%, #3fc46a 55%, #1f6e45 100%);
  --radius: 16px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 650;
  background: var(--grad); color: #04130b; transition: transform .1s, filter .2s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.97); }
.btn:disabled { filter: grayscale(.8) brightness(.6); cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: #3a1620; color: #ffb3b3; border: 1px solid #5a2330; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }

input, textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; outline: none; width: 100%;
}
input:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(63,196,106,.18); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% 0%, rgba(47,155,234,.18), transparent 60%),
              radial-gradient(900px 600px at 100% 100%, rgba(63,196,106,.18), transparent 60%), var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; background: rgba(17,26,46,.85); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 24px; padding: 28px; text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.login-card h1 { margin: 6px 0 4px; font-size: 32px; letter-spacing: -.5px; }
.login-card h1 span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-card form { display: grid; gap: 10px; margin-top: 18px; }
.err { color: var(--danger); min-height: 20px; font-size: 14px; }
.tagline { color: var(--muted); font-size: 14px; margin: 0; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 290px 1fr; height: 100%; }
.side {
  background: var(--panel); border-right: 1px solid var(--line); padding: 18px;
  display: flex; flex-direction: column; gap: 16px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.nav { display: grid; gap: 6px; }
.nav button {
  text-align: left; background: transparent; border: 1px solid transparent; border-radius: 12px;
  padding: 10px 12px; color: var(--muted); font-weight: 600;
}
.nav button.active, .nav button:hover { background: var(--panel2); color: var(--text); border-color: var(--line); }

.meter { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.meter h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.meter .big { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 99px; background: #0a1324; overflow: hidden; margin: 10px 0 6px; }
.bar > div { height: 100%; background: var(--grad); border-radius: 99px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.meter .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 4px; }
.meter .row b { color: var(--text); font-variant-numeric: tabular-nums; }
.side .spacer { flex: 1; }
.who { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.topbar { display: none; }

/* ---------- Chat ---------- */
.chat { flex: 1; overflow-y: auto; padding: 24px 0 12px; }
.chat-inner { max-width: 820px; margin: 0 auto; padding: 0 20px; display: flex; flex-direction: column; gap: 22px; }
.empty { text-align: center; padding: 8vh 0 0; }
.empty h2 { font-size: 30px; margin: 8px 0 4px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.suggestions button { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 8px 14px; color: var(--muted); }
.suggestions button:hover { color: var(--text); border-color: var(--green); }

.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--panel2); border: 1px solid var(--line); border-radius: 18px 18px 4px 18px; max-width: 75%; }
.bubble { padding: 12px 16px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.msg.ai .bubble { padding: 4px 0 0; flex: 1; min-width: 0; }
.msg.ai .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: rgba(63,196,106,.12); color: var(--green2); border: 1px solid rgba(63,196,106,.25); }
.bubble code { background: #0a1324; padding: 2px 6px; border-radius: 6px; font-size: .92em; }
.bubble pre { background: #0a1324; padding: 12px; border-radius: 10px; overflow-x: auto; border: 1px solid var(--line); }
.bubble pre code { padding: 0; background: none; }
.thinking-text { color: var(--muted); font-style: italic; }
.thinking-text .shimmer {
  background: linear-gradient(90deg, var(--muted) 0%, #fff 50%, var(--muted) 100%); background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.8s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.declined { color: #ffb3b3; }
.caret::after { content: '▋'; animation: blink 1s steps(1) infinite; color: var(--green2); }
@keyframes blink { 50% { opacity: 0; } }

.composer { padding: 10px 20px 18px; }
.composer-inner { max-width: 820px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 10px; }
.composer textarea { border: 0; background: transparent; resize: none; min-height: 52px; max-height: 220px; padding: 8px 10px; box-shadow: none; }
.composer-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 0 4px; }
.cost { font-size: 12px; color: var(--muted); }
.cost b { color: var(--green2); }
.outofTokens { max-width: 820px; margin: 0 auto 10px; display: flex; gap: 14px; align-items: center; background: #2a1a10; border: 1px solid #5a3a20; border-radius: 16px; padding: 10px 16px; }

/* ---------- Store ---------- */
.store { flex: 1; overflow-y: auto; padding: 24px; }
.store-head { max-width: 1100px; margin: 0 auto 18px; display: flex; gap: 18px; align-items: center; }
.store-head h2 { margin: 0; font-size: 28px; }
.cats { max-width: 1100px; margin: 0 auto 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.cats button { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 6px 14px; color: var(--muted); font-weight: 600; }
.cats button.active { background: var(--grad); color: #04130b; border-color: transparent; }
.grid { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.item {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px;
  display: flex; flex-direction: column; gap: 8px; transition: transform .15s, border-color .15s;
}
.item:hover { transform: translateY(-3px); border-color: var(--green); }
.item .emoji { font-size: 38px; width: 64px; height: 64px; display: grid; place-items: center; background: var(--panel2); border-radius: 16px; }
.item h4 { margin: 4px 0 0; font-size: 16px; }
.item .cat { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.item p { margin: 0; font-size: 13px; color: var(--muted); flex: 1; }
.item .price { display: flex; justify-content: space-between; align-items: baseline; }
.item .price b { font-size: 18px; }
.item .reward { color: var(--green2); font-weight: 700; font-size: 13px; }
.orders { max-width: 1100px; margin: 28px auto 0; }
.order-row { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin-bottom: 8px; }
.status { font-size: 12px; padding: 3px 10px; border-radius: 99px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.status.pending { background: #2b2610; color: #f5d76e; }
.status.approved { background: #10301c; color: var(--green2); }
.status.rejected { background: #3a1620; color: #ffb3b3; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(3,6,14,.7); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 22px; display: grid; gap: 12px; }
.modal h3 { margin: 0; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.qty { display: flex; gap: 8px; align-items: center; }
.qty input { width: 80px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--green); padding: 12px 18px; border-radius: 14px; display: flex; align-items: center; gap: 10px; z-index: 60; box-shadow: 0 10px 40px rgba(0,0,0,.4); }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .side.open { display: flex; position: fixed; inset: 0; z-index: 40; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
  .topbar .tok { font-size: 13px; color: var(--muted); }
  .msg.user .bubble { max-width: 88%; }
}

/* ---------- Models ---------- */
select { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--text); font: inherit; width: 100%; outline: none; }
select:focus { border-color: var(--green); }
.models { display: grid; gap: 6px; }
.model-btn { display: flex; align-items: center; gap: 10px; text-align: left; background: transparent; border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; color: var(--muted); position: relative; }
.model-btn b { color: var(--text); }
.model-btn .ver { font-size: 12px; padding: 1px 6px; border-radius: 6px; background: var(--panel2); }
.model-btn.active { border-color: var(--green); background: rgba(63,196,106,.08); }
.model-btn.busy::after { content: ''; position: absolute; right: 12px; width: 8px; height: 8px; border-radius: 50%; background: #f5d76e; animation: blink 1s infinite; }
.model-select { width: auto; padding: 4px 8px; font-weight: 700; }
.who button { white-space: nowrap; }
