/* ===================================================================
   未央神人交易所 · 样式
   ① 主题：浅色单主题
   ② 移动端：<=720px 走卡片式布局，表格自动转卡片
   ③ 组件：Logo 头像、面板、表单、K线容器、订单流
   =================================================================== */

/* ---------------------------------------------------------------- 浅色主题（唯一） */
:root {
  --bg: #f2f5fa;
  --panel: #ffffff;
  --panel-2: #eef2f8;
  --line: #dde4ee;
  --line-soft: #e9eef5;
  --text: #1f2a37;
  --title: #10192a;
  --muted: #6b7a90;
  --input-bg: #ffffff;
  --topbar-hi: #ffffff;
  --topbar-lo: #f7f9fc;
  /* 中国市场惯例：红涨绿跌 */
  --up: #e5484d;
  --down: #12a48f;
  --up-text: #c62b31;
  --down-text: #0b7d6d;
  --accent: #e0a800;
  --accent-text: #2a2000;
  --accent-2: #2f6fed;
  --accent-2-text: #ffffff;
  --up-soft: rgba(229, 72, 77, .1);
  --down-soft: rgba(18, 164, 143, .12);
  --row-hover: rgba(47, 111, 237, .05);
  --shadow: 0 8px 24px rgba(18, 32, 56, .1);
  --grid-line: #eaeff6;
  color-scheme: light;
}


* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  overflow-x: hidden;          /* 防止图表/长表格把页面撑出横向滚动 */
  max-width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, -apple-system, sans-serif;
  font-size: 14px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.num { font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
/* 桌面端不做任何样式改动：绝不能设 display，否则会破坏 <td>/<th> 的 table-cell */
/* 只在移动端隐藏，见下方 @media (max-width:720px) */

/* ---------------------------------------------------------------- Logo 头像 */
.avatar {
  --av-1: #4c8dff; --av-2: #7c5cff;
  width: 34px; height: 34px; flex: 0 0 auto; border-radius: 10px; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--av-1), var(--av-2));
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .5px;
  user-select: none; border: 1px solid rgba(255, 255, 255, .16);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.lg { width: 46px; height: 46px; border-radius: 13px; font-size: 19px; }
.avatar.sm { width: 28px; height: 28px; border-radius: 8px; font-size: 12px; }

/* 标的名称那一格：头像 + 代码 + 名称 */
.sym-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sym-cell .meta { min-width: 0; }
.sym-cell .code { font-weight: 700; }
.sym-cell .nm { color: var(--muted); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--topbar-hi), var(--topbar-lo));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: baseline; gap: 8px; font-weight: 700; letter-spacing: .5px; white-space: nowrap; }
.brand .glyph { color: var(--accent); font-size: 18px; }
.brand .name { font-size: 16px; }
.brand .tag { font-size: 11px; color: var(--muted); }
.topbar nav { display: flex; gap: 6px; margin-left: 6px; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; color: var(--text); border: 1px solid transparent; white-space: nowrap; }
.topbar nav a:hover { background: var(--panel-2); text-decoration: none; }
.topbar nav a.active { background: var(--panel-2); border-color: var(--line); font-weight: 600; }
.spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 10px; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }


/* 移动端汉堡菜单 */
.nav-toggle { display: none; }

/* ---------------------------------------------------------------- 容器 */
.wrap { max-width: 1500px; margin: 0 auto; padding: 16px 18px 60px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.panel h2, .panel h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; color: var(--title); }
.panel h3 .sub { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }

/* ---------------------------------------------------------------- 表格 */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--line-soft); }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: var(--row-hover); }

