/* 使用记录：上方筛选与汇总、中间独立滚动的明细、底部常驻分页。
 * 手机仍按记录展示，避免八列表横向滚动。 */

#view-usage { overflow: hidden; }

.usage-head {
  flex-direction: row; align-items: center; justify-content: space-between; gap: 20px;
}
.usage-head > div:first-child { min-width: 0; }
.usage-zone {
  flex: none;
  display: flex; align-items: center; gap: 9px;
  padding: 6px 0;
}
.usage-zone-dot {
  width: 7px; height: 7px; flex: none;
  border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 14%, transparent);
}
.usage-zone > span:last-child { display: flex; flex-direction: column; line-height: 1.35; }
.usage-zone b { font-size: 11.5px; font-weight: 500; color: var(--text); }
.usage-zone code { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }

.usage-body {
  flex: 1; min-height: 0; min-width: 0;
  display: flex; flex-direction: column; gap: 16px;
  width: 100%; padding: 20px 28px 16px;
  overflow: hidden;
}
/* 只有明细占用剩余高度；分页不进入滚动容器，也不覆盖末尾记录。 */
.usage-filters, .usage-summary, .usage-pager { flex: none; }

/* ---- 筛选条 ---- */

/* 整条可折叠：标题行常驻，收起时只留下当前生效条件的摘要。窄屏上这六个筛选项
 * 能吃掉大半屏，不收起来就看不见下面的明细表。重置/刷新/导出挂在标题行右侧，
 * 不跟着字段折叠。 */
.usage-filters {
  min-height: 0;
}
.uf-head {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 8px;
}
.usage-filters.collapsed .uf-head { padding-bottom: 0; }
.uf-toggle {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0; text-align: left;
  background: none; border: 0;
  color: var(--muted); font-size: 12.5px;
}
.uf-toggle:hover { color: var(--text); }
.uf-title { color: var(--text); font-weight: 500; }
.uf-caret {
  flex: none;
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent; border-bottom: 4px solid transparent;
  transform: rotate(90deg);
  transition: transform 0.15s ease;
}
.usage-filters.collapsed .uf-caret { transform: none; }
.uf-active {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text);
}
/* 展开时字段本身就写着条件，摘要只会重复一遍 */
.usage-filters:not(.collapsed) .uf-active { display: none; }

