/* =====================================================================
   闲鱼产品库 · 公共样式（手机 + 电脑双端自适应）
   ---------------------------------------------------------------------
   断点约定：
     ≥ 901px  电脑/大屏：表格视图 + 顶栏横排
     ≤ 900px  平板竖屏：次要列隐藏、统计卡 2 列
     ≤ 720px  手机：卡片视图 + 底部 Tab 导航 + 弹窗全屏化
   ===================================================================== */

:root {
  --bg: #f5f5f8;
  --card: #ffffff;
  --line: #e7e7ef;
  --line-strong: #d5d5e2;
  --text: #1e1f2e;
  --muted: #73738c;
  --hint: #9a9ab0;
  --brand: #5b4ee0;
  --brand-weak: #eeecfd;
  --brand-line: #cec8f7;
  --ok: #12805c;
  --ok-weak: #e4f4ee;
  --warn: #a86a10;
  --warn-weak: #fbf1de;
  --danger: #c93a3a;
  --danger-weak: #fbeaea;
  --radius: 12px;

  /* 响应式相关 */
  --pad: 20px;          /* 页面左右内边距 */
  --tabbar-h: 56px;     /* 手机底部导航高度 */
  --touch: 38px;        /* 触控目标最小高度 */
  --side-w: 216px;      /* 电脑端左侧菜单栏宽度（窄屏会自动收窄） */
  --page-max: 1220px;   /* 内容区最大宽度 */
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--brand); }
a.btn { text-decoration: none; }

