:root {
  --bg: #0e1117;
  --surface: #171b24;
  --surface-2: #1f2430;
  --surface-3: #272d3b;
  --line: #2e3442;
  --text: #e8ecf4;
  --muted: #949db0;
  --accent: #7c6cf0;
  --accent-2: #5ee0a0;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Nastaliq Urdu", "Microsoft YaHei", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.fine { font-size: 11px; color: var(--muted); margin-top: 16px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
}

.btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; transition: .15s; font-size: 13px;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.soft { background: var(--surface-2); border-color: var(--line); }
.btn.small { padding: 6px 11px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  background: none; border: none; color: var(--muted); font-size: 18px;
  padding: 6px 10px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: block; margin-top: 16px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.field input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,108,240,.15); }
.hint { display: block; color: var(--muted); font-size: 11px; margin-top: 6px; }
.phone-row, .code-row { display: flex; gap: 8px; }
.prefix {
  display: grid; place-items: center; min-width: 58px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; color: var(--muted);
}
.code-row input { flex: 1; }
.code-row .btn { white-space: nowrap; }

.notice {
  margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 12px;
  background: rgba(124,108,240,.12); border: 1px solid rgba(124,108,240,.35); color: var(--text);
}
.notice.warn { background: rgba(251,191,36,.10); border-color: rgba(251,191,36,.35); color: var(--warn); }
.notice.err { background: rgba(248,113,113,.10); border-color: rgba(248,113,113,.35); color: var(--danger); }
.notice.ok { background: rgba(94,224,160,.10); border-color: rgba(94,224,160,.35); color: var(--accent-2); }

.auth-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 24px; position: relative;
}
.auth-card {
  width: min(100%, 420px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 30px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.auth-card h1 { font-size: 22px; margin: 22px 0 4px; font-weight: 600; }
.auth-card > .muted { margin: 0 0 6px; font-size: 13px; }
.lang-switch { position: absolute; inset-block-end: 24px; display: flex; gap: 6px; }
.lang-switch button {
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 5px 10px; font-size: 12px;
}
.lang-switch button.active { color: var(--text); border-color: var(--accent); }

.app { display: flex; height: 100vh; }
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--surface); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px; gap: 14px;
}
.side-top { display: grid; gap: 16px; }
.session-list { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 4px; }
.session-item {
  padding: 9px 11px; border-radius: 9px; cursor: pointer; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted);
}
.session-item:hover { background: var(--surface-2); color: var(--text); }
.session-item.active { background: var(--surface-3); color: var(--text); }
.side-bottom { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 6px; }
.account { font-size: 12px; color: var(--muted); padding: 6px; line-height: 1.7; }
.account b { color: var(--text); font-weight: 500; }
.side-link {
  background: none; border: none; color: var(--muted); text-align: start;
  padding: 7px 6px; border-radius: 8px; font-size: 12px;
}
.side-link:hover { background: var(--surface-2); color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; flex-shrink: 0; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; padding: 0 18px;
}
.top-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; }
.model-select, .lang-select {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 10px; font-size: 12px; outline: none;
}
.pill {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; white-space: nowrap;
}
.pill b { color: var(--accent-2); font-weight: 600; }

.messages { flex: 1; overflow-y: auto; padding: 28px max(20px, calc((100% - 780px) / 2)); }
.welcome { max-width: 640px; margin: 12vh auto 0; text-align: center; }
.welcome-icon {
  width: 54px; height: 54px; border-radius: 16px; margin: 0 auto 18px;
  display: grid; place-items: center; background: var(--accent); color: #fff;
  font-size: 24px; font-weight: 700;
}
.welcome h2 { font-size: 24px; font-weight: 500; margin: 0 0 8px; }
.welcome p { color: var(--muted); margin: 0; font-size: 13px; }

.msg { display: flex; gap: 14px; margin-bottom: 24px; }
.msg .avatar {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 9px;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--muted);
}
.msg.user .avatar { background: var(--accent); color: #fff; }
.msg .body { min-width: 0; flex: 1; }
.msg .body p { margin: 3px 0; white-space: pre-wrap; word-break: break-word; }
.msg.user { flex-direction: row-reverse; }
.msg.user .body { text-align: start; }
.msg.user .body .bubble {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 14px 14px 4px 14px; padding: 10px 14px; display: inline-block; max-width: 100%;
}
.msg.assistant .bubble { padding: 2px 0; }
.msg.assistant pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; overflow-x: auto; font-size: 12px; direction: ltr; text-align: left;
}
.msg.assistant code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.msg.assistant :not(pre) > code { background: var(--surface-2); padding: 2px 5px; border-radius: 4px; font-size: 12px; }
.typing span { animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

.composer-wrap { padding: 10px max(20px, calc((100% - 780px) / 2)) 18px; }
.composer {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 10px 10px 16px;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; resize: none; background: none; border: none; outline: none;
  max-height: 180px; line-height: 1.5; padding: 5px 0;
}
.composer textarea::placeholder { color: var(--muted); }
.send-btn {
  width: 34px; height: 34px; border-radius: 10px; border: none; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 14px;
}
.send-btn:disabled { opacity: .4; }
.composer-note { text-align: center; font-size: 11px; color: var(--muted); margin: 8px 0 0; }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); }
.modal-card {
  position: relative; width: min(100%, 840px); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 18px; margin: 0; font-weight: 500; }
.modal-card > .muted { margin: 4px 0 0; font-size: 12px; }
.modal-card h3 { font-size: 14px; font-weight: 500; margin: 24px 0 10px; }
.topup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 12px; }
.amount-options, .network-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 9px; padding: 8px 12px; font-size: 12px;
}
.chip.active { border-color: var(--accent); background: rgba(124,108,240,.15); }
.address-box {
  margin-top: 16px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; display: grid; gap: 8px;
}
.address-box code { font-size: 11px; word-break: break-all; color: var(--accent-2); line-height: 1.5; }
.qr-box { margin-top: 12px; display: flex; justify-content: center; }
.qr-box svg { width: 150px; height: 150px; background: #fff; padding: 6px; border-radius: 8px; }
.rate-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 8px; }
.rate-line b { color: var(--text); font-weight: 500; }
.order-list { display: grid; gap: 6px; }
.order-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; font-size: 12px;
}
.order-row .status { margin-inline-start: auto; padding: 3px 8px; border-radius: 999px; font-size: 11px; }
.status.pending { background: rgba(251,191,36,.14); color: var(--warn); }
.status.confirmed { background: rgba(94,224,160,.14); color: var(--accent-2); }
.status.rejected { background: rgba(248,113,113,.14); color: var(--danger); }

.toast {
  position: fixed; inset-block-end: 24px; inset-inline-start: 50%; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 100;
}

[dir="rtl"] .msg.user { flex-direction: row; }
[dir="rtl"] .msg.user .body { text-align: right; }
[dir="rtl"] .msg.user .body .bubble { border-radius: 14px 14px 14px 4px; }
[dir="rtl"] .send-btn { transform: scaleX(-1); }

@media (max-width: 720px) {
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 30; transform: translateX(-100%); transition: .2s; width: 260px; }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 0 10px; }
  .top-actions { gap: 6px; }
  .lang-select { display: none; }
  .pill { display: none; }
  .topup-grid { grid-template-columns: 1fr; gap: 12px; }
  .messages { padding: 18px 14px; }
  .composer-wrap { padding: 8px 12px 14px; }
  .auth-card { padding: 22px; }
}
