:root {
  color-scheme: light;
  --ink: #172033;
  --text: #172033;
  --muted: #667085;
  --line: #d8dee9;
  --line-soft: #e8edf3;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-2: #b45309;
  --sidebar: #111827;
  --sidebar-hover: #243044;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

body.auth-locked .sidebar,
body.auth-locked .shell {
  display: none;
}

body:not(.auth-locked) .login-screen {
  display: none;
}

.role-hidden {
  display: none !important;
}

.login-screen {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef2f6;
}

.login-card {
  width: min(100%, 380px);
  display: grid;
  gap: 16px;
  padding: 32px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(23, 32, 51, 0.12);
}

.login-card h1,
.login-card p {
  margin-bottom: 0;
}

.login-brand {
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
}

.login-error {
  min-height: 20px;
  color: #b42318;
  font-size: 14px;
}

.icp-footer {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 18px;
  text-align: center;
  font-size: 13px;
}

.icp-footer a {
  color: #667085;
  text-decoration: none;
}

.icp-footer a:hover {
  color: var(--accent);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 224px;
  overflow: auto;
  background: var(--sidebar);
  color: #fff;
  padding: 22px 16px;
}

.brand {
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 26px;
}

nav {
  display: grid;
  gap: 6px;
}

nav a {
  color: #d1d5db;
  text-decoration: none;
  padding: 9px 11px;
  border-radius: 6px;
  font-size: 14px;
}

nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

nav a.active {
  background: #0f766e;
  color: #fff;
  font-weight: 700;
}

.shell {
  margin-left: 224px;
  width: calc(100% - 224px);
  min-width: 0;
  padding: 24px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: -24px -24px 18px;
  padding: 16px 24px;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 251, 0.96);
  backdrop-filter: blur(8px);
}

.account-tools,
.inline-password-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.inline-password-form input {
  width: 132px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: 28px;
  margin-bottom: 6px;
}

h2 {
  font-size: 18px;
}

.band {
  max-width: 1480px;
  margin: 0 auto 18px;
  padding: 18px 0;
  border-top: 1px solid var(--line-soft);
}

main.shell > section.inactive-section,
main.shell > section[hidden] {
  display: none !important;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
  gap: 18px;
  align-items: start;
}

.three-col {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 340px) minmax(300px, 420px);
  gap: 16px;
  align-items: start;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.setup-guide {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  background: #ffffff;
}

.setup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.setup-head h2 {
  margin: 0 0 4px;
}

.setup-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.setup-step {
  display: grid;
  gap: 5px;
  min-height: 86px;
  padding: 12px;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  background: #f8fafc;
}

.setup-step.done {
  border-color: #99f6e4;
  background: #ecfdf5;
}

.setup-step span {
  width: fit-content;
  padding: 2px 7px;
  border-radius: 999px;
  color: #475569;
  background: #e2e8f0;
  font-size: 12px;
}

.setup-step.done span {
  color: #047857;
  background: #ccfbf1;
}

.setup-step small {
  color: #64748b;
  line-height: 1.5;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.report-grid section {
  min-width: 0;
}

.stats article,
.panel,
.table,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats article {
  padding: 18px;
}

.compact-stats {
  margin: 14px 0;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.compact-stats article {
  padding: 12px;
}

.compact-stats strong {
  font-size: 22px;
}

.stats strong {
  display: block;
  font-size: 30px;
}

.stats span,
.muted,
#current-user {
  color: var(--muted);
}

.panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  min-width: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.toolbar label {
  min-width: 0;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: #344054;
}

input,
select,
button,
textarea {
  width: 100%;
  max-width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

button {
  width: auto;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.toolbar button,
.toolbar .button-link {
  width: 100%;
  min-width: 0;
}

.secondary-link {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

button.small {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 13px;
}

button.danger {
  border-color: #dc2626;
  background: #dc2626;
  color: #fff;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox input {
  width: auto;
  min-height: auto;
}

.empty {
  padding: 16px;
  color: var(--muted);
}

.table {
  overflow: auto;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

td,
th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

#score-list th:first-child,
#score-list td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  min-width: 104px;
  box-shadow: 1px 0 0 var(--line);
}

#score-list th:first-child {
  z-index: 2;
}

#score-list th:nth-child(2),
#score-list td:nth-child(2) {
  position: sticky;
  left: 104px;
  z-index: 1;
  background: #fff;
  min-width: 88px;
  box-shadow: 1px 0 0 var(--line);
}

#score-list th:nth-child(2) {
  z-index: 2;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.card {
  padding: 16px;
  min-width: 0;
}

.review-list {
  display: grid;
  gap: 14px;
}

.review-load-more,
.review-load-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
}

.review-load-more p,
.review-load-state {
  margin: 0;
}

.review-card-horizontal {
  display: grid;
  gap: 12px;
  width: 100%;
  overflow: hidden;
}

.review-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.review-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.review-horizontal-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.82fr) minmax(300px, 1fr) minmax(340px, 1.12fr);
  gap: 14px;
  align-items: start;
}

