:root {
  --bg: #f5f7fb;
  --card: #fff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #377dff;
  --primary-dark: #2563eb;
  --green: #067647;
  --red: #b42318;
  --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1120px; margin: 0 auto; padding: 24px 20px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.topbar > button { flex-shrink: 0; white-space: nowrap; }
.logo {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #377dff, #7c3aed); color: #fff; font-weight: 800; font-size: 20px;
}
.brand h1 { margin: 0; font-size: 20px; line-height: 1.3; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }

.layout {
  max-width: 1120px; margin: 0 auto; padding: 16px 20px 40px;
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; align-items: start;
}
.side { display: grid; gap: 20px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card-head h2 { margin: 0; }
.form-card { display: grid; gap: 16px; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label, .label-row label { font-weight: 600; font-size: 13px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.label-row a { font-size: 13px; }
.optional { color: var(--muted); font-weight: 400; font-size: 12px; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d0d5dd; border-radius: 8px;
  font: inherit; color: var(--text); background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(55, 125, 255, .15); }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 400; }
.check input { width: auto; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid #d0d5dd; background: #fff;
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { background: #f9fafb; text-decoration: none; }
button:disabled { opacity: .6; cursor: not-allowed; }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.block { width: 100%; padding: 12px; font-size: 15px; }
.ghost { background: transparent; }
.link { border: none; background: none; color: var(--primary); padding: 0; font-weight: 500; }
.link:hover { background: none; text-decoration: underline; }
.icon { padding: 2px 10px; font-size: 20px; line-height: 1; border: none; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: #f2f4f7; border-radius: 10px; padding: 4px; gap: 4px; }
.segmented button { border: none; background: transparent; color: var(--muted); padding: 8px; }
.segmented button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }

.state { padding: 12px; border-radius: 8px; font-size: 13px; word-break: break-word; }
.state--idle { background: #f9fafb; color: var(--muted); }
.state--loading { background: #eef4ff; color: #1d4ed8; }
.state--ok { background: #e9f7ef; color: var(--green); margin-bottom: 12px; }
.state--error { background: #fff0ef; color: var(--red); }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.actions > * { flex: 1; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 14px 0 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-all; }

.history { list-style: none; margin: 12px 0 10px; padding: 0; display: grid; gap: 8px; }
.history li { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: grid; gap: 6px; }
.history .row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.history .title { color: var(--text); font-weight: 600; font-size: 13px; }
.history .url { font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .ops { display: flex; gap: 12px; }
.history .empty { color: var(--muted); text-align: center; border-style: dashed; }

dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 64px); padding: 0;
  border: none; border-radius: var(--radius); box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-body { padding: 4px 20px 20px; }
.dialog-body h3 { font-size: 14px; margin: 16px 0 6px; }
.dialog-body ul, .dialog-body ol { margin: 0; padding-left: 20px; }
.dialog-body pre { background: #f6f8fa; border-radius: 8px; padding: 10px 12px; font-size: 12px; overflow: auto; margin: 6px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: rgba(17, 24, 39, .9); color: #fff; padding: 8px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: all .2s ease; font-size: 13px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { padding-top: 16px; }
}
@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr; }
}
