:root {
  color-scheme: light;
  --bg: #f7f5fa;
  --surface: #ffffff;
  --surface-soft: #faf9fc;
  --sidebar: #25243c;
  --sidebar-soft: #32304d;
  --text: #202033;
  --muted: #8d899a;
  --border: #e7e4eb;
  --primary: #7567d8;
  --primary-hover: #6558c7;
  --primary-soft: #f0edff;
  --green: #67c9a3;
  --amber: #f7c955;
  --red: #ea665f;
  --shadow: 0 4px 14px rgba(40, 36, 61, .07);
  --radius: 6px;
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171620;
  --surface: #22212d;
  --surface-soft: #292734;
  --text: #f1eef6;
  --muted: #aaa6b7;
  --border: #393644;
  --primary-soft: #332f52;
  --shadow: 0 5px 18px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; letter-spacing: 0; }
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.eyebrow { color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: 1.3px; }
.auth-view { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, 44%) 1fr; }
.auth-brand { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: center; padding: 10vw; color: white; background: #282541; }
.auth-brand::after { content: ""; position: absolute; right: -130px; bottom: -150px; width: 440px; height: 440px; border: 80px solid rgba(117, 103, 216, .22); border-radius: 50%; }
.brand-mark { display: grid; place-items: center; width: 58px; height: 58px; margin-bottom: 44px; border-radius: 6px; background: var(--primary); font-weight: 800; }
.auth-brand .eyebrow { color: #aaa1ff; }
.auth-brand h1 { margin: 14px 0; font-size: clamp(30px, 4vw, 48px); line-height: 1.2; }
.auth-brand > p { margin: 0; color: #c6c1d4; font-size: 17px; }
.auth-brand-stats { z-index: 1; display: flex; gap: 52px; margin-top: 80px; }
.auth-brand-stats span { display: grid; gap: 7px; }
.auth-brand-stats strong { font-size: 18px; }
.auth-brand-stats small { color: #aaa5b8; }
.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: min(430px, 100%); }
.auth-heading h2 { margin: 10px 0 8px; font-size: 30px; }
.auth-heading p { margin: 0; color: var(--muted); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: 34px 0 28px; padding: 4px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.auth-tabs button { height: 42px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-weight: 700; }
.auth-tabs button.is-active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.auth-form, .form-field { display: grid; gap: 9px; }
.auth-form { gap: 20px; }
.form-field > span { color: #6c6878; font-weight: 600; }
input { width: 100%; height: 50px; padding: 0 15px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); outline: 0; }
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(117, 103, 216, .12); }
.password-field { position: relative; }
.password-field input { padding-right: 48px; }
.password-field .icon-button { position: absolute; top: 5px; right: 5px; }
.form-error { padding: 12px 14px; color: #c54540; background: rgba(234, 102, 95, .1); border: 1px solid rgba(234, 102, 95, .25); border-radius: var(--radius); }
.email-code-controls { display: flex; align-items: stretch; gap: 12px; }
.email-code-controls input { flex: 1 1 0; min-width: 0; }
.email-code-controls .button { flex: 0 0 auto; padding: 0 14px; font-size: 13px; white-space: nowrap; }
.email-code-controls .button:disabled { cursor: not-allowed; opacity: .6; }
.email-code-status { color: var(--muted); font-size: 12px; line-height: 1.6; }
.email-code-status:empty { display: none; }
.email-code-status.is-error { color: var(--red); }

.button, .icon-button { display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius); font-weight: 700; }
.button { min-height: 44px; padding: 0 20px; border: 1px solid transparent; }
.button-primary { color: white; background: var(--primary); }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { color: var(--text); background: var(--surface); border-color: var(--border); }
.button-block { width: 100%; height: 50px; }
.icon-button { width: 40px; height: 40px; padding: 0; color: var(--muted); background: transparent; border: 0; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; display: flex; flex-direction: column; width: 250px; padding: 24px 18px; color: #dfdbea; background: var(--sidebar); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 34px; }
.sidebar-brand > span:last-child { display: grid; gap: 3px; }
.sidebar-brand small { color: #9994aa; font-size: 11px; }
.sidebar-logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 5px; color: white; background: var(--primary); }
.sidebar-logo svg { display: block; width: 24px; height: 24px; fill: #ffffff; }
.nav-caption { padding: 8px 12px; color: #777388; font-size: 11px; font-weight: 700; letter-spacing: 1px; }
.nav-list { display: grid; gap: 5px; }
.nav-item { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 13px; border-radius: 5px; color: #aaa6b8; font-weight: 600; }
.nav-item:hover, .nav-item.is-active { color: white; background: var(--sidebar-soft); }
.nav-item.is-active { box-shadow: inset 3px 0 var(--primary); }
.nav-icon { display: grid; place-items: center; width: 24px; font-size: 20px; }
.sidebar-bottom { display: grid; gap: 6px; margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-action { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; color: #aaa6b8; background: transparent; border: 0; border-radius: 5px; text-align: left; }
.sidebar-action:hover { color: white; background: var(--sidebar-soft); }
.main-area { min-height: 100vh; margin-left: 250px; }
.topbar { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; height: 78px; padding: 0 32px; background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--border); backdrop-filter: blur(10px); }
.topbar-title { display: flex; align-items: center; gap: 10px; }
.topbar-title small { color: var(--muted); }
.topbar-title h1 { margin: 3px 0 0; font-size: 20px; }
.user-menu { display: flex; align-items: center; gap: 11px; }
.user-menu > div { display: grid; gap: 2px; }
.user-menu small { color: var(--muted); font-size: 12px; }
.user-avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; color: var(--primary); background: var(--primary-soft); font-weight: 800; }
.main-content { padding: 30px 32px 56px; }
.page { display: none; }
.page.is-visible { display: block; }
.section-intro, .panel-header, .repeat-heading, .form-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-intro { margin-bottom: 24px; }
.section-intro h2 { margin: 7px 0 6px; font-size: 26px; }
.section-intro p, .repeat-heading p { margin: 0; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card { display: flex; align-items: center; gap: 16px; min-height: 132px; padding: 22px; }
.stat-card > div:last-child { display: grid; gap: 6px; }
.stat-card span, .stat-card small { color: var(--muted); }
.stat-card strong { font-size: 30px; }
.stat-icon { display: grid; place-items: center; flex: 0 0 46px; width: 46px; height: 46px; border-radius: 5px; font-size: 21px; font-weight: 800; }
.stat-icon.purple { color: var(--primary); background: var(--primary-soft); }
.stat-icon.green { color: #2b9a72; background: rgba(103,201,163,.16); }
.stat-icon.amber { color: #bd8b0b; background: rgba(247,201,85,.18); }
.stat-icon.red { color: #d1524c; background: rgba(234,102,95,.14); }
.panel { padding: 24px; }
.profile-form { max-width: 720px; }
.profile-form .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.profile-form .form-actions { margin-top: 22px; }
.profile-form input[readonly] { color: var(--muted); background: var(--surface-soft); cursor: default; }
.profile-password-dialog { width: min(460px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 8px; padding: 24px; color: var(--text); background: var(--surface); box-shadow: 0 18px 50px rgba(20, 20, 40, .22); }
.profile-password-dialog::backdrop { background: rgba(16, 16, 32, .48); }
.profile-password-dialog .section-intro { display: flex; align-items: center; justify-content: space-between; margin: 0 0 18px; }
.profile-password-dialog .section-intro h2 { margin: 0; }
.profile-password-dialog .form-field { display: grid; gap: 7px; margin-top: 14px; }
.profile-password-new-fields[hidden], .profile-password-dialog button[hidden] { display: none; }
.profile-password-dialog .form-field span { color: var(--muted); font-size: 12px; font-weight: 700; }
.profile-password-dialog input { width: 100%; min-height: 40px; border: 1px solid var(--border); border-radius: 5px; padding: 0 11px; color: var(--text); background: var(--surface); }
.profile-password-dialog small, #profile-password-status { display: block; margin-top: 12px; color: var(--muted); }
.profile-password-dialog .form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
html[data-theme="dark"] .profile-password-dialog { border-color: #3b3b57; background: #24243c; }
html[data-theme="dark"] .profile-password-dialog input { border-color: #3b3b57; color: #eff2f7; background: #24243c; }
.bind-email-description { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.bind-email-dialog .email-code-controls { margin-top: 7px; }
.bind-email-dialog .email-code-controls input { margin: 0; height: 44px; }
.bind-email-dialog .form-error { margin-top: 14px; }
@media (max-width: 640px) { .profile-form .form-grid { grid-template-columns: 1fr; } }
.panel-header { margin-bottom: 20px; }
.panel-header h2 { margin: 6px 0 0; font-size: 19px; }
.table-wrap { overflow-x: auto; }
.task-summary-list { display: grid; gap: 6px; min-width: 180px; }
.task-summary-item { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.task-summary-item strong { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.task-summary-item span { color: var(--muted); font-size: 0.9em; white-space: nowrap; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 13px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--surface-soft); font-size: 13px; font-weight: 700; }
td { max-width: 440px; }
.empty-state { padding: 34px; color: var(--muted); text-align: center; }
.status-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 14px; color: var(--primary); background: var(--primary-soft); font-size: 12px; font-weight: 700; }
.status-badge.status-rejected { color: #b8444c; background: #fff0f1; }
.status-badge.status-completed { color: #237b59; background: #eaf8f1; }
.status-badge.status-submitted_labeled { color: #8b6500; background: #fff7d8; }
.submission-rejection { margin-top: 5px; color: #b8444c; font-size: 11px; line-height: 1.45; }
.submission-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.button-danger { color: #b8444c; background: #fff0f1; border-color: #f1c7cb; }
.button-danger:hover { color: #fff; background: #d1525b; border-color: #d1525b; }

.submission-form { display: grid; gap: 0; padding: 0; overflow: hidden; }
.portal-selection-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 25px 28px 5px; }
.portal-selection-grid { grid-template-columns: minmax(0, 1fr); }
.portal-selection-grid select { width: 100%; height: 46px; }
.task-search { width: 100%; height: 42px; margin-top: 16px; }
.task-options { display: grid; width: 100%; gap: 9px; max-height: 430px; margin-top: 12px; overflow-x: hidden; overflow-y: auto; padding-right: 4px; box-sizing: border-box; }
.task-option { display: grid; width: 100%; grid-template-columns: 18px minmax(0, 1.15fr) minmax(220px, .85fr); align-items: center; gap: 12px; border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; box-sizing: border-box; }
.task-option:hover { border-color: var(--primary); background: var(--primary-soft); }
.task-option input[type="checkbox"] { width: 16px !important; min-width: 16px; height: 16px !important; margin: 0; padding: 0; accent-color: var(--primary); cursor: pointer; }
.task-option-api { display: grid; min-width: 0; gap: 4px; cursor: pointer; }
.task-option-api strong { color: var(--ink); font-size: 13px; overflow-wrap: anywhere; }
.task-option-api small { color: var(--muted); }
.task-option-link { min-width: 0; color: var(--primary); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; text-decoration: none; }
.task-option-value { color: var(--muted); }
.task-option-link:hover { text-decoration: underline; }
.repeat-section { padding: 25px 28px; border-bottom: 1px solid var(--border); }
.repeat-heading { align-items: flex-start; }
.repeat-heading h3 { margin: 0 0 7px; font-size: 17px; }
.repeat-heading p { font-size: 13px; }
.icon-add { display: grid; place-items: center; flex: 0 0 38px; width: 38px; height: 38px; color: white; background: var(--primary); border: 0; border-radius: 5px; font-size: 24px; line-height: 1; }
.repeat-list { display: grid; gap: 11px; margin-top: 18px; }
.repeat-list:empty { margin: 0; }
.repeat-row { display: grid; grid-template-columns: 1fr 38px; gap: 10px; }
.repeat-row input { height: 46px; }
.remove-row { width: 38px; height: 46px; color: var(--muted); background: var(--surface-soft); border: 1px solid var(--border); border-radius: 5px; font-size: 20px; }
.remove-row:hover { color: var(--red); border-color: var(--red); }
.submission-form > .form-error { margin: 22px 28px 0; }
.form-actions { justify-content: flex-end; padding: 22px 28px; }
.toast-region { position: fixed; z-index: 100; right: 22px; bottom: 22px; display: grid; gap: 10px; }
.toast { min-width: 280px; max-width: 400px; padding: 15px 17px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius); box-shadow: 0 12px 34px rgba(0,0,0,.18); }
.toast.error { border-left-color: var(--red); }
.mobile-only { display: none; }
.auth-forgot-password { justify-self: end; padding: 2px 0; border: 0; color: var(--primary); background: transparent; font-size: 13px; cursor: pointer; }
.auth-forgot-password:hover { text-decoration: underline; }
.forgot-password-fields { display: grid; gap: 16px; min-width: 0; padding: 0; margin: 0; border: 0; }
.forgot-password-dialog .form-actions { padding: 16px 0 0; }
.sidebar-backdrop { display: none; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .auth-view { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; z-index: 25; inset: 0; display: block; visibility: hidden; opacity: 0; background: rgba(15,14,23,.5); transition: .2s; }
  .sidebar-backdrop.is-visible { visibility: visible; opacity: 1; }
  .main-area { margin-left: 0; }
  .mobile-only { display: inline-flex; }
  .topbar { height: 70px; padding: 0 18px; }
  .main-content { padding: 24px 16px 40px; }
  .stats-grid { grid-template-columns: 1fr; }
  .section-intro { align-items: flex-start; }
  .user-menu > div { display: none; }
  .panel, .repeat-section { padding: 20px 16px; }
  .portal-selection-grid { grid-template-columns: 1fr; padding: 20px 16px 4px; }
  .task-option { grid-template-columns: 18px minmax(0, 1fr); }
  .task-option-link { grid-column: 2; }
  .submission-form { padding: 0; }
  .form-actions { padding: 18px 16px; }
}