.review-panel {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.review-panel h4 {
  margin: 0 0 8px;
}

.review-image-panel .wrong-image {
  max-height: 320px;
}

.review-ai-panel p,
.review-generated-panel p {
  line-height: 1.55;
}

.review-actions {
  padding-top: 4px;
}

.generated-review-item {
  display: grid;
  gap: 6px;
}

.generated-pending {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.review-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-weight: 700;
}

.review-select input,
.checkbox input {
  width: auto;
}

.image-preview,
.wrong-image {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.image-preview:not([src]) {
  display: none;
}

.wrong-image {
  margin: 10px 0;
}

.wrong-image-frame {
  margin: 10px 0;
}

.wrong-image-frame .wrong-image {
  margin: 0;
}

.wrong-image-frame figcaption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.generated-image-frame {
  padding: 8px;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  background: #fffbeb;
}

.generated-image-frame figcaption {
  color: #92400e;
  font-weight: 700;
}

.geometry-figure {
  padding: 8px;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  background: #fffbeb;
}

.review-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.review-history {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.timeline {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.timeline summary {
  cursor: pointer;
  font-weight: 700;
}

.timeline p {
  display: grid;
  gap: 2px;
  margin: 10px 0 0;
  padding-left: 10px;
  border-left: 3px solid #bfdbfe;
}

.timeline span,
.timeline em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.review-history h4 {
  margin: 0 0 8px;
}

.review-history p {
  margin: 6px 0;
  color: var(--muted);
}

.wrong-detail {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.wrong-detail summary {
  cursor: pointer;
  font-weight: 700;
}

.ocr-compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.ocr-compare section {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.ocr-compare h4 {
  margin: 0 0 8px;
}

.ocr-compare p {
  margin: 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.detail-grid section {
  min-width: 0;
}

.detail-grid h4 {
  margin: 0 0 8px;
}

.detail-grid p {
  white-space: normal;
  word-break: break-word;
}

.generated-editor {
  display: grid;
  gap: 10px;
  margin: 10px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.generated-editor legend {
  padding: 0 6px;
  color: var(--accent);
  font-weight: 700;
}

.alert {
  display: grid;
  gap: 8px;
  margin: 10px 0;
  padding: 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff7f7;
  color: #7f1d1d;
}

.alert p {
  margin: 0;
}

.notice {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
}

.quality-warning {
  display: grid;
  gap: 8px;
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
}

.quality-warning div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quality-warning span {
  padding: 4px 8px;
  border-radius: 999px;
  background: #ffedd5;
  font-size: 12px;
  font-weight: 700;
}

.import-errors {
  margin-top: 8px;
  color: #b91c1c;
}

.import-error-link {
  min-height: 30px;
  margin-left: 8px;
  padding: 4px 8px;
}

.generated-list {
  margin: 10px 0;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.generated-list p {
  margin: 4px 0;
}

.generated-figure-diagnostics,
.generated-figure-spec {
  margin: 8px 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.generated-figure-diagnostics summary,
.generated-figure-spec summary {
  cursor: pointer;
  font-weight: 700;
}

.figure-diagnostic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.figure-diagnostic-grid span {
  padding: 5px 6px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
}

@media (max-width: 1100px) {
  .review-horizontal-grid {
    grid-template-columns: 1fr;
  }

  .review-card-head {
    display: grid;
  }

  .review-tags {
    justify-content: flex-start;
  }
}

@media (max-width: 1180px) {
  .two-col,
  .three-col {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

.math-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Cambria Math", "STIX Two Math", "Times New Roman", "Microsoft YaHei", serif;
}

.math-editor {
  display: grid;
  gap: 6px;
}

.math-preview {
  padding: 8px 10px;
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
}

.math-preview strong {
  display: block;
  margin-bottom: 4px;
  color: #475569;
  font-size: 12px;
}

.math-text sup,
.math-text sub {
  line-height: 0;
}

.math-frac {
  display: inline-grid;
  grid-template-rows: auto auto;
  margin: 0 2px;
  text-align: center;
  vertical-align: middle;
  line-height: 1.05;
}

.math-frac .num {
  border-bottom: 1px solid currentColor;
  padding: 0 4px 1px;
}

.math-frac .den {
  padding: 1px 4px 0;
}

.math-root {
  display: inline-flex;
  align-items: flex-start;
  gap: 1px;
  vertical-align: middle;
}

.math-root .root-body {
  border-top: 1px solid currentColor;
  padding: 0 3px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions button,
.actions .button-link {
  width: auto;
}

.block-gap {
  margin-top: 16px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e6f4f1;
  color: var(--accent);
  font-size: 12px;
}

.tag.danger {
  background: #fee2e2;
  color: #b91c1c;
}

.tag.warning {
  background: #fef3c7;
  color: #92400e;
}

.tag.geometry {
  background: #fef3c7;
  color: #92400e;
}

.tag.formula {
  background: #dbeafe;
  color: #1d4ed8;
}

.tag.image {
  background: #dcfce7;
  color: #166534;
}

.tag.quality-good {
  background: #dcfce7;
  color: #166534;
}

.tag.quality-warn {
  background: #fef3c7;
  color: #92400e;
}

.generated-risk {
  display: block;
  margin-top: 5px;
  color: #b45309;
  font-size: 12px;
  line-height: 1.35;
}

.secondary {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

@media (max-width: 860px) {
  .sidebar {
    position: static;
    width: auto;
    max-height: none;
  }

  .shell {
    margin-left: 0;
    width: 100%;
    padding: 16px;
  }

  .topbar {
    position: static;
    margin: -16px -16px 16px;
    padding: 14px 16px;
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-grid {
    grid-template-columns: 1fr;
  }

  .cards {
    grid-template-columns: 1fr;
  }
}
