:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6ea;
  --border-strong: #d0d5db;
  --text: #1f2328;
  --text-muted: #656d76;
  --text-faint: #8b949e;
  --accent: #185fa5;
  --accent-soft: #e6f1fb;
  --accent-hover: #14507f;
  --success: #0f6e56;
  --success-soft: #e1f5ee;
  --danger: #a32d2d;
  --danger-soft: #fcebeb;
  --warning: #854f0b;
  --warning-soft: #faeeda;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  flex-shrink: 0;
  position: relative;
}

.logo::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 3px;
  background: #fff;
  clip-path: polygon(0 0, 100% 0, 100% 42%, 22% 42%, 22% 58%, 100% 58%, 100% 100%, 0 100%, 0 58%, 0 42%);
}

.brand-text { min-width: 0; }

.brand-text h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill-ok { background: var(--success-soft); color: var(--success); border-color: #b8e6d6; }
.pill-warn { background: var(--warning-soft); color: var(--warning); border-color: #f0d9a8; }
.pill-bad { background: var(--danger-soft); color: var(--danger); border-color: #f5c6c6; }
.pill-muted { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

/* ------------------------------------------------------------ buttons */

.btn {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: #fff;
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn.ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn.tiny { padding: 5px 11px; font-size: 12px; }

/* --------------------------------------------------------- composer */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 24px 24px;
  gap: 16px;
  min-height: 0;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  flex-shrink: 0;
}

.composer-row {
  display: flex;
  gap: 10px;
}

#url-input {
  flex: 1;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
}

#url-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.check input { accent-color: var(--accent); cursor: pointer; margin: 0; }

.hint { font-size: 12px; color: var(--text-faint); }

.composer-error {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  border: 1px solid #f5c6c6;
}

.composer-error.notice {
  background: rgba(34, 150, 94, .08);
  color: #1c7a4c;
  border-color: #bfe3cf;
}

/* -------------------------------------------------------- mode tabs */

.mode-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-btn {
  border: 1px solid var(--border);
  background: var(--surface, #fff);
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s;
}

.mode-btn:hover { border-color: var(--accent); color: var(--accent); }

.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* 批量面板：读取 / 写入字段分组 + 可增删的动态行 */

.batch-group { margin-top: 14px; }

.group-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 7px;
  flex-wrap: wrap;
}

.group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.field-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.row-select {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.row-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-row .write-role { flex: 0 0 84px; }

.row-remove {
  flex: 0 0 auto;
  padding: 6px 10px;
  line-height: 1;
}

.batch-group .btn.tiny { margin-top: 8px; }

#batch-probe-note { margin-top: 8px; }
#batch-probe-note:empty { display: none; }

#batch-panel .composer-foot { margin-top: 14px; gap: 18px; }

#batch-panel .composer-row:last-of-type { margin-top: 6px; }

/* -------------------------------------------------------- workspace */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}

.sidebar, .viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title { font-size: 13px; font-weight: 500; color: var(--text-muted); }

.task-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-empty {
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  padding: 28px 0;
  margin: 0;
}

.task-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
  transition: background 0.12s;
}

.task-item:hover { background: var(--surface-2); }
.task-item.active { background: var(--accent-soft); border-color: #b5d4f4; }

.task-item-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-faint);
}
.dot.running { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot.done { background: var(--success); }
.dot.failed { background: var(--danger); }
.dot.pending { background: var(--text-faint); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ----------------------------------------------------------- viewer */

.viewer { position: relative; }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-faint);
}

.empty-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--surface-2);
  margin-bottom: 10px;
  position: relative;
}

.empty-icon::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  top: 20px;
  height: 2px;
  background: var(--border-strong);
  box-shadow: 0 6px 0 var(--border-strong), 0 12px 0 var(--border-strong);
}

.empty-title { margin: 0; font-size: 14px; color: var(--text-muted); }
.empty-sub { margin: 0; font-size: 12.5px; }

/* --------------------------------------------------------- progress */

.progress-panel {
  flex: 1;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
}

