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

#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-toggle {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 0 0 12px; 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; }
.usage-filters.collapsed .uf-toggle { padding-bottom: 0; }
.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) auto;
  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: 8px; background: var(--panel); font-size: 13px; text-overflow: ellipsis; }
.uf-actions {
  display: flex; gap: 5px; align-items: center; justify-content: flex-end;
}
.uf-actions .btn { min-height: 40px; white-space: nowrap; border-radius: 8px; }
.uf-actions .btn:not(.btn-ghost) { background: var(--panel); }
.uf-fields:has(#uf-user-wrap.hidden) { grid-template-columns: repeat(3, minmax(85px, 1fr)) minmax(210px, 1.7fr) auto; }

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

.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(--amber); font-size: 25px; margin-top: 0; }

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

.usage-table-frame {
  display: flex; flex: 1; min-height: 0; min-width: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: 10px; 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;
  background: color-mix(in srgb, var(--panel-2) 35%, var(--panel));
  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(--bg) 80%, var(--panel)); }
.usage-table tbody tr:hover { background: color-mix(in srgb, var(--amber) 4%, var(--panel)); }
.usage-table :is(.u-sub, .u-cache, .u-billing) { margin-top: 2px; }
.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 { 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：输入/输出一行，缓存另起一行。箭头只是方向记号，别抢数字的注意力 */
.u-io { display: inline-flex; align-items: baseline; gap: 3px; }
.u-arrow { font-style: normal; color: var(--muted); margin-left: 6px; }
.u-io .u-arrow:first-child { margin-left: 0; }
.u-cache { font-size: 10.5px; color: var(--muted); margin-top: 4px; }

/* 类型 / 计费的小标签 */
.u-chip {
  display: inline-block;
  font-size: 11.5px; line-height: 1.6;
  padding: 2px 8px; border-radius: 5px;
  border: 1px solid transparent;
  background: color-mix(in srgb, var(--panel-2) 55%, transparent);
  color: var(--muted);
  white-space: nowrap;
}
.u-chip.title { color: var(--amber); background: color-mix(in srgb, var(--amber) 8%, transparent); }
/* 终端行要和对话行区分开，但这一列旁边就是计费列（绿/红），再加一种色相会
 * 让两列串味。所以只提墨色不换色相：对话最安静，终端比它重一档。 */
.u-chip.term { color: var(--text); }
.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: 10px;
  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: 6px;
  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, .uf-fields:has(#uf-user-wrap.hidden) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .uf-date { grid-column: 1 / span 2; }
  .uf-actions { grid-column: 3 / -1; }
  .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-date { grid-column: 1 / -1; }
  .uf-actions { grid-column: 1 / -1; width: 100%; }
  .uf-actions .btn { flex: 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); }
  .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 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; }
}

/* 手机横屏和矮窗口为列表留空间，筛选仍可在自身区域滚动操作。 */
@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; }
}
