:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #dbe2e8;
  --blue: #2563eb;
  --green: #17875d;
  --orange: #c26a16;
  --red: #c43d32;
  --teal: #0f766e;
  --shadow: 0 12px 28px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

body {
  overflow-x: hidden;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: #152033;
  color: #edf3f8;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  padding: 8px 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.35;
}

.brand span {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: #b9c6d2;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav a {
  min-height: 40px;
  padding: 10px 11px;
  border-radius: 7px;
  color: #cdd8e2;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
}

.nav a.active,
.nav a:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #60a5fa;
  flex: 0 0 auto;
}

.side-note {
  margin-top: auto;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  color: #d8e1ea;
  font-size: 12px;
  line-height: 1.6;
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 70px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.page-title h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.page-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e0ebff;
  color: var(--blue);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.content {
  padding: 24px 28px 38px;
  max-width: 1500px;
}

.hero-band {
  margin-bottom: 20px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.8fr);
  gap: 18px;
  align-items: center;
}

.hero-band h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.28;
}

.hero-band p {
  margin: 9px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.hero-cover {
  min-height: 280px;
  margin-bottom: 20px;
  padding: 24px;
  border-radius: 8px;
  background-position: center;
  background-size: cover;
  color: #ffffff;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.65fr);
  gap: 18px;
  align-items: end;
  box-shadow: var(--shadow);
}

.hero-cover-copy {
  max-width: 760px;
}

.hero-cover h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.22;
}

.hero-cover p {
  margin: 10px 0 0;
  max-width: 720px;
  color: #e6eef7;
  line-height: 1.7;
}

.mode-row,
.toolbar,
.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 16px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  color: var(--muted);
  cursor: pointer;
}

.segmented button.active {
  background: #e9f1ff;
  color: var(--blue);
  font-weight: 700;
}

.btn {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 7px;
  min-height: 36px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

.btn.active {
  background: #eaf2ff;
  border-color: var(--blue);
  color: var(--blue);
  font-weight: 700;
}

.btn.success {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
}

.btn.warn {
  background: #fff4e5;
  color: #9a4d07;
  border-color: #ffd59b;
}

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

.kpi,
.panel,
.project-card,
.sample-card,
.rule-card,
.batch-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.kpi {
  padding: 16px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.kpi em {
  display: block;
  margin-top: 8px;
  color: var(--green);
  font-style: normal;
  font-size: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.72fr);
  gap: 16px;
}

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

.panel {
  margin-bottom: 16px;
}

.panel-head {
  min-height: 50px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 16px;
}

.panel-body {
  padding: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #4b5563;
  font-size: 12px;
  white-space: nowrap;
}

.badge.blue {
  background: #e9f1ff;
  color: var(--blue);
}

.badge.green {
  background: #e7f6ef;
  color: var(--green);
}

.badge.orange {
  background: #fff4e5;
  color: var(--orange);
}

.badge.red {
  background: #fdecea;
  color: var(--red);
}

.progress {
  height: 8px;
  background: #e9edf2;
  border-radius: 999px;
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  width: var(--value, 50%);
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.project-list,
.sample-grid,
.rule-grid,
.batch-grid {
  display: grid;
  gap: 12px;
}

.project-card,
.sample-card,
.rule-card,
.batch-card {
  padding: 14px;
}

.project-card h3,
.rule-card h3,
.batch-card h3 {
  margin: 8px 0 8px;
  font-size: 16px;
}

.meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #f8fafc;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  padding: 9px 10px;
  color: var(--ink);
}

.field textarea {
  min-height: 94px;
  resize: vertical;
}

.upload-zone {
  min-height: 220px;
  border: 1px dashed #a8b5c2;
  border-radius: 8px;
  background: #f9fbfd;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 22px;
}

.upload-zone strong {
  display: block;
  font-size: 18px;
  margin-bottom: 8px;
}

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

.thumb {
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #ffffff;
}

.thumb img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}

.thumb span {
  display: block;
  padding: 8px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
}

.canvas {
  position: relative;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  overflow: hidden;
  cursor: default;
  user-select: none;
}

.canvas.drawing-enabled {
  cursor: crosshair;
}

.canvas img {
  width: 100%;
  height: 100%;
  min-height: 560px;
  object-fit: contain;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.box {
  position: absolute;
  border: 3px solid #35d399;
  background: rgba(53, 211, 153, 0.1);
  pointer-events: none;
}

.box.drawing {
  border-style: dashed;
  background: rgba(96, 165, 250, 0.12);
}

.box span {
  position: absolute;
  left: -3px;
  top: -28px;
  max-width: 220px;
  padding: 4px 7px;
  border-radius: 5px 5px 5px 0;
  background: #0b6b4c;
  color: #ffffff;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.polygon-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.polygon-layer polygon,
.polygon-layer polyline {
  fill: rgba(53, 211, 153, 0.14);
  stroke: #35d399;
  stroke-width: 0.55;
  vector-effect: non-scaling-stroke;
}

.polygon-layer polyline {
  fill: none;
  stroke-dasharray: 2 2;
}

.poly-point {
  position: absolute;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  margin-top: -5px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #35d399;
  box-shadow: 0 0 0 2px rgba(53, 211, 153, 0.32);
  pointer-events: none;
}

.sample-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.sample-strip button {
  border: 2px solid transparent;
  border-radius: 7px;
  padding: 0;
  overflow: hidden;
  background: #ffffff;
  cursor: pointer;
}

.sample-strip button.active {
  border-color: var(--blue);
}

.sample-strip img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  border: 1px solid #c8d5e2;
  border-radius: 999px;
  padding: 5px 8px;
  color: #344054;
  background: #ffffff;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17202a;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.18s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  background: #eef3f7;
}

.login-visual {
  position: relative;
  min-height: 100vh;
  background: #10243d;
  background-position: center;
  background-size: cover;
  overflow: hidden;
}

.login-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.82;
}

.login-copy {
  position: absolute;
  left: 48px;
  right: 48px;
  bottom: 44px;
  color: #ffffff;
}

.login-copy h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.25;
}

.login-copy p {
  max-width: 760px;
  line-height: 1.7;
  color: #dbe7f3;
}

.login-form {
  display: flex;
  align-items: center;
  padding: 34px;
  background: #ffffff;
}

.login-form .panel {
  width: 100%;
  box-shadow: none;
}

.empty-note {
  padding: 20px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

@media (max-width: 1120px) {
  .app-shell,
  .hero-band,
  .hero-cover,
  .grid-2,
  .workbench,
  .login-page {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .login-visual {
    min-height: 360px;
  }
}

@media (max-width: 680px) {
  .topbar,
  .content {
    padding-left: 16px;
    padding-right: 16px;
  }

  .nav,
  .kpi-grid,
  .grid-3,
  .field-grid,
  .thumb-grid,
  .sample-strip {
    grid-template-columns: 1fr;
  }

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

  .canvas,
  .canvas img {
    min-height: 360px;
  }
}
