/* ============================================================
   AI Light Proxy — application stylesheet (no framework)
   Theme: "new-api" Ant-style light theme
   bg #f5f5f5 · card #ffffff · border #e8e8e8 · hover #f0f0f0
   primary #1677ff · primaryHover #4096ff
   text #1f1f1f · textSecondary #595959
   Inter / JetBrains Mono (system fallbacks)
   ============================================================ */
:root {
  --bg: #f5f5f5;
  --panel: #ffffff;
  --ink: #1f1f1f;
  --muted: #595959;
  --faint: #8c8c8c;
  --line: #e8e8e8;
  --line-soft: #f0f0f0;
  --hover: #f0f0f0;
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow-pop: 0 8px 24px -8px rgba(0, 0, 0, .16);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, kbd, .mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 700; letter-spacing: -.01em; color: var(--ink); }
img { max-width: 100%; }
::selection { background: #bae0ff; }

/* ---------- buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none !important;
  background: #fff; color: var(--ink);
  box-shadow: var(--shadow);
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.btn:hover { background: var(--hover); border-color: #d9d9d9; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: #fff; color: var(--red); border-color: #ffccc7; }
.btn-danger:hover { background: #fff1f0; border-color: #ffa39e; }
.btn-danger-solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger-solid:hover { background: #ff7875; border-color: #ff7875; }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
/* Emerald top-up button in the panel header (theme "Top Up Balance") */
.btn-topup {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857;
  text-decoration: none !important; transition: background .15s;
}
.btn-topup:hover { background: #d1fae5; text-decoration: none; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; color: var(--ink); background: #fafafa;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px rgba(22, 119, 255, .12);
}
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 14px; }
.hint { color: var(--faint); font-size: 12.5px; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .span2 { grid-column: span 2; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span2 { grid-column: span 1; } }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; font-size: 13.5px; }
.check input { width: auto; }

