/* Simple, modern dashboard style. The palette is intentionally subdued so charts pop. */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: #f6f7f9;
  color: #111827;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Visually hidden but still announced by screen readers. Used for the filter
   labels on the dashboard, where the pill text already describes the control. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Login page ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
}

.login-card {
  width: 360px;
  background: #fff;
  padding: 32px 28px 24px;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  color: #111827;
}

.login-card .subtitle {
  margin: 0 0 22px;
  color: #6b7280;
  font-size: 13px;
}

.login-card label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 600;
  color: #374151;
}

.login-card label.inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  color: #4b5563;
  margin-top: 10px;
}

.login-card input[type=text],
.login-card input[type=password] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-card input:focus {
  border-color: #4f46e5;
}

.login-card button {
  margin-top: 18px;
  width: 100%;
  padding: 11px 16px;
  border: 0;
  border-radius: 8px;
  background: #4f46e5;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.login-card button:hover {
  background: #4338ca;
}

.login-card button:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

.login-card .error {
  margin-top: 12px;
  padding: 8px 12px;
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 6px;
  font-size: 13px;
}

.login-card footer {
  margin-top: 20px;
  text-align: center;
  color: #9ca3af;
  font-size: 12px;
}

/* ---------- Dashboard ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid #eeeeef;
}

.brand {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-info {
  color: #6b7280;
  font-size: 13px;
}

.ghost-btn {
  background: #fff;
  border: 1px solid #e3e3e6;
  color: #374151;
  padding: 7px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.ghost-btn:hover {
  background: #fafafa;
  border-color: #cfd0d4;
  color: #111827;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-end;
  padding: 14px 16px;
  background: #fff;
  margin: 16px 24px 0;
  border: 1px solid #eeeeef;
  border-radius: 14px;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* The flex display above would otherwise defeat the [hidden] attribute
   (used by the custom time-range row). */
.filter-item[hidden] {
  display: none;
}

.filter-item.btns {
  justify-content: flex-end;
}

.filter-item label {
  font-size: 12px;
  color: #6b7280;
  font-weight: 600;
}

.filter-item label.inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  color: #4b5563;
}

.filter-item input,
.filter-item select {
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  background: #fff;
  min-width: 140px;
}

/* Checkboxes share the .filter-item input selector but must not inherit the
   text-input sizing (padding / min-width), otherwise the box gets stretched
   to ~140px and the trailing label text appears far away from the tick mark. */
.filter-item input[type="checkbox"] {
  padding: 0;
  min-width: 0;
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: #4f46e5;
}

.filter-item input:focus,
.filter-item select:focus {
  border-color: #111827;
}

/* ---------- Pill filter bar (dashboard header) ----------
   Controls sit in a single right-aligned row. Each control is wrapped in a
   rounded outline so the row reads as a toolbar rather than a form: no
   per-field labels, no inner borders, one consistent 40px control height. */
.filters--pills {
  align-items: center;
  padding: 0;
  margin-top: 16px;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  width: 100%;
  justify-content: flex-start;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid #e3e3e6;
  border-radius: 10px;
  transition: border-color 0.15s, background 0.15s;
}

.pill:hover {
  background: #fcfcfd;
  border-color: #cfd0d4;
}

.pill:focus-within {
  border-color: #111827;
}

.pill input[type="text"],
.pill select {
  height: 100%;
  min-width: 92px;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #111827;
  font-size: 14px;
  font-family: inherit;
}

.pill input[type="text"]::placeholder {
  color: #9ca3af;
}

.pill select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 18px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
}

.pill-prefix {
  color: #9ca3af;
  font-size: 13px;
  white-space: nowrap;
}

/* ---------- Model picker (combo) ----------
   A free-text input that still offers the model names seen in the data: the
   caret opens the full list, typing narrows it, and any typed value is passed
   through to the backend (which matches on exact model name). */
.pill--combo {
  position: relative;
  padding-right: 6px;
}

.pill--combo input[type="text"] {
  min-width: 110px;
}

.pill-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  background: none;
  color: #6b7280;
  cursor: pointer;
}

.pill-caret::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.18s;
}

.pill-caret[aria-expanded="true"]::after {
  margin-top: 3px;
  transform: rotate(-135deg);
}

.combo-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  min-width: 100%;
  max-height: 260px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid #e3e3e6;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.1);
}

.combo-menu[hidden] {
  display: none;
}

.combo-item {
  padding: 7px 10px;
  border-radius: 7px;
  color: #374151;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.combo-item:hover,
.combo-item.is-active {
  background: #f4f5f7;
  color: #111827;
}

.combo-empty {
  padding: 8px 10px;
  color: #9ca3af;
  font-size: 12px;
}

.pill--check {
  gap: 8px;
  cursor: pointer;
  color: #374151;
  font-size: 13px;
  user-select: none;
}

.pill--check input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  padding: 0;
  min-width: 0;
  accent-color: #111827;
  cursor: pointer;
}

