:root {
  color-scheme: light;
  --background: #f4f7fa;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #d9e1eb;
  --border-strong: #bdc9d8;
  --text: #18212f;
  --muted: #5b6a7e;
  --blue: #1766d6;
  --blue-deep: #124ea8;
  --blue-soft: #e8f1fd;
  --success: #157347;
  --success-soft: #e7f6ed;
  --warning: #805700;
  --warning-soft: #fff4d6;
  --error: #b42318;
  --error-soft: #fdecea;
  --radius-panel: 12px;
  --radius-control: 8px;
  --focus: 0 0 0 3px rgba(23, 102, 214, 0.22);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--background);
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

h1,
h2,
p,
dl,
dd { margin: 0; }

h1 { font-size: 22px; line-height: 1.25; letter-spacing: -0.02em; }
h2 { font-size: 16px; line-height: 1.3; }

.skip-link {
  position: fixed;
  left: 16px;
  top: -60px;
  z-index: 100;
  padding: 10px 14px;
  color: #fff;
  background: var(--blue-deep);
  border-radius: var(--radius-control);
}

.skip-link:focus { top: 12px; }

.app-header {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px clamp(16px, 2.4vw, 34px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.brand-lockup img { flex: none; border-radius: 9px; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: 0.02em; }
.brand-subtitle { color: var(--muted); font-size: 12px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.environment-badge,
.connection-state,
.stage-label {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.environment-badge { color: var(--blue-deep); background: var(--blue-soft); }
.connection-state { color: var(--muted); background: var(--surface-muted); }
.connection-state.is-online { color: var(--success); background: var(--success-soft); }
.connection-state.is-offline { color: var(--error); background: var(--error-soft); }

.global-status {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin: 12px clamp(16px, 2.4vw, 34px) 0;
  padding: 8px 12px;
  border: 1px solid #cbdcf4;
  border-radius: 10px;
  color: var(--blue-deep);
  background: var(--blue-soft);
}

.global-status.status-success { color: var(--success); border-color: #bfe2cd; background: var(--success-soft); }
.global-status.status-warning { color: var(--warning); border-color: #ead397; background: var(--warning-soft); }
.global-status.status-error { color: var(--error); border-color: #efc5bf; background: var(--error-soft); }
.stage-label { padding-inline: 8px; color: inherit; background: rgba(255, 255, 255, 0.68); }

.workspace {
  width: min(100%, 1740px);
  margin: 0 auto;
  padding: 14px clamp(16px, 2.4vw, 34px) 28px;
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(500px, 1fr) minmax(300px, 370px);
  align-items: start;
  gap: 14px;
}

.workspace-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
}

.activity-panel,
.success-panel {
  position: sticky;
  top: 14px;
  max-height: calc(100dvh - 112px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header,
.task-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.panel-header p,
.task-heading p,
.step-heading p,
.settings-content section > p { margin-top: 4px; color: var(--muted); font-size: 12px; }

.activity-log {
  list-style: none;
  margin: 0;
  padding: 4px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.activity-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child { border-bottom: 0; }
.activity-time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.activity-copy strong { display: block; margin-bottom: 3px; font-size: 13px; }
.activity-copy p { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.activity-item[data-level="success"] strong { color: var(--success); }
.activity-item[data-level="warning"] strong { color: var(--warning); }
.activity-item[data-level="error"] strong { color: var(--error); }

.privacy-note {
  margin: auto 12px 12px;
  padding: 12px;
  color: var(--blue-deep);
  background: var(--blue-soft);
  border-radius: 10px;
}

.privacy-note strong { font-size: 12px; }
.privacy-note p { margin-top: 4px; font-size: 11px; }

.task-panel { overflow: hidden; }
.task-heading { padding: 20px 22px 16px; }

.task-step {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.step-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.step-index {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  flex: none;
  color: var(--blue-deep);
  background: var(--blue-soft);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 800;
}

.entry-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(160px, 220px);
  gap: 12px;
}

.field-group { min-width: 0; }
.field-group label { display: block; margin-bottom: 6px; color: #3c4b60; font-size: 12px; font-weight: 700; }
.field-help { margin-top: 6px; color: var(--muted); font-size: 12px; }

input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

input::placeholder { color: #66758a; opacity: 1; }
input:hover { border-color: #91a5bf; }
input:focus { border-color: var(--blue); box-shadow: var(--focus); }
input:disabled { color: #526074; background: #edf1f5; }

.phone-row,
.submit-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.phone-field { flex: 1 1 250px; }
.code-field { flex: 1 1 260px; }
.action-cluster { display: flex; gap: 10px; }

.runtime-line {
  min-height: 24px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease, transform 120ms ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:focus-visible { outline: none; box-shadow: var(--focus); }
.button:disabled { color: #526074; background: #e1e6ed; border-color: #e1e6ed; }

.button-primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.button-primary:hover:not(:disabled) { background: var(--blue-deep); border-color: var(--blue-deep); }
.button-secondary { color: var(--blue-deep); background: var(--blue-soft); border-color: #c9dbf3; }
.button-secondary:hover:not(:disabled) { color: #fff; background: var(--blue-deep); border-color: var(--blue-deep); }
.button-quiet { color: var(--muted); background: var(--surface); border-color: var(--border); }
.button-quiet:hover:not(:disabled) { color: var(--blue-deep); border-color: #9bb5d9; }
.button-danger { color: var(--error); background: var(--surface); border-color: #e7b7b2; }
.button-danger:hover:not(:disabled) { color: #fff; background: var(--error); border-color: var(--error); }
.button-small { min-height: 34px; padding-inline: 12px; font-size: 12px; }

.settings-disclosure { border-bottom: 1px solid var(--border); }
.settings-disclosure > summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 22px;
  color: var(--blue-deep);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.settings-disclosure > summary::-webkit-details-marker { display: none; }
.settings-disclosure > summary::after { content: "展开"; margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 400; }
.settings-disclosure[open] > summary::after { content: "收起"; }
.settings-disclosure > summary:focus-visible { outline: none; box-shadow: inset var(--focus); }

.settings-content { padding: 0 22px 22px; }
.settings-content section { padding: 16px; background: var(--surface-muted); border-radius: 10px; }
.settings-content section + section { margin-top: 12px; }
.settings-grid { margin-top: 14px; display: grid; grid-template-columns: repeat(2, minmax(160px, 1fr)); gap: 12px; }
.settings-grid.two-columns { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
.settings-actions { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-actions p { color: var(--muted); font-size: 12px; }

.task-footer {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 22px;
  color: var(--muted);
  background: var(--surface-muted);
}

.task-footer p { font-size: 12px; }

.text-link { align-self: center; color: var(--blue); font-size: 12px; font-weight: 700; text-decoration: none; }
.text-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.text-link:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.success-list {
  min-height: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.success-record { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.success-record:last-child { border-bottom: 0; }
.success-record-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.phone-copy { padding: 0; color: var(--blue); background: transparent; border: 0; font-size: 15px; font-weight: 800; }
.phone-copy:hover { color: var(--blue-deep); text-decoration: underline; text-underline-offset: 3px; }
.record-delete { padding: 4px 6px; color: var(--muted); background: transparent; border: 0; font-size: 11px; }
.record-delete:hover { color: var(--error); }
.success-meta { margin-top: 7px; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; color: var(--muted); font-size: 11px; }
.password-ok { color: var(--success); font-weight: 700; }
.password-failed { color: var(--warning); font-weight: 700; }

.empty-state { min-height: 250px; display: grid; place-content: center; justify-items: center; padding: 28px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--text); font-size: 15px; }
.empty-state p { max-width: 24ch; margin-top: 5px; font-size: 12px; }
.empty-state-mark { width: 42px; height: 2px; margin-bottom: 16px; background: var(--blue); }

.skeleton-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.skeleton-row span,
.loading-state span {
  display: block;
  width: 76%;
  height: 10px;
  margin: 0 0 8px;
  background: #e4e9f0;
  border-radius: 4px;
  animation: skeleton 1.2s ease-in-out infinite alternate;
}
.skeleton-row span:last-child { width: 52%; }

@keyframes skeleton { to { background: #f1f4f8; } }

.dialog {
  width: min(92vw, 460px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-panel);
}

.dialog::backdrop { background: rgba(19, 31, 48, 0.48); }
.dialog > form,
.dialog > div { padding: 20px; }
.dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog > form > p,
.dialog > div > p { margin-top: 10px; color: var(--muted); }
.dialog-close { min-height: 32px; padding: 0 8px; color: var(--muted); background: transparent; border: 0; font-size: 12px; }
.dialog-close:hover { color: var(--text); }

.slider-track {
  position: relative;
  height: 58px;
  margin-top: 22px;
  overflow: hidden;
  background: var(--blue-soft);
  border: 1px solid #c9dbf3;
  border-radius: var(--radius-control);
  touch-action: none;
}

.slider-target {
  position: absolute;
  right: 14px;
  inset-block: 0;
  display: flex;
  align-items: center;
  color: var(--blue-deep);
  font-size: 12px;
  font-weight: 700;
}

.slider-handle {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 82px;
  height: 48px;
  color: #fff;
  background: var(--blue);
  border: 0;
  border-radius: 6px;
  font-weight: 700;
  touch-action: none;
  will-change: transform;
}

.slider-handle:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.dialog-help { font-size: 12px; }
.dialog-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px; }
.success-phone { display: block; margin-top: 8px; color: var(--blue-deep); font-size: 24px; letter-spacing: 0.02em; }

.toast {
  position: fixed;
  z-index: 120;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 11px 14px;
  color: #fff;
  background: #233247;
  border-radius: var(--radius-control);
  font-weight: 700;
}

.form-error { padding: 10px 12px; color: var(--error); background: var(--error-soft); border-radius: var(--radius-control); }

.mobile-nav { display: none; }

/* Login */
.login-page { min-height: 100dvh; background: #eef3f8; }
.login-shell { min-height: 100dvh; display: grid; grid-template-columns: minmax(420px, 1.15fr) minmax(380px, 0.85fr); }
.login-brand {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: clamp(34px, 6vw, 84px);
  color: #fff;
  background: #123765;
}
.login-brand .brand-subtitle { color: #c6d8ee; }
.login-statement { margin-block: auto; max-width: 690px; padding-block: 72px; }
.login-statement h1 { max-width: 13ch; font-size: clamp(38px, 5.3vw, 72px); line-height: 1.08; letter-spacing: -0.035em; }
.login-statement p { max-width: 46ch; margin-top: 24px; color: #d8e5f4; font-size: 16px; }
.login-facts { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid rgba(255,255,255,.24); }
.login-facts div { padding: 16px 16px 0 0; }
.login-facts dt { color: #b9cee7; font-size: 11px; }
.login-facts dd { margin-top: 5px; font-weight: 700; }

.login-form-side { display: grid; place-items: center; padding: 32px; }
.login-form { width: min(100%, 420px); padding: 34px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-panel); }
.login-form header { margin-bottom: 26px; }
.login-form header h2 { font-size: 24px; }
.login-form header p { margin-top: 7px; color: var(--muted); }
.login-form .field-group + .field-group { margin-top: 18px; }
.login-form .form-error { margin-top: 16px; }
.login-submit { width: 100%; margin-top: 22px; }
.login-notice { margin-top: 18px; color: var(--muted); font-size: 11px; text-align: center; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(220px, 250px) minmax(470px, 1fr) minmax(270px, 310px); }
  .action-cluster { flex-direction: column; }
  .action-cluster .button { width: 100%; }
}

@media (max-width: 980px) {
  body.app-page { padding-bottom: 62px; }
  .workspace { grid-template-columns: 1fr; max-width: 820px; }
  .task-panel { order: 1; }
  .activity-panel { order: 2; }
  .success-panel { order: 3; }
  .activity-panel,
  .success-panel { position: static; max-height: none; }
  .activity-log,
  .success-list { max-height: 420px; }
  .mobile-nav {
    position: fixed;
    z-index: 90;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: 58px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .mobile-nav a { display: grid; place-items: center; color: var(--muted); font-size: 12px; font-weight: 700; text-decoration: none; border-radius: 6px; }
  .mobile-nav a:active,
  .mobile-nav a:focus-visible { color: var(--blue); background: var(--blue-soft); outline: none; }
}

@media (max-width: 760px) {
  .app-header { min-height: 62px; }
  .app-header .brand-subtitle,
  .environment-badge { display: none; }
  .global-status { align-items: flex-start; margin-top: 10px; }
  .workspace { padding-top: 10px; }
  .panel-header,
  .task-heading,
  .task-step { padding-inline: 16px; }
  .entry-grid,
  .settings-grid,
  .settings-grid.two-columns { grid-template-columns: 1fr; }
  .phone-row,
  .submit-row { align-items: stretch; flex-direction: column; }
  .phone-field,
  .code-field { flex: none; width: 100%; }
  .action-cluster { flex-direction: row; }
  .action-cluster .button { flex: 1 1 0; min-width: 0; }
  .submit-row > .button { width: 100%; }
  .runtime-line { align-items: flex-start; flex-direction: column; gap: 4px; }
  .settings-content { padding-inline: 16px; }
  .settings-actions { align-items: stretch; flex-direction: column; }
  .settings-actions .button { width: 100%; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: auto; padding: 24px; }
  .login-statement { padding-block: 44px; }
  .login-statement h1 { font-size: 38px; }
  .login-facts { display: none; }
  .login-form-side { padding: 24px 16px; }
  .login-form { padding: 24px; }
}

@media (max-width: 520px) {
  .brand-lockup img { width: 38px; height: 38px; }
  .brand-name { font-size: 18px; }
  .header-actions { gap: 5px; }
  .global-status { margin-inline: 10px; }
  .workspace { padding-inline: 10px; }
  .task-heading { align-items: center; }
  .action-cluster { flex-direction: column; }
  .dialog-actions { align-items: stretch; flex-direction: column; }
  .dialog-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
