:root {
  --orange: #ff6a16;
  --orange-strong: #f25a10;
  --orange-soft: #fff0dc;
  --ink: #111c2f;
  --muted: #778196;
  --line: #f0dcc9;
  --disabled: #f3f5f8;
  --disabled-ink: #a5adbb;
  --surface: #ffffff;
  --page: #faf9f6;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
}

.page-shell {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(520px, 700px);
  align-items: center;
  gap: clamp(52px, 7vw, 120px);
  padding: clamp(44px, 7vw, 96px) clamp(46px, 11vw, 210px);
}

.page-shell::before,
.page-shell::after {
  content: "";
  position: absolute;
  z-index: -1;
  background: rgba(255, 111, 22, 0.055);
  pointer-events: none;
}

.page-shell::before {
  left: 7vw;
  bottom: 1vh;
  width: min(47vw, 780px);
  height: min(62vh, 720px);
  border-radius: 54% 46% 51% 49% / 68% 42% 58% 32%;
  transform: rotate(-18deg);
}

.page-shell::after {
  right: -6vw;
  bottom: -18vh;
  width: min(31vw, 520px);
  height: min(49vh, 510px);
  border-radius: 49% 51% 50% 50% / 57% 56% 44% 43%;
  transform: rotate(28deg);
}

.logo-box,
.icon-box {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.logo-box {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, #ff7d1f 0%, #f25a10 100%);
  box-shadow: 0 12px 22px rgba(242, 90, 16, 0.2);
}

.logo-box svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-card {
  width: min(100%, 700px);
  padding: clamp(44px, 4.1vw, 58px) clamp(48px, 4vw, 50px) 50px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 48px rgba(29, 34, 43, 0.08), 0 1px 0 rgba(17, 28, 47, 0.02);
}

.login-card header {
  margin-bottom: 48px;
}

.login-card h1 {
  margin: 0;
  color: #061126;
  font-size: clamp(34px, 3vw, 42px);
  line-height: 1.12;
  font-weight: 900;
  letter-spacing: 0;
}

.login-card p {
  margin: 10px 0 0;
  color: #a0a9b9;
  font-size: 17px;
  line-height: 1.45;
}

.role-list {
  display: grid;
  gap: 18px;
}

.role-option {
  position: relative;
  width: 100%;
  min-height: 130px;
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: 24px 22px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--ink);
  background: rgba(255, 250, 245, 0.72);
  text-align: left;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.role-option:hover,
.role-option:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255, 106, 22, 0.48);
  box-shadow: 0 16px 30px rgba(255, 106, 22, 0.11);
  outline: none;
}

.role-option.is-active {
  background: rgba(255, 250, 245, 0.88);
}

.role-option.is-disabled {
  border-color: #dfe3ea;
  color: var(--disabled-ink);
  background: var(--disabled);
  cursor: not-allowed;
}

.role-option.is-disabled:hover {
  transform: none;
  box-shadow: none;
}

.icon-box {
  width: 70px;
  height: 70px;
  border-radius: 16px;
  color: var(--orange-strong);
  background: var(--orange-soft);
}

.is-disabled .icon-box {
  color: #98a2b3;
  background: #ffffff;
}

