:root {
  --bg-body: #F4F5F7;
  --bg-card: #FFFFFF;
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --success: #10B981;
  --danger: #EF4444;
  --text-main: #111827;
  --text-body: #4B5563;
  --text-muted: #6B7280;
  --border: #E5E7EB;
  --border-dark: #D1D5DB;
  --font-sans: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }
body { background-color: var(--bg-body); color: var(--text-body); font-family: var(--font-sans); margin: 0; line-height: 1.5; }

.topbar {
  background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 0 40px;
  display: flex; justify-content: space-between; align-items: center; height: 60px;
  position: sticky; top: 0; z-index: 100;
}
.brand { font-weight: 600; font-size: 18px; color: var(--text-main); letter-spacing: -0.5px; }
.nav-links { display: flex; gap: 4px; height: 100%; }
.nav-link {
  display: flex; align-items: center; padding: 0 20px; height: 100%;
  color: var(--text-muted); text-decoration: none; font-size: 14px; font-weight: 500;
  border-bottom: 2px solid transparent; cursor: pointer; transition: all 0.2s;
}
.nav-link.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-link:hover:not(.active) { color: var(--text-main); background: #F9FAFB; }

.container { max-width: 1200px; margin: 32px auto; padding: 0 24px; }
.view { display: none; animation: fadeIn 0.2s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.03); margin-bottom: 24px; overflow: hidden; }
.card-header { padding: 16px 24px; border-bottom: 1px solid var(--border); background: #F9FAFB; display: flex; justify-content: space-between; align-items: center; }
.card-title { font-size: 16px; font-weight: 600; color: var(--text-main); margin: 0; }
.card-body { padding: 24px; }

.alert-box { padding: 16px; border-radius: 6px; margin-bottom: 20px; border: 1px solid; }
.alert-info { background-color: #EFF6FF; border-color: #BFDBFE; color: #1E3A8A; }
.alert-warning { background-color: #FEFCE8; border-color: #FDE047; color: #854D0E; }
.alert-title { font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.alert-content { font-size: 13px; margin: 0; padding-left: 20px; }
.about-acks { text-align: left; margin: 18px 0; }
.about-acks strong { display: block; margin-bottom: 10px; font-size: 15px; color: #1E3A8A; }
.about-acks p { margin: 0; font-size: 13px; line-height: 1.65; }
.about-ack-group { border-top: 1px solid rgba(30,58,138,.16); padding-top: 12px; margin-top: 12px; }
.about-ack-label { font-size: 12px; font-weight: 700; color: #1E3A8A; margin-bottom: 4px; }

.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 14px; font-weight: 500; color: var(--text-main); margin-bottom: 8px; }
.input-field {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-dark); border-radius: 6px;
  font-size: 14px; font-family: var(--font-sans); color: var(--text-main); outline: none; transition: border 0.2s;
}
.input-field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.input-field.mono { font-family: var(--font-mono); font-size: 13px; }
textarea.input-field { resize: vertical; min-height: 80px; background: #F9FAFB; }
.input-group { display: flex; gap: 12px; }
.input-group .input-field { flex: 1; }
.config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px 20px; align-items: end; }
.toggle-row {
  min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; background: #F9FAFB; color: var(--text-main); font-size: 14px; font-weight: 500;
}
.toggle-row input { width: 18px; height: 18px; }

.btn {
  padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-secondary { background: white; color: var(--text-main); border-color: var(--border-dark); box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.btn-secondary:hover { background: #F9FAFB; }
.btn-danger-outline { background: white; color: var(--danger); border-color: #FECACA; }
.btn-danger-outline:hover { background: #FEF2F2; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; margin-bottom: 24px; }
.stat-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 24px; text-align: center; }
.stat-title { font-size: 14px; font-weight: 600; color: var(--text-main); margin-bottom: 16px; }
.stat-metrics { display: flex; justify-content: space-around; align-items: center; }
.metric { display: flex; flex-direction: column; align-items: center; }
.metric-value { font-size: 28px; font-weight: 600; font-family: var(--font-sans); color: var(--text-main); }
.metric-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.divider { width: 1px; height: 36px; background: var(--border); }
.usage-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.usage-panel, .usage-panel-wide { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 18px; }
.usage-panel-wide { margin-bottom: 20px; }
.usage-panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.usage-panel-head h4 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-main); }
.usage-panel-head p { margin: 4px 0 0; font-size: 12px; color: var(--text-muted); }
.usage-stat { padding: 18px 20px; text-align: left; }
.usage-stat-sub { margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.usage-bars { display: flex; flex-direction: column; gap: 10px; }
.usage-rank-row { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; background: #fff; }
.usage-rank-main { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 6px; }
.usage-rank-main span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-main); font-size: 13px; font-weight: 600; }
.usage-rank-main strong { color: var(--text-main); font-size: 13px; font-weight: 600; }
.usage-rank-track { height: 8px; border-radius: 999px; background: #E5E7EB; overflow: hidden; }
.usage-rank-track div { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--success)); }
.usage-rank-meta { margin-top: 6px; font-size: 11px; color: var(--text-muted); }
.usage-failure-row .usage-rank-track div { background: linear-gradient(90deg, #F59E0B, var(--danger)); }
.usage-table-wrap { overflow-x: auto; }
.usage-pill { display: inline-flex; align-items: center; justify-content: center; min-height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.usage-pill.ok { background: #ECFDF5; color: #059669; border: 1px solid #D1FAE5; }
.usage-pill.fail { background: #FEF2F2; color: #DC2626; border: 1px solid #FEE2E2; }
.usage-legend { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 8px; font-size: 11px; color: var(--text-muted); }
.usage-legend span { display: inline-flex; gap: 6px; align-items: center; }
.usage-legend b { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.legend-input { background: var(--success); }
.legend-output { background: #F97316; }
.legend-cache { background: #3B82F6; }
.usage-chart-area { display: flex; gap: 10px; align-items: stretch; min-width: 0; height: 220px; }
.usage-y-axis { position: relative; width: 52px; flex: 0 0 52px; font-size: 10px; color: var(--text-muted); }
.usage-y-axis span { position: absolute; left: 0; transform: translateY(50%); white-space: nowrap; }
.usage-plot { position: relative; flex: 1; min-width: 0; height: 100%; background: #F9FAFB; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.usage-grid-lines { position: absolute; inset: 0 0 24px 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.usage-grid-lines span { display: block; border-top: 1px solid #E5E7EB; width: 100%; }
.usage-bars-row { position: relative; z-index: 1; display: flex; align-items: flex-end; gap: 2px; height: calc(100% - 24px); padding: 8px 8px 4px; overflow-x: auto; }
.usage-bar-stack { width: 70%; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 3px 3px 0 0; overflow: hidden; min-height: 1px; }
.usage-bar-input { display: block; background: var(--success); min-height: 1px; }
.usage-bar-output { display: block; background: #F97316; min-height: 1px; }
.usage-bar-cache { display: block; background: #3B82F6; min-height: 1px; }
.usage-pager { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.usage-pager-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--text-muted); font-size: 12px; }
.usage-pager-left .input-field { width: auto; padding: 4px 8px; font-size: 12px; }
.usage-pager-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.usage-pager-buttons .btn { padding: 4px 10px; font-size: 12px; }
.empty-state { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }
.quota-section { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.quota-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.quota-section-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.quota-section-head h4 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-main); }
.quota-section-head p { margin: 0; font-size: 12px; color: var(--text-muted); }
.quota-note { font-size: 12px; color: var(--text-muted); margin: 0 0 8px; }
.quota-table { font-size: 12px; }
.quota-source-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.quota-source { padding: 4px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border); background: #F9FAFB; color: var(--text-muted); }
.quota-source.ok { background: #ECFDF5; color: #059669; border-color: #D1FAE5; }
.quota-source.fail { background: #FEF2F2; color: #DC2626; border-color: #FEE2E2; }
.quota-credit-card .quota-card-head strong { font-size: 15px; }
.quota-credit-card .quota-card-foot { text-align: left; }
.quota-credit-card .quota-note { margin-top: 6px; font-size: 11px; }
.usage-cache-row { align-items: flex-start; gap: 12px; }
.usage-cache-main { flex: 1; min-width: 0; }
.usage-cache-title { font-size: 13px; font-weight: 600; color: var(--text-main); word-break: break-word; }
.usage-cache-sub, .usage-cache-meta { font-size: 11px; color: var(--text-muted); word-break: break-all; }
.usage-cache-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.list-row { display: flex; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: #F9FAFB; }
.list-text-main { font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--text-main); }
.credential-item { border-bottom: 1px solid var(--border); }
.credential-item:last-child { border-bottom: none; }
.credential-item .list-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) max-content;
  align-items: start;
  gap: 16px;
  border-bottom: none;
}
.cred-select { grid-column: 1; margin: 4px 0 0; width: 16px; height: 16px; }
.cred-main { grid-column: 2; min-width: 0; }
.cred-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}
.cred-identity .list-text-main {
  flex: 0 1 auto;
  min-width: 120px;
  max-width: 56%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cred-email {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 13px;
}
.cred-status-inline {
  flex: 0 0 auto;
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.cred-meta-row {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
.cred-meta-row .badge {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cred-error-inline { color: var(--danger); font-size: 11px; }
.cred-actions {
  grid-column: 3;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 520px;
}
.cred-usage-strip { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cred-usage-strip span { background: #F3F4F6; border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); font-size: 11px; padding: 2px 8px; }
.cred-usage-strip b { color: var(--text-main); font-weight: 600; }
.credit-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.credit-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.credit-switch-track {
  position: relative;
  width: 34px;
  height: 18px;
  flex: 0 0 34px;
  border-radius: 999px;
  background: #D1D5DB;
  border: 1px solid #CBD5E1;
  transition: background .15s ease, border-color .15s ease;
}
.credit-switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0,0,0,.18);
  transition: transform .15s ease;
}
.credit-switch input:checked + .credit-switch-track {
  background: var(--success);
  border-color: #059669;
}
.credit-switch input:checked + .credit-switch-track::after { transform: translateX(16px); }
.cred-quota-details { padding: 0 24px 16px 56px; background: #F9FAFB; }
.cred-quota-content { border: 1px solid var(--border); border-radius: 8px; background: white; padding: 12px; }
.quota-panel-head { display: flex; justify-content: space-between; gap: 12px; color: var(--text-muted); font-size: 12px; margin-bottom: 12px; }
.quota-panel-head span:first-child { color: var(--text-main); font-weight: 600; }
.quota-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.quota-card { border: 1px solid var(--border); border-left: 4px solid var(--success); border-radius: 6px; padding: 10px; background: #FFFFFF; }
.quota-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; }
.quota-card-head span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text-main); font-weight: 600; }
.quota-card-head strong { font-size: 13px; }
.quota-progress { width: 100%; height: 7px; border-radius: 999px; background: #E5E7EB; overflow: hidden; margin-bottom: 6px; }
.quota-progress div { height: 100%; transition: width .2s ease; }
.quota-card-foot { color: var(--text-muted); font-size: 11px; text-align: right; }
.quota-empty { color: var(--text-muted); text-align: center; font-size: 13px; padding: 18px; }
.badge { padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; display: inline-flex; }
.badge-green { background: #ECFDF5; color: #059669; border: 1px solid #D1FAE5; }
.badge-red { background: #FEF2F2; color: #DC2626; border: 1px solid #FEE2E2; }
.badge-amber { background: #FFFBEB; color: #D97706; border: 1px solid #FDE68A; }
.badge-gray { background: #F3F4F6; color: #4B5563; border: 1px solid #E5E7EB; }

.terminal-container { background: #0D1117; border-radius: 8px; overflow: hidden; border: 1px solid #30363D; }
.terminal-body { height: 500px; overflow-y: auto; padding: 16px; font-family: var(--font-mono); font-size: 13px; color: #E6EDF3; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.log-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.segmented-control { display: inline-flex; padding: 2px; border: 1px solid var(--border-dark); border-radius: 6px; background: #F3F4F6; }
.segmented-control button {
  min-width: 72px; padding: 6px 10px; border: 0; border-radius: 4px; background: transparent;
  color: var(--text-muted); font-size: 13px; font-weight: 500; cursor: pointer;
}
.segmented-control button.active { background: #FFFFFF; color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

#login-overlay { position: fixed; inset: 0; background: rgba(244, 245, 247, 0.9); z-index: 999; display: flex; justify-content: center; align-items: center; }
#force-pwd-overlay { position: fixed; inset: 0; background: rgba(244, 245, 247, 0.95); z-index: 1000; display: flex; justify-content: center; align-items: center; }

.model-grid.collapsed {
  display: flex; flex-wrap: wrap; gap: 8px;
  max-height: 36px; overflow: hidden;
}
.model-grid.expanded {
  display: flex; flex-wrap: wrap; gap: 8px;
  max-height: none; overflow: visible;
}

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; justify-content: center; align-items: center; }
.modal-box { background: var(--bg-card); border-radius: 12px; padding: 24px; max-width: 480px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.1); }
.upload-dropzone {
  border: 1px dashed var(--border-dark);
  border-radius: 8px;
  background: #F9FAFB;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 18px;
  text-align: center;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.upload-dropzone strong { color: var(--text-main); font-size: 14px; }
.upload-dropzone span { color: var(--text-muted); font-size: 12px; }
.upload-dropzone.dragover {
  border-color: var(--primary);
  background: #EFF6FF;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.toast { position: fixed; top: 80px; right: 24px; padding: 12px 20px; border-radius: 6px; font-size: 14px; font-weight: 500; z-index: 9999; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.toast.success { background: #ECFDF5; color: #059669; border: 1px solid #D1FAE5; }
.toast.error { background: #FEF2F2; color: #DC2626; border: 1px solid #FEE2E2; }
.toast.show { opacity: 1; }

@media (max-width: 600px) {
  .container { padding: 0 12px; }
  .stats-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 12px; }
  .nav-link { padding: 0 10px; font-size: 12px; }
  .list-row { gap: 8px; }
  .credential-item .list-row { grid-template-columns: 16px minmax(0, 1fr) max-content; gap: 8px; padding: 14px 12px; overflow-x: auto; }
  .cred-identity { flex-wrap: wrap; gap: 4px 8px; }
  .cred-identity .list-text-main { max-width: 100%; }
  .cred-email { flex-basis: 100%; }
  .cred-meta-row { gap: 4px; }
  .cred-actions { justify-content: flex-end; max-width: 312px; }
  .cred-quota-details { padding: 0 12px 12px; }
  .input-group { flex-direction: column; }
  .usage-chart-area { height: 200px; }
  .usage-y-axis { width: 42px; flex-basis: 42px; }
  .usage-pager { align-items: stretch; }
}
@media (max-width: 900px) {
  .cred-actions { max-width: 312px; }
}

/* ===== 使用统计柱状图 ===== */
.usage-chart {
  display: block;
}
.usage-bar {
  flex: 1 0 8px; min-width: 6px; display: flex; flex-direction: column;
  justify-content: flex-end; align-items: center; height: 100%; position: relative;
}
.usage-bar:hover .usage-bar-input { background: var(--primary-hover); }
.usage-bar-label { font-size: 9px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.usage-table th, .usage-table td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--border); }
.usage-table th:first-child, .usage-table td:first-child { text-align: left; }
.usage-table th { color: var(--text-muted); font-weight: 500; background: #F9FAFB; }
@media (max-width: 900px) {
  .usage-layout { grid-template-columns: 1fr; }
}