.uf-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(85px, 1fr)) minmax(210px, 1.7fr);
  align-items: end; gap: 10px;
  max-height: 30dvh; overflow-y: auto;
}
.usage-filters.collapsed .uf-fields { display: none; }
.uf-item { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.uf-item > span { font-size: 11px; color: var(--muted); padding-left: 1px; }
.uf-item :is(select, .select-trigger) { width: 100%; min-height: 40px; border-radius: calc(8px * var(--radius-scale)); background: var(--panel); font-size: 13px; text-overflow: ellipsis; }
.uf-actions {
  flex: none;
  display: flex; gap: 2px; align-items: center; justify-content: flex-end;
}
.uf-fields:has(#uf-user-wrap.hidden) { grid-template-columns: repeat(3, minmax(85px, 1fr)) minmax(210px, 1.7fr); }

/* ---- 合计条 ---- */

.usage-summary {
  display: grid;
  grid-template-columns: minmax(150px, 1.35fr) repeat(5, minmax(85px, 1fr));
  padding: 14px 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.us-item {
  min-width: 0; min-height: 48px;
  display: flex; flex-direction: column; justify-content: center;
  padding: 0 20px; border-left: 1px solid var(--line);
}
.us-label { font-size: 12px; color: var(--muted); }
.us-value { font-size: 20px; line-height: 1.35; margin-top: 4px; letter-spacing: -0.6px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.us-item:first-child { padding-left: 0; border-left: 0; }
/* 金额全站统一：正文色 + 等宽数字。绿色表示成功、琥珀表示主操作，都不该给钱 */
.us-item:first-child .us-value { color: var(--text-hi); font-size: 25px; margin-top: 0; font-family: var(--mono); }

/* ---- 明细表 ---- */

.usage-table-frame {
  display: flex; flex: 1; min-height: 0; min-width: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: calc(10px * var(--radius-scale)); background: var(--panel);
}
.usage-table-frame:has(.usage-table-wrap:focus-visible) {
  outline: 2px solid var(--amber); outline-offset: 2px;
}
.usage-table-wrap:focus-visible { outline: none; }
.usage-table-wrap {
  position: relative; flex: 1; min-height: 0; min-width: 0;
  padding: 0; overflow: auto; overscroll-behavior: contain;
  scrollbar-gutter: stable;
  border-radius: inherit;
}
.usage-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.usage-table th {
  text-align: left; font-weight: 600; font-size: 11.5px; color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
  position: sticky; top: 0;
  /* 吸顶：底色必须不透明（--panel-solid），否则滚上来的行会透过表头 */
  background: linear-gradient(color-mix(in srgb, var(--panel-2) 35%, transparent), color-mix(in srgb, var(--panel-2) 35%, transparent)), var(--panel-solid);
  z-index: 1;
}
/* 一行里最高的是会话/模型/Token 这类两行格，单行格（类型、费用、时间）跟着居中，
 * 整行读起来才在一条视觉线上 */
.usage-table td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.usage-table tr:last-child td { border-bottom: none; }
.usage-table tbody tr { transition: background-color 0.12s ease; }
.usage-table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--page) 80%, var(--panel)); }
.usage-table tbody tr:hover { background: color-mix(in srgb, var(--amber) 4%, var(--panel)); }
.usage-table :is(.u-sub, .u-billing) { margin-top: 2px; }
/* 骨架行（usage.ts）高度对上两行格的真实行，数据换进来时表格不跳 */
.usage-table .skeleton-row td { padding-top: 17px; padding-bottom: 17px; }
.usage-table .num { text-align: right; white-space: nowrap; }
.usage-table th.num { text-align: right; }

/* 时间列的排序控件：上下两个三角，各自代表一个方向，选中的那个点上琥珀
 * （与日期选择器的强调色一致）。用 CSS 三角而不是 ▲▼ 字形——后者在不同
 * 字体里大小差得离谱，两个叠起来会一大一小。 */
.u-sort { display: inline-flex; align-items: center; gap: 7px; }
.u-sort-btns { display: inline-flex; flex-direction: column; gap: 3px; }
.u-sort-b {
  display: block; padding: 1px 2px;
  border: 0; background: none; line-height: 0;
  color: var(--muted); opacity: 0.45;
}
.u-sort-b .ui-icon { width: 12px; height: 9px; }
.u-sort-b:hover { color: var(--text); opacity: 1; }
.u-sort-b.on { color: var(--amber); opacity: 1; }
.u-sort-b:focus-visible { opacity: 1; }

/* 次要信息（账号、provider、总耗时）压一号，主行才是扫读的那一行 */
.u-sub { font-size: 11px; color: var(--muted); margin-top: 4px; font-weight: 400; }
.u-sess { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-model { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.u-model > span { display: block; max-width: 235px; overflow: hidden; text-overflow: ellipsis; }
.u-model + .u-sub { padding-left: 21px; }
.u-time, .u-lat, .u-tok, .u-hit { font-family: var(--mono); font-size: 12px; }
.u-cost { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--text); }
.u-cost.zero { color: var(--muted); }
.u-billing { margin-top: 4px; font-family: var(--sans); font-weight: 400; }
.u-billing .u-chip { padding: 0; border: 0; background: none; font-size: 10.5px; }

/* token：照 sub2api 排两行——↓ 输入 ↑ 输出（完整数字），缓存读取 / 写入按
 * K/M/B 缩写；每个桶一种颜色，取自各风格都定义了的全局令牌。右边 ⓘ 悬停看完整数字。 */
.usage-table td.u-tok { text-align: left; }
.usage-table td.u-tok .u-v { display: inline-flex; align-items: center; gap: 8px; }
.u-tk-lines { display: grid; gap: 4px; justify-items: start; }
.u-tk-line { display: inline-flex; align-items: center; gap: 10px; }
.u-tk { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; }
.u-tk .ui-icon { flex: none; stroke-width: 2.2; }
.u-tk.in .ui-icon { color: var(--green); }
.u-tk.out .ui-icon { color: var(--syntax-keyword); }
.u-tk.in, .u-tk.out { color: var(--text-hi); font-weight: 500; }
.u-tk.read, .u-tk.read .ui-icon { color: var(--info); }
.u-tk.write, .u-tk.write .ui-icon { color: var(--warn); }
.u-tk-info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: color-mix(in srgb, var(--panel-2) 70%, transparent);
  color: var(--muted); cursor: help;
}
.u-tk-info:hover, .u-tk-info:focus-visible { color: var(--info); background: color-mix(in srgb, var(--info) 14%, transparent); }
/* 类型下方「第 3/27 次」：同回合连着的几行一眼看出是一组 */
.u-seq { white-space: nowrap; font-variant-numeric: tabular-nums; }
/* 模型下面一行：服务方 · 思考强度 */
.u-sub:has(.u-effort) { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 8px; }
.u-effort { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.u-effort .ui-icon { color: var(--muted); }

/* 类型：一枚图标，名称在里面（桌面只给读屏，窄屏卡片上直接显示）。墨色分档见 usage.ts 的 KIND_TONE */
.u-kind {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  width: 28px; height: 28px;
  border: 1px solid var(--line); border-radius: calc(7px * var(--radius-scale));
  background: color-mix(in srgb, var(--panel-2) 45%, transparent);
  color: var(--muted);
  vertical-align: middle;
}
.u-kind .ui-icon { flex: none; }
.u-kind.chat { color: var(--text-hi); }
.u-kind.term { color: var(--text); }
.u-kind.title { color: var(--muted); }
.u-kind-label {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* 计费的小标签 */
.u-chip {
  display: inline-block;
  font-size: 11.5px; line-height: 1.6;
  padding: 2px 8px; border-radius: calc(5px * var(--radius-scale));
  border: 1px solid transparent;
  background: color-mix(in srgb, var(--panel-2) 55%, transparent);
  color: var(--muted);
  white-space: nowrap;
}
.u-chip.bill-provider { border-color: var(--green-line); color: var(--green); background: transparent; }
.u-chip.bill-none { border-color: var(--red-line); color: var(--red); background: transparent; }

/* ---- 费用旁的「?」与费用明细弹窗（弹窗底座在 dialogs.css） ---- */

/* 问号全亮会盖过金额本身：平时压淡，指到这一行才浮出来。 */
.u-why {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px; padding: 0;
  width: 15px; height: 15px;
  border: 0; border-radius: 50%;
  background: none; color: var(--muted);
  font-family: var(--mono); font-size: 10px; line-height: 1;
  vertical-align: middle;
  opacity: 0.45;
}
.usage-table tbody tr:hover .u-why, .u-why:focus-visible { opacity: 1; }
.u-why:hover { color: var(--amber); border-color: var(--amber); opacity: 1; }

.dlg-cost { width: min(520px, 94vw); }
.cost-model { display: flex; align-items: center; gap: 7px; font-size: 13.5px; }
.cost-sub { margin-top: 4px; font-size: 11.5px; color: var(--muted); }

.cost-wrap { margin-top: 14px; overflow-x: auto; }
.cost-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.cost-table th {
  text-align: left; font-weight: 500; font-size: 11.5px; color: var(--muted);
  padding: 0 0 6px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.cost-table td {
  padding: 6px 0; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap; font-family: var(--mono);
}
.cost-table th + th, .cost-table td + td { padding-left: 12px; }
.cost-table th.num, .cost-table td.num { text-align: right; }
/* 项目名是文字不是数字，跟着正文字体走 */
.cost-table td:first-child { font-family: var(--sans); color: var(--muted); }
/* 推算出来的合计只是过程，实收/合计才是落进账本的那个数 */
.cost-sum td { color: var(--muted); }
.cost-total td { border-bottom: none; }
.cost-total td:first-child { color: var(--text); }
.cost-total td:last-child { color: var(--green); font-size: 13.5px; }

.cost-note { margin-top: 12px; font-size: 11.5px; line-height: 1.7; color: var(--muted); }
.cost-note p { margin: 0 0 6px; }
.cost-note p:last-child { margin-bottom: 0; }

/* ---- 翻页 ---- */

.usage-pager {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  font-size: 12.5px; color: var(--muted);
  padding: 12px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: calc(10px * var(--radius-scale));
  font-variant-numeric: tabular-nums;
}
.usage-page-info, .usage-page-size, .usage-page-nav, .usage-page-numbers {
  display: flex; align-items: center;
}
.usage-page-info { gap: 20px; flex-wrap: wrap; }
.usage-page-size { gap: 8px; white-space: nowrap; }
.usage-page-size :is(select, .select-trigger) {
  width: 76px; min-height: 36px; padding: 6px 10px; background: var(--panel);
}
.usage-page-nav { flex: none; gap: 4px; }
.usage-page-numbers { gap: 4px; }
.usage-page-button {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: calc(6px * var(--radius-scale));
  background: var(--panel); color: var(--muted); font-size: 13px;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.usage-page-button svg { width: 14px; height: 14px; }
.usage-page-button:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.usage-page-button[aria-current="page"] {
  color: var(--amber); border-color: var(--amber-dim);
  background: color-mix(in srgb, var(--amber) 9%, var(--panel));
}
.usage-page-gap { width: 20px; text-align: center; }
.usage-pager button:disabled { opacity: 0.4; cursor: default; }

@media (max-width: 1320px) and (min-width: 761px) {
  .uf-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .uf-date { grid-column: 1 / span 2; }
  /* 普通用户少一列「用户」：三个下拉加时间正好一行 */
  .uf-fields:has(#uf-user-wrap.hidden) { grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(190px, 1.6fr); }
  .uf-fields:has(#uf-user-wrap.hidden) .uf-date { grid-column: auto; }
  .us-item { padding: 0 12px; }
  .us-value { font-size: 17px; }
  .usage-table td, .usage-table th { padding-left: 12px; padding-right: 12px; }
}

@media (max-width: 1100px) and (min-width: 761px) {
  .usage-summary { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .us-item { padding: 0 10px; }
  .us-value { font-size: 15px; }
  .us-item:first-child .us-value { font-size: 20px; }
  .usage-page-info { gap: 8px 14px; }
}

/* ---- 窄屏：筛选可折叠，汇总两行，明细逐条展示 ---- */

@media (max-width: 760px) {
  .usage-head { gap: 12px; }
  .usage-head p { font-size: 11px; }
  .usage-zone { min-width: 0; padding: 6px 0; }
  .usage-zone b { display: none; }
  .usage-zone code { font-size: 10px; }
  .usage-body { padding: 12px 12px max(12px, env(safe-area-inset-bottom)); gap: 10px; }

  .uf-fields, .uf-fields:has(#uf-user-wrap.hidden) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .uf-fields:has(#uf-user-wrap.hidden) .uf-date, .uf-date { grid-column: 1 / -1; }

  .usage-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 0; padding: 10px 0; }
  .us-item { padding: 0 10px; min-height: 40px; }
  .us-item:nth-child(4) { border-left: 0; padding-left: 0; }
  .us-label { font-size: 10.5px; }
  .us-value { font-size: 15px; margin-top: 2px; }
  .us-item:first-child .us-value { font-size: 19px; }

  .usage-pager { flex-direction: column; gap: 10px; padding: 10px 12px; font-size: 11px; }
  .usage-page-info { width: 100%; justify-content: space-between; gap: 8px; }
  .usage-page-button { min-width: 32px; height: 36px; padding: 0 6px; }
  .usage-page-size :is(select, .select-trigger) { width: 64px; min-height: 32px; padding: 4px 8px; }
  .usage-page-gap { width: 14px; }

  /* 多列的表在手机上只能横向滚动，等于看不见明细：改成按记录纵向展示，
   * 表头名由 td[data-l] 补在每格左边，值统一靠右。 */
  .usage-table, .usage-table tbody, .usage-table tr, .usage-table td { display: block; }
  /* 表头本身在卡片布局里没用了，但排序箭头得留着——整条表头压成一行，只显示
   * 时间那一格，当卡片列表的排序条 */
  .usage-table thead { display: block; position: sticky; top: 0; z-index: 1; background: var(--panel-solid); }
  .usage-table thead th { display: none; }
  .usage-table thead tr { display: flex; justify-content: flex-end; padding: 8px 12px; }
  .usage-table th.col-time {
    display: block;
    position: static;
    padding: 0; border: 0;
  }
  /* 触屏没有 hover，两个箭头都得看得清、点得着 */
  .u-sort-b { padding: 4px 7px; opacity: 0.6; }
  .usage-table tr { padding: 16px; border-bottom: 1px solid var(--line); }
  .usage-table tbody tr:last-child { border-bottom: none; }
  .usage-table td {
    display: flex; align-items: baseline; gap: 12px;
    padding: 5px 0; border-bottom: none;
    text-align: left; white-space: normal;
  }
  .usage-table .skeleton-row td { padding-top: 7px; padding-bottom: 7px; }
  .usage-table td::before {
    content: attr(data-l);
    flex: none; min-width: 44px;
    font-family: var(--sans); font-size: 11.5px; color: var(--muted);
  }
  .usage-table td .u-v { flex: 1; min-width: 0; text-align: right; }

  /* 触屏没有 hover，问号得一直看得见，也得点得着 */
  .u-why { opacity: 1; width: 19px; height: 19px; margin-left: 8px; font-size: 11px; }

  /* 会话名当卡片标题：占满一行、不要标签，账号仍旧压在下面当副行 */
  .usage-table td.u-cell-sess { padding-bottom: 6px; }
  .usage-table td.u-cell-sess::before { display: none; }
  .usage-table td.u-cell-sess .u-v { text-align: left; }
  .u-cell-sess .u-sess { max-width: 100%; font-weight: 500; font-size: 13.5px; }

  .u-model { justify-content: flex-end; white-space: normal; }
  .u-model > span { max-width: 100%; overflow-wrap: anywhere; }
  .u-model + .u-sub { padding-left: 0; }

  .usage-table td.u-tok .u-v { justify-content: flex-end; }

  /* 卡片里有地方写字，也没有悬停：图标旁直接写类型名 */
  .u-kind { width: auto; height: auto; padding: 2px 8px; }
  .u-kind-label { position: static; width: auto; height: auto; overflow: visible; clip-path: none; font-size: 11.5px; }
  .u-tk-lines { justify-items: end; }
}

/* 手机横屏和矮窗口为列表留空间，筛选仍可在自身区域滚动操作。 */
@media (max-height: 700px) {
  .usage-head { padding-top: 10px; padding-bottom: 10px; }
  .usage-head p { display: none; }
  .usage-body { gap: 8px; padding-top: 10px; padding-bottom: 10px; }
  .uf-fields { max-height: 22dvh; }
  .usage-summary { padding: 8px 0; }
  .us-item { min-height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  .uf-caret, .usage-table tbody tr, .usage-page-button { transition: none; }
}