.icon-box svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.role-copy {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.role-copy strong {
  color: #0a1428;
  font-size: 25px;
  line-height: 1.1;
  font-weight: 900;
}

.is-disabled .role-copy strong,
.is-disabled .role-copy span {
  color: #9ca6b6;
}

.role-copy span {
  color: #566174;
  font-size: 16px;
  line-height: 1.4;
  font-weight: 500;
}

.status-pill {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  color: #8a94a5;
  background: #fff;
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .page-shell {
    grid-template-columns: 1fr;
    gap: 38px;
    padding: 44px 24px;
  }

  .login-card {
    justify-self: center;
  }
}

@media (max-width: 640px) {
  .page-shell {
    min-height: 100svh;
    padding: 28px 16px;
  }

  .page-shell::before {
    left: -32vw;
    width: 120vw;
    height: 54vh;
  }

  .page-shell::after {
    right: -40vw;
    bottom: -22vh;
    width: 82vw;
    height: 42vh;
  }

  .logo-box {
    width: 44px;
    height: 44px;
  }

  .login-card {
    padding: 30px 18px 22px;
    border-radius: 22px;
  }

  .login-card header {
    margin-bottom: 28px;
  }

  .login-card h1 {
    font-size: 30px;
  }

  .role-list {
    gap: 14px;
  }

  .role-option {
    min-height: 104px;
    grid-template-columns: 58px minmax(0, 1fr) auto;
    gap: 14px;
    padding: 18px 16px;
    border-radius: 16px;
  }

  .icon-box {
    width: 58px;
    height: 58px;
    border-radius: 14px;
  }

  .icon-box svg {
    width: 30px;
    height: 30px;
  }

  .role-copy strong {
    font-size: 22px;
  }

  .role-copy span {
    font-size: 14px;
  }

  .status-pill {
    min-width: 76px;
    height: 34px;
    padding: 0 12px;
    font-size: 13px;
  }
}

@media (max-width: 420px) {
  .role-option {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .status-pill {
    grid-column: 2;
    justify-self: start;
  }
}

.console-shell {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  overflow: hidden;
  padding: 34px clamp(24px, 7vw, 120px) clamp(42px, 7vw, 88px);
}

.console-shell::before,
.console-shell::after {
  content: "";
  position: absolute;
  z-index: -1;
  background: rgba(255, 111, 22, 0.055);
  pointer-events: none;
}

.console-shell::before {
  left: -10vw;
  top: 18vh;
  width: min(43vw, 720px);
  height: min(58vh, 660px);
  border-radius: 54% 46% 51% 49% / 63% 43% 57% 37%;
  transform: rotate(-22deg);
}

.console-shell::after {
  right: -8vw;
  bottom: -18vh;
  width: min(36vw, 560px);
  height: min(52vh, 540px);
  border-radius: 49% 51% 50% 50% / 57% 56% 44% 43%;
  transform: rotate(22deg);
}

.console-topbar {
  width: min(100%, 1320px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.console-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin-right: auto;
  color: var(--orange-strong);
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(240, 220, 201, 0.95);
  border-radius: 999px;
  color: #566174;
  background: rgba(255, 255, 255, 0.75);
  font-size: 15px;
  font-weight: 700;
  transition: border-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.back-link:hover,
.back-link:focus-visible {
  border-color: rgba(255, 106, 22, 0.42);
  color: var(--orange-strong);
  box-shadow: 0 12px 24px rgba(255, 106, 22, 0.1);
  outline: none;
}

.console-kicker {
  margin: 0 0 16px;
  color: var(--orange-strong);
  font-size: 18px;
  font-weight: 900;
}

.console-shell-modules {
  display: flex;
  flex-direction: column;
}

.console-shell-modules .console-modules-stack {
  width: 100%;
  margin-block: auto;
  padding-block: clamp(20px, 4vh, 52px);
  display: grid;
  gap: 22px;
}

.module-grid {
  width: min(100%, 1320px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.module-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 20px 22px;
  border: 1px solid rgba(240, 220, 201, 0.95);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 30px rgba(29, 34, 43, 0.05);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.module-card:hover,
.module-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255, 106, 22, 0.52);
  box-shadow: 0 20px 40px rgba(255, 106, 22, 0.12);
  outline: none;
}

.module-card-primary {
  border-color: rgba(255, 138, 61, 0.42);
  background: linear-gradient(135deg, rgba(255, 250, 244, 0.98) 0%, rgba(255, 255, 255, 0.96) 62%);
  box-shadow: 0 18px 36px rgba(242, 90, 16, 0.1);
}

.module-card-locked {
  color: var(--disabled-ink);
  background: #f4f6f9;
  cursor: not-allowed;
}

.module-card-locked:hover {
  transform: none;
  border-color: rgba(223, 227, 234, 0.95);
  box-shadow: 0 14px 30px rgba(29, 34, 43, 0.05);
}

.module-card-locked .module-icon {
  color: #98a2b3;
  background: #fff;
}

.module-card-locked .module-copy strong {
  color: #9ca6b6;
}

.module-icon {
  display: inline-grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 16px;
  color: var(--orange-strong);
  background: var(--orange-soft);
  flex: 0 0 auto;
}

.module-card-primary .module-icon {
  color: #fff;
  background: linear-gradient(135deg, #ff7d1f 0%, #f25a10 100%);
  box-shadow: 0 12px 22px rgba(242, 90, 16, 0.22);
}

.module-icon svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.module-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.module-copy strong {
  color: #071226;
  font-size: clamp(19px, 1.6vw, 22px);
  line-height: 1.3;
  font-weight: 900;
}

.module-copy small {
  color: #5f6a7c;
  font-size: 13.5px;
  line-height: 1.5;
  font-weight: 500;
}

.module-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: end;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  color: #fff;
  background: var(--orange-strong);
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 12px 24px rgba(242, 90, 16, 0.18);
}

.module-card:not(.module-card-primary) .module-action {
  color: var(--orange-strong);
  background: var(--orange-soft);
  box-shadow: none;
}

.module-action-locked {
  color: #8a94a5;
  background: #fff;
  box-shadow: none;
}

.module-tools {
  width: min(100%, 1320px);
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

.module-tools-title {
  margin: 0;
  padding-left: 4px;
  color: #6b7688;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.tool-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 24px;
  border: 1px solid rgba(240, 220, 201, 0.95);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 30px rgba(29, 34, 43, 0.05);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.tool-card:hover,
.tool-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255, 106, 22, 0.52);
  box-shadow: 0 20px 40px rgba(255, 106, 22, 0.12);
  outline: none;
}

.tool-icon {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  color: var(--orange-strong);
  background: var(--orange-soft);
}

.tool-icon svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-copy {
  display: grid;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.tool-copy strong {
  color: #071226;
  font-size: 19px;
  font-weight: 900;
}

.tool-copy small {
  color: #5f6a7c;
  font-size: 13px;
  line-height: 1.5;
}

.tool-action {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  color: var(--orange-strong);
  background: var(--orange-soft);
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .console-shell {
    padding: 26px 18px 44px;
  }

  .console-shell-modules .console-modules-stack {
    margin-block: 0;
    padding-block: 28px 48px;
  }

  .console-topbar {
    align-items: flex-start;
  }

  .console-brand {
    font-size: 21px;
  }

  .module-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
}

@media (max-width: 520px) {
  .console-brand {
    gap: 10px;
    font-size: 18px;
  }

  .back-link {
    min-height: 38px;
    padding: 0 12px;
    font-size: 14px;
  }

  .module-card {
    min-height: 96px;
    gap: 12px;
    padding: 16px 14px;
    border-radius: 16px;
  }

  .module-icon {
    width: 46px;
    height: 46px;
    border-radius: 13px;
  }

  .module-icon svg {
    width: 24px;
    height: 24px;
  }

  .module-copy strong {
    font-size: 17px;
  }

  .module-copy small {
    font-size: 12.5px;
  }

  .module-action {
    min-height: 36px;
    padding: 0 14px;
    font-size: 13px;
  }

  .tool-card {
    gap: 12px;
    padding: 14px 16px;
    border-radius: 16px;
  }

  .tool-icon {
    width: 48px;
    height: 48px;
    border-radius: 13px;
  }

  .tool-icon svg {
    width: 26px;
    height: 26px;
  }

  .tool-copy strong {
    font-size: 17px;
  }

  .tool-copy small {
    display: none;
  }

  .tool-action {
    min-height: 36px;
    padding: 0 14px;
    font-size: 13px;
  }
}

.grading-shell {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  padding: 34px clamp(18px, 5vw, 90px) 56px;
  overflow-x: hidden;
}

.grading-shell::before,
.grading-shell::after {
  content: "";
  position: absolute;
  z-index: -1;
  background: rgba(255, 111, 22, 0.05);
  pointer-events: none;
}

.grading-shell::before {
  left: -16vw;
  top: 16vh;
  width: min(46vw, 720px);
  height: min(56vh, 660px);
  border-radius: 54% 46% 51% 49% / 63% 43% 57% 37%;
  transform: rotate(-20deg);
}

.grading-shell::after {
  right: -12vw;
  bottom: -24vh;
  width: min(42vw, 620px);
  height: min(56vh, 570px);
  border-radius: 49% 51% 50% 50% / 57% 56% 44% 43%;
  transform: rotate(24deg);
}

.grading-header {
  width: min(100%, 1420px);
  margin: 54px auto 30px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.grading-header > div {
  max-width: 840px;
}

.grading-header h1 {
  margin: 0;
  color: #111c2f;
  font-size: clamp(34px, 4vw, 54px);
  line-height: 1.14;
  font-weight: 900;
  letter-spacing: 0;
}

.grading-header p:not(.console-kicker) {
  margin: 16px 0 0;
  color: #647084;
  font-size: clamp(17px, 1.5vw, 21px);
  line-height: 1.58;
  font-weight: 500;
}

.header-action-button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 46px;
}

.header-action-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.grading-layout {
  width: min(100%, 1420px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: start;
}

.grading-main {
  display: grid;
  gap: 20px;
}

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

.upload-tile {
  position: relative;
  min-height: 116px;
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: 22px;
  border: 1px dashed rgba(255, 106, 22, 0.42);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.88);
  cursor: pointer;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.upload-tile:hover,
.upload-tile:focus-within {
  transform: translateY(-2px);
  border-color: rgba(255, 106, 22, 0.75);
  box-shadow: 0 16px 30px rgba(255, 106, 22, 0.1);
}

.upload-tile input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-icon {
  display: inline-grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 16px;
  color: var(--orange-strong);
  background: var(--orange-soft);
}

.upload-icon svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-tile strong {
  display: block;
  color: #111c2f;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 900;
}

.upload-tile small {
  display: block;
  min-width: 0;
  margin-top: 8px;
  color: #7b8597;
  font-size: 14px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.crop-panel,
.pair-toolbar,
.pair-list-panel,
.history-panel {
  border: 1px solid rgba(240, 220, 201, 0.9);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 38px rgba(29, 34, 43, 0.06);
}

.crop-panel {
  overflow: hidden;
}

.crop-panel header,
.pair-list-panel header,
.history-panel header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid rgba(240, 220, 201, 0.72);
}

.crop-panel h2,
.pair-list-panel h2,
.history-panel h2 {
  margin: 0;
  color: #111c2f;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 900;
}

.crop-panel p,
.history-panel p {
  margin: 7px 0 0;
  color: #798397;
  font-size: 14px;
  line-height: 1.45;
}

.crop-panel header > span,
.pair-list-panel header > span {
  flex: 0 0 auto;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border-radius: 999px;
  color: #8a94a5;
  background: #f5f7fa;
  font-size: 13px;
  font-weight: 800;
}

.crop-panel header > span.is-ready {
  color: var(--orange-strong);
  background: var(--orange-soft);
}

.crop-stage {
  position: relative;
  height: min(50vh, 520px);
  min-height: 360px;
  display: grid;
  place-items: center;
  overflow: auto;
  background: #f7f8fa;
  user-select: none;
  touch-action: none;
}

.crop-stage img {
  display: none;
  max-width: none;
  width: min(100%, 720px);
  height: auto;
  pointer-events: none;
}

.crop-stage.has-image {
  display: block;
  cursor: crosshair;
}

.crop-stage.has-image img {
  display: block;
}

.crop-empty {
  color: #9ca6b6;
  font-size: 16px;
  font-weight: 700;
}

.crop-stage.has-image .crop-empty {
  display: none;
}

.selection-box {
  position: absolute;
  border: 2px solid var(--orange);
  background: rgba(255, 106, 22, 0.16);
  box-shadow: 0 0 0 9999px rgba(17, 28, 47, 0.2);
  pointer-events: none;
}

.pair-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px;
}

.pair-toolbar strong {
  display: block;
  color: #111c2f;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 900;
}

.pair-toolbar span {
  display: block;
  margin-top: 7px;
  color: #798397;
  font-size: 14px;
  line-height: 1.45;
}

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

.primary-button,
.ghost-button,
.text-button {
  border: 0;
  border-radius: 999px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  min-height: 42px;
  padding: 0 18px;
  color: #fff;
  background: var(--orange-strong);
  box-shadow: 0 14px 26px rgba(242, 90, 16, 0.18);
}

.primary-button:disabled {
  color: #9ca6b6;
  background: #edf0f4;
  box-shadow: none;
  cursor: not-allowed;
}

.ghost-button {
  min-height: 42px;
  padding: 0 16px;
  color: #566174;
  background: #f5f7fa;
}

.text-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--orange-strong);
  background: transparent;
}

.pair-list,
.history-list {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.pair-item {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
  border: 1px solid #eceff3;
  border-radius: 14px;
  background: #fafbfc;
}

.pair-preview {
  min-width: 0;
}

.pair-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #e5e8ee;
  background: #fff;
}

.pair-preview span {
  display: block;
  margin-top: 8px;
  color: #6b7688;
  font-size: 13px;
  font-weight: 800;
}

.history-panel {
  position: sticky;
  top: 24px;
  overflow: hidden;
}

.grading-history-panel {
  position: static;
}

.history-list {
  max-height: calc(100vh - 240px);
  overflow: auto;
}

.grading-history-list {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  max-height: none;
}

.history-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid #eceff3;
  border-radius: 14px;
  background: #fafbfc;
}

.history-item img {
  width: 76px;
  height: 58px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #e5e8ee;
  background: #fff;
}

.history-item strong {
  display: block;
  min-width: 0;
  color: #111c2f;
  font-size: 14px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item span {
  display: block;
  margin-top: 5px;
  color: #8791a2;
  font-size: 12px;
  line-height: 1.35;
}

.ai-history-item {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 10px;
}

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

.history-images img,
.history-image-empty {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #e5e8ee;
  background: #fff;
}

.history-image-empty {
  display: grid;
  place-items: center;
  color: #98a2b3;
  font-size: 12px;
  font-weight: 800;
}

.history-content {
  min-width: 0;
}

.history-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.history-title-row strong {
  color: var(--orange-strong);
  font-size: 18px;
  line-height: 1.2;
  white-space: normal;
}

.history-title-row span {
  flex: 0 0 auto;
  margin-top: 2px;
}

.history-meta {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}

.history-meta div {
  min-width: 0;
}

.history-meta dt {
  color: #4f5a6c;
  font-size: 12px;
  font-weight: 900;
}

.history-meta dd {
  min-width: 0;
  margin: 3px 0 0;
  color: #6b7688;
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-content p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: #5f6a7c;
  font-size: 13px;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  white-space: pre-line;
}

.grading-history-list .history-meta dd {
  white-space: pre-line;
  overflow: visible;
  text-overflow: clip;
}

.ai-history-summary {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.ai-history-summary p {
  margin: 8px 0 0;
  color: #5f6a7c;
  font-size: 13px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-history-summary small {
  display: block;
  margin-top: 5px;
  color: #8791a2;
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-detail-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
  white-space: nowrap;
}

.has-history-modal {
  overflow: hidden;
}

.history-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  padding: 28px;
}

.history-modal.is-open {
  display: grid;
  place-items: center;
}

.history-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 28, 47, 0.42);
}

.history-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  max-height: min(86vh, 820px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(240, 220, 201, 0.95);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 32px 80px rgba(17, 28, 47, 0.22);
}

.history-modal-dialog > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid rgba(240, 220, 201, 0.72);
}

.history-modal-dialog h2,
.history-modal-dialog h3 {
  margin: 0;
  color: #111c2f;
  font-weight: 900;
}

.history-modal-dialog h2 {
  font-size: 22px;
  line-height: 1.25;
}

.history-modal-dialog header p {
  margin: 7px 0 0;
  color: #8791a2;
  font-size: 13px;
  font-weight: 800;
}

.history-modal-close {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #566174;
  background: #f5f7fa;
  cursor: pointer;
}

.history-modal-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-modal-body {
  display: grid;
  gap: 14px;
  padding: 18px;
  overflow: auto;
}

.history-modal-score,
.history-modal-section,
.history-modal-images article {
  border: 1px solid #eceff3;
  border-radius: 14px;
  background: #fafbfc;
}

.history-modal-score {
  padding: 18px;
}

.history-modal-score span {
  color: #6b7688;
  font-size: 13px;
  font-weight: 900;
}

.history-modal-score strong {
  display: block;
  margin-top: 8px;
  color: var(--orange-strong);
  font-size: 34px;
  line-height: 1.1;
  font-weight: 900;
}

.history-modal-score small {
  display: block;
  margin-top: 8px;
  color: #7b8597;
  font-size: 13px;
  font-weight: 800;
}

.history-modal-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.history-modal-images article,
.history-modal-section {
  padding: 16px;
}

.history-modal-images h3,
.history-modal-section h3 {
  margin-bottom: 10px;
  font-size: 16px;
  line-height: 1.35;
}

.history-modal-images img,
.history-modal-image-empty {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid #e5e8ee;
  border-radius: 12px;
  background: #fff;
}

.history-modal-image-empty {
  display: grid;
  place-items: center;
  color: #98a2b3;
  font-size: 14px;
  font-weight: 800;
}

.history-modal-images p,
.history-modal-section p,
.history-modal-section li {
  color: #5f6a7c;
  font-size: 14px;
  line-height: 1.65;
}

.history-modal-images p {
  margin: 10px 0 0;
  overflow-wrap: anywhere;
}

.history-modal-section p {
  margin: 0;
  white-space: pre-line;
}

.history-modal-section ul {
  margin: 0;
  padding-left: 20px;
}

.empty-text {
  margin: 0;
  padding: 18px;
  color: #9ca6b6;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
}

.ai-review-header {
  margin-bottom: 24px;
}

.ai-review-layout {
  width: min(100%, 1420px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  align-items: start;
}

.ai-review-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.ai-panel,
.ai-result-panel {
  border: 1px solid rgba(240, 220, 201, 0.9);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 38px rgba(29, 34, 43, 0.06);
  overflow: hidden;
}

.ai-panel:nth-child(3) {
  grid-column: 1 / -1;
}

.ai-panel header,
.ai-result-panel header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid rgba(240, 220, 201, 0.72);
}

.ai-panel h2,
.ai-result-panel h2 {
  margin: 0;
  color: #111c2f;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 900;
}

.ai-panel p,
.ai-result-panel p {
  margin: 7px 0 0;
  color: #798397;
  font-size: 14px;
  line-height: 1.45;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 18px 18px 0;
  padding: 5px;
  border-radius: 14px;
  background: #f4f6f9;
}

.segment-button {
  min-height: 38px;
  border: 0;
  border-radius: 10px;
  color: #6b7688;
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}

.segment-button.is-active {
  color: var(--orange-strong);
  background: #fff;
  box-shadow: 0 8px 18px rgba(29, 34, 43, 0.08);
}

.mode-panel {
  display: none;
  padding: 16px 18px 0;
}

.mode-panel.is-active {
  display: block;
}

.saved-paper-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
}

