/* Trang Thống kê — giao diện theo 9router (Usage & Analytics). Tiền tố .us- */

.us-page { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.us-page [hidden], .us-page[hidden] { display: none !important; }
.us-page .nowrap { white-space: nowrap; }
.us-page .center { text-align: center; }
.us-page .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.us-overview, .us-details { display: flex; flex-direction: column; gap: 24px; min-width: 0; }

/* hàng trên: Tổng quan / Chi tiết + khoảng thời gian */
.us-bar { display: flex; flex-direction: column; gap: 8px; }
.us-tab-slot { display: flex; min-width: 0; }
.us-tabs, .us-period { width: 100%; }
.us-tabs button, .us-period button { flex: 1 0 auto; justify-content: center; }
.us-period.seg.sm button { padding: 0 16px; }
@media (min-width: 640px) {
  .us-bar { flex-direction: row; align-items: center; justify-content: space-between; }
  .us-tabs, .us-period { width: auto; }
  .us-tabs button, .us-period button { flex: none; }
}

/* 5 thẻ số liệu */
.us-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }
.us-card.card { display: flex; flex-direction: column; gap: 4px; padding: 16px; min-width: 0; }
.card.us-card + .card.us-card { margin-top: 0; }
.us-card-k { color: var(--text-muted); font-size: 14px; line-height: 20px; font-weight: 600; text-transform: uppercase; }
.us-card-v { font-size: 24px; line-height: 32px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.us-v-input { color: var(--primary); }
.us-v-latency { color: var(--info); }
.us-v-output { color: var(--success); }
.us-v-cost { color: var(--warning); }
.us-card-note { font-size: 10px; line-height: 15px; color: var(--text-muted); }
@media (min-width: 640px) { .us-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 768px) { .us-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .us-cards { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

/* sơ đồ + request gần đây */
.us-topo-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; align-items: stretch; min-width: 0; }
@media (min-width: 1024px) { .us-topo-row { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); } }

.us-topo { position: relative; height: 320px; width: 100%; min-width: 0; overflow: hidden; border: 1px solid var(--border);
  border-radius: 8px; cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
@media (min-width: 640px) { .us-topo { height: 480px; } }
.us-topo.dragging { cursor: grabbing; }
.us-tp-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.us-tp-world.anim { transition: transform .2s ease; }
.us-tp-edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.us-tp-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); font-size: 14px; }

.us-tp-node { position: absolute; display: flex; align-items: center; gap: 10px; padding: 10px 16px; min-width: 150px; white-space: nowrap;
  border: 2px solid var(--border); border-radius: 8px; background: var(--bg); transition: border-color .3s, box-shadow .3s; }
.us-tp-ic { width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center; flex: none; font-size: 14px; line-height: 20px; font-weight: 700; }
.us-tp-name { font-size: 16px; line-height: 24px; font-weight: 500; color: var(--text); max-width: 240px; overflow: hidden; text-overflow: ellipsis; transition: color .3s; }
.us-tp-ping { position: relative; display: inline-flex; width: 8px; height: 8px; flex: none; }
.us-tp-ping i { position: absolute; inset: 0; border-radius: 50%; background: currentColor; }
.us-tp-ping i:first-child { opacity: .75; animation: us-ping 1s cubic-bezier(0, 0, .2, 1) infinite; }
@keyframes us-ping { 75%, 100% { transform: scale(2); opacity: 0; } }

.us-tp-router { position: absolute; z-index: 1; display: flex; align-items: center; justify-content: center; min-width: 130px; padding: 12px 20px;
  white-space: nowrap; border: 2px solid var(--primary); border-radius: 12px; background: rgba(229, 106, 74, .05);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -2px rgba(0, 0, 0, .1); }
