:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-subtle: #eef2f6;
  --text: #111b27;
  --text-soft: #334155;
  --muted: #718096;
  --line: #dfe6ee;
  --line-strong: #cbd5df;
  --blue: #3b82f6;
  --blue-soft: #eaf2ff;
  --success: #0f9f6e;
  --success-soft: #e3f7ef;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  padding: 0 14px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

button:hover {
  border-color: #2563eb;
  background: #2563eb;
}

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

button.secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text-soft);
}

button.secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

button.delete,
button.danger-action {
  border-color: rgba(180, 35, 24, 0.28);
  background: var(--surface);
  color: var(--danger);
}

button.delete:hover,
button.danger-action:hover {
  border-color: rgba(180, 35, 24, 0.45);
  background: var(--danger-soft);
  color: var(--danger);
}

input,
textarea {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

textarea {
  padding-top: 9px;
  padding-bottom: 9px;
  line-height: 1.5;
  resize: vertical;
}

input:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.22);
  outline-offset: 1px;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

[hidden] {
  display: none !important;
}

.login-panel {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-form {
  padding: 0;
}

.app-shell {
  min-height: 100vh;
  width: 100vw;
  max-width: 100vw;
  overflow-x: hidden;
  padding: 18px 22px 28px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(520px, 0.95fr);
  align-items: start;
  gap: 20px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 17px 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar-title {
  min-width: 0;
}

.eyebrow {
  display: block;
  margin-bottom: 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--text);
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 800;
}

h2 {
  font-size: 17px;
  line-height: 1.35;
  font-weight: 800;
}

h3 {
  font-size: 14px;
  line-height: 1.35;
  font-weight: 800;
}

p {
  margin: 0;
}

.topbar p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.connection-panel {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto auto;
  align-items: end;
  gap: 10px;
  min-width: 0;
}

.connection-panel label,
.compact-form label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.connection-panel label span,
.compact-form label span {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}

.service-status {
  grid-column: 1 / -1;
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
}

.service-status.ok {
  color: var(--success);
}

.service-status.error {
  color: var(--danger);
}

.update-layout {
  display: grid;
  grid-template-columns: minmax(410px, 0.82fr) minmax(0, 1.18fr);
  gap: 18px;
  margin-top: 18px;
  min-width: 0;
}

.update-pane {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.update-pane.wide {
  overflow: hidden;
}

.pane-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding: 13px 16px;
}

.pane-title span {
  color: var(--muted);
  font-size: 13px;
}

.compact-form {
  display: grid;
  gap: 14px;
  padding: 14px 16px 16px;
}

.update-card {
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stacked-field {
  grid-column: 1 / -1;
}

.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 700;
}

.check-row input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.form-section {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: var(--surface-muted);
}

.form-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.api-preview-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px 16px 0;
}

.api-preview {
  min-width: 0;
  min-height: 36px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface-muted);
  color: var(--text-soft);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.update-version-editor {
  padding-top: 14px;
}

.update-download-grid textarea {
  min-height: 118px;
}

.update-check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  overflow: auto;
}

.update-app-list {
  max-height: 270px;
}

.update-version-list {
  max-height: 390px;
  border-top: 1px solid var(--line);
}

.data-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: var(--text-soft);
  font-weight: 800;
}

.data-table td.empty {
  padding: 30px 12px;
  color: var(--muted);
  text-align: center;
}

.data-table tr.selectable-row {
  cursor: pointer;
}

.data-table tr.selectable-row:hover td {
  background: #f8fbff;
}

.data-table tr.selected-row td {
  background: var(--blue-soft);
}

.cell-stack {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.cell-stack strong,
.cell-stack span,
.cell-stack code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-stack code {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.muted-text {
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.status.active {
  background: var(--success-soft);
  color: var(--success);
}

.status.inactive {
  background: var(--danger-soft);
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.json-example-card {
  margin: 0 16px 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.json-example {
  max-height: 300px;
  margin: 0;
  overflow: auto;
  padding: 14px 16px;
  background: #0f172a;
  color: #dbeafe;
  font-size: 12px;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 40px));
  transform: translateY(12px);
  border: 1px solid rgba(15, 159, 110, 0.28);
  border-radius: 8px;
  padding: 12px 14px;
  background: #ecfdf5;
  color: #047857;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  border-color: rgba(180, 35, 24, 0.28);
  background: var(--danger-soft);
  color: var(--danger);
}

@media (max-width: 1180px) {
  .topbar,
  .update-layout {
    grid-template-columns: 1fr;
  }

  .connection-panel {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    padding: 14px;
  }

  .connection-panel,
  .form-grid.two-col,
  .form-grid.three-col,
  .update-check-grid,
  .api-preview-row {
    grid-template-columns: 1fr;
  }

  .form-actions {
    justify-content: stretch;
  }

  .form-actions button,
  .connection-panel button {
    width: 100%;
  }
}