.custom-range {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
}

.custom-range .field-label {
  flex: 0 0 auto;
  color: #6b7280;
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
}

.custom-range input[type="datetime-local"] {
  height: 40px;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid #e3e3e6;
  border-radius: 10px;
  background: #fff;
  color: #111827;
  font-size: 14px;
  font-family: inherit;
}

.custom-range input[type="datetime-local"]:focus {
  border-color: #111827;
  outline: none;
}

.primary-btn {
  height: 40px;
  padding: 0 20px;
  background: #111827;
  color: #fff;
  border: 1px solid #111827;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}

.primary-btn:hover {
  background: #000;
  border-color: #000;
}

.primary-btn:disabled {
  background: #9ca3af;
  border-color: #9ca3af;
  cursor: not-allowed;
}

.summary {
  padding: 16px 24px 0;
}

/* The 12 metrics are laid out in balanced rows (2 / 4 / 6 columns) so no row
   is left with a ragged tail; a fixed count also keeps every card the same
   width instead of letting auto-fit produce an uneven last row. */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 700px) {
  .summary-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .summary-cards {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.card {
  background: #fff;
  border: 1px solid #eeeeef;
  border-radius: 12px;
  padding: 12px 14px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover {
  border-color: #dcdde0;
  box-shadow: 0 2px 10px rgba(17, 24, 39, 0.05);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #6b7280;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

/* Small "?" affordance next to a metric name: the explanation is shown as a
   dark tooltip on hover/focus, sourced from data-tip (filled by i18n). */
.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border: 1px solid #d8d9dd;
  border-radius: 50%;
  color: #9ca3af;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  cursor: help;
}

.help-tip::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 20;
  width: max-content;
  max-width: 240px;
  padding: 7px 10px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-2px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
  pointer-events: none;
}

.help-tip:hover::after,
.help-tip:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* A centred tooltip on the left-most card would be clipped by the viewport,
   so anchor it to the icon's left edge instead. */
.summary-cards .card:first-child .help-tip::after {
  left: 0;
  transform: translateY(-2px);
}

.summary-cards .card:first-child .help-tip:hover::after,
.summary-cards .card:first-child .help-tip:focus-visible::after {
  transform: translateY(0);
}

.card-value {
  margin-top: 6px;
  color: #101114;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.charts {
  padding: 16px 24px 0;
}

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 1100px) {
  .chart-row {
    grid-template-columns: 1fr;
  }
}

.chart-box {
  background: #fff;
  border: 1px solid #eeeeef;
  border-radius: 14px;
  height: 320px;
  padding: 8px;
}

/* Chart cards that host an action button in a header bar above the canvas.
   The header sits *outside* the echarts canvas so it never overlaps the
   legend, title or bars — the button and the chart occupy disjoint vertical
   regions of the card. */
.chart-box--with-action {
  display: flex;
  flex-direction: column;
  padding: 0;
}

.chart-action-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 6px 8px 0 8px;
}

.chart-box--with-action .chart-canvas {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}

.chart-action-btn {
  font-size: 12px;
  padding: 4px 10px;
  background: #fff;
}

.table-section {
  background: #fff;
  margin: 0 24px 24px;
  padding: 16px 18px;
  border: 1px solid #eeeeef;
  border-radius: 14px;
}

.table-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.table-head h3 {
  margin: 0;
}

/* Push the download button to the right edge regardless of how much text
   #tableInfo has produced. */
.table-head #downloadDetailBtn,
.table-head #downloadApiKeyModelBtn {
  margin-left: auto;
}

.muted {
  color: #9ca3af;
  font-size: 12px;
}

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  background: #f9fafb;
  color: #4b5563;
  font-weight: 600;
}

tbody tr:hover {
  background: #f9fafb;
}

/* API Key × Model matrix: highlight the trailing "Total" column and the
   trailing "Total" row so users can quickly locate the summary values. */
#apiKeyModelTable td.col-total,
#apiKeyModelTable th.col-total {
  background: #f3f4f6;
  font-weight: 600;
}

#apiKeyModelTable tr.row-total td {
  background: #f3f4f6;
  font-weight: 600;
  border-top: 1px solid #d1d5db;
}

#apiKeyModelTable tr.row-total:hover td {
  background: #f3f4f6;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.pagination button {
  background: #fff;
  border: 1px solid #d1d5db;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.pagination button:disabled {
  color: #9ca3af;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: #1f2937;
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  z-index: 1000;
}

.sub-app-notice {
  margin: 12px 24px 0 24px;
  padding: 10px 14px;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fdba74;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
}

.sub-app-notice #noticeAppId {
  font-weight: 600;
}

/* ---------- Language switcher ---------- */
.lang-switcher {
  min-width: 40px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.lang-switcher-floating {
  position: fixed;
  top: 18px;
  right: 20px;
  z-index: 1001;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.6);
  color: #4f46e5;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.lang-switcher-floating:hover {
  background: #fff;
}