.saved-paper-card {
  width: 100%;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid #eceff3;
  border-radius: 14px;
  color: inherit;
  background: #fafbfc;
  text-align: left;
  cursor: pointer;
}

.saved-paper-card.is-active {
  border-color: rgba(255, 106, 22, 0.64);
  background: #fff7ef;
}

.saved-paper-card img {
  width: 78px;
  height: 58px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #e5e8ee;
  background: #fff;
}

.saved-paper-card strong,
.selected-preview strong {
  display: block;
  min-width: 0;
  color: #111c2f;
  font-size: 14px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-paper-card small,
.selected-preview span {
  display: block;
  margin-top: 5px;
  color: #8791a2;
  font-size: 12px;
  line-height: 1.35;
}

.compact-upload {
  min-height: 96px;
  margin: 0;
}

.selected-preview {
  min-height: 174px;
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin: 18px;
  padding: 12px;
  border: 1px solid #eceff3;
  border-radius: 16px;
  background: #fafbfc;
}

.selected-preview:has(.empty-text) {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
}

.selected-preview img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid #e5e8ee;
  border-radius: 12px;
  background: #fff;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(160px, 220px);
  gap: 16px;
  padding: 18px 18px 0;
}

.field-control {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.settings-grid .field-control {
  padding: 0;
}

.field-control span {
  color: #4f5a6c;
  font-size: 14px;
  font-weight: 900;
}

.field-control input,
.field-control textarea,
.field-control select,
.scan-row select {
  width: 100%;
  border: 1px solid #dde3ec;
  border-radius: 12px;
  color: #111c2f;
  background: #fff;
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.field-control input,
.field-control select,
.scan-row select {
  min-height: 44px;
  padding: 0 13px;
}

.field-control textarea {
  resize: vertical;
  min-height: 140px;
  padding: 12px 13px;
  line-height: 1.6;
}

.field-control input:focus,
.field-control textarea:focus,
.field-control select:focus,
.scan-row select:focus {
  border-color: rgba(255, 106, 22, 0.64);
  box-shadow: 0 0 0 3px rgba(255, 106, 22, 0.12);
}

.batch-dashboard {
  width: min(100%, 1500px);
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.batch-panel {
  border: 1px solid #e4e7ec;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 20px rgba(29, 34, 43, 0.04);
  overflow: hidden;
}

.batch-panel > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid #edf0f4;
}

.batch-panel h2,
.batch-panel h3 {
  margin: 0;
  color: #111c2f;
  font-weight: 900;
}

.batch-panel h2 {
  font-size: 18px;
  line-height: 1.25;
}

.batch-panel h3 {
  font-size: 15px;
}

.batch-panel p {
  margin: 5px 0 0;
  color: #798397;
  font-size: 13px;
  line-height: 1.45;
}

.batch-shell .primary-button {
  border-radius: 8px;
  background: #5e6ad2;
  box-shadow: none;
}

.batch-shell .primary-button:hover {
  background: #4f5dc6;
}

.batch-shell .ghost-button {
  border: 1px solid #dde3ec;
  border-radius: 8px;
  background: #fff;
}

.batch-shell .field-control input,
.batch-shell .field-control textarea,
.batch-shell .field-control select,
.batch-shell .scan-row select {
  border-radius: 8px;
  font-size: 14px;
}

.batch-shell .field-control input,
.batch-shell .field-control select,
.batch-shell .scan-row select {
  min-height: 38px;
}

.setup-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 18px 0;
}

.setup-metric {
  padding: 12px;
  border: 1px solid #edf0f4;
  border-radius: 10px;
  background: #fafbfc;
}

.setup-metric span {
  display: block;
  color: #798397;
  font-size: 12px;
  font-weight: 800;
}

.setup-metric strong {
  display: block;
  margin-top: 4px;
  color: #111c2f;
  font-size: 24px;
  line-height: 1;
  font-weight: 900;
}

.setup-tabs {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 4px;
  margin: 14px 18px 0;
  padding: 4px;
  border: 1px solid #edf0f4;
  border-radius: 10px;
  background: #f6f8fb;
}

.setup-tab {
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  color: #667085;
  background: transparent;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.setup-tab.is-active {
  color: #111c2f;
  background: #fff;
  box-shadow: 0 1px 3px rgba(29, 34, 43, 0.08);
}

.setup-editor {
  padding: 14px 18px 18px;
}

.setup-form {
  display: none;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.setup-form.is-active {
  display: grid;
}

.setup-form-question {
  grid-template-columns: 1.2fr 0.8fr 0.7fr 1fr 1.2fr minmax(220px, 1.4fr) auto;
}

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

.compact-form,
.inline-form {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 12px;
  border: 1px solid #eceff3;
  border-radius: 10px;
  background: #fafbfc;
}

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

.compact-form-wide {
  grid-column: 1 / -1;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.compact-form .field-control,
.inline-form .field-control,
.template-toolbar .field-control,
.batch-runbar .field-control {
  padding: 0;
}

.compact-form button {
  align-self: end;
}

.setup-form:not(.is-active) {
  display: none;
}

.field-span-2 {
  grid-column: span 2;
}

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

.batch-lists > div {
  display: grid;
  gap: 10px;
}

.mini-list {
  display: grid;
  gap: 10px;
}

.horizontal-list {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  padding: 16px 18px 18px;
}

.mini-item {
  min-width: 0;
  padding: 12px;
  border: 1px solid #eceff3;
  border-radius: 10px;
  background: #fafbfc;
}

.mini-item strong,
.scan-row span {
  display: block;
  color: #111c2f;
  font-size: 14px;
  line-height: 1.35;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.mini-item span {
  display: block;
  margin-top: 5px;
  color: #798397;
  font-size: 12px;
  line-height: 1.45;
}

.template-toolbar,
.batch-actions-row,
.batch-runbar {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.template-toolbar {
  grid-template-columns: minmax(180px, 240px) minmax(220px, 320px) minmax(180px, 240px) auto;
  align-items: end;
}

.template-stage {
  position: relative;
  min-height: 380px;
  margin: 0 18px 18px;
  overflow: auto;
  border: 1px solid #dde3ec;
  border-radius: 10px;
  background: #f6f8fb;
}

.template-stage img {
  display: none;
  max-width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.template-stage img.is-visible {
  display: block;
}

.template-stage .crop-empty {
  position: absolute;
  inset: 0;
}

.selection-box {
  position: absolute;
  border: 2px solid var(--orange-strong);
  background: rgba(255, 106, 22, 0.14);
  pointer-events: none;
}

.batch-actions-row {
  grid-template-columns: minmax(0, 1fr) minmax(240px, 340px);
  align-items: stretch;
}

.inline-form {
  grid-template-columns: minmax(180px, 240px) minmax(220px, 1fr) auto;
  align-items: end;
}

.batch-runbar {
  grid-template-columns: minmax(200px, 1fr) repeat(3, auto) minmax(180px, auto);
  align-items: end;
  padding-top: 0;
}

.batch-runbar > span {
  align-self: center;
  color: #6b7688;
  font-size: 13px;
  font-weight: 800;
}

.scan-list {
  display: grid;
  gap: 10px;
  padding: 0 18px 18px;
}

.scan-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(170px, 260px);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #eceff3;
  border-radius: 10px;
  background: #fafbfc;
}

.progress-track {
  height: 10px;
  margin: 18px 18px 0;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0f4;
}

.progress-track > div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--orange-strong);
  transition: width 180ms ease;
}

.result-table-wrap {
  padding: 18px;
  overflow: auto;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.result-table th,
.result-table td {
  padding: 12px;
  border-bottom: 1px solid #eceff3;
  color: #4f5a6c;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
  vertical-align: top;
}

.result-table th {
  color: #111c2f;
  font-weight: 900;
  background: #fafbfc;
}

.result-row-error td {
  color: #9f2d20;
  background: #fff6f4;
}

@media (max-width: 980px) {
  .setup-summary,
  .batch-form-grid,
  .batch-lists,
  .batch-actions-row,
  .inline-form,
  .template-toolbar,
  .batch-runbar {
    grid-template-columns: 1fr;
  }

  .compact-form,
  .compact-form-wide,
  .setup-form-question {
    grid-template-columns: 1fr;
  }

  .field-span-2 {
    grid-column: auto;
  }

  .scan-row {
    grid-template-columns: 1fr;
  }
}

.ai-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px 18px;
}

.ai-actions span {
  color: #798397;
  font-size: 13px;
  font-weight: 800;
}

.ai-result-panel {
  position: sticky;
  top: 24px;
}

.ai-result {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.ai-detail-panel {
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.ai-detail-panel .ai-result {
  min-height: 240px;
  overflow: auto;
}

.history-detail-preview img,
.history-detail-preview .history-modal-image-empty {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid #e5e8ee;
  border-radius: 12px;
  background: #fff;
}

.ai-score-card,
.ai-result-card {
  border: 1px solid #eceff3;
  border-radius: 14px;
  background: #fafbfc;
}

.ai-score-card {
  padding: 18px;
}

.ai-score-card span {
  color: #6b7688;
  font-size: 13px;
  font-weight: 900;
}

.ai-score-card strong {
  display: block;
  margin-top: 8px;
  color: var(--orange-strong);
  font-size: 34px;
  line-height: 1.1;
  font-weight: 900;
}

.ai-score-card small {
  display: block;
  margin-top: 8px;
  color: #7b8597;
  font-size: 13px;
  font-weight: 800;
}

.ai-result-card {
  padding: 16px;
}

.ai-result-card.is-error {
  border-color: rgba(210, 73, 54, 0.35);
  background: #fff6f4;
}

.ai-result-card h3 {
  margin: 0 0 10px;
  color: #111c2f;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 900;
}

.ai-result-card p,
.ai-result-card li,
.ai-result-card pre {
  color: #5f6a7c;
  font-size: 14px;
  line-height: 1.65;
}

.ai-result-card p {
  margin: 0;
}

.history-detail-preview p {
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.ai-result-card ul {
  margin: 0;
  padding-left: 20px;
}

.ai-result-card pre {
  max-height: 280px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
}

@media (max-width: 1180px) {
  .grading-layout {
    grid-template-columns: 1fr;
  }

  .ai-review-layout {
    grid-template-columns: 1fr;
  }

  .history-panel {
    position: static;
  }

  .ai-result-panel {
    position: static;
  }

  .history-list {
    max-height: none;
  }
}

@media (max-width: 820px) {
  .upload-grid,
  .crop-grid {
    grid-template-columns: 1fr;
  }

  .pair-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .pair-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .grading-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .ai-review-form {
    grid-template-columns: 1fr;
  }

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

  .selected-preview {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .grading-shell {
    padding: 26px 14px 38px;
  }

  .grading-header {
    margin-top: 44px;
  }

  .grading-header h1 {
    font-size: 34px;
  }

  .crop-stage {
    min-height: 300px;
  }

  .pair-item {
    grid-template-columns: 1fr;
  }

  .history-modal {
    padding: 12px;
  }

  .history-modal-images {
    grid-template-columns: 1fr;
  }

  .ai-history-summary {
    grid-template-columns: 1fr;
  }

  .history-detail-button {
    justify-self: start;
  }
}