/* ------------------------------------------------------------ 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px var(--pad);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .title { font-size: 15px; font-weight: 600; white-space: nowrap; }
.topbar .sub { font-size: 12px; color: var(--muted); }
.spacer { flex: 1; }

/* ------------------------------------------------------------ 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--brand-line); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { opacity: .92; color: #fff; }
.btn.danger { color: var(--danger); border-color: #efc9c9; }
.btn.danger:hover { background: var(--danger-weak); color: var(--danger); }
.btn.small { padding: 5px 11px; font-size: 12px; min-height: 30px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------ 表单 */
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  min-height: var(--touch);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-weak); border-color: var(--brand-line); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ------------------------------------------------------------ 基础块 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--brand-weak);
  color: var(--brand);
  white-space: nowrap;
}
.tag.ok { background: var(--ok-weak); color: var(--ok); }
.tag.warn { background: var(--warn-weak); color: var(--warn); }
.tag.bad { background: var(--danger-weak); color: var(--danger); }
.tag.mute { background: #f0f0f5; color: var(--muted); }

/* 大模型花费：钱的事要让用户一眼看见，所以单独一个暖色小标签 */
.cost { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap;
        font-size: 12px; padding: 1px 8px; border-radius: 999px;
        background: var(--warn-weak); color: var(--warn); }
.cost.mute { background: #f0f0f5; color: var(--muted); }

.empty { text-align: center; color: var(--hint); padding: 48px 0; }
.muted { color: var(--muted); }
.hint { color: var(--hint); font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------ 提示条 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #26263c;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  max-width: 82vw;
  z-index: 999;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  text-align: center;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ------------------------------------------------------------ 弹窗 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(24, 24, 40, .42);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}
.modal h3 { margin: 0 0 14px; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* =====================================================================
   公共页面骨架
   ===================================================================== */
.page { max-width: 1220px; margin: 0 auto; padding: 18px var(--pad) 60px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 600; margin-top: 2px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }
.nav a { text-decoration: none; }

.section { margin-bottom: 26px; }
.section > h2 { font-size: 14px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.section > h2 .count { font-size: 12px; color: var(--muted); font-weight: 400; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin-bottom: 0; }
.checkline input { width: auto; min-height: 0; margin: 0; }

.tip { background: var(--brand-weak); border: 1px solid var(--brand-line); color: #4b3fc4;
       border-radius: 10px; padding: 9px 14px; font-size: 12.5px; margin-bottom: 14px; }
.warnbar { background: var(--warn-weak); border: 1px solid #eccf9a; color: var(--warn);
           border-radius: 10px; padding: 9px 14px; font-size: 12.5px; margin-bottom: 14px; }

/* ------------------------------------------------------------ 表格 */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.grid, table.tbl { width: 100%; border-collapse: collapse; background: var(--card);
             border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td,
table.tbl th, table.tbl td { padding: 10px 12px; text-align: left; font-size: 13px;
             border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid th, table.tbl th { background: #fafafd; color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
table.grid tr:last-child td, table.tbl tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover, table.tbl tbody tr:hover { background: #fbfbfe; }

/* =====================================================================
   手机端专用：卡片列表（宽屏隐藏，窄屏替换表格）
   ===================================================================== */
.mlist { display: none; }

.mcard {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.mcard.sel { border-color: var(--brand-line); box-shadow: 0 0 0 1px var(--brand-line) inset; }
.mcard .hd { display: flex; gap: 10px; align-items: flex-start; }
.mcard .cv {
  width: 64px; height: 64px; flex: 0 0 auto; border-radius: 9px; object-fit: cover;
  border: 1px solid var(--line); background: #f2f2f6;
}
.mcard .cv.ph { display: flex; align-items: center; justify-content: center;
                color: var(--hint); font-size: 20px; }
.mcard .tb { flex: 1; min-width: 0; }
.mcard .nm { font-weight: 600; font-size: 14px; line-height: 1.45;
             display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mcard .sk { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: var(--hint);
             margin-top: 1px; word-break: break-all; }
.mcard .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.mcard .meta b { font-weight: 600; color: var(--text); }
.mcard .acts { margin-top: 10px; gap: 8px; }
.mcard .acts .btn { flex: 1 1 auto; justify-content: center; min-height: var(--touch); }
.mcard .ck {
  position: absolute; right: 10px; top: 10px; width: 22px; height: 22px;
  min-height: 0; margin: 0; cursor: pointer; accent-color: var(--brand);
}
.mcard .prog { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.mcard .prog .bar { height: 5px; border-radius: 3px; background: #eeeef4; margin-top: 4px; overflow: hidden; }
.mcard .prog .bar i { display: block; height: 100%; background: var(--ok); }
.mcard .hd .nm-wrap { padding-right: 26px; }

/* =====================================================================
   手机端底部 Tab 导航（由 ui.js 注入；upload 页有自己的底栏，不注入）
   ===================================================================== */
.mtab {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: none;
  background: rgba(255, 255, 255, .97);
  backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 60;
}
.mtab .it {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; height: var(--tabbar-h);
  font-size: 11px; color: var(--muted); text-decoration: none;
  background: none; border: 0; font-family: inherit; cursor: pointer; padding: 0;
}
.mtab .it .ic { font-size: 19px; line-height: 1; }
.mtab .it.on { color: var(--brand); font-weight: 600; }
body.has-mtab { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
body.has-mtab .toast { bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); }

/* =====================================================================
   电脑端左侧菜单栏（由 ui.js 注入，body 带 has-sidebar 时生效）
   ---------------------------------------------------------------------
   ≥ 901px  完整侧栏：品牌区 + 分组标题 + 图标&文字菜单 + 底部账号/退出
   721–900  窄侧栏：只剩图标，分组标题变成一条分隔线，鼠标悬停有文字提示
   ≤ 720px  完全不显示，导航交给底部 Tab（手机上左侧栏太占地方）
   ===================================================================== */
.side { display: none; }

@media (min-width: 721px) {
  body.has-sidebar { padding-left: var(--side-w); }

  body.has-sidebar .side {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--side-w);
    background: var(--card);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 40;
  }

  /* 超宽屏：让顶栏内容与页面内容左右对齐，不再左对齐贴边 */
  body.has-sidebar .topbar {
    padding-left: max(var(--pad), calc((100% - var(--page-max)) / 2));
    padding-right: max(var(--pad), calc((100% - var(--page-max)) / 2));
  }
}

.side .brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
.side .brand .lg {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 10px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600;
}
.side .brand .tx { display: flex; flex-direction: column; min-width: 0; }
.side .brand .nm { font-size: 14px; font-weight: 600; line-height: 1.3; white-space: nowrap; }
.side .brand .sb { font-size: 11px; color: var(--hint); line-height: 1.3; white-space: nowrap; }

.side .grp {
  padding: 12px 20px 4px;
  font-size: 11px; color: var(--hint);
  letter-spacing: .06em;
}

.side .mi {
  display: flex; align-items: center; gap: 10px;
  margin: 1px 10px; padding: 9px 11px;
  border-radius: 9px;
  color: var(--text); text-decoration: none; font-size: 13.5px;
  white-space: nowrap;
  touch-action: manipulation;
}
.side .mi .ic { flex: 0 0 20px; width: 20px; text-align: center; font-size: 16px; line-height: 1; }
.side .mi .lb { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.side .mi:hover { background: #f4f4f9; color: var(--brand); }
.side .mi.on { background: var(--brand-weak); color: var(--brand); font-weight: 600; }

.side .foot { margin-top: auto; padding: 12px 10px 14px; border-top: 1px solid var(--line); }
.side .foot .un {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px 10px; font-size: 12.5px; color: var(--muted);
}
.side .foot .un .ic { flex: 0 0 20px; width: 20px; text-align: center; font-size: 15px; }
.side .foot .un .lb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .foot .btn { width: 100%; justify-content: center; }

/* ------------------------------------------------- 721–900px：收成窄图标栏 */
@media (min-width: 721px) and (max-width: 900px) {
  :root { --side-w: 68px; }

  .side .brand { justify-content: center; padding: 16px 0 12px; gap: 0; }
  .side .brand .tx { display: none; }

  /* 分组标题在图标栏里没意义，改成一条分隔线 */
  .side .grp { height: 1px; padding: 0; margin: 10px 18px; background: var(--line); font-size: 0; }

  .side .mi { justify-content: center; margin: 2px 10px; padding: 11px 0; gap: 0; }
  .side .mi .lb { display: none; }
  .side .mi .ic { flex: 0 0 auto; }

  .side .foot { padding: 10px 8px 12px; }
  .side .foot .un { justify-content: center; padding: 4px 0 10px; }
  .side .foot .un .lb { display: none; }
  .side .foot .btn { padding: 6px 0; font-size: 0; }
  .side .foot .btn::after { content: "\9000\51FA"; font-size: 12px; }
}


/* =====================================================================
   显示控制小工具
   ===================================================================== */
.only-m { display: none; }

/* =====================================================================
   ≤ 900px  平板竖屏
   ===================================================================== */
@media (max-width: 900px) {
  :root { --pad: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .hide-s { display: none; }
  .row2 { grid-template-columns: 1fr; }
}

/* =====================================================================
   ≤ 720px  手机
   ===================================================================== */
@media (max-width: 720px) {
  :root { --pad: 12px; }

  /* iOS 上字号 < 16px 的表单会触发页面自动放大，这里统一顶到 16px */
  input, select, textarea { font-size: 16px; }
  .btn { min-height: var(--touch); }
  .btn.small { min-height: 32px; }

  .hide-m { display: none !important; }
  .only-m { display: inline-flex !important; }
  .mtab { display: flex; }

  /* 顶栏：允许换行，标题不挤掉按钮 */
  .topbar {
    padding: 10px var(--pad);
    gap: 8px;
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .topbar .sub { font-size: 11px; }
  .topbar > .spacer { flex: 1 1 0; }

  .page { padding: 14px var(--pad) 40px; }
  .card { padding: 14px; border-radius: 10px; }

  .stats { gap: 8px; margin-bottom: 14px; }
  .stat { padding: 10px 12px; border-radius: 10px; }
  .stat .k { font-size: 11px; }
  .stat .v { font-size: 20px; }

  /* 工具栏在手机上占满一行 */
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { width: 100%; flex: 1 1 100%; }
  .toolbar .spacer { display: none; }
  .toolbar .hint { flex: 1 1 100%; text-align: right; }

  /* 表格 → 卡片列表 */
  .table-desktop { display: none; }
  .mlist { display: block; }

  /* 弹窗全屏化，底部按钮更好按 */
  .modal-mask { padding: 10px; align-items: center; }
  .modal { max-width: 100%; max-height: 92vh; padding: 16px; border-radius: 14px; }
  .modal-actions { gap: 8px; }
  .modal-actions .btn { flex: 1 1 0; justify-content: center; min-height: 42px; font-size: 14px; }

  .section > h2 { font-size: 13px; }
  .empty { padding: 36px 0; }

  /* 通用表格（如设置页）在手机上自动变卡片：靠 td 的 data-label */
  table.grid.resp { border: 0; background: transparent; }
  table.grid.resp thead { display: none; }
  table.grid.resp, table.grid.resp tbody, table.grid.resp tr, table.grid.resp td { display: block; width: 100%; }
  table.grid.resp tr {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 10px 12px; margin-bottom: 10px;
  }
  table.grid.resp td {
    border: 0; padding: 4px 0; display: flex; gap: 10px; align-items: center;
  }
  table.grid.resp td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 76px; color: var(--muted); font-size: 12px;
  }
  table.grid.resp td.nolabel { display: block; }
  table.grid.resp td .acts { width: 100%; }
  table.grid.resp td .acts .btn { flex: 1 1 auto; justify-content: center; }
}

@media (max-width: 380px) {
  .mcard .cv { width: 56px; height: 56px; }
  .mtab .it { font-size: 10px; }
}