/* ---------- alerts / badges ---------- */
.alert { padding: 12px 15px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13.5px; border: 1px solid transparent; overflow-wrap: anywhere; }
.alert-success { background: #f6ffed; color: #389e0d; border-color: #b7eb8f; }
.alert-error { background: #fff1f0; color: #cf1322; border-color: #ffa39e; }
.alert-info { background: #e6f4ff; color: #0958d9; border-color: #91caff; }
.alert-warn { background: #fffbe6; color: #d48806; border-color: #ffe58f; }
.alert a { text-decoration: underline; word-break: break-all; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent; }
.badge-green { background: #f6ffed; color: #389e0d; border-color: #b7eb8f; }
.badge-red { background: #fff1f0; color: #cf1322; border-color: #ffa39e; }
.badge-amber { background: #fffbe6; color: #d48806; border-color: #ffe58f; }
.badge-gray { background: #fafafa; color: #595959; border-color: #e8e8e8; }
.badge-blue { background: #e6f4ff; color: #0958d9; border-color: #91caff; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 12.5px; text-transform: none; letter-spacing: 0;
  color: var(--muted); background: #fafafa; padding: 11px 16px; border-bottom: 1px solid var(--line);
  white-space: nowrap; font-weight: 600;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; color: #434343; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fafafa; }
.table tr.row-highlight td { background: #fffbe6; }
.table tr.row-highlight:hover td { background: #fff1b8; }
/* Dense variant for wide tables (e.g. routing channels) */
.table-dense th, .table-dense td { padding: 8px 10px; }
.table-dense .col-model { min-width: 130px; }
.tnum { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--faint); }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 15px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 15.5px; }
.card-body { padding: 20px; }

/* ---------- stat cards (theme: label + pastel icon chip, mono value) ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); transition: box-shadow .15s;
}
.stat:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, .09); }
.stat-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.stat .stat-label { color: var(--muted); font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0; }
.stat-ic {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.stat-ic-green { background: #f6ffed; color: #52c41a; }
.stat-ic-blue { background: #e6f4ff; color: #1677ff; }
.stat-ic-purple { background: #f9f0ff; color: #9254de; }
.stat-ic-amber { background: #fffbe6; color: #faad14; }
.stat .stat-value { font-size: 22px; font-weight: 700; margin-top: 0; font-variant-numeric: tabular-nums; }
.stat .stat-sub { color: var(--faint); font-size: 12px; margin-top: 3px; }

/* ---------- pagination ---------- */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.pagination .page {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font-size: 13px; color: var(--ink); text-decoration: none !important;
}
.pagination .page:hover { background: var(--hover); }
.pagination .page.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .page.disabled { color: #d9d9d9; pointer-events: none; }

/* ---------- public layout ---------- */
.pub-nav {
  background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.pub-nav-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px; height: 64px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16.5px; color: var(--ink); text-decoration: none !important; }
/* Blue rounded logo square (theme: w-9 h-9 rounded-lg bg-primary) */
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(22, 119, 255, .28);
}
.brand-mark { color: var(--primary); font-size: 19px; }
.pub-links { display: flex; align-items: center; gap: 8px; }
.pub-links a.nav-link { color: var(--muted); font-weight: 600; padding: 8px 10px; border-radius: 8px; }
.pub-links a.nav-link:hover { color: var(--ink); background: var(--hover); text-decoration: none; }
.pub-footer { border-top: 1px solid var(--line); margin-top: 60px; background: #fff; }
.pub-footer-inner { max-width: 1080px; margin: 0 auto; padding: 22px 20px; color: var(--faint); font-size: 13px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.hero {
  padding: 84px 20px 60px; max-width: 1080px; margin: 0 auto; text-align: center;
  background: radial-gradient(900px 320px at 50% -80px, #e6f4ff 0%, rgba(230, 244, 255, 0) 70%);
}
.hero h1 { font-size: clamp(30px, 5vw, 48px); letter-spacing: -.02em; margin-bottom: 16px; }
.hero p.lead { font-size: 18px; color: var(--muted); max-width: 640px; margin: 0 auto 28px; }
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero-eyebrow { display: inline-block; background: #e6f4ff; color: var(--primary); border: 1px solid #91caff; font-weight: 700; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; padding: 5px 12px; border-radius: 999px; margin-bottom: 18px; }
.section { max-width: 1080px; margin: 0 auto; padding: 34px 20px; }
.section > h2 { font-size: 26px; margin-bottom: 6px; }
.section > p.section-sub { color: var(--muted); margin: 0 0 24px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
.feature { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.feature .f-icon { font-size: 22px; margin-bottom: 8px; }
.feature h3 { font-size: 15.5px; margin-bottom: 5px; }
.feature p { color: var(--muted); font-size: 13.5px; margin: 0; }
.code-sample { background: #1e293b; color: #e2e8f0; border-radius: var(--radius-sm); padding: 20px; overflow-x: auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; tab-size: 4; font-size: 13px; line-height: 1.6; box-shadow: var(--shadow); }
.code-sample .c-cmd { color: #7cc7f5; }
.code-sample .c-str { color: #b5e07a; }
.step-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; counter-reset: step; }
.step { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 20px 18px 56px; box-shadow: var(--shadow); }
.step::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 16px; top: 18px; width: 28px; height: 28px; border-radius: 8px;
  background: #e6f4ff; color: var(--primary); font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.step h3 { font-size: 15px; } .step p { color: var(--muted); font-size: 13.5px; margin: 0; }

/* ---------- auth pages ---------- */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 28px 16px; background: radial-gradient(700px 300px at 50% -60px, #e6f4ff 0%, rgba(230, 244, 255, 0) 70%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px 28px; }
.auth-brand { text-align: center; margin-bottom: 0; }
.auth-card .auth-brand { margin-bottom: 20px; }
.auth-brand .brand { font-size: 24px; }
.auth-brand .brand-logo { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; margin-bottom: 8px; }
.auth-brand h1 { font-size: 20px; margin: 6px 0 2px; }
.auth-brand p { color: var(--muted); margin: 0; font-size: 13.5px; }
.auth-alt { text-align: center; color: var(--muted); font-size: 13.5px; margin-top: 16px; }

/* honeypot: invisible to humans, visible to dumb bots */
.hp-field { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* ---------- app (panel) layout: header on top, sidebar below ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.app-body { display: flex; flex: 1; min-width: 0; align-items: stretch; }

/* Top header (theme: white bar h-16 with logo, stats, actions) */
.app-header {
  background: #fff; border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 0 20px; height: 64px; flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 50;
}
.app-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--ink); text-decoration: none !important; flex-shrink: 0; }
.app-brand:hover { text-decoration: none; }
.brand-chip {
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: #e6f4ff; color: var(--primary); border: 1px solid #91caff; white-space: nowrap;
}
.page-title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.header-div { width: 1px; height: 22px; background: var(--line); }
/* Header balance stat (theme: wallet icon + label + green mono value) */
.hstat { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); font-weight: 500; }
.hstat-ic { font-size: 14px; }
.hstat-ic-green { color: #52c41a; }
.hstat-v { font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; font-weight: 700; font-size: 14.5px; color: #389e0d; font-variant-numeric: tabular-nums; }
/* Avatar + name/email (theme header right) */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(22, 119, 255, .3);
}
.um-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.um-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.um-mail { font-size: 11px; color: var(--faint); }
@media (max-width: 860px) { .hstat, .um-meta, .btn-topup .btn-topup-label { display: none; } }
@media (max-width: 640px) { .page-title { display: none; } .brand-chip { display: none; } }

/* Sidebar (theme: white, w-64, nav pill buttons) */
.sidebar {
  width: 256px; flex-shrink: 0; background: #fff; color: var(--ink);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 64px; height: calc(100vh - 64px); overflow-y: auto;
  padding: 14px;
}
.side-nav { display: flex; flex-direction: column; gap: 6px; }
.side-nav .nav-heading { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); padding: 12px 12px 4px; font-weight: 600; }
.side-nav a {
  color: var(--muted); padding: 11px 14px; border-radius: var(--radius-sm); font-weight: 500; font-size: 14px;
  display: flex; align-items: center; gap: 12px; text-decoration: none !important;
  border: 1px solid transparent; transition: background .15s, color .15s, border-color .15s;
}
.side-nav a:hover { background: var(--hover); color: var(--ink); }
.side-nav a.active { background: var(--primary-soft); border-color: var(--primary-border); color: var(--primary); font-weight: 600; }
.side-nav .nav-icon { width: 20px; text-align: center; font-size: 15px; color: var(--faint); }
.side-nav a.active .nav-icon { color: var(--primary); }
.sidebar-foot { margin-top: auto; padding: 12px 6px 2px; border-top: 1px solid var(--line-soft); font-size: 12.5px; color: var(--faint); }
.sidebar-foot a { color: var(--faint); text-decoration: underline; }
.sidebar-foot a:hover { color: var(--ink); }

/* Sidebar chat history box (under the Chat nav link) */
.nav-chat-box { display: flex; flex-direction: column; gap: 6px; padding-left: 33px; }
.nav-conv-list {
  max-height: 150px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; box-shadow: var(--shadow);
}
.side-nav .nav-conv-list a.conv-item {
  padding: 8px 10px; border-radius: 0; border: 0; border-bottom: 1px solid var(--line-soft);
  gap: 6px; font-size: 12.5px; color: var(--ink); display: flex; align-items: center;
  text-decoration: none !important; transition: background .15s;
}
.side-nav .nav-conv-list a.conv-item:last-child { border-bottom: 0; }
.side-nav .nav-conv-list a.conv-item:hover { background: #fafafa; color: var(--ink); }
.side-nav .nav-conv-list a.conv-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-conv-list .conv-item .conv-title { font-size: 12.5px; font-weight: 500; }
.conv-empty { padding: 10px 12px; font-size: 12px; color: var(--faint); }

/* Content area (theme: p-6/8 on #f5f5f5) */
.content { flex: 1; min-width: 0; padding: 24px; width: 100%; }
.menu-toggle { display: none; }

/* User dropdown menu */
.user-menu { position: relative; }
.user-menu summary, .menu-btn {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; font-size: 13.5px; color: var(--ink);
  background: transparent; border: 0; padding: 5px 8px; border-radius: 10px;
  transition: background .15s;
}
.user-menu summary:hover, .menu-btn:hover { background: var(--hover); }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu .chev { font-size: 10px; color: var(--faint); }
.user-menu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); min-width: 190px; padding: 6px; z-index: 60;
}
.user-menu .menu a, .user-menu .menu button {
  display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: 8px;
  font-size: 13.5px; color: var(--ink); background: none; border: 0; cursor: pointer; text-decoration: none !important;
}
.user-menu .menu a:hover, .user-menu .menu button:hover { background: var(--hover); }

/* Mobile drawer */
@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 100; left: 0; top: 0; height: 100vh; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .16); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .app-header { padding: 0 14px; }
}
.sidebar-backdrop { display: none; }
@media (max-width: 900px) {
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 90; }
}

/* ---------- chat UI ---------- */
.chat-layout { display: flex; gap: 16px; height: calc(100vh - 64px - 48px); min-height: 480px; }
.chat-side { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; }
.conv-list { flex: 1; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.conv-item { display: flex; align-items: center; gap: 6px; padding: 11px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.conv-item:hover { background: #fafafa; }
.conv-item.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.conv-item .conv-title { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-actions { display: none; gap: 2px; }
.conv-item:hover .conv-actions { display: flex; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 3px 6px; border-radius: 6px; font-size: 13px; color: var(--faint); }
.icon-btn:hover { background: var(--line-soft); color: var(--ink); }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.chat-header { padding: 12px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: #fff; }
.chat-header select { max-width: 260px; width: auto; }
.chat-header #effortSelect { max-width: 170px; font-size: 13px; }
.chat-head-right { display: flex; align-items: center; gap: 10px; max-width: 60%; min-width: 0; }
.chat-head-right #chatConvLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head-right .btn { white-space: nowrap; }
.chat-head-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.chat-conv-div { width: 1px; height: 18px; background: var(--line); flex-shrink: 0; }

/* ---------- chat: model picker ---------- */
.model-picker { position: relative; min-width: 0; }
.model-picker-btn {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  cursor: pointer; box-shadow: var(--shadow); transition: background .15s, border-color .15s;
  max-width: 340px;
}
.model-picker-btn:hover { background: var(--hover); border-color: #d9d9d9; }
.mp-text { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; }
.mp-title { font-size: 13.5px; font-weight: 600; color: var(--ink); line-height: 1.25; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-sub { font-size: 11px; color: var(--faint); line-height: 1.25; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-chev { color: var(--faint); font-size: 11px; transition: transform .15s; flex-shrink: 0; }
.model-picker.open .mp-chev { transform: rotate(180deg); }
.model-picker-pop {
  position: absolute; top: calc(100% + 6px); left: 0; width: 440px; max-width: min(calc(100vw - 48px), 440px);
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-pop); z-index: 70; overflow: hidden;
}
.mp-search { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.mp-search input { width: 100%; font-size: 13px; }
.mp-list { max-height: 360px; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.mp-item { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 10px; padding: 10px 12px; cursor: pointer; transition: background .12s; }
.mp-item:hover { background: var(--hover); }
.mp-item.selected { background: var(--primary-soft); }
.mp-item-top { display: flex; align-items: center; gap: 8px; }
.mp-item-title { font-size: 13.5px; font-weight: 600; color: var(--ink); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-item-check { color: var(--primary); font-size: 13px; flex-shrink: 0; }
.mp-item-id { font-size: 11px; color: var(--faint); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-badges { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.mp-badge { font-size: 10.5px; font-weight: 600; padding: 1.5px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: #fafafa; white-space: nowrap; }
.mp-badge.b-reason { color: #7c3aed; border-color: #ddd6fe; background: #f5f3ff; }
.mp-badge.b-vision { color: #0d9488; border-color: #99f6e4; background: #f0fdfa; }
.mp-badge.b-tools { color: #d97706; border-color: #fde68a; background: #fffbeb; }
.mp-badge.b-web { color: #0284c7; border-color: #bae6fd; background: #f0f9ff; }
.mp-badge.b-long { color: #2563eb; border-color: #bfdbfe; background: #eff6ff; }
.mp-desc { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mp-price { font-size: 11.5px; color: var(--faint); margin-top: 6px; }
.mp-empty { padding: 18px; text-align: center; color: var(--faint); font-size: 13px; }

/* ---------- chat: hero empty state ---------- */
.chat-messages .empty { margin: auto; }
.chat-hero { text-align: center; padding: 44px 24px; max-width: 560px; }
.chat-hero-icon {
  width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px;
  background: var(--primary-soft); border: 1px solid var(--primary-border);
  color: var(--primary); font-size: 24px; display: flex; align-items: center; justify-content: center;
}
.chat-hero h3 { margin: 0 0 8px; font-size: 19px; }
.chat-hero p { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 14px; font-size: 12.5px; color: var(--muted); cursor: pointer;
  transition: border-color .15s, color .15s, background .15s; font-family: inherit;
}
.chip:hover { border-color: var(--primary-border); color: var(--primary); background: var(--primary-soft); }

/* Attach button icon (inline SVG) */
.attach-btn svg { width: 18px; height: 18px; display: block; margin: 0 auto; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; background: var(--bg); }
.msg { display: flex; flex-direction: column; max-width: min(86%, 880px); min-width: 0; }
.msg-user { align-self: flex-end; align-items: flex-end; max-width: min(78%, 760px); }
.msg-assistant { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 14px; border-radius: 14px; font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap; max-width: 100%; min-width: 0; }
.msg-user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; box-shadow: 0 2px 8px rgba(22, 119, 255, .25); }
.msg-assistant .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble code { background: rgba(0, 0, 0, .06); padding: 1px 5px; border-radius: 5px; }
.msg-user .bubble code { background: rgba(255, 255, 255, .2); }
.bubble pre { background: #1f2937; color: #e5e7eb; padding: 10px 12px; border-radius: 8px; overflow: auto; max-height: 420px; overscroll-behavior: contain; margin: 8px 0; }
.bubble pre code { background: none; padding: 0; color: inherit; }
.msg-meta { font-size: 11.5px; color: var(--faint); margin-top: 4px; padding: 0 4px; }
.chat-inputbar { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; align-items: flex-end; background: #fff; }
.chat-inputbar textarea { min-height: 46px; max-height: 160px; resize: none; background: #fafafa; }
.chat-status { font-size: 12px; color: var(--muted); padding: 0 18px 10px; }

/* Chat: image attachments (vision) */
.attach-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  font-size: 16px; line-height: 1; padding: 0 12px; height: 46px; cursor: pointer; color: var(--muted);
  transition: background .15s, color .15s;
}
.attach-btn:hover { background: var(--hover); color: var(--ink); }
.attach-btn[hidden] { display: none; }
.web-search-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  font-size: 12.5px; font-weight: 600; line-height: 1; padding: 0 11px; height: 46px;
  cursor: pointer; color: var(--muted); display: inline-flex; align-items: center; gap: 5px;
  transition: background .15s, color .15s, border-color .15s; flex-shrink: 0;
}
.web-search-btn:hover { background: var(--hover); color: var(--ink); }
.web-search-btn.active { background: #eff6ff; border-color: #60a5fa; color: #1d4ed8; }
.web-search-btn[hidden] { display: none; }
.chat-previews { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px 0; }
.preview-item { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--bg); }
.preview-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-remove {
  position: absolute; top: 2px; right: 2px; border: 0; border-radius: 50%;
  width: 18px; height: 18px; line-height: 16px; text-align: center;
  background: rgba(0, 0, 0, .68); color: #fff; font-size: 10px; cursor: pointer; padding: 0;
}
.preview-remove:hover { background: rgba(0, 0, 0, .88); }
.msg-thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; justify-content: flex-end; }
.msg-assistant .msg-thumbs { justify-content: flex-start; }
.msg-thumb {
  width: 96px; height: 96px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; display: block; cursor: zoom-in;
}
@media (max-width: 640px) { .msg-thumb { width: 72px; height: 72px; } }
@media (max-width: 640px) {
  .chat-inputbar { padding: 10px 12px; gap: 8px; }
  .chat-inputbar .input-hint { display: none; }
  .attach-btn { padding: 0 10px; }
}

/* Full-screen image viewer */
.lightbox {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, .82);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out; padding: 24px;
}
.lightbox img {
  max-width: 92vw; max-height: 92vh;
  border-radius: 10px; box-shadow: 0 12px 48px rgba(0, 0, 0, .5);
  background: #fff;
}

/* Chat: rendered assistant markdown */
.bubble.md { white-space: normal; }
.md-answer { line-height: 1.55; }
.md-answer h1, .md-answer h2, .md-answer h3, .md-answer h4 { margin: 10px 0 6px; line-height: 1.3; }
.md-answer h1 { font-size: 1.25em; } .md-answer h2 { font-size: 1.15em; } .md-answer h3 { font-size: 1.05em; } .md-answer h4 { font-size: 1em; }
.md-answer h1:first-child, .md-answer h2:first-child, .md-answer h3:first-child { margin-top: 0; }
.md-answer p { margin: 0 0 8px; } .md-answer p:last-child { margin-bottom: 0; }
.md-answer ul, .md-answer ol { margin: 0 0 8px; padding-left: 22px; }
.md-answer li { margin: 2px 0; }
.md-answer blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid #d9d9d9; color: var(--muted); background: #fafafa; border-radius: 0 6px 6px 0; }
.md-answer blockquote p:last-child { margin-bottom: 0; }
.md-answer hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.md-answer a { color: var(--primary); }
.md-answer code { font-size: 12.5px; }

/* Chat: code blocks with copy button (dark for readability) */
.code-block { margin: 8px 0; border-radius: 8px; overflow: hidden; border: 1px solid #374151; background: #1f2937; min-width: 0; }
.code-block:first-child { margin-top: 0; }
.code-block:last-child { margin-bottom: 0; }
.code-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 8px 5px 12px; background: #111827; color: #9ca3af; font-size: 11.5px; }
.code-lang { font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; text-transform: lowercase; }
.copy-btn { background: rgba(255, 255, 255, .08); color: #e5e7eb; border: 0; border-radius: 5px; padding: 3px 9px; font-size: 11px; cursor: pointer; font-family: inherit; }
.copy-btn:hover { background: rgba(255, 255, 255, .18); }
.code-block pre { margin: 0; padding: 10px 12px; overflow: auto; max-height: 420px; overscroll-behavior: contain; background: transparent; }
.code-block pre code { background: none; padding: 0; color: #e5e7eb; font-size: 12.5px; line-height: 1.5; }

/* Chat: collapsible thinking (reasoning) box */
.think-box { border: 1px solid var(--line); border-left: 3px solid #91caff; border-radius: 8px; background: #fafafa; margin-bottom: 8px; overflow: hidden; }
.think-toggle { width: 100%; display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: none; border: 0; font: inherit; font-size: 12.5px; color: var(--muted); cursor: pointer; text-align: left; }
.think-toggle:hover { color: var(--ink); }
.think-toggle .chev { display: inline-block; transition: transform .15s ease; font-size: 11px; }
.think-box.open .chev { transform: rotate(90deg); }
.think-body { display: none; padding: 2px 12px 10px; font-size: 12.5px; line-height: 1.55; color: var(--faint); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow-y: auto; }
.think-box.open .think-body { display: block; }

/* Chat: context meter + input hint */
.ctx-meter { white-space: nowrap; }
.ctx-meter.warn { color: #d48806; }
.ctx-meter.danger { color: #cf1322; }
.input-hint { font-size: 11px; color: var(--faint); white-space: nowrap; align-self: center; min-width: 52px; text-align: right; }
.bubble-error { border-color: #ffa39e !important; background: #fff1f0 !important; color: #cf1322 !important; }
@media (max-width: 860px) {
  .chat-layout { height: auto; flex-direction: column; }
  .chat-side { width: 100%; max-height: 220px; }
  .chat-messages { min-height: 320px; }
}

/* ---------- docs ---------- */
.docs-section { max-width: 1200px; }
.docs-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 26px; }
.docs-toc { position: sticky; top: 84px; align-self: start; font-size: 13.5px; }
.docs-toc a { display: block; padding: 5px 10px; color: var(--muted); border-left: 2px solid var(--line); }
.docs-toc a:hover { color: var(--primary); border-color: var(--primary); text-decoration: none; }
@media (max-width: 860px) { .docs-layout { grid-template-columns: minmax(0, 1fr); } .docs-toc { display: none; } }
.doc-block { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); overflow-x: auto; }
.doc-block h2 { font-size: 18px; margin-top: 0; scroll-margin-top: 84px; }
.doc-block h3 { font-size: 14.5px; margin: 18px 0 6px; }
.doc-block table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 10px 0; }
.doc-block th, .doc-block td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.doc-block th { background: #fafafa; }
.doc-block ul { padding-left: 20px; margin: 8px 0; font-size: 13.5px; }
.doc-block li { margin: 4px 0; }
.method-tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; padding: 2px 9px; border-radius: 999px; background: #e6f4ff; color: var(--primary); border: 1px solid #91caff; vertical-align: 1px; }
.doc-block h3 .method-tag { margin-left: 8px; }
.os-details { border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; background: #fafafa; overflow: hidden; }
.os-details summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: 13.5px; list-style: none; display: flex; align-items: center; gap: 8px; user-select: none; }
.os-details summary::-webkit-details-marker { display: none; }
.os-details summary::before { content: "\25B8"; color: var(--muted); font-size: 12px; }
.os-details[open] summary::before { content: "\25BE"; }
.os-details[open] summary { border-bottom: 1px solid var(--line); }
.os-details .os-body { padding: 12px 14px 14px; }
.os-details .code-sample { margin: 8px 0; }
.os-details p:last-child { margin-bottom: 0; }

/* ---------- admin specifics ---------- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filter-bar .field { margin: 0; }
.inline-form { display: inline; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.test-result { background: #1f2937; color: #e5e7eb; border-radius: 10px; padding: 12px; font-size: 12.5px; white-space: pre-wrap; overflow-x: auto; max-height: 320px; overflow-y: auto; margin-top: 10px; display: none; }
.checkbox-row { display: flex; gap: 16px; flex-wrap: wrap; margin: 4px 0 10px; }
.checkbox-row label { display: flex; gap: 6px; align-items: center; font-weight: 500; margin: 0; }
.checkbox-row input { width: auto; }

/* ---------- install ---------- */
.install-page { background: linear-gradient(180deg, #e6f4ff, #f5f5f5); }
.install-shell { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; }
.install-card { width: 100%; max-width: 640px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px; }
.install-brand { text-align: center; margin-bottom: 22px; }
.install-brand h1 { font-size: 22px; margin: 4px 0 2px; }
.install-brand p { color: var(--muted); margin: 0; }
.req-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 22px; }
@media (max-width: 560px) { .req-grid { grid-template-columns: 1fr; } }
.req-item { display: flex; align-items: center; gap: 8px; font-size: 13px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fff; }
.req-status.ok { color: #52c41a; font-weight: 800; }
.req-status.fail { color: #cf1322; font-weight: 800; }
.req-label { font-weight: 600; flex: 1; }
.req-value { color: var(--faint); font-size: 12px; }
.install-form h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 10px; }
.install-note { color: var(--muted); font-size: 12.5px; margin-top: 12px; }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.w-auto { width: auto; }
.detail-box { background: #fafafa; border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 12px; white-space: pre-wrap; overflow-x: auto; }
.toast-stack { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast { background: #262626; color: #fff; padding: 11px 15px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow-pop); }
.toast.toast-success { background: #389e0d; }
.toast.toast-error { background: #cf1322; }

/* ---------- tabbed settings ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  border: none; background: transparent; padding: 9px 16px;
  font: inherit; font-weight: 600; font-size: 13.5px; color: var(--muted);
  cursor: pointer; border-radius: 10px 10px 0 0; border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--ink); background: var(--hover); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel[hidden] { display: none; }

/* ---------- payments ---------- */
/* Newly created invoice row on the top-up page (and other highlighted rows) */
.tr-current { background: #fffbe6; }
.tr-current td { border-top-color: #ffe58f; }
/* Pay address shown inside the success banner on the top-up page */
.pay-addr {
  display: inline-block;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: rgba(255, 255, 255, .92);
  color: var(--ink);
  border-radius: 6px;
  padding: 4px 8px;
  margin-top: 4px;
  word-break: break-all;
  max-width: 100%;
  user-select: all;
}
/* Expandable full-record panel under an admin payments table row */
.details-row > td {
  background: #fafafa;
  border-top: 1px dashed var(--line);
  box-shadow: inset 0 2px 0 rgba(22, 119, 255, .07);
}
.pd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px 18px;
  padding: 4px 2px;
}
.pd-item { min-width: 0; }
.pd-k {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--faint);
  margin-bottom: 2px;
}
.pd-v { font-size: 13.5px; overflow-wrap: anywhere; }
.pd-v .mono, .pd-v.mono { font-size: 12.5px; }
.pd-addr {
  display: inline-block;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 7px;
  word-break: break-all;
  max-width: 100%;
  user-select: all;
}
/* Payment-address QR codes (banner on the top-up page + on-demand toggles) */
.pay-qr { margin: 8px 0 2px; }
.qr-slot { margin-top: 6px; }
.pay-qr svg, .qr-slot svg {
  display: block;
  width: 132px;
  height: 132px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
}
@media (max-width: 600px) {
  .pay-qr svg, .qr-slot svg { width: 116px; height: 116px; }
}

/* ---------- models.dev reference pricing picker ---------- */
.ref-picker { position: relative; margin: 6px 0 2px; }
.ref-picker .field { margin-bottom: 8px; }
.ref-results {
  position: absolute;
  z-index: 60;
  left: 0; right: 0; top: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  max-height: 300px;
  overflow-y: auto;
}
.ref-item {
  display: block; width: 100%; text-align: left;
  border: none; border-bottom: 1px solid var(--line-soft);
  background: #fff; padding: 8px 12px; cursor: pointer;
  font: inherit; color: inherit;
}
.ref-item:last-child { border-bottom: none; }
.ref-item:hover { background: #fafafa; }
.ref-item-sub { display: block; font-size: 12px; color: var(--muted); }
.ref-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }
.ref-selected {
  border: 1px solid var(--line);
  background: #fafafa;
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 6px;
  font-size: 13.5px;
}
