:root{
  --primary:#2563eb;
  --primary-dark:#1d4ed8;
  --primary-soft:#eff4ff;
  --bg:#f5f6f8;
  --card:#ffffff;
  --line:#e8eaef;
  --text:#16181d;
  --text-2:#5a6070;
  --text-3:#9aa1b1;
  --ok:#16a34a;
  --err:#dc2626;
  --radius:14px;
  --sb-w:240px;
  --shadow:0 1px 2px rgba(16,24,40,.04),0 8px 24px rgba(16,24,40,.06);
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;}
html,body{height:100%;}
body{
  margin:0;background:var(--bg);color:var(--text);
  font:15px/1.6 -apple-system,BlinkMacSystemFont,"PingFang SC","Helvetica Neue","Microsoft YaHei",sans-serif;
  -webkit-font-smoothing:antialiased;
}
a{color:inherit;text-decoration:none;}
[hidden]{display:none !important;}

/* ---------- 按钮 ---------- */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:6px;
  height:38px;padding:0 16px;border:1px solid transparent;border-radius:10px;
  font-size:14px;font-weight:500;cursor:pointer;background:none;
  transition:background .15s,border-color .15s,transform .1s;font-family:inherit;
}
.btn:active{transform:scale(.985);}
.btn:disabled{opacity:.55;cursor:not-allowed;}
.btn-primary{background:var(--primary);color:#fff;}
.btn-primary:hover{background:var(--primary-dark);}
.btn-ghost{background:#fff;border-color:var(--line);color:var(--text-2);}
.btn-ghost:hover{border-color:#d3d8e2;color:var(--text);}
.btn-sm{height:32px;padding:0 12px;font-size:13px;border-radius:8px;}
.btn-lg{height:46px;font-size:15px;border-radius:12px;}
.btn-block{width:100%;}
.input{
  width:100%;height:42px;padding:0 14px;border:1px solid var(--line);border-radius:10px;
  background:#fff;font-size:14px;color:var(--text);outline:none;font-family:inherit;
  transition:border-color .15s,box-shadow .15s;
}
.input:focus{border-color:var(--primary);box-shadow:0 0 0 3px rgba(37,99,235,.12);}

/* ---------- 访问墙 ---------- */
.gate-view{
  position:fixed;inset:0;display:flex;align-items:center;justify-content:center;
  background:linear-gradient(160deg,#f7f9fc,#eef2f9);padding:24px;z-index:100;
}
.gate-box{
  width:100%;max-width:360px;background:#fff;border-radius:18px;padding:32px 26px;
  box-shadow:var(--shadow);text-align:center;
}
.gate-logo{font-size:22px;font-weight:700;letter-spacing:-.5px;margin-bottom:6px;}
.gate-tip{font-size:13px;color:var(--text-3);margin-bottom:20px;}
.gate-input{
  width:100%;height:46px;padding:0 16px;border:1px solid var(--line);border-radius:11px;
  font-size:15px;text-align:center;letter-spacing:2px;outline:none;font-family:inherit;
}
.gate-input:focus{border-color:var(--primary);box-shadow:0 0 0 3px rgba(37,99,235,.12);}
.gate-btn{width:100%;margin-top:14px;height:46px;}
.gate-err{color:var(--err);font-size:13px;margin-top:12px;min-height:20px;}
.gate-input{margin-bottom:10px;}
#authRegBox{display:block;}
#authRegBox[hidden]{display:none !important;}
#authSendCode{margin-top:0;height:42px;background:#fff;color:var(--primary);border:1px solid var(--primary);}
#authSendCode:disabled{opacity:.5;}
.gate-switch{text-align:center;font-size:13px;color:var(--text-3);margin-top:16px;}
.gate-switch a{color:var(--primary);margin-left:4px;font-weight:500;text-decoration:none;}


/* ---------- 布局 ---------- */
.site{display:flex;min-height:100vh;}

.sidebar{
  width:var(--sb-w);flex-shrink:0;background:#fff;border-right:1px solid var(--line);
  display:flex;flex-direction:column;position:fixed;top:0;left:0;bottom:0;z-index:60;
}
.sb-brand{display:flex;align-items:center;gap:10px;padding:18px 16px 14px;}
.sb-logo{
  width:34px;height:34px;border-radius:10px;background:var(--primary);color:#fff;
  display:flex;align-items:center;justify-content:center;font-weight:700;font-size:16px;flex-shrink:0;
}
.sb-brand-txt{min-width:0;}
.sb-name{font-size:15px;font-weight:600;line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.sb-sub{font-size:11px;color:var(--text-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}

.sb-nav{flex:1;overflow-y:auto;padding:6px 10px;}
.sb-group{font-size:11px;color:var(--text-3);padding:10px 8px 6px;letter-spacing:.5px;}
.sb-sep{height:1px;background:var(--line);margin:10px 8px;}
.sb-item{
  display:flex;align-items:center;gap:10px;height:40px;padding:0 10px;border-radius:9px;
  color:var(--text-2);font-size:14px;margin-bottom:2px;cursor:pointer;
  transition:background .13s,color .13s;
}
.sb-item:hover{background:#f6f7fa;color:var(--text);}
.sb-item.on{background:var(--primary-soft);color:var(--primary);font-weight:600;}
.sb-ico{
  width:22px;height:22px;border-radius:6px;background:#f1f3f7;color:var(--text-2);
  display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:700;flex-shrink:0;
}
.sb-item.on .sb-ico{background:var(--primary);color:#fff;}
.sb-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}

.sb-foot{padding:12px;border-top:1px solid var(--line);}
.sb-balance{
  background:var(--primary-soft);border-radius:11px;padding:10px 12px;margin-bottom:10px;
}
.sb-bal-label{font-size:11px;color:var(--text-2);}
.sb-bal-num{font-size:18px;font-weight:700;color:var(--primary);letter-spacing:-.3px;}
.sb-user{
  font-size:12px;color:var(--text-2);margin-top:10px;text-align:center;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.sb-logout{
  width:100%;margin-top:6px;height:30px;border:none;background:none;
  color:var(--text-3);font-size:12px;cursor:pointer;font-family:inherit;
}
.sb-logout:hover{color:var(--err);}

.main{flex:1;margin-left:var(--sb-w);display:flex;flex-direction:column;min-width:0;}

.topbar{
  height:58px;flex-shrink:0;display:flex;align-items:center;gap:12px;padding:0 24px;
  background:rgba(255,255,255,.86);backdrop-filter:blur(12px);
  border-bottom:1px solid var(--line);position:sticky;top:0;z-index:40;
}
.menu-btn{
  display:none;flex-direction:column;justify-content:center;gap:4px;width:36px;height:36px;
  border:none;background:none;cursor:pointer;padding:0 8px;
}
.menu-btn span{height:2px;background:var(--text);border-radius:2px;display:block;}
.top-title{font-size:15px;font-weight:600;}
.top-right{margin-left:auto;}
.top-bal{font-size:13px;color:var(--text-2);font-weight:500;}

.content{padding:26px 24px 48px;max-width:1080px;width:100%;}
.page-head{margin-bottom:20px;}
.page-head h1{font-size:22px;margin:0 0 4px;letter-spacing:-.4px;}
.page-desc{margin:0;font-size:13px;color:var(--text-3);}

/* ---------- 卡片 ---------- */
.card-grid{
  display:grid;grid-template-columns:repeat(3,1fr);gap:14px;margin-bottom:16px;
}
.stat-card{
  background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  padding:18px;display:flex;flex-direction:column;gap:6px;
}
.stat-label{font-size:12px;color:var(--text-3);}
.stat-num{font-size:24px;font-weight:700;letter-spacing:-.6px;}
.stat-card .btn{align-self:flex-start;margin-top:4px;}

.panel{
  background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  padding:18px;margin-bottom:16px;
}
.panel-head{font-size:14px;font-weight:600;margin-bottom:12px;}

.kv{display:flex;justify-content:space-between;padding:9px 0;border-bottom:1px solid #f2f4f7;font-size:14px;}
.kv:last-child{border-bottom:none;}
.kv span{color:var(--text-3);}
.kv b{font-weight:500;}

.day-row,.log-row{
  display:flex;align-items:center;gap:12px;padding:10px 0;border-bottom:1px solid #f2f4f7;font-size:13px;
}
.day-row:last-child,.log-row:last-child{border-bottom:none;}
.day-row span:first-child{color:var(--text-3);width:96px;flex-shrink:0;}
.day-row b,.log-row b{margin-left:auto;color:var(--primary);font-weight:600;}
.log-model{font-weight:500;min-width:110px;}
.log-tk{color:var(--text-3);}
.log-time{margin-left:auto;color:var(--text-3);font-size:12px;}
.log-row b{margin-left:12px;}
.empty{color:var(--text-3);font-size:13px;text-align:center;padding:22px 0;}

/* ---------- 对话 ---------- */
.chat-wrap{padding:0;display:flex;flex-direction:column;height:calc(100vh - 58px);max-width:none;}
.chat-head{
  display:flex;align-items:center;gap:10px;padding:14px 24px;border-bottom:1px solid var(--line);
  background:#fff;flex-shrink:0;
}
.model-select{
  height:36px;padding:0 32px 0 12px;border:1px solid var(--line);border-radius:9px;
  background:#fff url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%239aa1b1' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
  font-size:13px;color:var(--text);outline:none;appearance:none;font-family:inherit;cursor:pointer;
}
.model-select:focus{border-color:var(--primary);}
.chat-head .btn{margin-left:auto;}

.chat-box{
  flex:1;overflow-y:auto;padding:24px;display:flex;flex-direction:column;gap:18px;
  scroll-behavior:smooth;
}
.chat-empty{
  margin:auto;text-align:center;color:var(--text-3);
}
.chat-empty-title{font-size:17px;font-weight:600;color:var(--text-2);margin-bottom:6px;}
.chat-empty-tip{font-size:13px;}

.msg{display:flex;gap:10px;max-width:860px;width:100%;}
.msg-user{flex-direction:row-reverse;margin-left:auto;}
.msg-av{
  width:30px;height:30px;border-radius:9px;flex-shrink:0;display:flex;align-items:center;justify-content:center;
  font-size:12px;font-weight:700;
}
.msg-user .msg-av{background:var(--primary);color:#fff;}
.msg-assistant .msg-av{background:#eef1f6;color:var(--text-2);}
.msg-bubble{
  padding:11px 15px;border-radius:14px;font-size:14.5px;line-height:1.72;
  word-break:break-word;white-space:normal;
}
.msg-user .msg-bubble{background:var(--primary);color:#fff;border-bottom-right-radius:5px;}
.msg-assistant .msg-bubble{background:#fff;border:1px solid var(--line);border-bottom-left-radius:5px;}
.msg-bubble.err{background:#fef2f2;border-color:#fecaca;color:var(--err);}
.msg-bubble.pending{display:flex;align-items:center;min-height:42px;}

.dots{display:inline-flex;gap:4px;align-items:center;}
.dots i{width:6px;height:6px;border-radius:50%;background:var(--text-3);animation:bl 1.3s infinite;}
.dots i:nth-child(2){animation-delay:.18s;}
.dots i:nth-child(3){animation-delay:.36s;}
@keyframes bl{0%,60%,100%{opacity:.28;transform:translateY(0);}30%{opacity:1;transform:translateY(-3px);}}

.msg-bubble .code{
  background:#0f1420;color:#e6edf7;border-radius:10px;padding:12px 14px;overflow-x:auto;
  font:12.5px/1.6 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;margin:10px 0;
  white-space:pre;
}
.msg-bubble .inline{
  background:rgba(37,99,235,.08);color:var(--primary);padding:1px 5px;border-radius:5px;
  font:12.5px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}
.msg-user .msg-bubble .inline{background:rgba(255,255,255,.2);color:#fff;}

.composer{
  flex-shrink:0;padding:12px 24px 18px;background:#fff;border-top:1px solid var(--line);
  display:flex;gap:10px;align-items:flex-end;
}
.composer textarea{
  flex:1;resize:none;border:1px solid var(--line);border-radius:13px;padding:11px 14px;
  font:14.5px/1.55 inherit;outline:none;max-height:160px;background:#fafbfc;
  transition:border-color .15s,background .15s;
}
.composer textarea:focus{border-color:var(--primary);background:#fff;box-shadow:0 0 0 3px rgba(37,99,235,.1);}
.send-btn{height:42px;padding:0 20px;border-radius:12px;}

/* ---------- 模型市场 ---------- */
.market-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(264px,1fr));gap:14px;}
.m-card{
  background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  padding:16px;display:flex;flex-direction:column;gap:10px;
  transition:border-color .15s,box-shadow .15s,transform .15s;
}
.m-card:hover{border-color:#c9d4e8;box-shadow:var(--shadow);transform:translateY(-1px);}
.m-card-top{display:flex;align-items:center;gap:10px;}
.m-avatar{
  width:40px;height:40px;border-radius:11px;background:var(--primary-soft);color:var(--primary);
  display:flex;align-items:center;justify-content:center;font-weight:700;font-size:16px;
  overflow:hidden;flex-shrink:0;
}
.m-avatar img{width:100%;height:100%;object-fit:cover;}
.m-avatar-lg{width:52px;height:52px;border-radius:14px;font-size:20px;}
.m-title-wrap{min-width:0;flex:1;}
.m-name{font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.m-vendor{font-size:12px;color:var(--text-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.m-badge{
  font-size:11px;background:#fff7ed;color:#c2410c;border:1px solid #fed7aa;
  padding:1px 8px;border-radius:20px;flex-shrink:0;
}
.m-summary{font-size:13px;color:var(--text-2);line-height:1.6;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;min-height:42px;}
.m-meta{display:flex;flex-wrap:wrap;gap:6px;}
.chip{
  font-size:11.5px;background:#f3f5f9;color:var(--text-2);padding:2px 8px;border-radius:6px;
}
.chip-line{background:var(--primary-soft);color:var(--primary);}
.chip-hot{background:var(--primary);color:#fff;}
.m-foot{
  display:flex;justify-content:space-between;gap:8px;font-size:12px;color:var(--text-3);
  border-top:1px solid #f2f4f7;padding-top:10px;
}

.back-btn{margin-bottom:16px;}
.detail-head{display:flex;align-items:center;gap:14px;margin-bottom:14px;}
.detail-head h2{margin:0;font-size:20px;letter-spacing:-.3px;}
.detail-tags{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:16px;}
.detail-price{
  display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:16px;
}
.dp-item{
  background:#fff;border:1px solid var(--line);border-radius:12px;padding:14px;
  display:flex;flex-direction:column;gap:5px;
}
.dp-item span{font-size:12px;color:var(--text-3);}
.dp-item b{font-size:15px;font-weight:600;}
.detail-desc{font-size:14px;line-height:1.85;color:var(--text-2);}
.detail-use{width:100%;margin-bottom:20px;}

/* ---------- 令牌 ---------- */
.token-form{display:flex;gap:10px;flex-wrap:wrap;}
.token-form .input{flex:1;min-width:150px;}
.token-row{
  display:flex;align-items:center;gap:12px;padding:12px 0;border-bottom:1px solid #f2f4f7;
  flex-wrap:wrap;
}
.token-row:last-child{border-bottom:none;}
.token-main{flex:1;min-width:200px;}
.token-name{font-size:14px;font-weight:500;margin-bottom:3px;}
.token-val{
  font:12px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:var(--text-3);
  background:#f6f7fa;padding:3px 7px;border-radius:5px;display:inline-block;
  word-break:break-all;
}
.token-ops{display:flex;gap:6px;}

/* ---------- 弹窗 ---------- */
.modal{
  position:fixed;inset:0;background:rgba(16,24,40,.42);z-index:200;
  display:flex;align-items:center;justify-content:center;padding:20px;
  animation:fade .16s ease;
}
@keyframes fade{from{opacity:0}to{opacity:1}}
.modal-box{
  width:100%;max-width:380px;background:#fff;border-radius:18px;padding:26px;
  box-shadow:0 24px 60px rgba(16,24,40,.22);display:flex;flex-direction:column;gap:12px;
  animation:pop .18s ease;
}
@keyframes pop{from{transform:translateY(10px) scale(.98);opacity:0}to{transform:none;opacity:1}}
.modal-title{font-size:18px;font-weight:600;margin-bottom:2px;}
.modal-err{color:var(--err);font-size:13px;min-height:18px;}
.modal-switch{text-align:center;font-size:13px;color:var(--text-3);}
.modal-switch a{color:var(--primary);margin-left:4px;font-weight:500;}

.toast{
  position:fixed;left:50%;bottom:32px;transform:translateX(-50%);
  background:rgba(22,24,29,.92);color:#fff;padding:10px 18px;border-radius:10px;
  font-size:13px;z-index:300;animation:pop .18s ease;max-width:80vw;text-align:center;
}

.overlay{
  position:fixed;inset:0;background:rgba(16,24,40,.4);z-index:55;
  opacity:0;pointer-events:none;transition:opacity .22s;
}
.overlay.show{opacity:1;pointer-events:auto;}

/* ---------- 手机适配 ---------- */
@media (max-width:860px){
  :root{--sb-w:264px;}
  .sidebar{
    transform:translateX(-100%);transition:transform .26s cubic-bezier(.4,0,.2,1);
    box-shadow:0 0 40px rgba(16,24,40,.18);
  }
  .sidebar.open{transform:none;}
  .main{margin-left:0;}
  .menu-btn{display:flex;}
  .topbar{padding:0 14px;height:54px;}
  .content{padding:18px 14px 40px;}
  .chat-wrap{padding:0;height:calc(100vh - 54px);height:calc(100dvh - 54px);}
  .chat-head{padding:10px 14px;}
  .chat-box{padding:16px 14px;gap:16px;}
  .composer{padding:10px 12px 14px;}
  .card-grid{grid-template-columns:1fr;gap:10px;}
  .stat-card{padding:14px;}
  .stat-num{font-size:21px;}
  .market-list{grid-template-columns:1fr;}
  .detail-price{grid-template-columns:1fr;gap:8px;}
  .dp-item{padding:11px 13px;}
  .page-head h1{font-size:19px;}
  .msg-bubble{font-size:14px;padding:10px 13px;}
  .msg-av{width:27px;height:27px;font-size:11px;}
  .token-form .input{min-width:100%;}
  .token-ops{margin-left:0;}
  .log-time{display:none;}
  .chat-head .model-select{flex:1;max-width:60%;}
}

@media (prefers-color-scheme:dark){
  /* 保持浅色，不改暗色 */
}

/* ===== 充值弹窗 ===== */
.pay-methods{display:flex;gap:10px;flex-wrap:wrap;margin-top:6px}
.pay-method{flex:1 1 0;min-width:96px;padding:11px 10px;border-radius:12px;
  border:1px solid var(--line);background:#fff;color:var(--text);
  font:inherit;font-size:14px;cursor:pointer;transition:border-color .15s,background .15s}
.pay-method:hover{border-color:var(--text-3)}
.pay-method.on{border-color:var(--text);background:var(--bg-2,#f6f7f9);font-weight:600}
.pay-loading{padding:14px 2px;font-size:13px;color:var(--text-3)}
.pay-amount-row{margin-top:14px}
.pay-quick{display:flex;gap:8px;flex-wrap:wrap;margin:10px 0 14px}
.pay-quick-btn{padding:7px 14px;border-radius:10px;border:1px solid var(--line);
  background:#fff;color:var(--text-2,#5b6270);font:inherit;font-size:13px;cursor:pointer}
.pay-quick-btn:hover{border-color:var(--text-3);color:var(--text)}
.pay-close-row{display:flex;gap:10px;margin-top:16px}

/* ---------- 公告弹窗 ---------- */
.notice-modal{z-index:400;}
.notice-box{max-width:420px;}
.notice-body{
  font-size:14px;line-height:1.72;color:var(--text-1,#333);
  white-space:pre-wrap;word-break:break-word;
  max-height:52vh;overflow-y:auto;
  padding:14px 16px;border-radius:12px;
  background:rgba(0,0,0,.03);
  -webkit-overflow-scrolling:touch;
}
.notice-opt{
  display:flex;align-items:center;gap:8px;
  font-size:13px;color:var(--text-3,#888);
  cursor:pointer;user-select:none;
}
.notice-opt input{width:16px;height:16px;margin:0;cursor:pointer;flex:none;}
