:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --ink: #18201d;
  --muted: #68716d;
  --line: #dce2df;
  --strong-line: #c4cdc8;
  --green: #167a57;
  --green-dark: #105c43;
  --green-soft: #e7f3ed;
  --amber: #9a6200;
  --amber-soft: #fff4d9;
  --red: #a43d3d;
  --red-soft: #faeaea;
  --shadow: 0 8px 24px rgba(24, 32, 29, 0.07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.app-header h1 { margin: 0; font-size: 20px; font-weight: 680; }
.app-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { min-width: 0; max-width: 68vw; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px 18px; }
.header-actions > a { flex-shrink: 0; white-space: nowrap; }

.browser-status {
  min-width: 0;
  max-width: 390px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.browser-status span:last-child { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca5a1; }
.browser-status.ok .status-dot { background: var(--green); }
.browser-status.warn .status-dot { background: #d58a00; }
.browser-status.error .status-dot { background: var(--red); }

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.control-panel {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 24px;
  overflow-y: auto;
}

.control-panel section + section { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 24px; }
h2, h3, p { overflow-wrap: anywhere; }
.control-panel h2 { margin: 0 0 16px; font-size: 15px; }
.report-section h3 { margin: 0; font-size: 15px; }

label { display: block; margin: 0 0 7px; font-size: 12px; font-weight: 650; color: #3d4742; }
textarea, select, .group-name-field input, .account-form input {
  width: 100%;
  border: 1px solid var(--strong-line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
textarea { min-height: 116px; resize: vertical; padding: 11px 12px; line-height: 1.55; }
select { height: 38px; padding: 0 10px; }
.group-name-field { margin-bottom: 14px; }
.group-name-field input, .account-form input { height: 38px; padding: 0 11px; }
textarea:focus, select:focus, .group-name-field input:focus, .account-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 122, 87, 0.12); }

.proxy-section { margin-top: 0 !important; padding-top: 0 !important; border-top: 0 !important; }
.proxy-section .section-heading { align-items: center; }
.proxy-section .section-heading h2 { margin-bottom: 0; }
.proxy-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 12px; }
.proxy-controls .secondary-button { min-width: 72px; }
.proxy-note { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.proxy-note.error { color: var(--red); }
.network-context { margin-top: 5px; color: var(--muted); font-size: 11px; }

.account-pool-heading { align-items: center; }
.account-pool-heading h2 { margin-bottom: 0; }
.account-pool-list { border-top: 1px solid var(--strong-line); }
.account-pool-empty { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.account-row.disabled { opacity: 0.58; }
.account-identity { min-width: 0; display: grid; gap: 3px; }
.account-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.account-identity span { color: var(--muted); font-size: 10px; line-height: 1.35; }
.account-status.ok { color: var(--green-dark); }
.account-status.warn { color: var(--amber); }
.account-actions { display: flex; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; gap: 2px 7px; max-width: 116px; }
.account-actions .text-button { min-height: 22px; padding: 0; font-size: 10px; }
.account-actions .delete-account-button { color: var(--red); }
.account-form { margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line); }
.account-form > label { margin-top: 11px; }
.account-form #accountCityField { margin-top: 11px; }
.account-form-grid { margin-top: 0; }
.account-form-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.account-form-actions .secondary-button { flex: 1; }

.account-routing { margin: 0 0 16px; padding: 12px; border-left: 3px solid var(--green); background: #f3f8f5; }
.account-routing select { background: var(--surface); }
.account-routing #fixedAccountField { margin-top: 11px; }
.account-routing .proxy-note { margin-bottom: 0; }
.run-account-evidence { color: var(--green-dark) !important; font-weight: 620; }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 18px;
  border: 1px solid var(--strong-line);
  border-radius: 6px;
  overflow: hidden;
}
.mode-button { min-height: 36px; border: 0; background: #f4f6f5; color: var(--muted); cursor: pointer; }
.mode-button + .mode-button { border-left: 1px solid var(--strong-line); }
.mode-button.active { background: var(--surface); color: var(--green-dark); font-weight: 670; box-shadow: inset 0 -2px 0 var(--green); }
.mode-button:focus-visible, .history-tab:focus-visible, .member-item:focus-visible, .run-item summary:focus-visible {
  outline: 2px solid rgba(22, 122, 87, 0.35);
  outline-offset: -2px;
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.field-hint { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.estimate { color: var(--muted); font-size: 12px; margin: 12px 0; }
.submit-actions { display: grid; gap: 4px; }
.submit-help-button { justify-self: start; padding-left: 0; padding-right: 0; font-size: 12px; }
.submit-hint { margin: 7px 0 0; color: var(--red); font-size: 12px; line-height: 1.5; }

.primary-button, .secondary-button, .danger-button, .text-button {
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 12px;
}
.primary-button { width: 100%; color: #fff; background: var(--green); font-weight: 650; }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { color: var(--green-dark); border-color: #b4cec2; background: #f6fbf8; }
.danger-button { color: var(--red); border-color: #e5bcbc; background: #fffafa; }
.text-button { color: var(--green-dark); background: transparent; padding-left: 4px; padding-right: 4px; }
#logoutButton { flex-shrink: 0; white-space: nowrap; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.auth-section { background: var(--amber-soft); margin-left: -24px; margin-right: -24px; padding-left: 24px; padding-right: 24px; }
.auth-section p { color: #6f4c0a; line-height: 1.5; }
.auth-section img { display: block; width: 100%; max-height: 440px; object-fit: contain; margin-top: 12px; border: 1px solid #e5cf9b; background: #fff; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: 14px 0; border: 1px solid #d8c28f; border-radius: 6px; overflow: hidden; }
.auth-tab { min-height: 34px; border: 0; background: transparent; color: #6f4c0a; cursor: pointer; }
.auth-tab + .auth-tab { border-left: 1px solid #d8c28f; }
.auth-tab.active { background: #fff; color: var(--ink); font-weight: 650; }
.phone-auth-panel form + form { margin-top: 12px; }
.phone-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.phone-row input { min-width: 0; height: 38px; border: 1px solid #cbb67f; border-radius: 6px; padding: 0 10px; outline: none; background: #fff; }
.phone-row input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 122, 87, 0.12); }
.phone-row .secondary-button { min-width: 98px; }
.auth-detail { min-height: 18px; margin: 9px 0 0 !important; font-size: 12px; }
.check-auth-button { margin-top: 8px; }
.verification-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.verification-actions .check-auth-button { margin-top: 0; }
.remote-desktop-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.remote-desktop-link[hidden] { display: none !important; }
.account-remote-links { display: contents; }
.account-remote-links[hidden] { display: none; }
.remote-desktop-nav { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; white-space: nowrap; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-shell { width: min(100%, 390px); }
.login-brand { margin-bottom: 24px; }
.login-brand h1 { margin: 0; font-size: 24px; font-weight: 700; }
.login-brand p { margin: 7px 0 0; color: var(--muted); }
.login-panel { border-top: 3px solid var(--green); background: var(--surface); padding: 28px; box-shadow: var(--shadow); }
.login-panel h2 { margin: 0 0 22px; font-size: 17px; }
.login-field { margin-bottom: 16px; }
.login-field input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid var(--strong-line); border-radius: 6px; outline: none; }
.login-field input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 122, 87, 0.12); }
.login-error { min-height: 20px; margin: -4px 0 10px; color: var(--red); font-size: 12px; }

.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-heading h2, .section-heading h3 { margin-bottom: 0; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.history-tabs { display: flex; gap: 18px; margin: 14px 0 10px; border-bottom: 1px solid var(--line); }
.history-tab { min-height: 34px; padding: 0; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.history-tab.active { color: var(--green-dark); border-bottom-color: var(--green); font-weight: 670; }

.job-list { display: grid; gap: 8px; }
.job-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 11px 12px;
  cursor: pointer;
}
.job-item:hover, .job-item.active { border-color: #9fb9ad; background: #f7fbf9; }
.job-item-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 620; }
.job-item-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 7px; color: var(--muted); font-size: 11px; }

.report-panel { padding: 28px clamp(20px, 4vw, 56px) 48px; overflow: auto; }
.empty-state { max-width: 560px; margin: 18vh auto 0; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); font-size: 18px; }

.report-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.report-header h2 { margin: 6px 0 0; font-size: 19px; max-width: 820px; }
.eyebrow { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.report-actions { display: flex; gap: 8px; flex-shrink: 0; }
.export-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; white-space: nowrap; }

.progress-area { margin-top: 20px; }
.progress-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); }
.progress-track { height: 7px; background: #dfe5e2; margin-top: 8px; overflow: hidden; }
.progress-bar { width: 0; height: 100%; background: var(--green); transition: width 250ms ease; }
.error-message { padding: 10px 12px; background: var(--red-soft); color: var(--red); border-left: 3px solid var(--red); }

.metric-strip { display: grid; grid-template-columns: repeat(7, minmax(100px, 1fr)); gap: 1px; border: 1px solid var(--line); background: var(--line); margin-top: 24px; }
.group-metric-strip { grid-template-columns: repeat(6, minmax(100px, 1fr)); }
.metric { background: var(--surface); padding: 15px; min-height: 78px; }
.metric-value { display: block; font-size: 22px; font-weight: 680; }
.metric-label { display: block; color: var(--muted); font-size: 11px; margin-top: 5px; }
.answer-rank, .answer-presence { color: var(--green-dark); font-weight: 650; }

.report-section { margin-top: 32px; }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--strong-line); margin-top: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
.group-domain-ranking-table { min-width: 1380px; }
.group-domain-ranking-table th:not(:last-child),
.group-domain-ranking-table td:not(:last-child) { white-space: nowrap; }
.group-domain-ranking-table th:last-child,
.group-domain-ranking-table td:last-child { min-width: 360px; }
th { text-align: left; color: var(--muted); font-size: 11px; font-weight: 650; background: #eef2f0; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
td { font-size: 12px; line-height: 1.45; }
.domain-name { font-weight: 670; }
.score { font-weight: 700; color: var(--green-dark); }
.tag { display: inline-block; margin: 0 4px 4px 0; padding: 2px 6px; background: #edf1ef; color: #4f5954; border-radius: 3px; font-size: 10px; }
.article-link { color: #1b5f88; text-decoration: none; }
.article-link:hover { text-decoration: underline; }
.method-note { color: var(--muted); font-size: 11px; line-height: 1.5; }

.run-list { display: grid; gap: 8px; margin-top: 12px; }
.run-item { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.run-item summary { cursor: pointer; padding: 11px 12px; display: flex; justify-content: space-between; gap: 12px; }
.run-item-body { border-top: 1px solid var(--line); padding: 12px; }
.run-item-body p { margin: 4px 0; color: var(--muted); font-size: 12px; }
.source-list { margin: 8px 0 0; padding-left: 20px; }
.source-list li { margin: 5px 0; font-size: 12px; }
.raw-answer { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.raw-answer h4 { margin: 0 0 8px; font-size: 12px; }
.raw-answer pre {
  max-height: 520px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  background: #f7f9f8;
  padding: 13px 14px;
  color: #2e3833;
  font: 12px/1.7 "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  user-select: text;
}

.member-list { display: grid; margin-top: 12px; border-top: 1px solid var(--strong-line); }
.member-item {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 10px;
  padding: 13px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.member-item:hover { background: #f7fbf9; }
.member-order { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.member-copy { min-width: 0; display: grid; gap: 5px; }
.member-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.member-copy span { color: var(--muted); font-size: 11px; }
.member-arrow { color: var(--green-dark); font-size: 22px; text-align: right; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: 360px; background: #202824; color: #fff; padding: 11px 14px; border-radius: 6px; box-shadow: var(--shadow); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .control-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .group-metric-strip { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .app-header { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .app-header h1 { font-size: 17px; }
  .header-actions { flex: 1 1 100%; max-width: 100%; justify-content: flex-end; gap: 8px; }
  .browser-status { flex: 1 1 100%; max-width: 100%; }
  .browser-status span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .workspace { min-height: calc(100vh - 72px); }
  .control-panel, .report-panel { padding: 20px 16px; }
  .auth-section { margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 16px; }
  .field-grid { grid-template-columns: 1fr; }
  .proxy-controls { grid-template-columns: 1fr; }
  .report-header { flex-direction: column; }
  .report-actions { width: 100%; }
  .report-actions > * { flex: 1; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .run-item summary { align-items: flex-start; flex-direction: column; }
  .raw-answer pre { max-height: 420px; padding: 11px; }
}