#progress-percent { color: var(--accent); font-variant-numeric: tabular-nums; }

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.progress-message {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.queue-hint {
  margin: 0 0 8px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  background: var(--surface-2);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.queue-hint b {
  font-weight: 600;
  color: var(--accent);
}

.progress-log {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.9;
  max-height: 220px;
  overflow-y: auto;
}

/* ----------------------------------------------------------- result */

.result-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.tabs { display: flex; gap: 2px; }

.tab {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.viewer-actions { display: flex; gap: 8px; }

.warnings {
  margin: 12px 16px 0;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  border: 1px solid #f0d9a8;
  font-size: 12.5px;
  color: var(--warning);
}

.warnings ul { margin: 0; padding-left: 18px; }
.warnings li { margin: 2px 0; }

.markdown {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px 40px;
  font-size: 14px;
  line-height: 1.75;
  min-height: 0;
}

.markdown h1 {
  font-size: 20px;
  font-weight: 500;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.markdown h2 {
  font-size: 16px;
  font-weight: 500;
  margin: 26px 0 10px;
}

.markdown h3 {
  font-size: 14px;
  font-weight: 500;
  margin: 18px 0 8px;
  color: var(--text-muted);
}

.markdown p { margin: 8px 0; }

.markdown ul, .markdown ol { margin: 8px 0; padding-left: 22px; }
.markdown li { margin: 4px 0; }

.markdown blockquote {
  margin: 12px 0;
  padding: 10px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
}

.markdown blockquote p { margin: 3px 0; }

.markdown code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 4px;
}

.markdown pre {
  background: var(--surface-2);
  padding: 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.markdown pre code { background: none; padding: 0; }

.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}

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

.markdown th {
  background: var(--surface-2);
  font-weight: 500;
  white-space: nowrap;
}

.markdown strong { font-weight: 500; }

.markdown a { color: var(--accent); }

/* ------------------------------------------------------------ stats */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-2);
}

.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.stat-value { font-size: 19px; font-weight: 500; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: 14px; }

.bar-row {
  display: grid;
  grid-template-columns: 130px 1fr 74px;
  align-items: center;
  gap: 10px;
  margin: 7px 0;
  font-size: 13px;
}

.bar-track {
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.bar-value { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------- dialog */

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  max-width: 520px;
  width: calc(100% - 32px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.dialog::backdrop { background: rgba(15, 20, 26, 0.35); }

.dialog-body {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.dialog-body h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

.dialog-body fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px 16px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.dialog-body legend {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 6px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field > span { font-size: 12.5px; color: var(--text-muted); }

.field input {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-note {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.6;
}

.field-note.warn {
  margin-top: 10px;
  padding: 9px 12px;
  background: var(--amber-bg, #fdf6ec);
  border-left: 3px solid var(--amber, #b45309);
  border-radius: 6px;
  color: var(--amber-text, #7a4b0b);
}

.field-note.warn b {
  color: var(--amber, #b45309);
}

.field-note.warn code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  padding: 1px 5px;
  background: rgba(180, 83, 9, .1);
  border-radius: 4px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------------------------------------------------- 登录授权（公网） */

.auth-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.auth-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}

.auth-name {
  font-size: 13px;
  color: var(--text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(246, 247, 249, 0.94);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(31, 35, 40, 0.12);
  padding: 32px 28px;
  text-align: center;
}

.login-card .logo { margin: 0 auto 16px; display: block; }
.login-card h2 { margin: 0 0 10px; font-size: 18px; color: var(--text); }
.login-card p {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.7;
}
.login-card .btn { width: 100%; justify-content: center; }
.login-note { font-size: 12px !important; color: var(--text-faint) !important; margin-top: 18px !important; }

.login-error {
  margin: 16px 0 0 !important;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  text-align: left;
  line-height: 1.6;
}

body.locked { overflow: hidden; }

/* ------------------------------------------------------ responsive */

@media (max-width: 860px) {
  main { padding: 14px; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { max-height: 190px; }
  .composer-row { flex-direction: column; }
  .markdown { padding: 16px 18px 32px; }
}