.us-tp-logo { width: 24px; height: 24px; margin-right: 8px; flex: none; }
.us-tp-rlabel { font-size: 14px; line-height: 20px; font-weight: 700; color: var(--primary); }
.us-tp-badge { margin-left: 8px; padding: 2px 6px; border-radius: 9999px; background: #facc15; color: #000; font-size: 12px; line-height: 16px;
  font-weight: 700; box-shadow: 0 0 10px #fde047, 0 0 16px rgba(34, 211, 238, .6); }
.us-tp-router.power { border-color: #fde047; background: linear-gradient(to bottom right, rgba(229, 106, 74, .3), rgba(250, 204, 21, .2), rgba(34, 211, 238, .25));
  animation: us-tp-pulse .75s ease-in-out infinite; }
.us-tp-router.power .us-tp-logo { animation: us-tp-shake .45s ease-in-out infinite; }
.us-tp-router.power .us-tp-rlabel { color: #fde047; animation: us-tp-flicker .7s ease-in-out infinite; }
@keyframes us-tp-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 8px #fde047, 0 0 20px rgba(229, 106, 74, .65), 0 0 32px rgba(34, 211, 238, .4), inset 0 0 10px rgba(253, 224, 71, .3); }
  50% { transform: scale(1.06); box-shadow: 0 0 14px #fef08a, 0 0 28px #facc15, 0 0 44px rgba(34, 211, 238, .6), inset 0 0 14px rgba(255, 255, 255, .25); }
}
@keyframes us-tp-shake {
  0%, 100% { transform: rotate(0deg) scale(1); filter: drop-shadow(0 0 2px #fde047); }
  25% { transform: rotate(-5deg) scale(1.08); filter: drop-shadow(0 0 6px #facc15); }
  75% { transform: rotate(5deg) scale(1.08); filter: drop-shadow(0 0 6px #22d3ee); }
}
@keyframes us-tp-flicker { 0%, 100% { text-shadow: 0 0 6px #fde047, 0 0 12px #22d3ee; } 50% { text-shadow: 0 0 10px #fff, 0 0 18px #facc15; } }

.us-tp-edge { fill: none; }
.us-tp-edge.idle { stroke: var(--border); stroke-width: 1; opacity: .3; }
[data-theme="light"] .us-tp-edge.idle { stroke: #9ca3af; opacity: .45; }
.us-tp-edge.used { stroke: #f59e0b; stroke-width: 2; opacity: .75; stroke-dasharray: 6 6; animation: us-tp-dash 1.1s linear infinite; }
.us-tp-edge.error { stroke: #ef4444; stroke-width: 2.5; opacity: .9; }
.us-tp-halo { fill: none; stroke: #22d3ee; stroke-width: 10; stroke-opacity: .35; stroke-linecap: round; animation: us-tp-flick .18s steps(2) infinite; }
.us-tp-plasma { fill: none; stroke: #4ade80; stroke-width: 5; stroke-opacity: .85; stroke-linecap: round; stroke-dasharray: 14 10;
  animation: us-tp-dash-fast .18s linear infinite, us-tp-flick .22s steps(3) infinite; }
.us-tp-core { fill: none; stroke: #f8fafc; stroke-width: 2.2; stroke-dasharray: 8 6; animation: us-tp-dash-fast .22s linear infinite; }
.us-tp-orb { opacity: .95; filter: drop-shadow(0 0 4px #22d3ee); }
@keyframes us-tp-dash { to { stroke-dashoffset: -24; } }
@keyframes us-tp-dash-fast { to { stroke-dashoffset: -36; } }
@keyframes us-tp-flick { 0%, 100% { opacity: .85; } 40% { opacity: 1; } 55% { opacity: .55; } 70% { opacity: 1; } }

.us-tp-controls { position: absolute; left: 15px; bottom: 15px; z-index: 5; display: flex; flex-direction: column; overflow: hidden; cursor: default;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-soft); }
.us-tp-controls button { width: 26px; height: 26px; padding: 5px; display: grid; place-items: center; border: 0; border-bottom: 1px solid var(--border);
  background: var(--surface); color: var(--text); }
.us-tp-controls button:last-child { border-bottom: 0; }
.us-tp-controls button:hover { background: var(--bg-alt); }
.us-tp-controls svg { width: 100%; max-width: 12px; max-height: 12px; fill: currentColor; }
.us-tp-legend { margin-top: 10px; flex-wrap: wrap; }

.us-recent.card { height: 480px; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.us-recent-head { flex: none; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.us-recent-head span { font-size: 12px; line-height: 16px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .025em; }
.us-recent-body { flex: 1; min-height: 0; overflow-y: auto; }
.us-recent-empty { height: 100%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 14px; }
.us-recent-tbl { width: 100%; min-width: 300px; border-collapse: collapse; font-size: 12px; line-height: 16px; }
.us-recent-tbl th { position: sticky; top: 0; z-index: 1; background: var(--bg); padding: 6px 0; text-align: left; font-weight: 600;
  color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
.us-recent-tbl td { padding: 6px 0; }
.us-recent-tbl .num { text-align: right; padding-left: 8px; font-variant-numeric: tabular-nums; }
.us-recent-tbl th.num:last-child, .us-recent-tbl td.num:last-child { padding-right: 4px; }
.us-recent-tbl tbody tr + tr td { border-top: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
.us-recent-tbl tbody tr:hover td { background: var(--hover); }
.us-dotcol { width: 8px; }
.us-dot { display: block; width: 6px; height: 6px; border-radius: 50%; }
.us-dot.ok { background: #22c55e; }
.us-dot.bad { background: #ef4444; }
.us-recent-model { font-family: var(--mono); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 2px !important; }
.us-in { color: var(--primary); }
.us-out { color: var(--success); }
.us-when { color: var(--text-muted); white-space: nowrap; }

/* biểu đồ */
.us-chart-card.card { display: flex; flex-direction: column; gap: 12px; padding: 12px; min-width: 0; }
@media (min-width: 640px) { .us-chart-card.card { padding: 16px; } }
.us-pill { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border: 1px solid var(--border);
  border-radius: 8px; align-items: center; }
.us-pill button { padding: 4px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--text-muted); font-size: 14px;
  line-height: 20px; font-weight: 500; transition: color .15s, background .15s; white-space: nowrap; }
.us-pill button:hover { color: var(--text); background: var(--hover); }
.us-pill button.active { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
@media (min-width: 640px) { .us-pill { display: inline-flex; align-self: flex-start; } }
.us-chart { position: relative; min-width: 0; min-height: 192px; color: var(--text); }
.us-ch-svg { display: block; overflow: visible; }
.us-ch-grid { stroke: #ccc; stroke-opacity: .1; stroke-dasharray: 3 3; }
.us-ch-axis { fill: currentColor; fill-opacity: .5; font-size: 10px; font-family: var(--font); }
.us-ch-cursor { stroke: #ccc; stroke-width: 1; }
.us-ch-tip { position: absolute; z-index: 2; pointer-events: none; padding: 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; font-size: 12px; line-height: 18px; white-space: nowrap; }
.us-ch-tip-label { color: var(--text); margin-bottom: 2px; }
.us-ch-tip-sub { color: var(--text-muted); font-size: 11px; }
.us-chart-empty { height: 192px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 14px; }

/* bảng thống kê theo nhóm */
.us-table-sec { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.us-table-bar { display: flex; flex-direction: column; gap: 8px; }
.us-select { width: 100%; padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
  font-size: 14px; line-height: 20px; font-weight: 500; outline: none; }
.us-select:focus-visible { box-shadow: 0 0 0 2px rgba(229, 106, 74, .5); }
@media (min-width: 640px) {
  .us-table-bar { flex-direction: row; align-items: center; justify-content: space-between; }
  .us-select { width: auto; }
}
.us-table-card.card { overflow: hidden; }
.us-table-title { padding: 16px; border-bottom: 1px solid var(--border); }
table.us-tbl { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.us-tbl th { padding: 12px 24px; text-align: left; font-size: 12px; line-height: 16px; font-weight: 600; text-transform: uppercase;
  color: var(--text-muted); white-space: nowrap; cursor: pointer; user-select: none; }
.us-tbl th:hover { color: var(--text); }
.us-tbl th:focus-visible { outline: 2px solid rgba(229, 106, 74, .5); outline-offset: -2px; }
.us-tbl td { padding: 12px 24px; vertical-align: middle; }
.us-tbl tbody tr + tr td { border-top: 1px solid var(--border); }
.us-tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.us-sort { margin-left: 2px; }
.us-sort.off { opacity: .2; }
.us-group { cursor: pointer; transition: background .15s; }
.us-group:hover td, .us-detail:hover td { background: var(--hover); }
.us-group:focus-visible { outline: 2px solid rgba(229, 106, 74, .5); outline-offset: -2px; }
.us-group-label { display: flex; align-items: center; gap: 8px; min-width: 0; }
.us-group-label > span:last-child { font-weight: 500; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.us-chev { font-size: 18px; color: var(--text-muted); transition: transform .15s; }
.us-chev.open { transform: rotate(90deg); }
.us-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge.us-neutral { background: var(--surface-2); color: var(--text-muted); font-weight: 500; }
.us-err { color: var(--c-red); font-size: 12px; }
.us-total { font-weight: 500; }
.us-total-cost { font-weight: 500; color: var(--warning); }
.us-detail td { font-size: 13px; }
.us-detail-label { padding-left: 26px; min-width: 0; }
.us-detail-label .mono { font-size: 12.5px; display: inline-block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.us-detail.foot td { padding: 10px 24px 14px 50px; }
.us-detail.foot:hover td { background: transparent; }
.us-link { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; color: var(--primary); font-weight: 500; }
.us-link:hover { text-decoration: underline; }
.us-st { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.us-st i { width: 6px; height: 6px; border-radius: 50%; }
.us-st.ok { color: var(--c-green); } .us-st.ok i { background: #22c55e; }
.us-st.bad { color: var(--c-red); } .us-st.bad i { background: #ef4444; }
.us-table-empty { padding: 32px 24px !important; text-align: center; color: var(--text-muted); }

/* tab Chi tiết */
.us-filters.card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 640px) { .us-filters.card { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .us-filters.card { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.us-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.us-field > label, .us-field-ghost { font-size: 14px; line-height: 20px; font-weight: 500; color: var(--text); }
.us-field-ghost { display: none; opacity: 0; }
@media (min-width: 1024px) { .us-field-ghost { display: block; } }
.us-finput, .us-fselect { height: 36px; width: 100%; min-width: 0; padding: 0 12px; border-radius: 8px; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--text) 10%, transparent); outline: none; }
.us-finput::placeholder { color: var(--text-muted); opacity: .8; }
.us-finput:focus, .us-fselect:focus { box-shadow: 0 0 0 2px rgba(229, 106, 74, .2); }
.us-log-card.card { overflow: hidden; }
table.us-log { width: 100%; min-width: 1000px; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.us-log th { padding: 16px; text-align: left; font-weight: 600; color: var(--text); white-space: nowrap;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 6%, transparent); }
.us-log td { padding: 16px; color: var(--text); border-bottom: 1px solid color-mix(in srgb, var(--text) 6%, transparent); vertical-align: middle; }
.us-log tbody tr:last-child td { border-bottom: 0; }
.us-log tbody tr:hover td { background: color-mix(in srgb, var(--text) 2.5%, transparent); }
.us-log .num { text-align: right; font-variant-numeric: tabular-nums; }
.us-log td.mono { font-size: 13px; }
.us-log td.muted { color: var(--text-muted); }
.us-log-model { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.us-log-prov span { font-weight: 500; }
.us-log-prov { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.us-log .us-ellip, .us-log-conn .small { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.us-log td.us-log-msg { padding: 32px; text-align: center; color: var(--text-muted); }
.us-spin { display: inline-flex; vertical-align: middle; margin-right: 8px; animation: us-spin 1s linear infinite; }
.us-spin .ms { font-size: 20px; }
@keyframes us-spin { to { transform: rotate(360deg); } }
.us-pagination { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 16px; padding: 16px;
  border-top: 1px solid color-mix(in srgb, var(--text) 6%, transparent); }
.us-pg-info { font-size: 14px; color: var(--text-muted); }
.us-pg-info b { font-weight: 500; color: var(--text); }
.us-pg-right { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.us-pg-size { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.us-fselect.us-size { width: auto; padding: 0 8px; }
.us-pg-btns { display: flex; align-items: center; gap: 4px; }
.btn.sm.us-pg { width: 36px; padding: 0; font-size: 12px; }
.btn.sm.us-pg .ms { font-size: 18px; }
.us-ellipsis { color: var(--text-muted); padding: 0 4px; }
.us-page .hide-sm { display: none; }
@media (min-width: 640px) {
  .us-pagination { flex-direction: row; }
  .us-pg-right { gap: 16px; }
  .us-page .hide-sm { display: inline-flex; }
}

/* hộp thoại chi tiết request */
.us-kv-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px 16px; font-size: 14px; }
@media (min-width: 640px) { .us-kv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.us-kv { overflow-wrap: anywhere; }
.us-kv .mono { font-size: 13px; }
.us-err-box { margin-top: 20px; padding: 12px; border: 1px solid rgba(239, 68, 68, .3); border-radius: 8px; background: rgba(239, 68, 68, .06); }
.us-err-title { display: flex; align-items: center; gap: 6px; color: var(--c-red); font-weight: 600; margin-bottom: 8px; }
.us-err-box pre { margin: 0; max-height: 300px; overflow: auto; font: 12px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Model Google THẬT SỰ phục vụ (VD "3.8 Flash · Extended thinking") dưới mã model */
.us-served { font-family: var(--font); font-size: 11px; line-height: 14px; color: var(--c-blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.us-recent-model .us-ellip, .us-log-model .us-ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.us-ttft { white-space: nowrap; }
