:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --text: #172033;
  --muted: #667085;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --green: #16a34a;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #e0ecff 0, transparent 34rem), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 20px;
}

h1 {
  margin: 0 0 8px;
  font-size: 30px;
  letter-spacing: -0.03em;
}

p {
  margin: 0;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
}

.dot.ok { background: var(--green); }
.dot.error { background: var(--danger); }

.panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(229, 231, 235, 0.95);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.controls {
  display: grid;
  grid-template-columns: 1.3fr 1.5fr 0.7fr 0.9fr auto;
  gap: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  align-self: end;
  gap: 8px;
  height: 40px;
}

.checkbox-label input {
  width: auto;
  height: auto;
}

.inline-select {
  min-width: 180px;
}

input,
select,
textarea,
button {
  border-radius: 12px;
  border: 1px solid #d0d5dd;
  font: inherit;
}

input,
select,
button {
  height: 40px;
}

input,
select,
textarea {
  width: 100%;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 180px;
  padding: 12px;
  line-height: 1.65;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

button {
  align-self: end;
  padding: 0 18px;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.hint {
  margin-bottom: 16px;
  padding: 12px 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.error {
  display: none;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 12px;
  color: #991b1b;
  white-space: pre-wrap;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.tab-button {
  align-self: auto;
  height: 38px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.74);
  border-color: var(--border);
}

.tab-button.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.card {
  padding: 16px;
}

.card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.card strong {
  font-size: 28px;
  letter-spacing: -0.04em;
}

.agent-runtime-layout {
  display: grid;
  gap: 16px;
}

.agent-runtime-card {
  display: grid;
  gap: 16px;
  max-width: 560px;
  padding: 18px;
}

.agent-runtime-card span {
  color: var(--muted);
  font-size: 13px;
}

.agent-runtime-card h3 {
  margin: 0;
  font-size: 18px;
}

.agent-runtime-card > strong {
  color: var(--primary);
  font-size: 38px;
  letter-spacing: -0.05em;
}

.agent-runtime-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.agent-runtime-metrics div {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-soft);
}

.agent-runtime-metrics small {
  color: var(--muted);
}

.agent-runtime-metrics b {
  font-size: 18px;
}

.agent-runtime-breakdown,
.agent-runtime-models {
  padding: 16px;
  overflow-x: auto;
}

.agent-runtime-breakdown h3,
.agent-runtime-models h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.card .card-link {
  color: var(--primary);
  font-size: 16px;
  letter-spacing: 0;
  text-decoration: none;
}

.card .card-link:hover {
  text-decoration: underline;
}

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

.section {
  padding: 16px;
}

.section h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

#tab-traffic > .panel.section {
  margin-bottom: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
}

.section-head p {
  margin-top: 6px;
  line-height: 1.5;
}

.pager {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.pager button {
  align-self: auto;
  height: 32px;
  padding: 0 10px;
  border-radius: 10px;
}

.pager input {
  width: 72px;
  height: 32px;
  padding: 0 8px;
  border-radius: 10px;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0 16px;
}

.link-button {
  align-self: auto;
  height: 30px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--primary);
  background: #eff6ff;
  border-color: #bfdbfe;
}

.client-dialog {
  width: min(1040px, calc(100vw - 32px));
  max-height: calc(100vh - 56px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.client-dialog::backdrop {
  background: rgba(15, 23, 42, 0.28);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-head h2 {
  margin: 0 0 6px;
}

.dialog-head button {
  align-self: auto;
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.usage-card {
  min-width: 0;
  overflow-x: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-soft);
}

.usage-card-wide {
  grid-column: 1 / -1;
}

.usage-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.notice-panel {
  margin-bottom: 16px;
}

.license-management-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.license-management-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.license-management-card h3 {
  margin: 0;
  font-size: 16px;
}

#licenseOfflineCode {
  min-height: 120px;
  font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;
  word-break: break-all;
}

.notice-form {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 12px;
  margin-top: 14px;
}

.notice-field-wide {
  grid-column: 1 / -1;
}

.notice-meta,
.notice-status {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  white-space: pre-wrap;
}

.notice-status {
  display: none;
  margin-top: 12px;
}

.notice-status.ok {
  display: block;
  color: #166534;
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.notice-status.error {
  display: block;
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}

.notice-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.notice-actions button {
  align-self: auto;
}

.notice-actions .danger-button {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}

.resource-panel {
  margin-bottom: 16px;
}

.resource-head-actions,
.resource-actions,
.resource-row-actions {
  display: flex;
  gap: 10px;
}

.resource-head-actions {
  flex: 0 0 auto;
  margin-left: auto;
}

.resource-head-actions button,
.resource-actions button,
.resource-row-actions button {
  align-self: auto;
  white-space: nowrap;
}

.resource-head-actions button {
  min-width: 98px;
}

.secondary-button {
  color: var(--primary);
  background: #eff6ff;
  border-color: #bfdbfe;
}

.danger-button {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}

.resource-form {
  display: grid;
  grid-template-columns: 180px 1.2fr 1fr 160px 120px;
  gap: 12px;
  margin: 14px 0;
  padding: 14px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.resource-image-editor {
  display: grid;
  grid-row: span 4;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.resource-image-preview {
  display: grid;
  min-height: 128px;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  background: #fff;
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
}

.resource-image-preview img {
  width: 100%;
  height: 128px;
  object-fit: contain;
}

.resource-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.resource-checkbox-row input {
  width: auto;
  height: auto;
}

.resource-field-wide,
.resource-actions {
  grid-column: 2 / -1;
}

.resource-actions {
  justify-content: flex-end;
}

.resource-table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}

.resource-table {
  min-width: 980px;
  table-layout: fixed;
}

.resource-image-cell {
  width: 92px;
}

.resource-title-cell {
  width: 190px;
}

.resource-tags-cell {
  width: 96px;
}

.resource-modal-cell {
  width: 220px;
}

.resource-row-actions {
  width: 128px;
}

.resource-thumb,
.resource-thumb-placeholder {
  display: grid;
  width: 76px;
  height: 58px;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.resource-thumb {
  object-fit: contain;
}

.resource-title-cell strong,
.resource-title-cell small,
.resource-tag-list span {
  white-space: nowrap;
}

.resource-tag-list {
  display: grid;
  align-content: start;
  gap: 4px;
}

.resource-description-cell,
.resource-modal-cell {
  line-height: 1.65;
}

.resource-row-actions button {
  height: 32px;
  padding: 0 10px;
  border-radius: 10px;
  white-space: nowrap;
}

td small {
  color: var(--muted);
}

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

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: var(--panel-soft);
  font-weight: 600;
}

code {
  padding: 2px 6px;
  border-radius: 8px;
  background: #eef2f7;
  color: #344054;
  word-break: break-all;
}

.empty {
  padding: 24px;
  border: 1px dashed #d0d5dd;
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  background: var(--panel-soft);
}

@media (max-width: 900px) {
  .hero,
  .controls,
  .cards,
  .grid,
  .agent-runtime-metrics,
  .usage-grid,
  .filter-row,
  .notice-form,
  .resource-form {
    grid-template-columns: 1fr;
    display: grid;
  }

  .notice-actions,
  .resource-head-actions,
  .resource-actions {
    display: grid;
  }

  .resource-image-editor,
  .resource-field-wide,
  .resource-actions {
    grid-column: auto;
  }

  button {
    width: 100%;
  }
}
