*{box-sizing:border-box}body{margin:0;background:#0f172a;color:#e5e7eb;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif}

/* ── Header & Tabs ── */
header{position:sticky;top:0;z-index:20;display:flex;justify-content:space-between;align-items:center;padding:14px 16px;background:rgba(15,23,42,.96);border-bottom:1px solid #1e293b;backdrop-filter:blur(8px)}
h1{font-size:20px;margin:0}h2{font-size:16px;margin:0 0 12px}p{margin:0}
#subTitle,.hint,.muted{color:#94a3b8;font-size:12px}
.tabs{display:grid;grid-template-columns:repeat(6,1fr);gap:4px;padding:8px 10px;background:#111827;position:sticky;top:64px;z-index:10}
.tab,button{border:0;border-radius:10px;background:#2563eb;color:white;font-weight:700;padding:10px 8px}
.tab{background:#1e293b;color:#cbd5e1;cursor:pointer}
.tab.active{background:#2563eb;color:white}
.ghost{background:#334155}
main{max-width:860px;margin:0 auto;padding:0 10px 40px}

/* ── Shared components ── */
.card{background:#111827;border:1px solid #1e293b;border-radius:16px;padding:14px;margin:12px 0;box-shadow:0 6px 20px rgba(0,0,0,.18)}
.hidden{display:none!important}
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.metric{background:#0b1220;border-radius:12px;padding:10px}
.metric .value{font-size:16px;font-weight:800}.metric .label{font-size:11px;color:#94a3b8}
.signal{border-top:1px solid #1e293b;padding:10px 0}.signal:first-child{border-top:0}
.buy{color:#22c55e}.sell{color:#ef4444}.hold{color:#94a3b8}.error{color:#f97316}
.form{display:grid;gap:10px}
input,select{width:100%;border:1px solid #334155;border-radius:10px;background:#0b1220;color:#e5e7eb;padding:11px;font-size:15px}
.row{display:flex;gap:8px;align-items:center;justify-content:space-between}
.row button{padding:7px 10px;background:#334155}
.table{width:100%;border-collapse:collapse;font-size:12px}
th,td{text-align:left;border-bottom:1px solid #1e293b;padding:7px 5px;white-space:nowrap}
.scroll{overflow-x:auto}
.toast{position:fixed;left:16px;right:16px;bottom:20px;background:#1e293b;border:1px solid #475569;border-radius:12px;padding:12px;display:none;z-index:200}
.toast.show{display:block}
.actions{display:flex;gap:8px;margin:10px 0}.actions button{flex:1}
.danger{background:#7f1d1d}
.badge{font-size:11px;border-radius:6px;padding:2px 7px;font-weight:600}
.badge-new{background:#166534;color:#4ade80}
.badge-dup{background:#713f12;color:#fbbf24}

/* ── AI Chat — fullscreen override ── */
body.on-chat main{max-width:none;padding:0;margin:0}
body.on-chat .card{margin:12px 10px}

#chatView{
  display:flex;flex-direction:column;
  height:calc(100dvh - 108px);   /* below header+tabs */
  background:#0b1220;
}
#chatView.hidden{display:none!important}

.chat-shell{
  flex:1;display:flex;flex-direction:column;
  max-width:860px;width:100%;margin:0 auto;
  min-height:0;
}

/* top bar */
.chat-topbar{
  display:flex;gap:8px;align-items:center;
  padding:10px 14px;
  background:#111827;border-bottom:1px solid #1e293b;
  flex-shrink:0;
}
.chat-topbar select{flex:1;padding:8px 10px;font-size:14px}

/* messages area */
.chat-body{
  flex:1;overflow-y:auto;overflow-x:hidden;
  padding:16px 16px 8px;
  min-height:0;
  scroll-behavior:smooth;
  display:flex;flex-direction:column;
}
.chat-body:empty{display:block}

.chat-empty{
  color:#64748b;text-align:center;padding:80px 20px 40px;
  margin:auto;
}
.chat-empty-icon{
  width:56px;height:56px;border-radius:50%;
  background:#1e293b;color:#475569;
  font-size:28px;line-height:56px;margin:0 auto 20px;
}
.chat-empty p{font-size:15px;margin:6px 0}

/* message bubble */
.chat-msg{margin:10px 0;display:flex;flex-direction:column;flex-shrink:0}
.msg-user{align-items:flex-end}
.msg-assistant{align-items:flex-start}
.chat-bubble{
  max-width:85%;border-radius:18px;padding:12px 16px;
  font-size:15px;line-height:1.65;word-break:break-word;
}
.msg-user .chat-bubble{
  background:#2563eb;color:#fff;
  border-bottom-right-radius:6px;
}
.msg-assistant .chat-bubble{
  background:#1e293b;color:#e5e7eb;
  border-bottom-left-radius:6px;
}

/* image in message */
.chat-img{
  max-width:70%;max-height:240px;border-radius:12px;
  margin-bottom:8px;cursor:pointer;border:1px solid #1e293b;
}
.chat-img.zoomed{
  max-width:96vw;max-height:96vh;
  position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);
  z-index:300;border-radius:16px;
  box-shadow:0 0 0 9999px rgba(0,0,0,.75);
}

/* trade cards inside assistant message */
.chat-trades{margin-top:10px;width:100%}
.chat-trade{
  background:#0a2215;border:1px solid #14522a;
  border-radius:12px;padding:10px 14px;margin:6px 0;
  display:flex;align-items:center;justify-content:space-between;
  gap:8px;flex-wrap:wrap;
}
.chat-trade.trade-saved{background:#1e293b;border-color:#334155;opacity:.65}
.chat-trade button{
  padding:6px 16px;font-size:13px;
  border-radius:8px;white-space:nowrap;
}
.batch-save-btn{
  display:block;width:100%;margin-bottom:10px;
  background:#166534;font-size:14px;padding:10px 0;
  border-radius:10px;cursor:pointer;
}
.batch-save-btn:hover{background:#15803d}
.dup-toggle{
  font-size:12px;color:#94a3b8;padding:8px 0;
  cursor:pointer;user-select:none;
  border-top:1px solid #1e293b;margin-top:6px;
}
.dup-toggle:hover{color:#cbd5e1}
.dup-arrow{display:inline-block;transition:transform .15s;font-size:10px;margin-right:4px}
.dup-arrow.open{transform:rotate(90deg)}

/* pending image preview (below topbar, above input) */
.chat-preview{
  position:relative;display:inline-block;
  margin:8px 14px 0;flex-shrink:0;
}
.chat-preview img{
  max-width:100px;max-height:100px;border-radius:10px;
  border:1px solid #334155;
}
.chat-preview button{
  position:absolute;top:-7px;right:-7px;
  background:#ef4444;border:none;border-radius:50%;
  width:22px;height:22px;font-size:13px;line-height:22px;
  color:#fff;padding:0;cursor:pointer;
}

/* input footer */
.chat-footer{
  flex-shrink:0;
  padding:12px 14px 14px;
  background:#111827;border-top:1px solid #1e293b;
}
.chat-footer textarea{
  display:block;width:100%;
  min-height:56px;max-height:160px;resize:none;
  font-size:15px;line-height:1.55;
  padding:12px 14px;
  border:1px solid #334155;border-radius:14px;
  background:#0b1220;color:#e5e7eb;
  transition:border-color .15s;
}
.chat-footer textarea:focus{
  outline:none;border-color:#2563eb;box-shadow:0 0 0 3px rgba(37,99,235,.15);
}
.chat-footer-actions{
  display:flex;justify-content:flex-end;gap:8px;margin-top:10px;
}
.chat-footer-actions button{
  padding:9px 18px;font-size:14px;border-radius:10px;
}
.chat-footer-actions .ghost{padding:9px 14px}

/* ── Mobile ── */
@media (max-width:520px){
  .grid{grid-template-columns:1fr 1fr}
  .tabs{top:62px;gap:3px;padding:5px 6px}
  .tab{font-size:11px;padding:8px 2px}
  #chatView{height:calc(100dvh - 100px)}
  .chat-body{padding:12px 12px 6px}
  .chat-bubble{max-width:90%;font-size:14px;padding:10px 14px}
  .chat-topbar{padding:8px 10px}
  .chat-footer{padding:10px 10px 12px}
  .chat-footer textarea{min-height:50px;font-size:14px}
  .chat-empty{padding:60px 16px 20px}
}