/* ---------------------------------------------------------------- 表单 */
input, select, button, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--input-bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-2); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.btn {
  cursor: pointer; font-weight: 600; padding: 9px 14px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
}
.btn:hover { filter: brightness(1.08); }
.btn.buy { background: var(--up-soft); border-color: var(--up); color: var(--up-text); }
.btn.sell { background: var(--down-soft); border-color: var(--down); color: var(--down-text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.blue { background: var(--accent-2); border-color: var(--accent-2); color: var(--accent-2-text); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row.tight { gap: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }

/* ---------------------------------------------------------------- 提示 */
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.toast .msg { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent-2); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); animation: pop .18s ease-out; color: var(--text); }
.toast .msg.err { border-left-color: var(--down); }
.toast .msg.ok { border-left-color: var(--up); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- 首页 */
.hero { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.hero .stats { display: flex; gap: 22px; flex-wrap: wrap; }
.hero .stat .k { color: var(--muted); font-size: 12px; }
.hero .stat .v { font-size: 18px; font-weight: 600; }

/* 移动端标的卡片列表 */
.sym-cards { display: none; flex-direction: column; gap: 10px; }
.sym-card {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.sym-card .info { flex: 1; min-width: 0; }
.sym-card .info .code { font-weight: 700; font-size: 15px; }
.sym-card .info .nm { color: var(--muted); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sym-card .info .sub { color: var(--muted); font-size: 11px; margin-top: 3px; }
.sym-card .price { text-align: right; flex: 0 0 auto; }
.sym-card .price .p { font-size: 16px; font-weight: 700; }
.sym-card .price .c { font-size: 12px; }

/* ---------------------------------------------------------------- 行情页 */
.quote-head { display: flex; gap: 24px; align-items: flex-end; flex-wrap: wrap; }
.quote-head .big { font-size: 30px; font-weight: 700; line-height: 1.1; }
.quote-head .item .k { font-size: 11px; color: var(--muted); }
.quote-head .item .v { font-size: 15px; }

.trade-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px 300px; gap: 14px; align-items: start; }
.trade-layout > div { min-width: 0; }   /* grid 子项默认 min-width:auto，会被 canvas 撑爆 */
@media (max-width: 1250px) {
  .trade-layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .trade-layout .col-flow { grid-column: 1 / -1; }
}
@media (max-width: 900px) { .trade-layout { grid-template-columns: 1fr; } }

#chart { width: 100%; height: 430px; max-width: 100%; }
#flow-chart { width: 100%; height: 190px; display: block; }
.chart-box { position: relative; }

.tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.tabs button {
  width: auto; padding: 5px 11px; font-size: 12px; border-radius: 999px;
  background: transparent; border: 1px solid var(--line); color: var(--muted); cursor: pointer;
}
.tabs button.active { background: var(--panel-2); color: var(--text); border-color: var(--accent-2); font-weight: 600; }

.book { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.book .side h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 500; }
.book table td { padding: 3px 4px; font-size: 12px; border-bottom: none; }
.book .depth-bar { position: relative; display: block; }
.book .depth-bar span { position: relative; z-index: 1; }
.book .depth-bar i { position: absolute; top: 0; bottom: 0; right: 0; z-index: 0; opacity: .18; display: block; }
.book .ask i { background: var(--down); }
.book .bid i { background: var(--up); }

.tick-list { max-height: 300px; overflow-y: auto; }
.tick-list table td { padding: 2px 4px; font-size: 12px; border-bottom: none; }
@keyframes flash { from { background: var(--up-soft); } to { background: transparent; } }
.tick-list tr.new { animation: flash .6s ease-out; }

.flow-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.flow-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }

.positions-mini td, .orders-mini td { font-size: 12px; }

.pill { padding: 1px 7px; border-radius: 6px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.open { color: var(--accent-2); border-color: var(--accent-2); }
.pill.filled { color: var(--up); border-color: var(--up); }
.pill.cancelled { color: var(--muted); }
.pill.partial { color: var(--accent); border-color: var(--accent); }

.login-wrap { max-width: 420px; margin: 8vh auto; }
.login-wrap .tabs button { flex: 1; text-align: center; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.7; }
.err-text { color: var(--down); font-size: 12px; min-height: 18px; }
.symbol-list td .name { font-weight: 600; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); }

/* 移动端底部固定操作条（行情页下单用） */
.mobile-bar { display: none; }

/* ===================================================================
   移动端适配
   =================================================================== */
@media (max-width: 720px) {
  .wrap { padding: 12px 12px 84px; }
  .hide-mobile { display: none !important; }
  .brand .tag { display: none; }

  /* 顶栏：汉堡菜单 */
  .topbar { padding: 9px 12px; gap: 10px; flex-wrap: wrap; }
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; flex: 0 0 auto; padding: 0; font-size: 17px;
    background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
    border-radius: 9px; cursor: pointer; margin-left: auto;
  }
  .topbar nav {
    display: none; order: 10; width: 100%; margin: 6px 0 0; flex-direction: column; gap: 4px;
  }
  .topbar.nav-open nav { display: flex; }
  .topbar nav a { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); }
  .who { order: 11; width: 100%; justify-content: space-between; }
  .who .badge { display: none; }

  /* 表格 → 卡片式：每行变成一张卡，两列排布，字段名用 data-label 显示 */
  .table-cards { display: block; }
  .table-cards thead { display: none; }
  .table-cards tbody { display: block; }
  .table-cards tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 12px;
    padding: 12px;
    margin-bottom: 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 12px;
  }
  .table-cards tbody tr:hover { background: var(--panel-2); }
  .table-cards tbody td {
    display: block;
    border: none;
    padding: 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .table-cards tbody td::before {
    content: attr(data-label) " ";
    color: var(--muted);
    font-size: 11px;
  }
  /* 主字段（标的）占满整行，不显示字段名 */
  .table-cards tbody td.cell-sym {
    grid-column: 1 / -1;
    white-space: normal;
  }
  .table-cards tbody td.cell-sym::before { content: none; }
  /* 需要占满整行的字段 */
  .table-cards tbody td.cell-full { grid-column: 1 / -1; }
  /* 空数据行：占满整行、居中 */
  .table-cards tbody tr td[colspan] {
    grid-column: 1 / -1;
    text-align: center;
    white-space: normal;
  }
  .table-cards .hide-mobile { display: none !important; }

  /* 首页：表格藏起来，显示卡片列表 */
  .symbol-table-wrap { display: none; }
  .sym-cards { display: flex; }

  /* 行情页 */
  #chart { height: 280px; }
  #flow-chart { height: 150px; }
  .quote-head { gap: 14px 20px; }
  .quote-head .big { font-size: 24px; }
  .panel { padding: 12px; border-radius: 12px; }

  /* 下单按钮做大，方便手指点 */
  .btn { padding: 11px 14px; }
  .tabs button { padding: 7px 12px; }
  input, select { padding: 11px; font-size: 16px; }  /* 16px 防止 iOS 自动缩放 */

  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

@media (max-width: 420px) {
  .book { grid-template-columns: 1fr; }
}
